wotann 0.5.39 → 0.5.41
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/autopilot/completion-oracle.d.ts +71 -0
- package/dist/autopilot/completion-oracle.d.ts.map +1 -1
- package/dist/autopilot/completion-oracle.js +69 -2
- package/dist/autopilot/completion-oracle.js.map +1 -1
- package/dist/context/compaction-floor.d.ts +100 -0
- package/dist/context/compaction-floor.d.ts.map +1 -0
- package/dist/context/compaction-floor.js +94 -0
- package/dist/context/compaction-floor.js.map +1 -0
- package/dist/context/compaction.d.ts +27 -1
- package/dist/context/compaction.d.ts.map +1 -1
- package/dist/context/compaction.js +31 -0
- package/dist/context/compaction.js.map +1 -1
- package/dist/daemon/kairos-rpc.d.ts +1 -0
- package/dist/daemon/kairos-rpc.d.ts.map +1 -1
- package/dist/daemon/kairos-rpc.js +24 -0
- package/dist/daemon/kairos-rpc.js.map +1 -1
- package/dist/daemon/rpc-handlers/ports-rpc.d.ts +100 -0
- package/dist/daemon/rpc-handlers/ports-rpc.d.ts.map +1 -0
- package/dist/daemon/rpc-handlers/ports-rpc.js +278 -0
- package/dist/daemon/rpc-handlers/ports-rpc.js.map +1 -0
- package/dist/hooks/agentmemory-event-taxonomy.d.ts +144 -0
- package/dist/hooks/agentmemory-event-taxonomy.d.ts.map +1 -0
- package/dist/hooks/agentmemory-event-taxonomy.js +85 -0
- package/dist/hooks/agentmemory-event-taxonomy.js.map +1 -0
- package/dist/hooks/built-in.d.ts.map +1 -1
- package/dist/hooks/built-in.js +7 -3
- package/dist/hooks/built-in.js.map +1 -1
- package/dist/hooks/engine.d.ts +14 -0
- package/dist/hooks/engine.d.ts.map +1 -1
- package/dist/hooks/engine.js +62 -0
- package/dist/hooks/engine.js.map +1 -1
- package/dist/index.js +91 -2
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/memory/injection-scanner.d.ts +78 -0
- package/dist/memory/injection-scanner.d.ts.map +1 -0
- package/dist/memory/injection-scanner.js +204 -0
- package/dist/memory/injection-scanner.js.map +1 -0
- package/dist/middleware/output-truncation.d.ts +18 -5
- package/dist/middleware/output-truncation.d.ts.map +1 -1
- package/dist/middleware/output-truncation.js +73 -1
- package/dist/middleware/output-truncation.js.map +1 -1
- package/dist/middleware/ttsr.d.ts +79 -3
- package/dist/middleware/ttsr.d.ts.map +1 -1
- package/dist/middleware/ttsr.js +136 -16
- package/dist/middleware/ttsr.js.map +1 -1
- package/dist/orchestration/autonomous.d.ts +182 -0
- package/dist/orchestration/autonomous.d.ts.map +1 -1
- package/dist/orchestration/autonomous.js +288 -1
- package/dist/orchestration/autonomous.js.map +1 -1
- package/dist/orchestration/ports-bridge.d.ts +325 -0
- package/dist/orchestration/ports-bridge.d.ts.map +1 -0
- package/dist/orchestration/ports-bridge.js +712 -0
- package/dist/orchestration/ports-bridge.js.map +1 -0
- package/dist/orchestration/textgrad-refinement.d.ts +123 -0
- package/dist/orchestration/textgrad-refinement.d.ts.map +1 -0
- package/dist/orchestration/textgrad-refinement.js +111 -0
- package/dist/orchestration/textgrad-refinement.js.map +1 -0
- package/dist/prompt/engine.d.ts +15 -0
- package/dist/prompt/engine.d.ts.map +1 -1
- package/dist/prompt/engine.js +20 -7
- package/dist/prompt/engine.js.map +1 -1
- package/dist/prompt/modules/capabilities.d.ts.map +1 -1
- package/dist/prompt/modules/capabilities.js +1 -0
- package/dist/prompt/modules/capabilities.js.map +1 -1
- package/dist/prompt/modules/caveman.d.ts.map +1 -1
- package/dist/prompt/modules/caveman.js +1 -0
- package/dist/prompt/modules/caveman.js.map +1 -1
- package/dist/prompt/modules/conventions.d.ts.map +1 -1
- package/dist/prompt/modules/conventions.js +1 -0
- package/dist/prompt/modules/conventions.js.map +1 -1
- package/dist/prompt/modules/identity.d.ts.map +1 -1
- package/dist/prompt/modules/identity.js +1 -0
- package/dist/prompt/modules/identity.js.map +1 -1
- package/dist/prompt/modules/index.d.ts +29 -0
- package/dist/prompt/modules/index.d.ts.map +1 -1
- package/dist/prompt/modules/index.js +51 -9
- package/dist/prompt/modules/index.js.map +1 -1
- package/dist/prompt/modules/llms-txt.d.ts.map +1 -1
- package/dist/prompt/modules/llms-txt.js +2 -4
- package/dist/prompt/modules/llms-txt.js.map +1 -1
- package/dist/prompt/modules/safety.d.ts.map +1 -1
- package/dist/prompt/modules/safety.js +1 -0
- package/dist/prompt/modules/safety.js.map +1 -1
- package/dist/prompt/modules/security.d.ts.map +1 -1
- package/dist/prompt/modules/security.js +1 -0
- package/dist/prompt/modules/security.js.map +1 -1
- package/dist/prompt/modules/skills.d.ts.map +1 -1
- package/dist/prompt/modules/skills.js +1 -0
- package/dist/prompt/modules/skills.js.map +1 -1
- package/dist/prompt/modules/tools.d.ts.map +1 -1
- package/dist/prompt/modules/tools.js +1 -0
- package/dist/prompt/modules/tools.js.map +1 -1
- package/dist/prompt/modules/user.d.ts.map +1 -1
- package/dist/prompt/modules/user.js +1 -0
- package/dist/prompt/modules/user.js.map +1 -1
- package/dist/providers/credential-pool.d.ts +45 -1
- package/dist/providers/credential-pool.d.ts.map +1 -1
- package/dist/providers/credential-pool.js +94 -1
- package/dist/providers/credential-pool.js.map +1 -1
- package/dist/providers/sticky-rotation-wire.d.ts +133 -0
- package/dist/providers/sticky-rotation-wire.d.ts.map +1 -0
- package/dist/providers/sticky-rotation-wire.js +185 -0
- package/dist/providers/sticky-rotation-wire.js.map +1 -0
- package/dist/runtime-hooks/ttsr-rule.d.ts +82 -0
- package/dist/runtime-hooks/ttsr-rule.d.ts.map +1 -0
- package/dist/runtime-hooks/ttsr-rule.js +207 -0
- package/dist/runtime-hooks/ttsr-rule.js.map +1 -0
- package/dist/runtime-hooks/ttsr-runner.d.ts +129 -0
- package/dist/runtime-hooks/ttsr-runner.d.ts.map +1 -0
- package/dist/runtime-hooks/ttsr-runner.js +193 -0
- package/dist/runtime-hooks/ttsr-runner.js.map +1 -0
- package/dist/runtime-hooks/ttsr-scope.d.ts +115 -0
- package/dist/runtime-hooks/ttsr-scope.d.ts.map +1 -0
- package/dist/runtime-hooks/ttsr-scope.js +378 -0
- package/dist/runtime-hooks/ttsr-scope.js.map +1 -0
- package/dist/sandbox/unified-exec.d.ts.map +1 -1
- package/dist/sandbox/unified-exec.js +6 -1
- package/dist/sandbox/unified-exec.js.map +1 -1
- package/dist/skills/cli-anything.d.ts.map +1 -1
- package/dist/skills/cli-anything.js +4 -1
- package/dist/skills/cli-anything.js.map +1 -1
- package/dist/skills/limits.d.ts +86 -0
- package/dist/skills/limits.d.ts.map +1 -0
- package/dist/skills/limits.js +140 -0
- package/dist/skills/limits.js.map +1 -0
- package/dist/skills/loader.d.ts +9 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +29 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/storage/session-artifacts.d.ts +105 -0
- package/dist/storage/session-artifacts.d.ts.map +1 -0
- package/dist/storage/session-artifacts.js +198 -0
- package/dist/storage/session-artifacts.js.map +1 -0
- package/dist/tools/workspace-pack.d.ts +97 -0
- package/dist/tools/workspace-pack.d.ts.map +1 -0
- package/dist/tools/workspace-pack.js +228 -0
- package/dist/tools/workspace-pack.js.map +1 -0
- package/dist/tui/composer-history.d.ts +99 -0
- package/dist/tui/composer-history.d.ts.map +1 -0
- package/dist/tui/composer-history.js +169 -0
- package/dist/tui/composer-history.js.map +1 -0
- package/dist/ui/components/PromptInput.d.ts.map +1 -1
- package/dist/ui/components/PromptInput.js +80 -9
- package/dist/ui/components/PromptInput.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ports-rpc — daemon JSON-RPC handlers wiring 4 zombie ports (audit
|
|
3
|
+
* finding #8 closure) into the agent's tool surface.
|
|
4
|
+
*
|
|
5
|
+
* Each handler delegates to a bridge function from
|
|
6
|
+
* `src/orchestration/ports-bridge.ts`. The bridges construct the
|
|
7
|
+
* dependency-injected primitive (ConverseFn, ResearchPipeline,
|
|
8
|
+
* GraphStore, DomAdapter) from the business-level RPC payload — JSON
|
|
9
|
+
* cannot transport callbacks, so the bridge is the seam.
|
|
10
|
+
*
|
|
11
|
+
* Methods registered:
|
|
12
|
+
* - ports.chatdev.run — runs a ChatDev waterfall (default 5-phase
|
|
13
|
+
* or a caller-supplied phase override).
|
|
14
|
+
* - ports.research.run — runs the deer-flow research pipeline
|
|
15
|
+
* (planner -> parallel researchers -> reporter).
|
|
16
|
+
* - ports.memgraph.ingest — ingests text into a mem0-style graph
|
|
17
|
+
* memory; returns triples + 2-hop neighborhoods.
|
|
18
|
+
* - ports.scrapling.locate — adaptively locates a DOM node within a
|
|
19
|
+
* caller-supplied snapshot.
|
|
20
|
+
*
|
|
21
|
+
* Quality bars honored:
|
|
22
|
+
* QB #3 honest stub — every handler reports an `ok:false` envelope
|
|
23
|
+
* when the bridge can't reach a real dependency (e.g. research
|
|
24
|
+
* with no search provider). No silent success.
|
|
25
|
+
* QB #5 structured failure envelopes for missing/invalid params.
|
|
26
|
+
* QB #6 invalid-params throws `-32602` (JSON-RPC standard).
|
|
27
|
+
* QB #7 zero module-level mutable state — each `registerPortsHandlers`
|
|
28
|
+
* call instantiates its own handler-set; runtime ref is closed
|
|
29
|
+
* over lazily.
|
|
30
|
+
* QB #14 real-code-path tests in `tests/daemon/rpc-handlers/ports-rpc.test.ts`
|
|
31
|
+
* register a fresh map and exercise every handler.
|
|
32
|
+
*
|
|
33
|
+
* The runtime ref is plumbed through `getRuntime` (same pattern as
|
|
34
|
+
* intelligence-rpc.ts). When the runtime is unreachable, handlers that
|
|
35
|
+
* benefit from LLM augmentation (chatdev runtime mode, research planner)
|
|
36
|
+
* fall back to honest envelopes — they never invent LLM output.
|
|
37
|
+
*/
|
|
38
|
+
import { type DomSnapshot, type RuntimeConverseRef } from "../../orchestration/ports-bridge.js";
|
|
39
|
+
import type { SearchProvider } from "../../intelligence/research-loops/strategies/base-strategy.js";
|
|
40
|
+
import type { WotannRuntime } from "../../core/runtime.js";
|
|
41
|
+
export type Handler = (params: Record<string, unknown>) => Promise<unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Narrow runtime ref the handlers need: just the streaming text-in /
|
|
44
|
+
* text-out callable. We adapt the full WotannRuntime to this shape so
|
|
45
|
+
* tests can pass a tiny mock.
|
|
46
|
+
*/
|
|
47
|
+
export interface PortsRuntimeRef {
|
|
48
|
+
/** Adapt the full runtime into the bridge's converse shape. */
|
|
49
|
+
toConverseRef(): RuntimeConverseRef;
|
|
50
|
+
}
|
|
51
|
+
export interface PortsHandlersOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the live runtime. Same lazy-getter pattern as
|
|
54
|
+
* intelligence-rpc.ts so a not-yet-wired runtime returns null
|
|
55
|
+
* gracefully without throwing during registration.
|
|
56
|
+
*/
|
|
57
|
+
readonly getRuntime?: () => WotannRuntime | null;
|
|
58
|
+
/**
|
|
59
|
+
* Optional explicit converse ref — used by tests to inject a stub
|
|
60
|
+
* without constructing a WotannRuntime. If supplied, this takes
|
|
61
|
+
* precedence over `getRuntime`.
|
|
62
|
+
*/
|
|
63
|
+
readonly getConverseRef?: () => RuntimeConverseRef | null;
|
|
64
|
+
/**
|
|
65
|
+
* Optional explicit search provider — used by tests and by deployments
|
|
66
|
+
* that don't want to read the WOTANN_SEARCH_PROVIDER env. When absent
|
|
67
|
+
* the handlers call `createDefaultWebSearchProvider()` which reads
|
|
68
|
+
* BRAVE_API_KEY / TAVILY_API_KEY from the environment. If no keys are
|
|
69
|
+
* set, the search provider is null and the research handler returns
|
|
70
|
+
* an honest ok:false envelope.
|
|
71
|
+
*/
|
|
72
|
+
readonly getSearchProvider?: () => SearchProvider | null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a {@link RuntimeConverseRef} that drives the WotannRuntime's
|
|
76
|
+
* `query()` async generator. Streams text chunks; concatenates and
|
|
77
|
+
* returns one string. Throws on any error chunk (the bridge catches
|
|
78
|
+
* and stamps it onto the phase outcome per QB#10).
|
|
79
|
+
*/
|
|
80
|
+
declare function adaptRuntime(runtime: WotannRuntime): RuntimeConverseRef;
|
|
81
|
+
declare function asDomSnapshot(x: unknown): DomSnapshot;
|
|
82
|
+
export declare function createPortsHandlers(options?: PortsHandlersOptions): {
|
|
83
|
+
readonly handlers: Readonly<Record<string, Handler>>;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Register the 4 ports.* handlers onto the given handler map. Mirrors
|
|
87
|
+
* the {@link registerIntelligenceHandlers} shape — a single import +
|
|
88
|
+
* a single call from kairos-rpc.ts.
|
|
89
|
+
*
|
|
90
|
+
* Idempotent: re-registering overwrites the existing entries with the
|
|
91
|
+
* new handler-set's bound closures.
|
|
92
|
+
*/
|
|
93
|
+
export declare function registerPortsHandlers(handlers: Map<string, Handler>, options?: PortsHandlersOptions): void;
|
|
94
|
+
export declare const _testOnly: {
|
|
95
|
+
readonly adaptRuntime: typeof adaptRuntime;
|
|
96
|
+
readonly asDomSnapshot: typeof asDomSnapshot;
|
|
97
|
+
readonly createPortsHandlers: typeof createPortsHandlers;
|
|
98
|
+
};
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=ports-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports-rpc.d.ts","sourceRoot":"","sources":["../../../src/daemon/rpc-handlers/ports-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAOL,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EAExB,MAAM,qCAAqC,CAAC;AAI7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+DAA+D,CAAC;AACpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAQ5E;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,aAAa,IAAI,kBAAkB,CAAC;CACrC;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,aAAa,GAAG,IAAI,CAAC;IACjD;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAC1D;;;;;;;OAOG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC;CAC1D;AAwCD;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,kBAAkB,CAmBhE;AAyBD,iBAAS,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,WAAW,CAe9C;AAID,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG;IACvE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACtD,CA4HA;AAID;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,GAAE,oBAAyB,GACjC,IAAI,CAKN;AAID,eAAO,MAAM,SAAS;;;;CAIZ,CAAC"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ports-rpc — daemon JSON-RPC handlers wiring 4 zombie ports (audit
|
|
3
|
+
* finding #8 closure) into the agent's tool surface.
|
|
4
|
+
*
|
|
5
|
+
* Each handler delegates to a bridge function from
|
|
6
|
+
* `src/orchestration/ports-bridge.ts`. The bridges construct the
|
|
7
|
+
* dependency-injected primitive (ConverseFn, ResearchPipeline,
|
|
8
|
+
* GraphStore, DomAdapter) from the business-level RPC payload — JSON
|
|
9
|
+
* cannot transport callbacks, so the bridge is the seam.
|
|
10
|
+
*
|
|
11
|
+
* Methods registered:
|
|
12
|
+
* - ports.chatdev.run — runs a ChatDev waterfall (default 5-phase
|
|
13
|
+
* or a caller-supplied phase override).
|
|
14
|
+
* - ports.research.run — runs the deer-flow research pipeline
|
|
15
|
+
* (planner -> parallel researchers -> reporter).
|
|
16
|
+
* - ports.memgraph.ingest — ingests text into a mem0-style graph
|
|
17
|
+
* memory; returns triples + 2-hop neighborhoods.
|
|
18
|
+
* - ports.scrapling.locate — adaptively locates a DOM node within a
|
|
19
|
+
* caller-supplied snapshot.
|
|
20
|
+
*
|
|
21
|
+
* Quality bars honored:
|
|
22
|
+
* QB #3 honest stub — every handler reports an `ok:false` envelope
|
|
23
|
+
* when the bridge can't reach a real dependency (e.g. research
|
|
24
|
+
* with no search provider). No silent success.
|
|
25
|
+
* QB #5 structured failure envelopes for missing/invalid params.
|
|
26
|
+
* QB #6 invalid-params throws `-32602` (JSON-RPC standard).
|
|
27
|
+
* QB #7 zero module-level mutable state — each `registerPortsHandlers`
|
|
28
|
+
* call instantiates its own handler-set; runtime ref is closed
|
|
29
|
+
* over lazily.
|
|
30
|
+
* QB #14 real-code-path tests in `tests/daemon/rpc-handlers/ports-rpc.test.ts`
|
|
31
|
+
* register a fresh map and exercise every handler.
|
|
32
|
+
*
|
|
33
|
+
* The runtime ref is plumbed through `getRuntime` (same pattern as
|
|
34
|
+
* intelligence-rpc.ts). When the runtime is unreachable, handlers that
|
|
35
|
+
* benefit from LLM augmentation (chatdev runtime mode, research planner)
|
|
36
|
+
* fall back to honest envelopes — they never invent LLM output.
|
|
37
|
+
*/
|
|
38
|
+
import { runChatDevWaterfall, runDeerFlowResearch, ingestTextToMemGraph, adaptiveLocateOnDom, } from "../../orchestration/ports-bridge.js";
|
|
39
|
+
import { createDefaultWebSearchProvider } from "../../intelligence/search-providers.js";
|
|
40
|
+
const RPC_INVALID_PARAMS = -32602;
|
|
41
|
+
function rpcInvalidParams(message) {
|
|
42
|
+
return Object.assign(new Error(message), { code: RPC_INVALID_PARAMS });
|
|
43
|
+
}
|
|
44
|
+
// ── Helpers ──────────────────────────────────────────────
|
|
45
|
+
function asString(x) {
|
|
46
|
+
return typeof x === "string" && x.length > 0 ? x : undefined;
|
|
47
|
+
}
|
|
48
|
+
function requireString(x, field, method) {
|
|
49
|
+
const v = asString(x);
|
|
50
|
+
if (v === undefined) {
|
|
51
|
+
throw rpcInvalidParams(`${method}: '${field}' is required (non-empty string)`);
|
|
52
|
+
}
|
|
53
|
+
return v;
|
|
54
|
+
}
|
|
55
|
+
function asObject(x) {
|
|
56
|
+
return x !== null && typeof x === "object" && !Array.isArray(x)
|
|
57
|
+
? x
|
|
58
|
+
: {};
|
|
59
|
+
}
|
|
60
|
+
function asArray(x) {
|
|
61
|
+
return Array.isArray(x) ? x : [];
|
|
62
|
+
}
|
|
63
|
+
function asBoolean(x, fallback) {
|
|
64
|
+
return typeof x === "boolean" ? x : fallback;
|
|
65
|
+
}
|
|
66
|
+
function asPositiveInt(x) {
|
|
67
|
+
return typeof x === "number" && Number.isFinite(x) && Number.isInteger(x) && x > 0
|
|
68
|
+
? x
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
function asNumber(x) {
|
|
72
|
+
return typeof x === "number" && Number.isFinite(x) ? x : undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a {@link RuntimeConverseRef} that drives the WotannRuntime's
|
|
76
|
+
* `query()` async generator. Streams text chunks; concatenates and
|
|
77
|
+
* returns one string. Throws on any error chunk (the bridge catches
|
|
78
|
+
* and stamps it onto the phase outcome per QB#10).
|
|
79
|
+
*/
|
|
80
|
+
function adaptRuntime(runtime) {
|
|
81
|
+
return {
|
|
82
|
+
complete: async (prompt, systemPrompt) => {
|
|
83
|
+
let out = "";
|
|
84
|
+
let firstError = null;
|
|
85
|
+
for await (const chunk of runtime.query({ prompt, systemPrompt })) {
|
|
86
|
+
if (chunk.type === "text") {
|
|
87
|
+
out += chunk.content;
|
|
88
|
+
}
|
|
89
|
+
else if (chunk.type === "error") {
|
|
90
|
+
firstError = chunk.content;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (firstError !== null) {
|
|
95
|
+
throw new Error(firstError);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// ── DomSnapshot validation ───────────────────────────────
|
|
102
|
+
function asDomSnapshotNode(x, path) {
|
|
103
|
+
const obj = asObject(x);
|
|
104
|
+
const tag = asString(obj["tag"]);
|
|
105
|
+
if (!tag) {
|
|
106
|
+
throw rpcInvalidParams(`ports.scrapling.locate: ${path}.tag is required`);
|
|
107
|
+
}
|
|
108
|
+
const classesRaw = asArray(obj["classes"]);
|
|
109
|
+
const classes = classesRaw.filter((c) => typeof c === "string");
|
|
110
|
+
const text = asString(obj["text"]) ?? "";
|
|
111
|
+
const childrenRaw = asArray(obj["children"]);
|
|
112
|
+
const children = childrenRaw.map((c, i) => asDomSnapshotNode(c, `${path}.children[${i}]`));
|
|
113
|
+
const id = asString(obj["id"]);
|
|
114
|
+
return {
|
|
115
|
+
tag,
|
|
116
|
+
classes,
|
|
117
|
+
text,
|
|
118
|
+
children,
|
|
119
|
+
...(id !== undefined ? { id } : {}),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function asDomSnapshot(x) {
|
|
123
|
+
const obj = asObject(x);
|
|
124
|
+
if (!obj["root"]) {
|
|
125
|
+
throw rpcInvalidParams("ports.scrapling.locate: 'domSnapshot.root' is required");
|
|
126
|
+
}
|
|
127
|
+
const root = asDomSnapshotNode(obj["root"], "domSnapshot.root");
|
|
128
|
+
const seedsRaw = asArray(obj["seeds"]);
|
|
129
|
+
const seeds = seedsRaw
|
|
130
|
+
.map((s) => asObject(s))
|
|
131
|
+
.map((s) => ({
|
|
132
|
+
label: asString(s["label"]) ?? "",
|
|
133
|
+
selector: asString(s["selector"]) ?? "",
|
|
134
|
+
}))
|
|
135
|
+
.filter((s) => s.label.length > 0 && s.selector.length > 0);
|
|
136
|
+
return seeds.length > 0 ? { root, seeds } : { root };
|
|
137
|
+
}
|
|
138
|
+
// ── Handler factory ──────────────────────────────────────
|
|
139
|
+
export function createPortsHandlers(options = {}) {
|
|
140
|
+
// Per-instance: resolve the converse ref lazily so a not-yet-wired
|
|
141
|
+
// runtime can become available between handler-set creation and the
|
|
142
|
+
// first dispatch.
|
|
143
|
+
function resolveConverseRef() {
|
|
144
|
+
if (options.getConverseRef) {
|
|
145
|
+
const explicit = options.getConverseRef();
|
|
146
|
+
if (explicit)
|
|
147
|
+
return explicit;
|
|
148
|
+
}
|
|
149
|
+
if (options.getRuntime) {
|
|
150
|
+
const runtime = options.getRuntime();
|
|
151
|
+
if (runtime)
|
|
152
|
+
return adaptRuntime(runtime);
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function resolveSearchProvider() {
|
|
157
|
+
if (options.getSearchProvider) {
|
|
158
|
+
return options.getSearchProvider();
|
|
159
|
+
}
|
|
160
|
+
const webProvider = createDefaultWebSearchProvider();
|
|
161
|
+
if (!webProvider)
|
|
162
|
+
return null;
|
|
163
|
+
// Adapt the WebSearchProvider shape (returns SearchHit[]) into the
|
|
164
|
+
// strategy SearchProvider shape (callback). Both already use the
|
|
165
|
+
// same SearchHit type re-exported from deep-research.
|
|
166
|
+
return async (query) => {
|
|
167
|
+
try {
|
|
168
|
+
return await webProvider.search(query);
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const handleChatDevRun = async (params) => {
|
|
176
|
+
const query = requireString(params["query"], "query", "ports.chatdev.run");
|
|
177
|
+
const specRaw = params["spec"];
|
|
178
|
+
let spec;
|
|
179
|
+
if (specRaw !== undefined) {
|
|
180
|
+
const specObj = asObject(specRaw);
|
|
181
|
+
const phasesRaw = asArray(specObj["phases"]);
|
|
182
|
+
const phases = phasesRaw
|
|
183
|
+
.map((p, i) => {
|
|
184
|
+
const o = asObject(p);
|
|
185
|
+
return {
|
|
186
|
+
id: asString(o["id"]) ?? `phase-${i}`,
|
|
187
|
+
description: asString(o["description"]) ?? "",
|
|
188
|
+
initiatorId: asString(o["initiatorId"]) ?? "",
|
|
189
|
+
responderId: asString(o["responderId"]) ?? "",
|
|
190
|
+
};
|
|
191
|
+
})
|
|
192
|
+
.filter((p) => p.initiatorId.length > 0 && p.responderId.length > 0);
|
|
193
|
+
const globalCharter = asString(specObj["globalCharter"]);
|
|
194
|
+
spec = {
|
|
195
|
+
...(phases.length > 0 ? { phases } : {}),
|
|
196
|
+
...(globalCharter !== undefined ? { globalCharter } : {}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const forceFixture = asBoolean(params["forceFixture"], false);
|
|
200
|
+
// When forceFixture is false (default) we use the runtime if reachable;
|
|
201
|
+
// otherwise we silently fall back to fixture mode. The result envelope
|
|
202
|
+
// tells the caller WHICH mode was used so they can decide whether to
|
|
203
|
+
// re-issue with a real runtime attached.
|
|
204
|
+
const converseRef = forceFixture ? null : resolveConverseRef();
|
|
205
|
+
const result = await runChatDevWaterfall(spec, query, {
|
|
206
|
+
forceFixture,
|
|
207
|
+
...(converseRef ? { runtime: converseRef } : {}),
|
|
208
|
+
});
|
|
209
|
+
return result;
|
|
210
|
+
};
|
|
211
|
+
const handleResearchRun = async (params) => {
|
|
212
|
+
const query = requireString(params["query"], "query", "ports.research.run");
|
|
213
|
+
const forceFixture = asBoolean(params["forceFixture"], false);
|
|
214
|
+
const maxSubQuestions = asPositiveInt(params["maxSubQuestions"]);
|
|
215
|
+
const converseRef = forceFixture ? null : resolveConverseRef();
|
|
216
|
+
const searchProvider = forceFixture ? null : resolveSearchProvider();
|
|
217
|
+
const bridgeOptions = {
|
|
218
|
+
forceFixture,
|
|
219
|
+
...(converseRef ? { runtime: converseRef } : {}),
|
|
220
|
+
...(searchProvider ? { searchProvider } : {}),
|
|
221
|
+
...(maxSubQuestions !== undefined ? { maxSubQuestions } : {}),
|
|
222
|
+
};
|
|
223
|
+
return await runDeerFlowResearch(query, bridgeOptions);
|
|
224
|
+
};
|
|
225
|
+
const handleMemGraphIngest = async (params) => {
|
|
226
|
+
const text = requireString(params["text"], "text", "ports.memgraph.ingest");
|
|
227
|
+
const persist = asBoolean(params["persist"], false);
|
|
228
|
+
const turnId = asString(params["turnId"]);
|
|
229
|
+
const persistencePath = asString(params["persistencePath"]);
|
|
230
|
+
return await ingestTextToMemGraph(text, {
|
|
231
|
+
persist,
|
|
232
|
+
...(turnId !== undefined ? { turnId } : {}),
|
|
233
|
+
...(persistencePath !== undefined ? { persistencePath } : {}),
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
const handleScraplingLocate = async (params) => {
|
|
237
|
+
const snapshotRaw = params["domSnapshot"];
|
|
238
|
+
if (snapshotRaw === undefined || snapshotRaw === null) {
|
|
239
|
+
throw rpcInvalidParams("ports.scrapling.locate: 'domSnapshot' is required");
|
|
240
|
+
}
|
|
241
|
+
const snapshot = asDomSnapshot(snapshotRaw);
|
|
242
|
+
const queryRaw = asObject(params["query"]);
|
|
243
|
+
const label = requireString(queryRaw["label"], "query.label", "ports.scrapling.locate");
|
|
244
|
+
const selector = asString(queryRaw["selector"]);
|
|
245
|
+
const minScore = asNumber(params["minScore"]);
|
|
246
|
+
const opts = minScore !== undefined ? { minScore } : {};
|
|
247
|
+
return await adaptiveLocateOnDom(snapshot, selector !== undefined ? { label, selector } : { label }, opts);
|
|
248
|
+
};
|
|
249
|
+
const handlers = {
|
|
250
|
+
"ports.chatdev.run": handleChatDevRun,
|
|
251
|
+
"ports.research.run": handleResearchRun,
|
|
252
|
+
"ports.memgraph.ingest": handleMemGraphIngest,
|
|
253
|
+
"ports.scrapling.locate": handleScraplingLocate,
|
|
254
|
+
};
|
|
255
|
+
return { handlers };
|
|
256
|
+
}
|
|
257
|
+
// ── Registration ────────────────────────────────────────
|
|
258
|
+
/**
|
|
259
|
+
* Register the 4 ports.* handlers onto the given handler map. Mirrors
|
|
260
|
+
* the {@link registerIntelligenceHandlers} shape — a single import +
|
|
261
|
+
* a single call from kairos-rpc.ts.
|
|
262
|
+
*
|
|
263
|
+
* Idempotent: re-registering overwrites the existing entries with the
|
|
264
|
+
* new handler-set's bound closures.
|
|
265
|
+
*/
|
|
266
|
+
export function registerPortsHandlers(handlers, options = {}) {
|
|
267
|
+
const { handlers: built } = createPortsHandlers(options);
|
|
268
|
+
for (const [method, handler] of Object.entries(built)) {
|
|
269
|
+
handlers.set(method, handler);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// ── Test-only exports ───────────────────────────────────
|
|
273
|
+
export const _testOnly = {
|
|
274
|
+
adaptRuntime,
|
|
275
|
+
asDomSnapshot,
|
|
276
|
+
createPortsHandlers,
|
|
277
|
+
};
|
|
278
|
+
//# sourceMappingURL=ports-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports-rpc.js","sourceRoot":"","sources":["../../../src/daemon/rpc-handlers/ports-rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,GAOpB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AASxF,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AAElC,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;AACzE,CAAC;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D;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA8B,EAC9B,UAAgC,EAAE;IAElC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACzD,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED,2DAA2D;AAE3D,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,YAAY;IACZ,aAAa;IACb,mBAAmB;CACX,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentmemory event taxonomy — ported from rohitg00/agentmemory's hook engine
|
|
3
|
+
* (plugin/hooks/hooks.json + src/hooks/*.ts).
|
|
4
|
+
*
|
|
5
|
+
* WHAT: The canonical 12-event schema that a hook engine emits to a memory
|
|
6
|
+
* backend. Each event is a discriminated union over the `event` field, so
|
|
7
|
+
* the receiver can fan out per-type handlers with full type safety.
|
|
8
|
+
*
|
|
9
|
+
* WHY: We're not porting the agentmemory backend (HTTP endpoints, REST
|
|
10
|
+
* client, image-data extraction) — those are integration-specific and
|
|
11
|
+
* live in a follow-up. What's portable today is the *taxonomy* itself:
|
|
12
|
+
* the 12 canonical event names plus the per-event payload shape. Pinning
|
|
13
|
+
* the schema in WOTANN now lets the hook engine, the memory backend, and
|
|
14
|
+
* any future plugins all speak the same vocabulary.
|
|
15
|
+
*
|
|
16
|
+
* WHERE: The hook engine emits these events; consumers (memory store,
|
|
17
|
+
* audit log, telemetry) subscribe. The TypeScript discriminated union
|
|
18
|
+
* lets a single switch statement cover every event type with exhaustive
|
|
19
|
+
* checking.
|
|
20
|
+
*
|
|
21
|
+
* HOW: `AGENTMEMORY_EVENT_TYPES` is a const tuple of the 12 strings,
|
|
22
|
+
* `AgentMemoryEventType` is its string-literal union, and
|
|
23
|
+
* `AgentMemoryEvent<T>` is the per-event payload shape keyed by `event`.
|
|
24
|
+
* `isAgentMemoryEvent` is a structural type guard for runtime validation
|
|
25
|
+
* (boundary use only — internal code should rely on the static union).
|
|
26
|
+
* `serializeEvent` produces a JSON string with sorted keys so identical
|
|
27
|
+
* events hash identically — useful for dedup and audit.
|
|
28
|
+
*
|
|
29
|
+
* NOTE: The user-spec deviates from the upstream taxonomy in one place:
|
|
30
|
+
* we expose `diagnostics` instead of `notification`. The intent is to
|
|
31
|
+
* reserve a generic "engine emitted a diagnostic" channel; the upstream
|
|
32
|
+
* `notification` carried Claude Code permission prompts specifically,
|
|
33
|
+
* which doesn't generalise. The 11 other events match the upstream 1:1.
|
|
34
|
+
*/
|
|
35
|
+
/** The 12 canonical event names, in the order they appear in the hook flow. */
|
|
36
|
+
export declare const AGENTMEMORY_EVENT_TYPES: readonly ["pre-tool-use", "post-tool-use", "post-tool-failure", "pre-compact", "prompt-submit", "session-start", "session-end", "stop", "subagent-start", "subagent-stop", "task-completed", "diagnostics"];
|
|
37
|
+
/** String-literal union over the 12 canonical event names. */
|
|
38
|
+
export type AgentMemoryEventType = (typeof AGENTMEMORY_EVENT_TYPES)[number];
|
|
39
|
+
interface BaseEventFields {
|
|
40
|
+
readonly sessionId: string;
|
|
41
|
+
readonly cwd?: string;
|
|
42
|
+
readonly timestamp?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface PreToolUsePayload extends BaseEventFields {
|
|
45
|
+
readonly toolName: string;
|
|
46
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
47
|
+
}
|
|
48
|
+
export interface PostToolUsePayload extends BaseEventFields {
|
|
49
|
+
readonly toolName: string;
|
|
50
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
51
|
+
readonly output: unknown;
|
|
52
|
+
}
|
|
53
|
+
export interface PostToolFailurePayload extends BaseEventFields {
|
|
54
|
+
readonly toolName: string;
|
|
55
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
56
|
+
readonly error: string;
|
|
57
|
+
}
|
|
58
|
+
export interface PreCompactPayload extends BaseEventFields {
|
|
59
|
+
readonly tokensUsed?: number;
|
|
60
|
+
readonly tokensWindow?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface PromptSubmitPayload extends BaseEventFields {
|
|
63
|
+
readonly prompt: string;
|
|
64
|
+
}
|
|
65
|
+
export interface SessionStartPayload extends BaseEventFields {
|
|
66
|
+
readonly entrypoint?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface SessionEndPayload extends BaseEventFields {
|
|
69
|
+
readonly reason?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface StopPayload extends BaseEventFields {
|
|
72
|
+
readonly lastAssistantMessage?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface SubagentStartPayload extends BaseEventFields {
|
|
75
|
+
readonly agentId: string;
|
|
76
|
+
readonly agentType?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface SubagentStopPayload extends BaseEventFields {
|
|
79
|
+
readonly agentId: string;
|
|
80
|
+
readonly agentType?: string;
|
|
81
|
+
readonly lastMessage?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface TaskCompletedPayload extends BaseEventFields {
|
|
84
|
+
readonly taskId: string;
|
|
85
|
+
readonly taskSubject?: string;
|
|
86
|
+
readonly taskDescription?: string;
|
|
87
|
+
readonly teammateName?: string;
|
|
88
|
+
readonly teamName?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface DiagnosticsPayload extends BaseEventFields {
|
|
91
|
+
/** Diagnostic level — info / warn / error. Free string to keep flexibility. */
|
|
92
|
+
readonly level: "info" | "warn" | "error";
|
|
93
|
+
readonly message: string;
|
|
94
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Lookup table: maps each event name to its payload shape. Used internally
|
|
98
|
+
* to derive `AgentMemoryEvent<T>`; not intended for direct consumer use.
|
|
99
|
+
*/
|
|
100
|
+
interface PayloadMap {
|
|
101
|
+
readonly "pre-tool-use": PreToolUsePayload;
|
|
102
|
+
readonly "post-tool-use": PostToolUsePayload;
|
|
103
|
+
readonly "post-tool-failure": PostToolFailurePayload;
|
|
104
|
+
readonly "pre-compact": PreCompactPayload;
|
|
105
|
+
readonly "prompt-submit": PromptSubmitPayload;
|
|
106
|
+
readonly "session-start": SessionStartPayload;
|
|
107
|
+
readonly "session-end": SessionEndPayload;
|
|
108
|
+
readonly stop: StopPayload;
|
|
109
|
+
readonly "subagent-start": SubagentStartPayload;
|
|
110
|
+
readonly "subagent-stop": SubagentStopPayload;
|
|
111
|
+
readonly "task-completed": TaskCompletedPayload;
|
|
112
|
+
readonly diagnostics: DiagnosticsPayload;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The discriminated union: an `AgentMemoryEvent<T>` is the payload for
|
|
116
|
+
* event type `T` plus an `event: T` tag. Default `T` is the full union.
|
|
117
|
+
*
|
|
118
|
+
* Use a `switch (e.event)` over `e: AgentMemoryEvent<AgentMemoryEventType>`
|
|
119
|
+
* to dispatch — TypeScript narrows the payload type per arm automatically.
|
|
120
|
+
*/
|
|
121
|
+
export type AgentMemoryEvent<T extends AgentMemoryEventType = AgentMemoryEventType> = T extends AgentMemoryEventType ? {
|
|
122
|
+
readonly event: T;
|
|
123
|
+
} & PayloadMap[T] : never;
|
|
124
|
+
/**
|
|
125
|
+
* Type guard: structurally verifies that `x` is an `AgentMemoryEvent`.
|
|
126
|
+
*
|
|
127
|
+
* The check confirms (a) it's an object, (b) `x.event` is one of the 12
|
|
128
|
+
* canonical names, and (c) `x.sessionId` is a string. Per-event field
|
|
129
|
+
* presence is NOT validated — that's the consumer's job once it knows the
|
|
130
|
+
* variant. Keeps this guard cheap for boundary checks.
|
|
131
|
+
*/
|
|
132
|
+
export declare function isAgentMemoryEvent(x: unknown): x is AgentMemoryEvent;
|
|
133
|
+
/**
|
|
134
|
+
* Serialise an event to JSON with stable key order so identical events
|
|
135
|
+
* hash to identical strings. Useful for dedup, replay, and audit logs.
|
|
136
|
+
*
|
|
137
|
+
* Sorting is lexicographic over top-level keys; nested objects keep their
|
|
138
|
+
* insertion order (deep sorting is rarely worth the cost — most nested
|
|
139
|
+
* payloads here are tool args, which the caller already produced in some
|
|
140
|
+
* canonical form).
|
|
141
|
+
*/
|
|
142
|
+
export declare function serializeEvent(e: AgentMemoryEvent): string;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=agentmemory-event-taxonomy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentmemory-event-taxonomy.d.ts","sourceRoot":"","sources":["../../src/hooks/agentmemory-event-taxonomy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,6MAa1B,CAAC;AAEX,8DAA8D;AAC9D,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAc5E,UAAU,eAAe;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,MAAM,EA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AK,CAAC;AAEjF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAMpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAO1D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentmemory event taxonomy — ported from rohitg00/agentmemory's hook engine
|
|
3
|
+
* (plugin/hooks/hooks.json + src/hooks/*.ts).
|
|
4
|
+
*
|
|
5
|
+
* WHAT: The canonical 12-event schema that a hook engine emits to a memory
|
|
6
|
+
* backend. Each event is a discriminated union over the `event` field, so
|
|
7
|
+
* the receiver can fan out per-type handlers with full type safety.
|
|
8
|
+
*
|
|
9
|
+
* WHY: We're not porting the agentmemory backend (HTTP endpoints, REST
|
|
10
|
+
* client, image-data extraction) — those are integration-specific and
|
|
11
|
+
* live in a follow-up. What's portable today is the *taxonomy* itself:
|
|
12
|
+
* the 12 canonical event names plus the per-event payload shape. Pinning
|
|
13
|
+
* the schema in WOTANN now lets the hook engine, the memory backend, and
|
|
14
|
+
* any future plugins all speak the same vocabulary.
|
|
15
|
+
*
|
|
16
|
+
* WHERE: The hook engine emits these events; consumers (memory store,
|
|
17
|
+
* audit log, telemetry) subscribe. The TypeScript discriminated union
|
|
18
|
+
* lets a single switch statement cover every event type with exhaustive
|
|
19
|
+
* checking.
|
|
20
|
+
*
|
|
21
|
+
* HOW: `AGENTMEMORY_EVENT_TYPES` is a const tuple of the 12 strings,
|
|
22
|
+
* `AgentMemoryEventType` is its string-literal union, and
|
|
23
|
+
* `AgentMemoryEvent<T>` is the per-event payload shape keyed by `event`.
|
|
24
|
+
* `isAgentMemoryEvent` is a structural type guard for runtime validation
|
|
25
|
+
* (boundary use only — internal code should rely on the static union).
|
|
26
|
+
* `serializeEvent` produces a JSON string with sorted keys so identical
|
|
27
|
+
* events hash identically — useful for dedup and audit.
|
|
28
|
+
*
|
|
29
|
+
* NOTE: The user-spec deviates from the upstream taxonomy in one place:
|
|
30
|
+
* we expose `diagnostics` instead of `notification`. The intent is to
|
|
31
|
+
* reserve a generic "engine emitted a diagnostic" channel; the upstream
|
|
32
|
+
* `notification` carried Claude Code permission prompts specifically,
|
|
33
|
+
* which doesn't generalise. The 11 other events match the upstream 1:1.
|
|
34
|
+
*/
|
|
35
|
+
/** The 12 canonical event names, in the order they appear in the hook flow. */
|
|
36
|
+
export const AGENTMEMORY_EVENT_TYPES = [
|
|
37
|
+
"pre-tool-use",
|
|
38
|
+
"post-tool-use",
|
|
39
|
+
"post-tool-failure",
|
|
40
|
+
"pre-compact",
|
|
41
|
+
"prompt-submit",
|
|
42
|
+
"session-start",
|
|
43
|
+
"session-end",
|
|
44
|
+
"stop",
|
|
45
|
+
"subagent-start",
|
|
46
|
+
"subagent-stop",
|
|
47
|
+
"task-completed",
|
|
48
|
+
"diagnostics",
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Type guard: structurally verifies that `x` is an `AgentMemoryEvent`.
|
|
52
|
+
*
|
|
53
|
+
* The check confirms (a) it's an object, (b) `x.event` is one of the 12
|
|
54
|
+
* canonical names, and (c) `x.sessionId` is a string. Per-event field
|
|
55
|
+
* presence is NOT validated — that's the consumer's job once it knows the
|
|
56
|
+
* variant. Keeps this guard cheap for boundary checks.
|
|
57
|
+
*/
|
|
58
|
+
export function isAgentMemoryEvent(x) {
|
|
59
|
+
if (typeof x !== "object" || x === null)
|
|
60
|
+
return false;
|
|
61
|
+
const obj = x;
|
|
62
|
+
if (typeof obj.event !== "string")
|
|
63
|
+
return false;
|
|
64
|
+
if (typeof obj.sessionId !== "string")
|
|
65
|
+
return false;
|
|
66
|
+
return AGENTMEMORY_EVENT_TYPES.includes(obj.event);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Serialise an event to JSON with stable key order so identical events
|
|
70
|
+
* hash to identical strings. Useful for dedup, replay, and audit logs.
|
|
71
|
+
*
|
|
72
|
+
* Sorting is lexicographic over top-level keys; nested objects keep their
|
|
73
|
+
* insertion order (deep sorting is rarely worth the cost — most nested
|
|
74
|
+
* payloads here are tool args, which the caller already produced in some
|
|
75
|
+
* canonical form).
|
|
76
|
+
*/
|
|
77
|
+
export function serializeEvent(e) {
|
|
78
|
+
const sortedKeys = Object.keys(e).sort();
|
|
79
|
+
const ordered = {};
|
|
80
|
+
for (const k of sortedKeys) {
|
|
81
|
+
ordered[k] = e[k];
|
|
82
|
+
}
|
|
83
|
+
return JSON.stringify(ordered);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=agentmemory-event-taxonomy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentmemory-event-taxonomy.js","sourceRoot":"","sources":["../../src/hooks/agentmemory-event-taxonomy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,cAAc;IACd,eAAe;IACf,mBAAmB;IACnB,aAAa;IACb,eAAe;IACf,eAAe;IACf,aAAa;IACb,MAAM;IACN,gBAAgB;IAChB,eAAe;IACf,gBAAgB;IAChB,aAAa;CACL,CAAC;AAoHX;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAU;IAC3C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,GAAG,GAAG,CAA6C,CAAC;IAC1D,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACpD,OAAQ,uBAA6C,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,CAAmB;IAChD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC,GAAI,CAAwC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"built-in.d.ts","sourceRoot":"","sources":["../../src/hooks/built-in.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"built-in.d.ts","sourceRoot":"","sources":["../../src/hooks/built-in.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,aAAa,CAAC;AAgBxE,eAAO,MAAM,aAAa,EAAE,WAgB3B,CAAC;AAuCF,eAAO,MAAM,gBAAgB,EAAE,WAiC9B,CAAC;AAIF,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAoBhE;AAID,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,MAAU,EAAE,OAAO,GAAE,MAAU,GAAG,WAAW,CA6BvF;AAID,eAAO,MAAM,mBAAmB,EAAE,WAejC,CAAC;AAqBF,eAAO,MAAM,gBAAgB,EAAE,WAiB9B,CAAC;AA8BF,eAAO,MAAM,eAAe,EAAE,WA4D7B,CAAC;AAiBF,eAAO,MAAM,cAAc,EAAE,WAuB5B,CAAC;AAIF,eAAO,MAAM,cAAc,EAAE,WA6C5B,CAAC;AAWF,eAAO,MAAM,oBAAoB,EAAE,WAiBlC,CAAC;AAcF,eAAO,MAAM,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