mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 22:03:45 +00:00
Add ReadonlySessionManager type for hooks
Hooks now receive ReadonlySessionManager in contexts, which only exposes read methods. Writes must go through pi.sendMessage() or pi.appendEntry().
This commit is contained in:
parent
26e1c9d91c
commit
38d65dfe59
3 changed files with 39 additions and 9 deletions
|
|
@ -33,6 +33,7 @@ export type {
|
|||
HookMessageRenderOptions,
|
||||
HookUIContext,
|
||||
LsToolResultEvent,
|
||||
ReadonlySessionManager,
|
||||
ReadToolResultEvent,
|
||||
RegisteredCommand,
|
||||
SessionEvent,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,34 @@ import type { CompactionPreparation, CompactionResult } from "../compaction.js";
|
|||
import type { ExecOptions, ExecResult } from "../exec.js";
|
||||
import type { HookMessage } from "../messages.js";
|
||||
import type { ModelRegistry } from "../model-registry.js";
|
||||
import type { CompactionEntry, SessionManager } from "../session-manager.js";
|
||||
import type {
|
||||
CompactionEntry,
|
||||
SessionEntry,
|
||||
SessionHeader,
|
||||
SessionManager,
|
||||
SessionTreeNode,
|
||||
} from "../session-manager.js";
|
||||
|
||||
/**
|
||||
* Read-only view of SessionManager for hooks.
|
||||
* Hooks should use pi.sendMessage() and pi.appendEntry() for writes.
|
||||
*/
|
||||
export type ReadonlySessionManager = Pick<
|
||||
SessionManager,
|
||||
| "getCwd"
|
||||
| "getSessionDir"
|
||||
| "getSessionId"
|
||||
| "getSessionFile"
|
||||
| "getLeafUuid"
|
||||
| "getLeafEntry"
|
||||
| "getEntry"
|
||||
| "getLabel"
|
||||
| "getPath"
|
||||
| "getHeader"
|
||||
| "getEntries"
|
||||
| "getTree"
|
||||
>;
|
||||
|
||||
import type { EditToolDetails } from "../tools/edit.js";
|
||||
import type {
|
||||
BashToolDetails,
|
||||
|
|
@ -76,8 +103,8 @@ export interface HookEventContext {
|
|||
hasUI: boolean;
|
||||
/** Current working directory */
|
||||
cwd: string;
|
||||
/** Session manager instance - use for entries, session file, etc. */
|
||||
sessionManager: SessionManager;
|
||||
/** Session manager (read-only) - use pi.sendMessage()/pi.appendEntry() for writes */
|
||||
sessionManager: ReadonlySessionManager;
|
||||
/** Model registry - use for API key resolution and model retrieval */
|
||||
modelRegistry: ModelRegistry;
|
||||
}
|
||||
|
|
@ -430,8 +457,8 @@ export interface HookCommandContext {
|
|||
hasUI: boolean;
|
||||
/** Current working directory */
|
||||
cwd: string;
|
||||
/** Session manager for reading/writing session entries */
|
||||
sessionManager: SessionManager;
|
||||
/** Session manager (read-only) - use pi.sendMessage()/pi.appendEntry() for writes */
|
||||
sessionManager: ReadonlySessionManager;
|
||||
/** Model registry for API keys */
|
||||
modelRegistry: ModelRegistry;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue