@kolisachint/hoocode-agent-core 0.4.105 → 0.4.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/harness/agent-harness.d.ts +1 -0
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +1 -1
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +10 -2
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +1 -4
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +5 -0
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +22 -2
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/compaction/utils.d.ts.map +1 -1
- package/dist/harness/compaction/utils.js +8 -5
- package/dist/harness/compaction/utils.js.map +1 -1
- package/dist/harness/messages.d.ts +73 -1
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js +119 -0
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/session/session.d.ts +1 -1
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +3 -2
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/types.d.ts +7 -42
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/output-compression.d.ts +53 -0
- package/dist/harness/utils/output-compression.d.ts.map +1 -0
- package/dist/harness/utils/output-compression.js +392 -0
- package/dist/harness/utils/output-compression.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/harness/session/session.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BA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,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAC/B,OAAO,IAAI,CAAC,gBAAgB,CAAC;YAC5B,IAAI,EAAE,gBAAgB;YACtB,EAAE,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YACtC,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,MAAM,EAAE,OAAO,IAAI,MAAM;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SACG,CAAC,CAAC;IAAA,CAChC;CACD","sourcesContent":["import type { ImageContent, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { AgentMessage } from \"../../types.js\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage, createCustomMessage } from \"../messages.js\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tLabelEntry,\n\tMessageEntry,\n\tModelChangeEntry,\n\tSessionContext,\n\tSessionInfoEntry,\n\tSessionMetadata,\n\tSessionStorage,\n\tSessionTreeEntry,\n\tThinkingLevelChangeEntry,\n} from \"../types.js\";\n\nexport function buildSessionContext(pathEntries: SessionTreeEntry[]): SessionContext {\n\tlet thinkingLevel = \"off\";\n\tlet model: { provider: string; modelId: string } | null = null;\n\tlet compaction: CompactionEntry | null = null;\n\n\tfor (const entry of pathEntries) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t} else if (entry.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t}\n\t}\n\n\tconst messages: AgentMessage[] = [];\n\tconst appendMessage = (entry: SessionTreeEntry) => {\n\t\tif (entry.type === \"message\") {\n\t\t\tmessages.push(entry.message as AgentMessage);\n\t\t} else if (entry.type === \"custom_message\") {\n\t\t\tmessages.push(\n\t\t\t\tcreateCustomMessage(\n\t\t\t\t\tentry.customType,\n\t\t\t\t\tentry.content as string | (TextContent | ImageContent)[],\n\t\t\t\t\tentry.display,\n\t\t\t\t\tentry.details,\n\t\t\t\t\tentry.timestamp,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (entry.type === \"branch_summary\" && entry.summary) {\n\t\t\tmessages.push(createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp));\n\t\t}\n\t};\n\n\tif (compaction) {\n\t\tmessages.push(createCompactionSummaryMessage(compaction.summary, compaction.tokensBefore, compaction.timestamp));\n\t\tconst compactionIdx = pathEntries.findIndex((e) => e.type === \"compaction\" && e.id === compaction.id);\n\t\tlet foundFirstKept = false;\n\t\tfor (let i = 0; i < compactionIdx; i++) {\n\t\t\tconst entry = pathEntries[i]!;\n\t\t\tif (entry.id === compaction.firstKeptEntryId) foundFirstKept = true;\n\t\t\tif (foundFirstKept) appendMessage(entry);\n\t\t}\n\t\tfor (let i = compactionIdx + 1; i < pathEntries.length; i++) {\n\t\t\tappendMessage(pathEntries[i]!);\n\t\t}\n\t} else {\n\t\tfor (const entry of pathEntries) {\n\t\t\tappendMessage(entry);\n\t\t}\n\t}\n\n\treturn { messages, thinkingLevel, model };\n}\n\nexport class Session<TMetadata extends SessionMetadata = SessionMetadata> {\n\tprivate storage: SessionStorage<TMetadata>;\n\n\tconstructor(storage: SessionStorage<TMetadata>) {\n\t\tthis.storage = storage;\n\t}\n\n\tgetMetadata(): Promise<TMetadata> {\n\t\treturn this.storage.getMetadata();\n\t}\n\n\tgetStorage(): SessionStorage<TMetadata> {\n\t\treturn this.storage;\n\t}\n\n\tgetLeafId(): Promise<string | null> {\n\t\treturn this.storage.getLeafId();\n\t}\n\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined> {\n\t\treturn this.storage.getEntry(id);\n\t}\n\n\tgetEntries(): Promise<SessionTreeEntry[]> {\n\t\treturn this.storage.getEntries();\n\t}\n\n\tasync getBranch(fromId?: string): Promise<SessionTreeEntry[]> {\n\t\tconst leafId = fromId ?? (await this.storage.getLeafId());\n\t\treturn this.storage.getPathToRoot(leafId);\n\t}\n\n\tasync buildContext(): Promise<SessionContext> {\n\t\treturn buildSessionContext(await this.getBranch());\n\t}\n\n\tgetLabel(id: string): Promise<string | undefined> {\n\t\treturn this.storage.getLabel(id);\n\t}\n\n\tasync getSessionName(): Promise<string | undefined> {\n\t\tconst entries = await this.storage.findEntries(\"session_info\");\n\t\treturn entries[entries.length - 1]?.name?.trim() || undefined;\n\t}\n\n\tprivate async appendTypedEntry<TEntry extends SessionTreeEntry>(entry: TEntry): Promise<string> {\n\t\tawait this.storage.appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\tasync appendMessage(message: AgentMessage): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"message\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tmessage,\n\t\t} satisfies MessageEntry);\n\t}\n\n\tasync appendThinkingLevelChange(thinkingLevel: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tthinkingLevel,\n\t\t} satisfies ThinkingLevelChangeEntry);\n\t}\n\n\tasync appendModelChange(provider: string, modelId: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"model_change\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tprovider,\n\t\t\tmodelId,\n\t\t} satisfies ModelChangeEntry);\n\t}\n\n\tasync appendCompaction<T = unknown>(\n\t\tsummary: string,\n\t\tfirstKeptEntryId: string,\n\t\ttokensBefore: number,\n\t\tdetails?: T,\n\t\tfromHook?: boolean,\n\t): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"compaction\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tsummary,\n\t\t\tfirstKeptEntryId,\n\t\t\ttokensBefore,\n\t\t\tdetails,\n\t\t\tfromHook,\n\t\t} satisfies CompactionEntry<T>);\n\t}\n\n\tasync appendCustomEntry(customType: string, data?: unknown): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"custom\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcustomType,\n\t\t\tdata,\n\t\t} satisfies CustomEntry);\n\t}\n\n\tasync appendCustomMessageEntry<T = unknown>(\n\t\tcustomType: string,\n\t\tcontent: string | (TextContent | ImageContent)[],\n\t\tdisplay: boolean,\n\t\tdetails?: T,\n\t): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"custom_message\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcustomType,\n\t\t\tcontent,\n\t\t\tdisplay,\n\t\t\tdetails,\n\t\t} satisfies CustomMessageEntry<T>);\n\t}\n\n\tasync appendLabel(targetId: string, label: string | undefined): Promise<string> {\n\t\tif (!(await this.storage.getEntry(targetId))) {\n\t\t\tthrow new Error(`Entry ${targetId} not found`);\n\t\t}\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"label\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\ttargetId,\n\t\t\tlabel,\n\t\t} satisfies LabelEntry);\n\t}\n\n\tasync appendSessionName(name: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"session_info\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tname: name.trim(),\n\t\t} satisfies SessionInfoEntry);\n\t}\n\n\tasync moveTo(\n\t\tentryId: string | null,\n\t\tsummary?: { summary: string; details?: unknown; fromHook?: boolean },\n\t): Promise<string | undefined> {\n\t\tif (entryId !== null && !(await this.storage.getEntry(entryId))) {\n\t\t\tthrow new Error(`Entry ${entryId} not found`);\n\t\t}\n\t\tawait this.storage.setLeafId(entryId);\n\t\tif (!summary) return undefined;\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: entryId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tfromId: entryId ?? \"root\",\n\t\t\tsummary: summary.summary,\n\t\t\tdetails: summary.details,\n\t\t\tfromHook: summary.fromHook,\n\t\t} satisfies BranchSummaryEntry);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/harness/session/session.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAiBjH,MAAM,UAAU,mBAAmB,CAAC,WAA+B,EAAkB;IACpF,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,IAAI,KAAK,GAAiD,IAAI,CAAC;IAC/D,IAAI,UAAU,GAA2B,IAAI,CAAC;IAE9C,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;QACjC,IAAI,KAAK,CAAC,IAAI,KAAK,uBAAuB,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AAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,MAAM,EAAE,OAAO,IAAI,MAAM;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SACG,CAAC,CAAC;IAAA,CAChC;CACD","sourcesContent":["import type { ImageContent, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { AgentMessage } from \"../../types.js\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage, createCustomMessage } from \"../messages.js\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tLabelEntry,\n\tMessageEntry,\n\tModelChangeEntry,\n\tSessionContext,\n\tSessionInfoEntry,\n\tSessionMetadata,\n\tSessionStorage,\n\tSessionTreeEntry,\n\tThinkingLevelChangeEntry,\n} from \"../types.js\";\n\nexport function buildSessionContext(pathEntries: SessionTreeEntry[]): SessionContext {\n\tlet thinkingLevel = \"off\";\n\tlet model: { provider: string; modelId: string } | null = null;\n\tlet compaction: CompactionEntry | null = null;\n\n\tfor (const entry of pathEntries) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t} else if (entry.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t}\n\t}\n\n\tconst messages: AgentMessage[] = [];\n\tconst appendMessage = (entry: SessionTreeEntry) => {\n\t\tif (entry.type === \"message\") {\n\t\t\tmessages.push(entry.message as AgentMessage);\n\t\t} else if (entry.type === \"custom_message\") {\n\t\t\tmessages.push(\n\t\t\t\tcreateCustomMessage(\n\t\t\t\t\tentry.customType,\n\t\t\t\t\tentry.content as string | (TextContent | ImageContent)[],\n\t\t\t\t\tentry.display,\n\t\t\t\t\tentry.details,\n\t\t\t\t\tentry.timestamp,\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (entry.type === \"branch_summary\" && entry.summary) {\n\t\t\tmessages.push(createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp));\n\t\t}\n\t};\n\n\tif (compaction) {\n\t\tmessages.push(\n\t\t\tcreateCompactionSummaryMessage(\n\t\t\t\tcompaction.summary,\n\t\t\t\tcompaction.tokensBefore,\n\t\t\t\tcompaction.timestamp,\n\t\t\t\tcompaction.tokensAfter,\n\t\t\t),\n\t\t);\n\t\tconst compactionIdx = pathEntries.findIndex((e) => e.type === \"compaction\" && e.id === compaction.id);\n\t\tlet foundFirstKept = false;\n\t\tfor (let i = 0; i < compactionIdx; i++) {\n\t\t\tconst entry = pathEntries[i]!;\n\t\t\tif (entry.id === compaction.firstKeptEntryId) foundFirstKept = true;\n\t\t\tif (foundFirstKept) appendMessage(entry);\n\t\t}\n\t\tfor (let i = compactionIdx + 1; i < pathEntries.length; i++) {\n\t\t\tappendMessage(pathEntries[i]!);\n\t\t}\n\t} else {\n\t\tfor (const entry of pathEntries) {\n\t\t\tappendMessage(entry);\n\t\t}\n\t}\n\n\treturn { messages, thinkingLevel, model };\n}\n\nexport class Session<TMetadata extends SessionMetadata = SessionMetadata> {\n\tprivate storage: SessionStorage<TMetadata>;\n\n\tconstructor(storage: SessionStorage<TMetadata>) {\n\t\tthis.storage = storage;\n\t}\n\n\tgetMetadata(): Promise<TMetadata> {\n\t\treturn this.storage.getMetadata();\n\t}\n\n\tgetStorage(): SessionStorage<TMetadata> {\n\t\treturn this.storage;\n\t}\n\n\tgetLeafId(): Promise<string | null> {\n\t\treturn this.storage.getLeafId();\n\t}\n\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined> {\n\t\treturn this.storage.getEntry(id);\n\t}\n\n\tgetEntries(): Promise<SessionTreeEntry[]> {\n\t\treturn this.storage.getEntries();\n\t}\n\n\tasync getBranch(fromId?: string): Promise<SessionTreeEntry[]> {\n\t\tconst leafId = fromId ?? (await this.storage.getLeafId());\n\t\treturn this.storage.getPathToRoot(leafId);\n\t}\n\n\tasync buildContext(): Promise<SessionContext> {\n\t\treturn buildSessionContext(await this.getBranch());\n\t}\n\n\tgetLabel(id: string): Promise<string | undefined> {\n\t\treturn this.storage.getLabel(id);\n\t}\n\n\tasync getSessionName(): Promise<string | undefined> {\n\t\tconst entries = await this.storage.findEntries(\"session_info\");\n\t\treturn entries[entries.length - 1]?.name?.trim() || undefined;\n\t}\n\n\tprivate async appendTypedEntry<TEntry extends SessionTreeEntry>(entry: TEntry): Promise<string> {\n\t\tawait this.storage.appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\tasync appendMessage(message: AgentMessage): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"message\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tmessage,\n\t\t} satisfies MessageEntry);\n\t}\n\n\tasync appendThinkingLevelChange(thinkingLevel: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tthinkingLevel,\n\t\t} satisfies ThinkingLevelChangeEntry);\n\t}\n\n\tasync appendModelChange(provider: string, modelId: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"model_change\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tprovider,\n\t\t\tmodelId,\n\t\t} satisfies ModelChangeEntry);\n\t}\n\n\tasync appendCompaction<T = unknown>(\n\t\tsummary: string,\n\t\tfirstKeptEntryId: string,\n\t\ttokensBefore: number,\n\t\tdetails?: T,\n\t\tfromHook?: boolean,\n\t\ttokensAfter?: number,\n\t): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"compaction\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tsummary,\n\t\t\tfirstKeptEntryId,\n\t\t\ttokensBefore,\n\t\t\ttokensAfter,\n\t\t\tdetails,\n\t\t\tfromHook,\n\t\t} satisfies CompactionEntry<T>);\n\t}\n\n\tasync appendCustomEntry(customType: string, data?: unknown): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"custom\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcustomType,\n\t\t\tdata,\n\t\t} satisfies CustomEntry);\n\t}\n\n\tasync appendCustomMessageEntry<T = unknown>(\n\t\tcustomType: string,\n\t\tcontent: string | (TextContent | ImageContent)[],\n\t\tdisplay: boolean,\n\t\tdetails?: T,\n\t): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"custom_message\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcustomType,\n\t\t\tcontent,\n\t\t\tdisplay,\n\t\t\tdetails,\n\t\t} satisfies CustomMessageEntry<T>);\n\t}\n\n\tasync appendLabel(targetId: string, label: string | undefined): Promise<string> {\n\t\tif (!(await this.storage.getEntry(targetId))) {\n\t\t\tthrow new Error(`Entry ${targetId} not found`);\n\t\t}\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"label\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\ttargetId,\n\t\t\tlabel,\n\t\t} satisfies LabelEntry);\n\t}\n\n\tasync appendSessionName(name: string): Promise<string> {\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"session_info\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: await this.storage.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tname: name.trim(),\n\t\t} satisfies SessionInfoEntry);\n\t}\n\n\tasync moveTo(\n\t\tentryId: string | null,\n\t\tsummary?: { summary: string; details?: unknown; fromHook?: boolean },\n\t): Promise<string | undefined> {\n\t\tif (entryId !== null && !(await this.storage.getEntry(entryId))) {\n\t\t\tthrow new Error(`Entry ${entryId} not found`);\n\t\t}\n\t\tawait this.storage.setLeafId(entryId);\n\t\tif (!summary) return undefined;\n\t\treturn this.appendTypedEntry({\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: await this.storage.createEntryId(),\n\t\t\tparentId: entryId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tfromId: entryId ?? \"root\",\n\t\t\tsummary: summary.summary,\n\t\t\tdetails: summary.details,\n\t\t\tfromHook: summary.fromHook,\n\t\t} satisfies BranchSummaryEntry);\n\t}\n}\n"]}
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ImageContent, Model, TextContent } from "@kolisachint/hoocode-ai";
|
|
2
2
|
import type { QueueMode } from "../agent.js";
|
|
3
3
|
import type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from "../index.js";
|
|
4
|
+
import type { CompactionPreparation, CompactionResult } from "./compaction/compaction.js";
|
|
4
5
|
import type { Session } from "./session/session.js";
|
|
5
6
|
/**
|
|
6
7
|
* Skill loaded from a `SKILL.md` file or provided by an application.
|
|
@@ -154,7 +155,11 @@ export interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {
|
|
|
154
155
|
summary: string;
|
|
155
156
|
firstKeptEntryId: string;
|
|
156
157
|
tokensBefore: number;
|
|
158
|
+
/** Estimated context tokens after compaction; absent on entries written before this field existed. */
|
|
159
|
+
tokensAfter?: number;
|
|
160
|
+
/** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
|
|
157
161
|
details?: T;
|
|
162
|
+
/** True if generated by an extension, undefined/false if harness-generated (backward compatible) */
|
|
158
163
|
fromHook?: boolean;
|
|
159
164
|
}
|
|
160
165
|
export interface BranchSummaryEntry<T = unknown> extends SessionTreeEntryBase {
|
|
@@ -409,37 +414,13 @@ export interface AbortResult {
|
|
|
409
414
|
clearedSteer: AgentMessage[];
|
|
410
415
|
clearedFollowUp: AgentMessage[];
|
|
411
416
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
firstKeptEntryId: string;
|
|
415
|
-
tokensBefore: number;
|
|
416
|
-
details?: unknown;
|
|
417
|
-
}
|
|
417
|
+
/** Alias kept for the harness event API; the canonical type lives in compaction. */
|
|
418
|
+
export type CompactResult = CompactionResult;
|
|
418
419
|
export interface NavigateTreeResult {
|
|
419
420
|
cancelled: boolean;
|
|
420
421
|
editorText?: string;
|
|
421
422
|
summaryEntry?: BranchSummaryEntry;
|
|
422
423
|
}
|
|
423
|
-
export interface CompactionSettings {
|
|
424
|
-
enabled: boolean;
|
|
425
|
-
reserveTokens: number;
|
|
426
|
-
keepRecentTokens: number;
|
|
427
|
-
}
|
|
428
|
-
export interface CompactionPreparation {
|
|
429
|
-
firstKeptEntryId: string;
|
|
430
|
-
messagesToSummarize: AgentMessage[];
|
|
431
|
-
turnPrefixMessages: AgentMessage[];
|
|
432
|
-
isSplitTurn: boolean;
|
|
433
|
-
tokensBefore: number;
|
|
434
|
-
previousSummary?: string;
|
|
435
|
-
fileOps: FileOperations;
|
|
436
|
-
settings: CompactionSettings;
|
|
437
|
-
}
|
|
438
|
-
export interface FileOperations {
|
|
439
|
-
read: Set<string>;
|
|
440
|
-
written: Set<string>;
|
|
441
|
-
edited: Set<string>;
|
|
442
|
-
}
|
|
443
424
|
export interface TreePreparation {
|
|
444
425
|
targetId: string;
|
|
445
426
|
oldLeafId: string | null;
|
|
@@ -450,22 +431,6 @@ export interface TreePreparation {
|
|
|
450
431
|
replaceInstructions?: boolean;
|
|
451
432
|
label?: string;
|
|
452
433
|
}
|
|
453
|
-
export interface GenerateBranchSummaryOptions {
|
|
454
|
-
model: Model<any>;
|
|
455
|
-
apiKey: string;
|
|
456
|
-
headers?: Record<string, string>;
|
|
457
|
-
signal: AbortSignal;
|
|
458
|
-
customInstructions?: string;
|
|
459
|
-
replaceInstructions?: boolean;
|
|
460
|
-
reserveTokens?: number;
|
|
461
|
-
}
|
|
462
|
-
export interface BranchSummaryResult {
|
|
463
|
-
summary?: string;
|
|
464
|
-
readFiles?: string[];
|
|
465
|
-
modifiedFiles?: string[];
|
|
466
|
-
aborted?: boolean;
|
|
467
|
-
error?: string;
|
|
468
|
-
}
|
|
469
434
|
export interface AgentHarnessOptions<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate, TTool extends AgentTool = AgentTool> {
|
|
470
435
|
env: ExecutionEnv;
|
|
471
436
|
session: Session;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACrB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,QAAQ,EAAE,MAAM,CAAC;IACjB,8GAA8G;IAC9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D,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,mBAAmB,CAAC,EAAE,CACrB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KACb,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAC/E,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["import type { ImageContent, Model, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { QueueMode } from \"../agent.js\";\nimport type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from \"../index.js\";\nimport type { Session } from \"./session/session.js\";\n\n/**\n * Skill loaded from a `SKILL.md` file or provided by an application.\n *\n * `name`, `description`, and `filePath` are inserted into the system prompt in an XML-formatted block as suggested by agentskills.io.\n * Use {@link formatSkillsForSystemPrompt} to generate the spec-compatible system prompt block.\n */\nexport interface Skill {\n\t/** Stable skill name used for lookup and model-visible listings. */\n\tname: string;\n\t/** Short model-visible description of when to use the skill. */\n\tdescription: string;\n\t/** Full skill instructions. */\n\tcontent: string;\n\t/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */\n\tfilePath: string;\n\t/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */\n\tdisableModelInvocation?: boolean;\n}\n\n/** Prompt template that can be formatted into a prompt for explicit invocation. */\nexport interface PromptTemplate {\n\t/** Stable template name used for lookup or application command routing. */\n\tname: string;\n\t/** Optional description for command lists or autocomplete. */\n\tdescription?: string;\n\t/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */\n\tcontent: string;\n}\n\n/** Resources made available to explicit invocation methods and system-prompt callbacks. */\nexport interface AgentHarnessResources<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\t/** Prompt templates available for explicit invocation. */\n\tpromptTemplates?: TPromptTemplate[];\n\t/** Skills available to the model and explicit skill invocation. */\n\tskills?: TSkill[];\n}\n\n/** Kind of filesystem object as addressed by an {@link ExecutionEnv}. Symlinks are not followed automatically. */\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\n/** Stable, backend-independent file error codes thrown by {@link ExecutionEnv} file operations. */\nexport type FileErrorCode =\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\n/** Error thrown by {@link ExecutionEnv} file operations. */\nexport class FileError extends Error {\n\tconstructor(\n\t\t/** Backend-independent error code. */\n\t\tpublic code: FileErrorCode,\n\t\tmessage: string,\n\t\t/** Absolute addressed path associated with the failure, when available. */\n\t\tpublic path?: string,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"FileError\";\n\t}\n}\n\n/** Metadata for one filesystem object in an {@link ExecutionEnv}. */\nexport interface FileInfo {\n\t/** Basename of {@link path}. */\n\tname: string;\n\t/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */\n\tpath: string;\n\t/** Object kind. Symlink targets are not followed; use {@link ExecutionEnv.resolvePath} explicitly. */\n\tkind: FileKind;\n\t/** Size in bytes for the addressed filesystem object. */\n\tsize: number;\n\t/** Modification time as milliseconds since Unix epoch. */\n\tmtimeMs: number;\n}\n\n/** Options for {@link ExecutionEnv.exec}. */\nexport interface ExecutionEnvExecOptions {\n\t/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. */\n\tcwd?: string;\n\t/** Additional environment variables for the command. Values override the environment defaults. */\n\tenv?: Record<string, string>;\n\t/** Timeout in seconds. Implementations should reject when the command exceeds this duration. */\n\ttimeout?: number;\n\t/** Abort signal used to terminate the command. */\n\tsignal?: AbortSignal;\n\t/** Called with stdout chunks as they are produced. */\n\tonStdout?: (chunk: string) => void;\n\t/** Called with stderr chunks as they are produced. */\n\tonStderr?: (chunk: string) => void;\n}\n\n/**\n * Filesystem and process execution environment used by the harness.\n *\n * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by this interface are absolute\n * addressed paths in the environment, but are not canonicalized through symlinks unless returned by {@link resolvePath}.\n *\n * File operations throw {@link FileError} for expected filesystem failures such as missing paths or permission errors.\n */\nexport interface ExecutionEnv {\n\t/** Current working directory for relative paths and command execution. */\n\tcwd: string;\n\n\t/** Execute a shell command in {@link cwd} unless `options.cwd` is provided. */\n\texec(\n\t\tcommand: string,\n\t\toptions?: ExecutionEnvExecOptions,\n\t): Promise<{ stdout: string; stderr: string; exitCode: number }>;\n\n\t/** Read a UTF-8 text file. Throws {@link FileError}. */\n\treadTextFile(path: string): Promise<string>;\n\t/** Read a binary file. Throws {@link FileError}. */\n\treadBinaryFile(path: string): Promise<Uint8Array>;\n\t/** Create or overwrite a file, creating parent directories when supported. Throws {@link FileError}. */\n\twriteFile(path: string, content: string | Uint8Array): Promise<void>;\n\t/** Return metadata for the addressed path without following symlinks. Throws {@link FileError}. */\n\tfileInfo(path: string): Promise<FileInfo>;\n\t/** List direct children of a directory without following symlinks. Throws {@link FileError}. */\n\tlistDir(path: string): Promise<FileInfo[]>;\n\t/** Return the canonical path for a path, following symlinks. Throws {@link FileError}. */\n\trealPath(path: string): Promise<string>;\n\t/** Return false for missing paths. Other errors, such as permission failures, may throw {@link FileError}. */\n\texists(path: string): Promise<boolean>;\n\t/** Create a directory. */\n\tcreateDir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\t/** Remove a file or directory. */\n\tremove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;\n\t/** Create a temporary directory and return its absolute path. */\n\tcreateTempDir(prefix?: string): Promise<string>;\n\t/** Create a temporary file and return its absolute path. */\n\tcreateTempFile(options?: { prefix?: string; suffix?: string }): Promise<string>;\n\n\t/** Release resources owned by the environment. */\n\tcleanup(): Promise<void>;\n}\n\nexport interface SessionTreeEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface MessageEntry extends SessionTreeEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface CustomEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n}\n\nexport interface LabelEntry extends SessionTreeEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\nexport interface SessionInfoEntry extends SessionTreeEntryBase {\n\ttype: \"session_info\"; // legacy name, kept for backwards compatibility\n\tname?: string;\n}\n\nexport type SessionTreeEntry =\n\t| MessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| CompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry;\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionMetadata {\n\tid: string;\n\tcreatedAt: string;\n}\n\nexport interface JsonlSessionMetadata extends SessionMetadata {\n\tcwd: string;\n\tpath: string;\n\tparentSessionPath?: string;\n}\n\nexport interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {\n\tgetMetadata(): Promise<TMetadata>;\n\tgetLeafId(): Promise<string | null>;\n\tsetLeafId(leafId: string | null): Promise<void>;\n\tcreateEntryId(): Promise<string>;\n\tappendEntry(entry: SessionTreeEntry): Promise<void>;\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined>;\n\tfindEntries<TType extends SessionTreeEntry[\"type\"]>(\n\t\ttype: TType,\n\t): Promise<Array<Extract<SessionTreeEntry, { type: TType }>>>;\n\tgetLabel(id: string): Promise<string | undefined>;\n\tgetPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;\n\tgetEntries(): Promise<SessionTreeEntry[]>;\n}\n\nexport type { Session } from \"./session/session.js\";\n\nexport interface SessionCreateOptions {\n\tid?: string;\n}\n\nexport interface SessionForkOptions {\n\tentryId?: string;\n\tposition?: \"before\" | \"at\";\n\tid?: string;\n}\n\nexport interface SessionRepo<\n\tTMetadata extends SessionMetadata = SessionMetadata,\n\tTCreateOptions extends SessionCreateOptions = SessionCreateOptions,\n\tTListOptions = void,\n> {\n\tcreate(options: TCreateOptions): Promise<Session<TMetadata>>;\n\topen(metadata: TMetadata): Promise<Session<TMetadata>>;\n\tlist(options?: TListOptions): Promise<TMetadata[]>;\n\tdelete(metadata: TMetadata): Promise<void>;\n\tfork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;\n}\n\nexport interface JsonlSessionCreateOptions extends SessionCreateOptions {\n\tcwd: string;\n\tparentSessionPath?: string;\n}\n\nexport interface JsonlSessionListOptions {\n\tcwd?: string;\n}\n\nexport interface JsonlSessionRepoApi\n\textends SessionRepo<JsonlSessionMetadata, JsonlSessionCreateOptions, JsonlSessionListOptions> {}\n\nexport type AgentHarnessPhase = \"idle\" | \"turn\" | \"compaction\" | \"branch_summary\" | \"retry\";\n\nexport type PendingSessionWrite = SessionTreeEntry extends infer TEntry\n\t? TEntry extends SessionTreeEntry\n\t\t? Omit<TEntry, \"id\" | \"parentId\" | \"timestamp\">\n\t\t: never\n\t: never;\n\nexport interface AgentHarnessTurnState<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tmessages: AgentMessage[];\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: TTool[];\n\tactiveTools: TTool[];\n}\n\nexport interface QueueUpdateEvent {\n\ttype: \"queue_update\";\n\tsteer: AgentMessage[];\n\tfollowUp: AgentMessage[];\n\tnextTurn: AgentMessage[];\n}\n\nexport interface SavePointEvent {\n\ttype: \"save_point\";\n\thadPendingMutations: boolean;\n}\n\nexport interface AbortEvent {\n\ttype: \"abort\";\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface SettledEvent {\n\ttype: \"settled\";\n\tnextTurnCount: number;\n}\n\nexport interface BeforeAgentStartEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"before_agent_start\";\n\tprompt: string;\n\timages?: ImageContent[];\n\tsystemPrompt: string;\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport interface ContextEvent {\n\ttype: \"context\";\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestEvent {\n\ttype: \"before_provider_request\";\n\tpayload: unknown;\n}\n\nexport interface AfterProviderResponseEvent {\n\ttype: \"after_provider_response\";\n\tstatus: number;\n\theaders: Record<string, string>;\n}\n\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tcontent: Array<TextContent | ImageContent>;\n\tdetails: unknown;\n\tisError: boolean;\n}\n\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\tpreparation: CompactionPreparation;\n\tbranchEntries: SessionTreeEntry[];\n\tcustomInstructions?: string;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\tfromHook: boolean;\n}\n\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\tpreparation: TreePreparation;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\tnewLeafId: string | null;\n\toldLeafId: string | null;\n\tsummaryEntry?: BranchSummaryEntry;\n\tfromHook?: boolean;\n}\n\nexport interface ModelSelectEvent {\n\ttype: \"model_select\";\n\tmodel: Model<any>;\n\tpreviousModel: Model<any> | undefined;\n\tsource: \"set\" | \"restore\";\n}\n\nexport interface ThinkingLevelSelectEvent {\n\ttype: \"thinking_level_select\";\n\tlevel: ThinkingLevel;\n\tpreviousLevel: ThinkingLevel;\n}\n\nexport interface ResourcesUpdateEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"resources_update\";\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tpreviousResources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport type AgentHarnessOwnEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> =\n\t| QueueUpdateEvent\n\t| SavePointEvent\n\t| AbortEvent\n\t| SettledEvent\n\t| BeforeAgentStartEvent<TSkill, TPromptTemplate>\n\t| ContextEvent\n\t| BeforeProviderRequestEvent\n\t| AfterProviderResponseEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent\n\t| ModelSelectEvent\n\t| ThinkingLevelSelectEvent\n\t| ResourcesUpdateEvent<TSkill, TPromptTemplate>;\n\nexport type AgentHarnessEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> =\n\t| AgentEvent\n\t| AgentHarnessOwnEvent<TSkill, TPromptTemplate>;\n\nexport interface BeforeAgentStartResult {\n\tmessages?: AgentMessage[];\n\tsystemPrompt?: string;\n}\n\nexport interface ContextResult {\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestResult {\n\tpayload: unknown;\n}\n\nexport interface ToolCallResult {\n\tblock?: boolean;\n\treason?: string;\n}\n\nexport interface ToolResultPatch {\n\tcontent?: Array<TextContent | ImageContent>;\n\tdetails?: unknown;\n\tisError?: boolean;\n\tterminate?: boolean;\n}\n\nexport interface SessionBeforeCompactResult {\n\tcancel?: boolean;\n\tcompaction?: CompactResult;\n}\n\nexport interface SessionBeforeTreeResult {\n\tcancel?: boolean;\n\tsummary?: { summary: string; details?: unknown };\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport type AgentHarnessEventResultMap = {\n\tbefore_agent_start: BeforeAgentStartResult | undefined;\n\tcontext: ContextResult | undefined;\n\tbefore_provider_request: BeforeProviderRequestResult | undefined;\n\tafter_provider_response: undefined;\n\ttool_call: ToolCallResult | undefined;\n\ttool_result: ToolResultPatch | undefined;\n\tsession_before_compact: SessionBeforeCompactResult | undefined;\n\tsession_compact: undefined;\n\tsession_before_tree: SessionBeforeTreeResult | undefined;\n\tsession_tree: undefined;\n\tmodel_select: undefined;\n\tthinking_level_select: undefined;\n\tresources_update: undefined;\n\tqueue_update: undefined;\n\tsave_point: undefined;\n\tabort: undefined;\n\tsettled: undefined;\n};\n\nexport interface AgentHarnessPromptOptions {\n\timages?: ImageContent[];\n}\n\nexport interface AbortResult {\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface CompactResult {\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: unknown;\n}\n\nexport interface NavigateTreeResult {\n\tcancelled: boolean;\n\teditorText?: string;\n\tsummaryEntry?: BranchSummaryEntry;\n}\n\nexport interface CompactionSettings {\n\tenabled: boolean;\n\treserveTokens: number;\n\tkeepRecentTokens: number;\n}\n\nexport interface CompactionPreparation {\n\tfirstKeptEntryId: string;\n\tmessagesToSummarize: AgentMessage[];\n\tturnPrefixMessages: AgentMessage[];\n\tisSplitTurn: boolean;\n\ttokensBefore: number;\n\tpreviousSummary?: string;\n\tfileOps: FileOperations;\n\tsettings: CompactionSettings;\n}\n\nexport interface FileOperations {\n\tread: Set<string>;\n\twritten: Set<string>;\n\tedited: Set<string>;\n}\n\nexport interface TreePreparation {\n\ttargetId: string;\n\toldLeafId: string | null;\n\tcommonAncestorId: string | null;\n\tentriesToSummarize: SessionTreeEntry[];\n\tuserWantsSummary: boolean;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport interface GenerateBranchSummaryOptions {\n\tmodel: Model<any>;\n\tapiKey: string;\n\theaders?: Record<string, string>;\n\tsignal: AbortSignal;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\treserveTokens?: number;\n}\n\nexport interface BranchSummaryResult {\n\tsummary?: string;\n\treadFiles?: string[];\n\tmodifiedFiles?: string[];\n\taborted?: boolean;\n\terror?: string;\n}\n\nexport interface AgentHarnessOptions<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tenv: ExecutionEnv;\n\tsession: Session;\n\ttools?: TTool[];\n\t/**\n\t * Concrete resources available to explicit invocation methods and system-prompt callbacks.\n\t * Applications own loading/reloading resources and should call `setResources()` with new values.\n\t */\n\tresources?: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt?:\n\t\t| string\n\t\t| ((context: {\n\t\t\t\tenv: ExecutionEnv;\n\t\t\t\tsession: Session;\n\t\t\t\tmodel: Model<any>;\n\t\t\t\tthinkingLevel: ThinkingLevel;\n\t\t\t\tactiveTools: TTool[];\n\t\t\t\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\t\t }) => string | Promise<string>);\n\tgetApiKeyAndHeaders?: (\n\t\tmodel: Model<any>,\n\t) => Promise<{ apiKey: string; headers?: Record<string, string> } | undefined>;\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tactiveToolNames?: string[];\n\tsteeringMode?: QueueMode;\n\tfollowUpMode?: QueueMode;\n}\n\nexport type { AgentHarness } from \"./agent-harness.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACrB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,WAAW,EAAE,MAAM,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CAAC;QACjB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,aAAa,EAAE,aAAa,CAAC;QAC7B,WAAW,EAAE,KAAK,EAAE,CAAC;QACrB,SAAS,EAAE,qBAAqB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KACzD,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,mBAAmB,CAAC,EAAE,CACrB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KACb,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAC/E,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["import type { ImageContent, Model, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { QueueMode } from \"../agent.js\";\nimport type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from \"../index.js\";\nimport type { CompactionPreparation, CompactionResult } from \"./compaction/compaction.js\";\nimport type { Session } from \"./session/session.js\";\n\n/**\n * Skill loaded from a `SKILL.md` file or provided by an application.\n *\n * `name`, `description`, and `filePath` are inserted into the system prompt in an XML-formatted block as suggested by agentskills.io.\n * Use {@link formatSkillsForSystemPrompt} to generate the spec-compatible system prompt block.\n */\nexport interface Skill {\n\t/** Stable skill name used for lookup and model-visible listings. */\n\tname: string;\n\t/** Short model-visible description of when to use the skill. */\n\tdescription: string;\n\t/** Full skill instructions. */\n\tcontent: string;\n\t/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */\n\tfilePath: string;\n\t/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */\n\tdisableModelInvocation?: boolean;\n}\n\n/** Prompt template that can be formatted into a prompt for explicit invocation. */\nexport interface PromptTemplate {\n\t/** Stable template name used for lookup or application command routing. */\n\tname: string;\n\t/** Optional description for command lists or autocomplete. */\n\tdescription?: string;\n\t/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */\n\tcontent: string;\n}\n\n/** Resources made available to explicit invocation methods and system-prompt callbacks. */\nexport interface AgentHarnessResources<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\t/** Prompt templates available for explicit invocation. */\n\tpromptTemplates?: TPromptTemplate[];\n\t/** Skills available to the model and explicit skill invocation. */\n\tskills?: TSkill[];\n}\n\n/** Kind of filesystem object as addressed by an {@link ExecutionEnv}. Symlinks are not followed automatically. */\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\n/** Stable, backend-independent file error codes thrown by {@link ExecutionEnv} file operations. */\nexport type FileErrorCode =\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\n/** Error thrown by {@link ExecutionEnv} file operations. */\nexport class FileError extends Error {\n\tconstructor(\n\t\t/** Backend-independent error code. */\n\t\tpublic code: FileErrorCode,\n\t\tmessage: string,\n\t\t/** Absolute addressed path associated with the failure, when available. */\n\t\tpublic path?: string,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"FileError\";\n\t}\n}\n\n/** Metadata for one filesystem object in an {@link ExecutionEnv}. */\nexport interface FileInfo {\n\t/** Basename of {@link path}. */\n\tname: string;\n\t/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */\n\tpath: string;\n\t/** Object kind. Symlink targets are not followed; use {@link ExecutionEnv.resolvePath} explicitly. */\n\tkind: FileKind;\n\t/** Size in bytes for the addressed filesystem object. */\n\tsize: number;\n\t/** Modification time as milliseconds since Unix epoch. */\n\tmtimeMs: number;\n}\n\n/** Options for {@link ExecutionEnv.exec}. */\nexport interface ExecutionEnvExecOptions {\n\t/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. */\n\tcwd?: string;\n\t/** Additional environment variables for the command. Values override the environment defaults. */\n\tenv?: Record<string, string>;\n\t/** Timeout in seconds. Implementations should reject when the command exceeds this duration. */\n\ttimeout?: number;\n\t/** Abort signal used to terminate the command. */\n\tsignal?: AbortSignal;\n\t/** Called with stdout chunks as they are produced. */\n\tonStdout?: (chunk: string) => void;\n\t/** Called with stderr chunks as they are produced. */\n\tonStderr?: (chunk: string) => void;\n}\n\n/**\n * Filesystem and process execution environment used by the harness.\n *\n * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by this interface are absolute\n * addressed paths in the environment, but are not canonicalized through symlinks unless returned by {@link resolvePath}.\n *\n * File operations throw {@link FileError} for expected filesystem failures such as missing paths or permission errors.\n */\nexport interface ExecutionEnv {\n\t/** Current working directory for relative paths and command execution. */\n\tcwd: string;\n\n\t/** Execute a shell command in {@link cwd} unless `options.cwd` is provided. */\n\texec(\n\t\tcommand: string,\n\t\toptions?: ExecutionEnvExecOptions,\n\t): Promise<{ stdout: string; stderr: string; exitCode: number }>;\n\n\t/** Read a UTF-8 text file. Throws {@link FileError}. */\n\treadTextFile(path: string): Promise<string>;\n\t/** Read a binary file. Throws {@link FileError}. */\n\treadBinaryFile(path: string): Promise<Uint8Array>;\n\t/** Create or overwrite a file, creating parent directories when supported. Throws {@link FileError}. */\n\twriteFile(path: string, content: string | Uint8Array): Promise<void>;\n\t/** Return metadata for the addressed path without following symlinks. Throws {@link FileError}. */\n\tfileInfo(path: string): Promise<FileInfo>;\n\t/** List direct children of a directory without following symlinks. Throws {@link FileError}. */\n\tlistDir(path: string): Promise<FileInfo[]>;\n\t/** Return the canonical path for a path, following symlinks. Throws {@link FileError}. */\n\trealPath(path: string): Promise<string>;\n\t/** Return false for missing paths. Other errors, such as permission failures, may throw {@link FileError}. */\n\texists(path: string): Promise<boolean>;\n\t/** Create a directory. */\n\tcreateDir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\t/** Remove a file or directory. */\n\tremove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;\n\t/** Create a temporary directory and return its absolute path. */\n\tcreateTempDir(prefix?: string): Promise<string>;\n\t/** Create a temporary file and return its absolute path. */\n\tcreateTempFile(options?: { prefix?: string; suffix?: string }): Promise<string>;\n\n\t/** Release resources owned by the environment. */\n\tcleanup(): Promise<void>;\n}\n\nexport interface SessionTreeEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface MessageEntry extends SessionTreeEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\t/** Estimated context tokens after compaction; absent on entries written before this field existed. */\n\ttokensAfter?: number;\n\t/** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */\n\tdetails?: T;\n\t/** True if generated by an extension, undefined/false if harness-generated (backward compatible) */\n\tfromHook?: boolean;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface CustomEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n}\n\nexport interface LabelEntry extends SessionTreeEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\nexport interface SessionInfoEntry extends SessionTreeEntryBase {\n\ttype: \"session_info\"; // legacy name, kept for backwards compatibility\n\tname?: string;\n}\n\nexport type SessionTreeEntry =\n\t| MessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| CompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry;\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionMetadata {\n\tid: string;\n\tcreatedAt: string;\n}\n\nexport interface JsonlSessionMetadata extends SessionMetadata {\n\tcwd: string;\n\tpath: string;\n\tparentSessionPath?: string;\n}\n\nexport interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {\n\tgetMetadata(): Promise<TMetadata>;\n\tgetLeafId(): Promise<string | null>;\n\tsetLeafId(leafId: string | null): Promise<void>;\n\tcreateEntryId(): Promise<string>;\n\tappendEntry(entry: SessionTreeEntry): Promise<void>;\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined>;\n\tfindEntries<TType extends SessionTreeEntry[\"type\"]>(\n\t\ttype: TType,\n\t): Promise<Array<Extract<SessionTreeEntry, { type: TType }>>>;\n\tgetLabel(id: string): Promise<string | undefined>;\n\tgetPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;\n\tgetEntries(): Promise<SessionTreeEntry[]>;\n}\n\nexport type { Session } from \"./session/session.js\";\n\nexport interface SessionCreateOptions {\n\tid?: string;\n}\n\nexport interface SessionForkOptions {\n\tentryId?: string;\n\tposition?: \"before\" | \"at\";\n\tid?: string;\n}\n\nexport interface SessionRepo<\n\tTMetadata extends SessionMetadata = SessionMetadata,\n\tTCreateOptions extends SessionCreateOptions = SessionCreateOptions,\n\tTListOptions = void,\n> {\n\tcreate(options: TCreateOptions): Promise<Session<TMetadata>>;\n\topen(metadata: TMetadata): Promise<Session<TMetadata>>;\n\tlist(options?: TListOptions): Promise<TMetadata[]>;\n\tdelete(metadata: TMetadata): Promise<void>;\n\tfork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;\n}\n\nexport interface JsonlSessionCreateOptions extends SessionCreateOptions {\n\tcwd: string;\n\tparentSessionPath?: string;\n}\n\nexport interface JsonlSessionListOptions {\n\tcwd?: string;\n}\n\nexport interface JsonlSessionRepoApi\n\textends SessionRepo<JsonlSessionMetadata, JsonlSessionCreateOptions, JsonlSessionListOptions> {}\n\nexport type AgentHarnessPhase = \"idle\" | \"turn\" | \"compaction\" | \"branch_summary\" | \"retry\";\n\nexport type PendingSessionWrite = SessionTreeEntry extends infer TEntry\n\t? TEntry extends SessionTreeEntry\n\t\t? Omit<TEntry, \"id\" | \"parentId\" | \"timestamp\">\n\t\t: never\n\t: never;\n\nexport interface AgentHarnessTurnState<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tmessages: AgentMessage[];\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: TTool[];\n\tactiveTools: TTool[];\n}\n\nexport interface QueueUpdateEvent {\n\ttype: \"queue_update\";\n\tsteer: AgentMessage[];\n\tfollowUp: AgentMessage[];\n\tnextTurn: AgentMessage[];\n}\n\nexport interface SavePointEvent {\n\ttype: \"save_point\";\n\thadPendingMutations: boolean;\n}\n\nexport interface AbortEvent {\n\ttype: \"abort\";\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface SettledEvent {\n\ttype: \"settled\";\n\tnextTurnCount: number;\n}\n\nexport interface BeforeAgentStartEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"before_agent_start\";\n\tprompt: string;\n\timages?: ImageContent[];\n\tsystemPrompt: string;\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport interface ContextEvent {\n\ttype: \"context\";\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestEvent {\n\ttype: \"before_provider_request\";\n\tpayload: unknown;\n}\n\nexport interface AfterProviderResponseEvent {\n\ttype: \"after_provider_response\";\n\tstatus: number;\n\theaders: Record<string, string>;\n}\n\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tcontent: Array<TextContent | ImageContent>;\n\tdetails: unknown;\n\tisError: boolean;\n}\n\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\tpreparation: CompactionPreparation;\n\tbranchEntries: SessionTreeEntry[];\n\tcustomInstructions?: string;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\tfromHook: boolean;\n}\n\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\tpreparation: TreePreparation;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\tnewLeafId: string | null;\n\toldLeafId: string | null;\n\tsummaryEntry?: BranchSummaryEntry;\n\tfromHook?: boolean;\n}\n\nexport interface ModelSelectEvent {\n\ttype: \"model_select\";\n\tmodel: Model<any>;\n\tpreviousModel: Model<any> | undefined;\n\tsource: \"set\" | \"restore\";\n}\n\nexport interface ThinkingLevelSelectEvent {\n\ttype: \"thinking_level_select\";\n\tlevel: ThinkingLevel;\n\tpreviousLevel: ThinkingLevel;\n}\n\nexport interface ResourcesUpdateEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"resources_update\";\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tpreviousResources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport type AgentHarnessOwnEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> =\n\t| QueueUpdateEvent\n\t| SavePointEvent\n\t| AbortEvent\n\t| SettledEvent\n\t| BeforeAgentStartEvent<TSkill, TPromptTemplate>\n\t| ContextEvent\n\t| BeforeProviderRequestEvent\n\t| AfterProviderResponseEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent\n\t| ModelSelectEvent\n\t| ThinkingLevelSelectEvent\n\t| ResourcesUpdateEvent<TSkill, TPromptTemplate>;\n\nexport type AgentHarnessEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> =\n\t| AgentEvent\n\t| AgentHarnessOwnEvent<TSkill, TPromptTemplate>;\n\nexport interface BeforeAgentStartResult {\n\tmessages?: AgentMessage[];\n\tsystemPrompt?: string;\n}\n\nexport interface ContextResult {\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestResult {\n\tpayload: unknown;\n}\n\nexport interface ToolCallResult {\n\tblock?: boolean;\n\treason?: string;\n}\n\nexport interface ToolResultPatch {\n\tcontent?: Array<TextContent | ImageContent>;\n\tdetails?: unknown;\n\tisError?: boolean;\n\tterminate?: boolean;\n}\n\nexport interface SessionBeforeCompactResult {\n\tcancel?: boolean;\n\tcompaction?: CompactResult;\n}\n\nexport interface SessionBeforeTreeResult {\n\tcancel?: boolean;\n\tsummary?: { summary: string; details?: unknown };\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport type AgentHarnessEventResultMap = {\n\tbefore_agent_start: BeforeAgentStartResult | undefined;\n\tcontext: ContextResult | undefined;\n\tbefore_provider_request: BeforeProviderRequestResult | undefined;\n\tafter_provider_response: undefined;\n\ttool_call: ToolCallResult | undefined;\n\ttool_result: ToolResultPatch | undefined;\n\tsession_before_compact: SessionBeforeCompactResult | undefined;\n\tsession_compact: undefined;\n\tsession_before_tree: SessionBeforeTreeResult | undefined;\n\tsession_tree: undefined;\n\tmodel_select: undefined;\n\tthinking_level_select: undefined;\n\tresources_update: undefined;\n\tqueue_update: undefined;\n\tsave_point: undefined;\n\tabort: undefined;\n\tsettled: undefined;\n};\n\nexport interface AgentHarnessPromptOptions {\n\timages?: ImageContent[];\n}\n\nexport interface AbortResult {\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\n/** Alias kept for the harness event API; the canonical type lives in compaction. */\nexport type CompactResult = CompactionResult;\n\nexport interface NavigateTreeResult {\n\tcancelled: boolean;\n\teditorText?: string;\n\tsummaryEntry?: BranchSummaryEntry;\n}\n\nexport interface TreePreparation {\n\ttargetId: string;\n\toldLeafId: string | null;\n\tcommonAncestorId: string | null;\n\tentriesToSummarize: SessionTreeEntry[];\n\tuserWantsSummary: boolean;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport interface AgentHarnessOptions<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tenv: ExecutionEnv;\n\tsession: Session;\n\ttools?: TTool[];\n\t/**\n\t * Concrete resources available to explicit invocation methods and system-prompt callbacks.\n\t * Applications own loading/reloading resources and should call `setResources()` with new values.\n\t */\n\tresources?: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt?:\n\t\t| string\n\t\t| ((context: {\n\t\t\t\tenv: ExecutionEnv;\n\t\t\t\tsession: Session;\n\t\t\t\tmodel: Model<any>;\n\t\t\t\tthinkingLevel: ThinkingLevel;\n\t\t\t\tactiveTools: TTool[];\n\t\t\t\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\t\t }) => string | Promise<string>);\n\tgetApiKeyAndHeaders?: (\n\t\tmodel: Model<any>,\n\t) => Promise<{ apiKey: string; headers?: Record<string, string> } | undefined>;\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tactiveToolNames?: string[];\n\tsteeringMode?: QueueMode;\n\tfollowUpMode?: QueueMode;\n}\n\nexport type { AgentHarness } from \"./agent-harness.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AA0DA,4DAA4D;AAC5D,MAAM,OAAO,SAAU,SAAQ,KAAK;IAG3B,IAAI;IAGJ,IAAI;IALZ;IACC,sCAAsC;IAC/B,IAAmB,EAC1B,OAAe;IACf,2EAA2E;IACpE,IAAa,EACpB,OAAsB,EACrB;QACD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBANjB,IAAI;oBAGJ,IAAI;QAIX,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import type { ImageContent, Model, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { QueueMode } from \"../agent.js\";\nimport type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from \"../index.js\";\nimport type { Session } from \"./session/session.js\";\n\n/**\n * Skill loaded from a `SKILL.md` file or provided by an application.\n *\n * `name`, `description`, and `filePath` are inserted into the system prompt in an XML-formatted block as suggested by agentskills.io.\n * Use {@link formatSkillsForSystemPrompt} to generate the spec-compatible system prompt block.\n */\nexport interface Skill {\n\t/** Stable skill name used for lookup and model-visible listings. */\n\tname: string;\n\t/** Short model-visible description of when to use the skill. */\n\tdescription: string;\n\t/** Full skill instructions. */\n\tcontent: string;\n\t/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */\n\tfilePath: string;\n\t/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */\n\tdisableModelInvocation?: boolean;\n}\n\n/** Prompt template that can be formatted into a prompt for explicit invocation. */\nexport interface PromptTemplate {\n\t/** Stable template name used for lookup or application command routing. */\n\tname: string;\n\t/** Optional description for command lists or autocomplete. */\n\tdescription?: string;\n\t/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */\n\tcontent: string;\n}\n\n/** Resources made available to explicit invocation methods and system-prompt callbacks. */\nexport interface AgentHarnessResources<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\t/** Prompt templates available for explicit invocation. */\n\tpromptTemplates?: TPromptTemplate[];\n\t/** Skills available to the model and explicit skill invocation. */\n\tskills?: TSkill[];\n}\n\n/** Kind of filesystem object as addressed by an {@link ExecutionEnv}. Symlinks are not followed automatically. */\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\n/** Stable, backend-independent file error codes thrown by {@link ExecutionEnv} file operations. */\nexport type FileErrorCode =\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\n/** Error thrown by {@link ExecutionEnv} file operations. */\nexport class FileError extends Error {\n\tconstructor(\n\t\t/** Backend-independent error code. */\n\t\tpublic code: FileErrorCode,\n\t\tmessage: string,\n\t\t/** Absolute addressed path associated with the failure, when available. */\n\t\tpublic path?: string,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"FileError\";\n\t}\n}\n\n/** Metadata for one filesystem object in an {@link ExecutionEnv}. */\nexport interface FileInfo {\n\t/** Basename of {@link path}. */\n\tname: string;\n\t/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */\n\tpath: string;\n\t/** Object kind. Symlink targets are not followed; use {@link ExecutionEnv.resolvePath} explicitly. */\n\tkind: FileKind;\n\t/** Size in bytes for the addressed filesystem object. */\n\tsize: number;\n\t/** Modification time as milliseconds since Unix epoch. */\n\tmtimeMs: number;\n}\n\n/** Options for {@link ExecutionEnv.exec}. */\nexport interface ExecutionEnvExecOptions {\n\t/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. */\n\tcwd?: string;\n\t/** Additional environment variables for the command. Values override the environment defaults. */\n\tenv?: Record<string, string>;\n\t/** Timeout in seconds. Implementations should reject when the command exceeds this duration. */\n\ttimeout?: number;\n\t/** Abort signal used to terminate the command. */\n\tsignal?: AbortSignal;\n\t/** Called with stdout chunks as they are produced. */\n\tonStdout?: (chunk: string) => void;\n\t/** Called with stderr chunks as they are produced. */\n\tonStderr?: (chunk: string) => void;\n}\n\n/**\n * Filesystem and process execution environment used by the harness.\n *\n * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by this interface are absolute\n * addressed paths in the environment, but are not canonicalized through symlinks unless returned by {@link resolvePath}.\n *\n * File operations throw {@link FileError} for expected filesystem failures such as missing paths or permission errors.\n */\nexport interface ExecutionEnv {\n\t/** Current working directory for relative paths and command execution. */\n\tcwd: string;\n\n\t/** Execute a shell command in {@link cwd} unless `options.cwd` is provided. */\n\texec(\n\t\tcommand: string,\n\t\toptions?: ExecutionEnvExecOptions,\n\t): Promise<{ stdout: string; stderr: string; exitCode: number }>;\n\n\t/** Read a UTF-8 text file. Throws {@link FileError}. */\n\treadTextFile(path: string): Promise<string>;\n\t/** Read a binary file. Throws {@link FileError}. */\n\treadBinaryFile(path: string): Promise<Uint8Array>;\n\t/** Create or overwrite a file, creating parent directories when supported. Throws {@link FileError}. */\n\twriteFile(path: string, content: string | Uint8Array): Promise<void>;\n\t/** Return metadata for the addressed path without following symlinks. Throws {@link FileError}. */\n\tfileInfo(path: string): Promise<FileInfo>;\n\t/** List direct children of a directory without following symlinks. Throws {@link FileError}. */\n\tlistDir(path: string): Promise<FileInfo[]>;\n\t/** Return the canonical path for a path, following symlinks. Throws {@link FileError}. */\n\trealPath(path: string): Promise<string>;\n\t/** Return false for missing paths. Other errors, such as permission failures, may throw {@link FileError}. */\n\texists(path: string): Promise<boolean>;\n\t/** Create a directory. */\n\tcreateDir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\t/** Remove a file or directory. */\n\tremove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;\n\t/** Create a temporary directory and return its absolute path. */\n\tcreateTempDir(prefix?: string): Promise<string>;\n\t/** Create a temporary file and return its absolute path. */\n\tcreateTempFile(options?: { prefix?: string; suffix?: string }): Promise<string>;\n\n\t/** Release resources owned by the environment. */\n\tcleanup(): Promise<void>;\n}\n\nexport interface SessionTreeEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface MessageEntry extends SessionTreeEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface CustomEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n}\n\nexport interface LabelEntry extends SessionTreeEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\nexport interface SessionInfoEntry extends SessionTreeEntryBase {\n\ttype: \"session_info\"; // legacy name, kept for backwards compatibility\n\tname?: string;\n}\n\nexport type SessionTreeEntry =\n\t| MessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| CompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry;\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionMetadata {\n\tid: string;\n\tcreatedAt: string;\n}\n\nexport interface JsonlSessionMetadata extends SessionMetadata {\n\tcwd: string;\n\tpath: string;\n\tparentSessionPath?: string;\n}\n\nexport interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {\n\tgetMetadata(): Promise<TMetadata>;\n\tgetLeafId(): Promise<string | null>;\n\tsetLeafId(leafId: string | null): Promise<void>;\n\tcreateEntryId(): Promise<string>;\n\tappendEntry(entry: SessionTreeEntry): Promise<void>;\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined>;\n\tfindEntries<TType extends SessionTreeEntry[\"type\"]>(\n\t\ttype: TType,\n\t): Promise<Array<Extract<SessionTreeEntry, { type: TType }>>>;\n\tgetLabel(id: string): Promise<string | undefined>;\n\tgetPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;\n\tgetEntries(): Promise<SessionTreeEntry[]>;\n}\n\nexport type { Session } from \"./session/session.js\";\n\nexport interface SessionCreateOptions {\n\tid?: string;\n}\n\nexport interface SessionForkOptions {\n\tentryId?: string;\n\tposition?: \"before\" | \"at\";\n\tid?: string;\n}\n\nexport interface SessionRepo<\n\tTMetadata extends SessionMetadata = SessionMetadata,\n\tTCreateOptions extends SessionCreateOptions = SessionCreateOptions,\n\tTListOptions = void,\n> {\n\tcreate(options: TCreateOptions): Promise<Session<TMetadata>>;\n\topen(metadata: TMetadata): Promise<Session<TMetadata>>;\n\tlist(options?: TListOptions): Promise<TMetadata[]>;\n\tdelete(metadata: TMetadata): Promise<void>;\n\tfork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;\n}\n\nexport interface JsonlSessionCreateOptions extends SessionCreateOptions {\n\tcwd: string;\n\tparentSessionPath?: string;\n}\n\nexport interface JsonlSessionListOptions {\n\tcwd?: string;\n}\n\nexport interface JsonlSessionRepoApi\n\textends SessionRepo<JsonlSessionMetadata, JsonlSessionCreateOptions, JsonlSessionListOptions> {}\n\nexport type AgentHarnessPhase = \"idle\" | \"turn\" | \"compaction\" | \"branch_summary\" | \"retry\";\n\nexport type PendingSessionWrite = SessionTreeEntry extends infer TEntry\n\t? TEntry extends SessionTreeEntry\n\t\t? Omit<TEntry, \"id\" | \"parentId\" | \"timestamp\">\n\t\t: never\n\t: never;\n\nexport interface AgentHarnessTurnState<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tmessages: AgentMessage[];\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: TTool[];\n\tactiveTools: TTool[];\n}\n\nexport interface QueueUpdateEvent {\n\ttype: \"queue_update\";\n\tsteer: AgentMessage[];\n\tfollowUp: AgentMessage[];\n\tnextTurn: AgentMessage[];\n}\n\nexport interface SavePointEvent {\n\ttype: \"save_point\";\n\thadPendingMutations: boolean;\n}\n\nexport interface AbortEvent {\n\ttype: \"abort\";\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface SettledEvent {\n\ttype: \"settled\";\n\tnextTurnCount: number;\n}\n\nexport interface BeforeAgentStartEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"before_agent_start\";\n\tprompt: string;\n\timages?: ImageContent[];\n\tsystemPrompt: string;\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport interface ContextEvent {\n\ttype: \"context\";\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestEvent {\n\ttype: \"before_provider_request\";\n\tpayload: unknown;\n}\n\nexport interface AfterProviderResponseEvent {\n\ttype: \"after_provider_response\";\n\tstatus: number;\n\theaders: Record<string, string>;\n}\n\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tcontent: Array<TextContent | ImageContent>;\n\tdetails: unknown;\n\tisError: boolean;\n}\n\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\tpreparation: CompactionPreparation;\n\tbranchEntries: SessionTreeEntry[];\n\tcustomInstructions?: string;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\tfromHook: boolean;\n}\n\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\tpreparation: TreePreparation;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\tnewLeafId: string | null;\n\toldLeafId: string | null;\n\tsummaryEntry?: BranchSummaryEntry;\n\tfromHook?: boolean;\n}\n\nexport interface ModelSelectEvent {\n\ttype: \"model_select\";\n\tmodel: Model<any>;\n\tpreviousModel: Model<any> | undefined;\n\tsource: \"set\" | \"restore\";\n}\n\nexport interface ThinkingLevelSelectEvent {\n\ttype: \"thinking_level_select\";\n\tlevel: ThinkingLevel;\n\tpreviousLevel: ThinkingLevel;\n}\n\nexport interface ResourcesUpdateEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"resources_update\";\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tpreviousResources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport type AgentHarnessOwnEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> =\n\t| QueueUpdateEvent\n\t| SavePointEvent\n\t| AbortEvent\n\t| SettledEvent\n\t| BeforeAgentStartEvent<TSkill, TPromptTemplate>\n\t| ContextEvent\n\t| BeforeProviderRequestEvent\n\t| AfterProviderResponseEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent\n\t| ModelSelectEvent\n\t| ThinkingLevelSelectEvent\n\t| ResourcesUpdateEvent<TSkill, TPromptTemplate>;\n\nexport type AgentHarnessEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> =\n\t| AgentEvent\n\t| AgentHarnessOwnEvent<TSkill, TPromptTemplate>;\n\nexport interface BeforeAgentStartResult {\n\tmessages?: AgentMessage[];\n\tsystemPrompt?: string;\n}\n\nexport interface ContextResult {\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestResult {\n\tpayload: unknown;\n}\n\nexport interface ToolCallResult {\n\tblock?: boolean;\n\treason?: string;\n}\n\nexport interface ToolResultPatch {\n\tcontent?: Array<TextContent | ImageContent>;\n\tdetails?: unknown;\n\tisError?: boolean;\n\tterminate?: boolean;\n}\n\nexport interface SessionBeforeCompactResult {\n\tcancel?: boolean;\n\tcompaction?: CompactResult;\n}\n\nexport interface SessionBeforeTreeResult {\n\tcancel?: boolean;\n\tsummary?: { summary: string; details?: unknown };\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport type AgentHarnessEventResultMap = {\n\tbefore_agent_start: BeforeAgentStartResult | undefined;\n\tcontext: ContextResult | undefined;\n\tbefore_provider_request: BeforeProviderRequestResult | undefined;\n\tafter_provider_response: undefined;\n\ttool_call: ToolCallResult | undefined;\n\ttool_result: ToolResultPatch | undefined;\n\tsession_before_compact: SessionBeforeCompactResult | undefined;\n\tsession_compact: undefined;\n\tsession_before_tree: SessionBeforeTreeResult | undefined;\n\tsession_tree: undefined;\n\tmodel_select: undefined;\n\tthinking_level_select: undefined;\n\tresources_update: undefined;\n\tqueue_update: undefined;\n\tsave_point: undefined;\n\tabort: undefined;\n\tsettled: undefined;\n};\n\nexport interface AgentHarnessPromptOptions {\n\timages?: ImageContent[];\n}\n\nexport interface AbortResult {\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface CompactResult {\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: unknown;\n}\n\nexport interface NavigateTreeResult {\n\tcancelled: boolean;\n\teditorText?: string;\n\tsummaryEntry?: BranchSummaryEntry;\n}\n\nexport interface CompactionSettings {\n\tenabled: boolean;\n\treserveTokens: number;\n\tkeepRecentTokens: number;\n}\n\nexport interface CompactionPreparation {\n\tfirstKeptEntryId: string;\n\tmessagesToSummarize: AgentMessage[];\n\tturnPrefixMessages: AgentMessage[];\n\tisSplitTurn: boolean;\n\ttokensBefore: number;\n\tpreviousSummary?: string;\n\tfileOps: FileOperations;\n\tsettings: CompactionSettings;\n}\n\nexport interface FileOperations {\n\tread: Set<string>;\n\twritten: Set<string>;\n\tedited: Set<string>;\n}\n\nexport interface TreePreparation {\n\ttargetId: string;\n\toldLeafId: string | null;\n\tcommonAncestorId: string | null;\n\tentriesToSummarize: SessionTreeEntry[];\n\tuserWantsSummary: boolean;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport interface GenerateBranchSummaryOptions {\n\tmodel: Model<any>;\n\tapiKey: string;\n\theaders?: Record<string, string>;\n\tsignal: AbortSignal;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\treserveTokens?: number;\n}\n\nexport interface BranchSummaryResult {\n\tsummary?: string;\n\treadFiles?: string[];\n\tmodifiedFiles?: string[];\n\taborted?: boolean;\n\terror?: string;\n}\n\nexport interface AgentHarnessOptions<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tenv: ExecutionEnv;\n\tsession: Session;\n\ttools?: TTool[];\n\t/**\n\t * Concrete resources available to explicit invocation methods and system-prompt callbacks.\n\t * Applications own loading/reloading resources and should call `setResources()` with new values.\n\t */\n\tresources?: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt?:\n\t\t| string\n\t\t| ((context: {\n\t\t\t\tenv: ExecutionEnv;\n\t\t\t\tsession: Session;\n\t\t\t\tmodel: Model<any>;\n\t\t\t\tthinkingLevel: ThinkingLevel;\n\t\t\t\tactiveTools: TTool[];\n\t\t\t\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\t\t }) => string | Promise<string>);\n\tgetApiKeyAndHeaders?: (\n\t\tmodel: Model<any>,\n\t) => Promise<{ apiKey: string; headers?: Record<string, string> } | undefined>;\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tactiveToolNames?: string[];\n\tsteeringMode?: QueueMode;\n\tfollowUpMode?: QueueMode;\n}\n\nexport type { AgentHarness } from \"./agent-harness.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/harness/types.ts"],"names":[],"mappings":"AA2DA,4DAA4D;AAC5D,MAAM,OAAO,SAAU,SAAQ,KAAK;IAG3B,IAAI;IAGJ,IAAI;IALZ;IACC,sCAAsC;IAC/B,IAAmB,EAC1B,OAAe;IACf,2EAA2E;IACpE,IAAa,EACpB,OAAsB,EACrB;QACD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBANjB,IAAI;oBAGJ,IAAI;QAIX,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import type { ImageContent, Model, TextContent } from \"@kolisachint/hoocode-ai\";\nimport type { QueueMode } from \"../agent.js\";\nimport type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from \"../index.js\";\nimport type { CompactionPreparation, CompactionResult } from \"./compaction/compaction.js\";\nimport type { Session } from \"./session/session.js\";\n\n/**\n * Skill loaded from a `SKILL.md` file or provided by an application.\n *\n * `name`, `description`, and `filePath` are inserted into the system prompt in an XML-formatted block as suggested by agentskills.io.\n * Use {@link formatSkillsForSystemPrompt} to generate the spec-compatible system prompt block.\n */\nexport interface Skill {\n\t/** Stable skill name used for lookup and model-visible listings. */\n\tname: string;\n\t/** Short model-visible description of when to use the skill. */\n\tdescription: string;\n\t/** Full skill instructions. */\n\tcontent: string;\n\t/** Absolute path to the skill file. Used for model-visible location and resolving relative references. */\n\tfilePath: string;\n\t/** Exclude this skill from model-visible skill lists while still allowing explicit application invocation. */\n\tdisableModelInvocation?: boolean;\n}\n\n/** Prompt template that can be formatted into a prompt for explicit invocation. */\nexport interface PromptTemplate {\n\t/** Stable template name used for lookup or application command routing. */\n\tname: string;\n\t/** Optional description for command lists or autocomplete. */\n\tdescription?: string;\n\t/** Template content. Argument placeholders are formatted by `formatPromptTemplateInvocation`. */\n\tcontent: string;\n}\n\n/** Resources made available to explicit invocation methods and system-prompt callbacks. */\nexport interface AgentHarnessResources<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\t/** Prompt templates available for explicit invocation. */\n\tpromptTemplates?: TPromptTemplate[];\n\t/** Skills available to the model and explicit skill invocation. */\n\tskills?: TSkill[];\n}\n\n/** Kind of filesystem object as addressed by an {@link ExecutionEnv}. Symlinks are not followed automatically. */\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\n/** Stable, backend-independent file error codes thrown by {@link ExecutionEnv} file operations. */\nexport type FileErrorCode =\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\n/** Error thrown by {@link ExecutionEnv} file operations. */\nexport class FileError extends Error {\n\tconstructor(\n\t\t/** Backend-independent error code. */\n\t\tpublic code: FileErrorCode,\n\t\tmessage: string,\n\t\t/** Absolute addressed path associated with the failure, when available. */\n\t\tpublic path?: string,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t\tthis.name = \"FileError\";\n\t}\n}\n\n/** Metadata for one filesystem object in an {@link ExecutionEnv}. */\nexport interface FileInfo {\n\t/** Basename of {@link path}. */\n\tname: string;\n\t/** Absolute, syntactically normalized addressed path in the execution environment. Symlinks are not followed. */\n\tpath: string;\n\t/** Object kind. Symlink targets are not followed; use {@link ExecutionEnv.resolvePath} explicitly. */\n\tkind: FileKind;\n\t/** Size in bytes for the addressed filesystem object. */\n\tsize: number;\n\t/** Modification time as milliseconds since Unix epoch. */\n\tmtimeMs: number;\n}\n\n/** Options for {@link ExecutionEnv.exec}. */\nexport interface ExecutionEnvExecOptions {\n\t/** Working directory for the command. Relative paths are resolved against {@link ExecutionEnv.cwd}. */\n\tcwd?: string;\n\t/** Additional environment variables for the command. Values override the environment defaults. */\n\tenv?: Record<string, string>;\n\t/** Timeout in seconds. Implementations should reject when the command exceeds this duration. */\n\ttimeout?: number;\n\t/** Abort signal used to terminate the command. */\n\tsignal?: AbortSignal;\n\t/** Called with stdout chunks as they are produced. */\n\tonStdout?: (chunk: string) => void;\n\t/** Called with stderr chunks as they are produced. */\n\tonStderr?: (chunk: string) => void;\n}\n\n/**\n * Filesystem and process execution environment used by the harness.\n *\n * Paths passed to methods may be absolute or relative to {@link cwd}. Paths returned by this interface are absolute\n * addressed paths in the environment, but are not canonicalized through symlinks unless returned by {@link resolvePath}.\n *\n * File operations throw {@link FileError} for expected filesystem failures such as missing paths or permission errors.\n */\nexport interface ExecutionEnv {\n\t/** Current working directory for relative paths and command execution. */\n\tcwd: string;\n\n\t/** Execute a shell command in {@link cwd} unless `options.cwd` is provided. */\n\texec(\n\t\tcommand: string,\n\t\toptions?: ExecutionEnvExecOptions,\n\t): Promise<{ stdout: string; stderr: string; exitCode: number }>;\n\n\t/** Read a UTF-8 text file. Throws {@link FileError}. */\n\treadTextFile(path: string): Promise<string>;\n\t/** Read a binary file. Throws {@link FileError}. */\n\treadBinaryFile(path: string): Promise<Uint8Array>;\n\t/** Create or overwrite a file, creating parent directories when supported. Throws {@link FileError}. */\n\twriteFile(path: string, content: string | Uint8Array): Promise<void>;\n\t/** Return metadata for the addressed path without following symlinks. Throws {@link FileError}. */\n\tfileInfo(path: string): Promise<FileInfo>;\n\t/** List direct children of a directory without following symlinks. Throws {@link FileError}. */\n\tlistDir(path: string): Promise<FileInfo[]>;\n\t/** Return the canonical path for a path, following symlinks. Throws {@link FileError}. */\n\trealPath(path: string): Promise<string>;\n\t/** Return false for missing paths. Other errors, such as permission failures, may throw {@link FileError}. */\n\texists(path: string): Promise<boolean>;\n\t/** Create a directory. */\n\tcreateDir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\t/** Remove a file or directory. */\n\tremove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;\n\t/** Create a temporary directory and return its absolute path. */\n\tcreateTempDir(prefix?: string): Promise<string>;\n\t/** Create a temporary file and return its absolute path. */\n\tcreateTempFile(options?: { prefix?: string; suffix?: string }): Promise<string>;\n\n\t/** Release resources owned by the environment. */\n\tcleanup(): Promise<void>;\n}\n\nexport interface SessionTreeEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\n\nexport interface MessageEntry extends SessionTreeEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\n\nexport interface ThinkingLevelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\n\nexport interface ModelChangeEntry extends SessionTreeEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\n\nexport interface CompactionEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\t/** Estimated context tokens after compaction; absent on entries written before this field existed. */\n\ttokensAfter?: number;\n\t/** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */\n\tdetails?: T;\n\t/** True if generated by an extension, undefined/false if harness-generated (backward compatible) */\n\tfromHook?: boolean;\n}\n\nexport interface BranchSummaryEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\n\nexport interface CustomEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\n\nexport interface CustomMessageEntry<T = unknown> extends SessionTreeEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n}\n\nexport interface LabelEntry extends SessionTreeEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\n\nexport interface SessionInfoEntry extends SessionTreeEntryBase {\n\ttype: \"session_info\"; // legacy name, kept for backwards compatibility\n\tname?: string;\n}\n\nexport type SessionTreeEntry =\n\t| MessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| CompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry;\n\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\n\nexport interface SessionMetadata {\n\tid: string;\n\tcreatedAt: string;\n}\n\nexport interface JsonlSessionMetadata extends SessionMetadata {\n\tcwd: string;\n\tpath: string;\n\tparentSessionPath?: string;\n}\n\nexport interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {\n\tgetMetadata(): Promise<TMetadata>;\n\tgetLeafId(): Promise<string | null>;\n\tsetLeafId(leafId: string | null): Promise<void>;\n\tcreateEntryId(): Promise<string>;\n\tappendEntry(entry: SessionTreeEntry): Promise<void>;\n\tgetEntry(id: string): Promise<SessionTreeEntry | undefined>;\n\tfindEntries<TType extends SessionTreeEntry[\"type\"]>(\n\t\ttype: TType,\n\t): Promise<Array<Extract<SessionTreeEntry, { type: TType }>>>;\n\tgetLabel(id: string): Promise<string | undefined>;\n\tgetPathToRoot(leafId: string | null): Promise<SessionTreeEntry[]>;\n\tgetEntries(): Promise<SessionTreeEntry[]>;\n}\n\nexport type { Session } from \"./session/session.js\";\n\nexport interface SessionCreateOptions {\n\tid?: string;\n}\n\nexport interface SessionForkOptions {\n\tentryId?: string;\n\tposition?: \"before\" | \"at\";\n\tid?: string;\n}\n\nexport interface SessionRepo<\n\tTMetadata extends SessionMetadata = SessionMetadata,\n\tTCreateOptions extends SessionCreateOptions = SessionCreateOptions,\n\tTListOptions = void,\n> {\n\tcreate(options: TCreateOptions): Promise<Session<TMetadata>>;\n\topen(metadata: TMetadata): Promise<Session<TMetadata>>;\n\tlist(options?: TListOptions): Promise<TMetadata[]>;\n\tdelete(metadata: TMetadata): Promise<void>;\n\tfork(source: TMetadata, options: SessionForkOptions & TCreateOptions): Promise<Session<TMetadata>>;\n}\n\nexport interface JsonlSessionCreateOptions extends SessionCreateOptions {\n\tcwd: string;\n\tparentSessionPath?: string;\n}\n\nexport interface JsonlSessionListOptions {\n\tcwd?: string;\n}\n\nexport interface JsonlSessionRepoApi\n\textends SessionRepo<JsonlSessionMetadata, JsonlSessionCreateOptions, JsonlSessionListOptions> {}\n\nexport type AgentHarnessPhase = \"idle\" | \"turn\" | \"compaction\" | \"branch_summary\" | \"retry\";\n\nexport type PendingSessionWrite = SessionTreeEntry extends infer TEntry\n\t? TEntry extends SessionTreeEntry\n\t\t? Omit<TEntry, \"id\" | \"parentId\" | \"timestamp\">\n\t\t: never\n\t: never;\n\nexport interface AgentHarnessTurnState<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tmessages: AgentMessage[];\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt: string;\n\tmodel: Model<any>;\n\tthinkingLevel: ThinkingLevel;\n\ttools: TTool[];\n\tactiveTools: TTool[];\n}\n\nexport interface QueueUpdateEvent {\n\ttype: \"queue_update\";\n\tsteer: AgentMessage[];\n\tfollowUp: AgentMessage[];\n\tnextTurn: AgentMessage[];\n}\n\nexport interface SavePointEvent {\n\ttype: \"save_point\";\n\thadPendingMutations: boolean;\n}\n\nexport interface AbortEvent {\n\ttype: \"abort\";\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\nexport interface SettledEvent {\n\ttype: \"settled\";\n\tnextTurnCount: number;\n}\n\nexport interface BeforeAgentStartEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"before_agent_start\";\n\tprompt: string;\n\timages?: ImageContent[];\n\tsystemPrompt: string;\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport interface ContextEvent {\n\ttype: \"context\";\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestEvent {\n\ttype: \"before_provider_request\";\n\tpayload: unknown;\n}\n\nexport interface AfterProviderResponseEvent {\n\ttype: \"after_provider_response\";\n\tstatus: number;\n\theaders: Record<string, string>;\n}\n\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tcontent: Array<TextContent | ImageContent>;\n\tdetails: unknown;\n\tisError: boolean;\n}\n\nexport interface SessionBeforeCompactEvent {\n\ttype: \"session_before_compact\";\n\tpreparation: CompactionPreparation;\n\tbranchEntries: SessionTreeEntry[];\n\tcustomInstructions?: string;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionCompactEvent {\n\ttype: \"session_compact\";\n\tcompactionEntry: CompactionEntry;\n\tfromHook: boolean;\n}\n\nexport interface SessionBeforeTreeEvent {\n\ttype: \"session_before_tree\";\n\tpreparation: TreePreparation;\n\tsignal: AbortSignal;\n}\n\nexport interface SessionTreeEvent {\n\ttype: \"session_tree\";\n\tnewLeafId: string | null;\n\toldLeafId: string | null;\n\tsummaryEntry?: BranchSummaryEntry;\n\tfromHook?: boolean;\n}\n\nexport interface ModelSelectEvent {\n\ttype: \"model_select\";\n\tmodel: Model<any>;\n\tpreviousModel: Model<any> | undefined;\n\tsource: \"set\" | \"restore\";\n}\n\nexport interface ThinkingLevelSelectEvent {\n\ttype: \"thinking_level_select\";\n\tlevel: ThinkingLevel;\n\tpreviousLevel: ThinkingLevel;\n}\n\nexport interface ResourcesUpdateEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> {\n\ttype: \"resources_update\";\n\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tpreviousResources: AgentHarnessResources<TSkill, TPromptTemplate>;\n}\n\nexport type AgentHarnessOwnEvent<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n> =\n\t| QueueUpdateEvent\n\t| SavePointEvent\n\t| AbortEvent\n\t| SettledEvent\n\t| BeforeAgentStartEvent<TSkill, TPromptTemplate>\n\t| ContextEvent\n\t| BeforeProviderRequestEvent\n\t| AfterProviderResponseEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| SessionBeforeCompactEvent\n\t| SessionCompactEvent\n\t| SessionBeforeTreeEvent\n\t| SessionTreeEvent\n\t| ModelSelectEvent\n\t| ThinkingLevelSelectEvent\n\t| ResourcesUpdateEvent<TSkill, TPromptTemplate>;\n\nexport type AgentHarnessEvent<TSkill extends Skill = Skill, TPromptTemplate extends PromptTemplate = PromptTemplate> =\n\t| AgentEvent\n\t| AgentHarnessOwnEvent<TSkill, TPromptTemplate>;\n\nexport interface BeforeAgentStartResult {\n\tmessages?: AgentMessage[];\n\tsystemPrompt?: string;\n}\n\nexport interface ContextResult {\n\tmessages: AgentMessage[];\n}\n\nexport interface BeforeProviderRequestResult {\n\tpayload: unknown;\n}\n\nexport interface ToolCallResult {\n\tblock?: boolean;\n\treason?: string;\n}\n\nexport interface ToolResultPatch {\n\tcontent?: Array<TextContent | ImageContent>;\n\tdetails?: unknown;\n\tisError?: boolean;\n\tterminate?: boolean;\n}\n\nexport interface SessionBeforeCompactResult {\n\tcancel?: boolean;\n\tcompaction?: CompactResult;\n}\n\nexport interface SessionBeforeTreeResult {\n\tcancel?: boolean;\n\tsummary?: { summary: string; details?: unknown };\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport type AgentHarnessEventResultMap = {\n\tbefore_agent_start: BeforeAgentStartResult | undefined;\n\tcontext: ContextResult | undefined;\n\tbefore_provider_request: BeforeProviderRequestResult | undefined;\n\tafter_provider_response: undefined;\n\ttool_call: ToolCallResult | undefined;\n\ttool_result: ToolResultPatch | undefined;\n\tsession_before_compact: SessionBeforeCompactResult | undefined;\n\tsession_compact: undefined;\n\tsession_before_tree: SessionBeforeTreeResult | undefined;\n\tsession_tree: undefined;\n\tmodel_select: undefined;\n\tthinking_level_select: undefined;\n\tresources_update: undefined;\n\tqueue_update: undefined;\n\tsave_point: undefined;\n\tabort: undefined;\n\tsettled: undefined;\n};\n\nexport interface AgentHarnessPromptOptions {\n\timages?: ImageContent[];\n}\n\nexport interface AbortResult {\n\tclearedSteer: AgentMessage[];\n\tclearedFollowUp: AgentMessage[];\n}\n\n/** Alias kept for the harness event API; the canonical type lives in compaction. */\nexport type CompactResult = CompactionResult;\n\nexport interface NavigateTreeResult {\n\tcancelled: boolean;\n\teditorText?: string;\n\tsummaryEntry?: BranchSummaryEntry;\n}\n\nexport interface TreePreparation {\n\ttargetId: string;\n\toldLeafId: string | null;\n\tcommonAncestorId: string | null;\n\tentriesToSummarize: SessionTreeEntry[];\n\tuserWantsSummary: boolean;\n\tcustomInstructions?: string;\n\treplaceInstructions?: boolean;\n\tlabel?: string;\n}\n\nexport interface AgentHarnessOptions<\n\tTSkill extends Skill = Skill,\n\tTPromptTemplate extends PromptTemplate = PromptTemplate,\n\tTTool extends AgentTool = AgentTool,\n> {\n\tenv: ExecutionEnv;\n\tsession: Session;\n\ttools?: TTool[];\n\t/**\n\t * Concrete resources available to explicit invocation methods and system-prompt callbacks.\n\t * Applications own loading/reloading resources and should call `setResources()` with new values.\n\t */\n\tresources?: AgentHarnessResources<TSkill, TPromptTemplate>;\n\tsystemPrompt?:\n\t\t| string\n\t\t| ((context: {\n\t\t\t\tenv: ExecutionEnv;\n\t\t\t\tsession: Session;\n\t\t\t\tmodel: Model<any>;\n\t\t\t\tthinkingLevel: ThinkingLevel;\n\t\t\t\tactiveTools: TTool[];\n\t\t\t\tresources: AgentHarnessResources<TSkill, TPromptTemplate>;\n\t\t }) => string | Promise<string>);\n\tgetApiKeyAndHeaders?: (\n\t\tmodel: Model<any>,\n\t) => Promise<{ apiKey: string; headers?: Record<string, string> } | undefined>;\n\tmodel: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tactiveToolNames?: string[];\n\tsteeringMode?: QueueMode;\n\tfollowUpMode?: QueueMode;\n}\n\nexport type { AgentHarness } from \"./agent-harness.js\";\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lossless output compression utilities for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* All compression is strictly lossless - no useful information is removed.
|
|
5
|
+
* Compression is command-aware where possible, and general-purpose otherwise.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Collapse 3+ consecutive blank lines to 2 (preserves paragraph separation).
|
|
9
|
+
*/
|
|
10
|
+
export declare function collapseBlankLines(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Strip trailing whitespace from each line.
|
|
13
|
+
*/
|
|
14
|
+
export declare function stripTrailingWhitespace(text: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Remove duplicate consecutive lines (keeps first occurrence).
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeDuplicateLines(text: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Apply general lossless compression to any output.
|
|
21
|
+
* Single-pass implementation for efficiency.
|
|
22
|
+
*/
|
|
23
|
+
export declare function compressGeneral(text: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Apply all compression to a bash command output.
|
|
26
|
+
* This is the main entry point for bash output compression.
|
|
27
|
+
*
|
|
28
|
+
* @param command - The bash command that was executed
|
|
29
|
+
* @param output - The raw output from the command
|
|
30
|
+
* @returns Compressed output (lossless)
|
|
31
|
+
*/
|
|
32
|
+
export declare function compressBashOutput(command: string, output: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Apply compression to grep output.
|
|
35
|
+
* This strips redundant context and normalizes output.
|
|
36
|
+
*/
|
|
37
|
+
export declare function compressGrepOutput(output: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Apply compression to read output.
|
|
40
|
+
* This normalizes whitespace but preserves content.
|
|
41
|
+
*/
|
|
42
|
+
export declare function compressReadOutput(output: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Apply compression to find output.
|
|
45
|
+
* This normalizes paths and removes duplicates.
|
|
46
|
+
*/
|
|
47
|
+
export declare function compressFindOutput(output: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Apply compression to ls output.
|
|
50
|
+
* This normalizes formatting.
|
|
51
|
+
*/
|
|
52
|
+
export declare function compressLsOutput(output: string): string;
|
|
53
|
+
//# sourceMappingURL=output-compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-compression.d.ts","sourceRoot":"","sources":["../../../src/harness/utils/output-compression.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK5D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAazD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBpD;AAuSD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAkB1E;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKvD","sourcesContent":["/**\n * Lossless output compression utilities for tool outputs.\n *\n * All compression is strictly lossless - no useful information is removed.\n * Compression is command-aware where possible, and general-purpose otherwise.\n */\n\n/** Minimum output size (in bytes) to apply compression. Below this, overhead exceeds savings. */\nconst MIN_COMPRESSION_SIZE = 1024; // 1KB\n\n// ============================================================================\n// General Compression (applied to all outputs)\n// ============================================================================\n\n/**\n * Collapse 3+ consecutive blank lines to 2 (preserves paragraph separation).\n */\nexport function collapseBlankLines(text: string): string {\n\treturn text.replace(/\\n{3,}/g, \"\\n\\n\");\n}\n\n/**\n * Strip trailing whitespace from each line.\n */\nexport function stripTrailingWhitespace(text: string): string {\n\treturn text\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trimEnd())\n\t\t.join(\"\\n\");\n}\n\n/**\n * Remove duplicate consecutive lines (keeps first occurrence).\n */\nexport function removeDuplicateLines(text: string): string {\n\tconst lines = text.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet prevLine: string | undefined;\n\n\tfor (const line of lines) {\n\t\tif (line !== prevLine) {\n\t\t\tresult.push(line);\n\t\t\tprevLine = line;\n\t\t}\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Apply general lossless compression to any output.\n * Single-pass implementation for efficiency.\n */\nexport function compressGeneral(text: string): string {\n\tconst lines = text.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet blankCount = 0;\n\n\tfor (const line of lines) {\n\t\tconst trimmed = line.trimEnd();\n\n\t\tif (trimmed === \"\") {\n\t\t\tblankCount++;\n\t\t\t// Allow at most 2 consecutive blank lines\n\t\t\tif (blankCount <= 2) {\n\t\t\t\tresult.push(trimmed);\n\t\t\t}\n\t\t} else {\n\t\t\tblankCount = 0;\n\t\t\tresult.push(trimmed);\n\t\t}\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n// ============================================================================\n// Command-Specific Compression (bash only)\n// ============================================================================\n\n/**\n * Detect the primary command from a bash command string.\n */\nfunction detectCommand(command: string): string {\n\tconst trimmed = command.trim();\n\t// Strip leading env vars (FOO=bar command)\n\tconst withoutEnv = trimmed.replace(/^[A-Z_]+=\\S+\\s+/, \"\");\n\t// Strip leading sudo\n\tconst withoutSudo = withoutEnv.replace(/^sudo\\s+/, \"\");\n\t// Get first word (the actual command)\n\tconst firstWord = withoutSudo.split(/\\s+/)[0] ?? \"\";\n\t// Strip path prefix if any\n\treturn firstWord.split(\"/\").pop() ?? \"\";\n}\n\n/**\n * Compress npm/yarn/pnpm install output.\n * - Remove download progress lines\n * - Collapse \"added N packages\" summaries\n */\nfunction compressNpmInstall(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\n\tfor (const line of lines) {\n\t\t// Skip download progress (e.g., \"fetchMetadata: ...\", \"reify: ...\")\n\t\tif (/^(fetchMetadata|reify|audit|idealTree|sill|warn)\\b/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Skip verbose fetch/cache lines\n\t\tif (/^\\s*(http|https|fetch|cache|tarball|extract)\\b/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Keep everything else (errors, warnings, summaries)\n\t\tresult.push(line);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Compress git diff output.\n * - Strip file headers (diff --git, index, ---, +++)\n * - Collapse unchanged context lines\n */\nfunction compressGitDiff(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet contextCount = 0;\n\n\tfor (const line of lines) {\n\t\t// Skip git diff metadata\n\t\tif (/^(diff --git|index [0-9a-f]+|--- a\\/|\\+\\+\\+ b\\/)/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Count context lines (lines starting with space)\n\t\tif (line.startsWith(\" \") && !line.startsWith(\" \")) {\n\t\t\tcontextCount++;\n\t\t\t// Only show first 2 context lines per hunk, then skip\n\t\t\tif (contextCount > 2) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t} else {\n\t\t\tcontextCount = 0;\n\t\t}\n\n\t\tresult.push(line);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Compress cargo/rustc test output.\n * - Collapse passing tests, keep failures\n */\nfunction compressCargoTest(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet passingCount = 0;\n\n\tfor (const line of lines) {\n\t\t// Count passing test lines (e.g., \"test foo ... ok\")\n\t\tif (/^test\\s+.+\\s+\\.\\.\\.\\s+ok\\s*$/.test(line)) {\n\t\t\tpassingCount++;\n\t\t\tcontinue;\n\t\t}\n\t\t// Count ignored tests\n\t\tif (/^test\\s+.+\\s+\\.\\.\\.\\s+ignored\\s*$/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Show test summary line\n\t\tif (/^test result:/.test(line)) {\n\t\t\tresult.push(line);\n\t\t\tcontinue;\n\t\t}\n\t\t// Keep failures, errors, and everything else\n\t\tif (passingCount > 0 && line === \"\") {\n\t\t\t// Add summary before blank line\n\t\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t\t\tpassingCount = 0;\n\t\t}\n\t\tresult.push(line);\n\t}\n\n\t// Handle case where output ends with passing tests\n\tif (passingCount > 0) {\n\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Compress docker build output.\n * - Strip layer download progress\n * - Keep build steps and errors\n */\nfunction compressDockerBuild(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\n\tfor (const line of lines) {\n\t\t// Skip download progress (e.g., \"Downloading layer...\")\n\t\tif (/^(Downloading|Pulling|Extracting|Waiting|Verifying)/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Skip progress bars\n\t\tif (/[\\u2588\\u2591\\u2592]{10,}/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Keep build steps (FROM, RUN, COPY, etc.) and errors\n\t\tresult.push(line);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Compress jest/mocha test output.\n * - Collapse passing tests\n * - Keep failures\n */\nfunction compressJsTest(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet passingCount = 0;\n\n\tfor (const line of lines) {\n\t\t// Skip passing test indicators (✓, ✔, ○)\n\t\tif (/^\\s*[✓✔○●]\\s+/.test(line)) {\n\t\t\tpassingCount++;\n\t\t\tcontinue;\n\t\t}\n\t\t// Skip passing test lines (e.g., \" PASS src/foo.test.ts\")\n\t\tif (/^\\s*PASS\\s+/.test(line)) {\n\t\t\tpassingCount++;\n\t\t\tcontinue;\n\t\t}\n\t\t// Show test summary\n\t\tif (/^(Tests|Test Suites):/.test(line)) {\n\t\t\tresult.push(line);\n\t\t\tcontinue;\n\t\t}\n\t\t// Keep failures (×, ✗, FAIL) and everything else\n\t\tif (passingCount > 0 && (line.includes(\"FAIL\") || line.includes(\"×\") || line.includes(\"✗\"))) {\n\t\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t\t\tpassingCount = 0;\n\t\t}\n\t\tresult.push(line);\n\t}\n\n\tif (passingCount > 0) {\n\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Compress go test output.\n * - Collapse passing tests\n * - Keep failures\n */\nfunction compressGoTest(output: string): string {\n\tconst lines = output.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet passingCount = 0;\n\n\tfor (const line of lines) {\n\t\t// Skip passing test lines (e.g., \"--- PASS: TestFoo (0.00s)\")\n\t\tif (/^---\\s+PASS:/.test(line)) {\n\t\t\tpassingCount++;\n\t\t\tcontinue;\n\t\t}\n\t\t// Skip PASS lines\n\t\tif (/^PASS$/.test(line)) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Show test summary\n\t\tif (/^(ok|FAIL)\\s+/.test(line)) {\n\t\t\tresult.push(line);\n\t\t\tcontinue;\n\t\t}\n\t\t// Keep failures and everything else\n\t\tif (passingCount > 0 && line.includes(\"FAIL\")) {\n\t\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t\t\tpassingCount = 0;\n\t\t}\n\t\tresult.push(line);\n\t}\n\n\tif (passingCount > 0) {\n\t\tresult.push(` (${passingCount} passing tests omitted)`);\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Apply command-specific compression based on the detected command.\n */\nfunction compressCommandSpecific(command: string, output: string): string {\n\tconst cmd = detectCommand(command);\n\n\tswitch (cmd) {\n\t\tcase \"npm\":\n\t\tcase \"yarn\":\n\t\tcase \"pnpm\":\n\t\t\t// Check if it's an install/add command\n\t\t\tif (/\\b(install|add|i)\\b/.test(command)) {\n\t\t\t\treturn compressNpmInstall(output);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"git\":\n\t\t\t// Check if it's a diff command\n\t\t\tif (/\\bdiff\\b/.test(command)) {\n\t\t\t\treturn compressGitDiff(output);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"cargo\":\n\t\t\t// Check if it's a test command\n\t\t\tif (/\\btest\\b/.test(command)) {\n\t\t\t\treturn compressCargoTest(output);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"docker\":\n\t\t\t// Check if it's a build command\n\t\t\tif (/\\bbuild\\b/.test(command)) {\n\t\t\t\treturn compressDockerBuild(output);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"jest\":\n\t\tcase \"mocha\":\n\t\tcase \"vitest\":\n\t\tcase \"pytest\":\n\t\t\treturn compressJsTest(output);\n\t\tcase \"go\":\n\t\t\t// Check if it's a test command\n\t\t\tif (/\\btest\\b/.test(command)) {\n\t\t\t\treturn compressGoTest(output);\n\t\t\t}\n\t\t\tbreak;\n\t}\n\n\treturn output;\n}\n\n/**\n * Strip common noise patterns from any bash output.\n * This is applied to all commands regardless of detection.\n */\nfunction stripNoisePatterns(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t// Strip npm warnings (keep errors)\n\t\t\t.replace(/^npm (warn|notice) .+$/gm, \"\")\n\t\t\t// Strip yarn warnings\n\t\t\t.replace(/^warning .+$/gm, \"\")\n\t\t\t// Strip pnpm warnings\n\t\t\t.replace(/^pnpm (warn|notice) .+$/gm, \"\")\n\t\t\t// Strip common shell warnings\n\t\t\t.replace(/^bash: .+ warning: .+$/gm, \"\")\n\t\t\t// Strip \"The command completed with non-zero exit status\" noise\n\t\t\t.replace(/^The command exited with exit code .+$/gm, \"\")\n\t);\n}\n\n/**\n * Apply all compression to a bash command output.\n * This is the main entry point for bash output compression.\n *\n * @param command - The bash command that was executed\n * @param output - The raw output from the command\n * @returns Compressed output (lossless)\n */\nexport function compressBashOutput(command: string, output: string): string {\n\t// Skip compression for small outputs (overhead > savings)\n\tif (Buffer.byteLength(output, \"utf-8\") < MIN_COMPRESSION_SIZE) {\n\t\treturn output;\n\t}\n\n\tlet result = output;\n\n\t// Phase 1: Strip noise patterns\n\tresult = stripNoisePatterns(result);\n\n\t// Phase 2: Command-specific compression\n\tresult = compressCommandSpecific(command, result);\n\n\t// Phase 3: General compression\n\tresult = compressGeneral(result);\n\n\treturn result;\n}\n\n/**\n * Apply compression to grep output.\n * This strips redundant context and normalizes output.\n */\nexport function compressGrepOutput(output: string): string {\n\tif (Buffer.byteLength(output, \"utf-8\") < MIN_COMPRESSION_SIZE) {\n\t\treturn output;\n\t}\n\treturn compressGeneral(output);\n}\n\n/**\n * Apply compression to read output.\n * This normalizes whitespace but preserves content.\n */\nexport function compressReadOutput(output: string): string {\n\t// For read, we only do light compression - no line collapsing\n\tif (Buffer.byteLength(output, \"utf-8\") < MIN_COMPRESSION_SIZE) {\n\t\treturn output;\n\t}\n\treturn stripTrailingWhitespace(output);\n}\n\n/**\n * Apply compression to find output.\n * This normalizes paths and removes duplicates.\n */\nexport function compressFindOutput(output: string): string {\n\tif (Buffer.byteLength(output, \"utf-8\") < MIN_COMPRESSION_SIZE) {\n\t\treturn output;\n\t}\n\treturn compressGeneral(output);\n}\n\n/**\n * Apply compression to ls output.\n * This normalizes formatting.\n */\nexport function compressLsOutput(output: string): string {\n\tif (Buffer.byteLength(output, \"utf-8\") < MIN_COMPRESSION_SIZE) {\n\t\treturn output;\n\t}\n\treturn compressGeneral(output);\n}\n"]}
|