@dungle-scrubs/harness-cli-normalizer 0.1.1
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/execution/channel.d.ts +33 -0
- package/dist/execution/channel.d.ts.map +1 -0
- package/dist/execution/channel.js +86 -0
- package/dist/execution/channel.js.map +1 -0
- package/dist/execution/decode.d.ts +16 -0
- package/dist/execution/decode.d.ts.map +1 -0
- package/dist/execution/decode.js +60 -0
- package/dist/execution/decode.js.map +1 -0
- package/dist/execution/deps.d.ts +53 -0
- package/dist/execution/deps.d.ts.map +1 -0
- package/dist/execution/deps.js +8 -0
- package/dist/execution/deps.js.map +1 -0
- package/dist/execution/events.d.ts +54 -0
- package/dist/execution/events.d.ts.map +1 -0
- package/dist/execution/events.js +2 -0
- package/dist/execution/events.js.map +1 -0
- package/dist/execution/index.d.ts +19 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +19 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/lines.d.ts +21 -0
- package/dist/execution/lines.d.ts.map +1 -0
- package/dist/execution/lines.js +70 -0
- package/dist/execution/lines.js.map +1 -0
- package/dist/execution/node-deps.d.ts +13 -0
- package/dist/execution/node-deps.d.ts.map +1 -0
- package/dist/execution/node-deps.js +164 -0
- package/dist/execution/node-deps.js.map +1 -0
- package/dist/execution/open-session.d.ts +31 -0
- package/dist/execution/open-session.d.ts.map +1 -0
- package/dist/execution/open-session.js +360 -0
- package/dist/execution/open-session.js.map +1 -0
- package/dist/execution/stream-turn.d.ts +43 -0
- package/dist/execution/stream-turn.d.ts.map +1 -0
- package/dist/execution/stream-turn.js +283 -0
- package/dist/execution/stream-turn.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/interpretation/argv.d.ts +35 -0
- package/dist/interpretation/argv.d.ts.map +1 -0
- package/dist/interpretation/argv.js +147 -0
- package/dist/interpretation/argv.js.map +1 -0
- package/dist/interpretation/capabilities.d.ts +19 -0
- package/dist/interpretation/capabilities.d.ts.map +1 -0
- package/dist/interpretation/capabilities.js +25 -0
- package/dist/interpretation/capabilities.js.map +1 -0
- package/dist/interpretation/content.d.ts +33 -0
- package/dist/interpretation/content.d.ts.map +1 -0
- package/dist/interpretation/content.js +169 -0
- package/dist/interpretation/content.js.map +1 -0
- package/dist/interpretation/context.d.ts +17 -0
- package/dist/interpretation/context.d.ts.map +1 -0
- package/dist/interpretation/context.js +16 -0
- package/dist/interpretation/context.js.map +1 -0
- package/dist/interpretation/dimensions.d.ts +13 -0
- package/dist/interpretation/dimensions.d.ts.map +1 -0
- package/dist/interpretation/dimensions.js +6 -0
- package/dist/interpretation/dimensions.js.map +1 -0
- package/dist/interpretation/identity.d.ts +32 -0
- package/dist/interpretation/identity.d.ts.map +1 -0
- package/dist/interpretation/identity.js +44 -0
- package/dist/interpretation/identity.js.map +1 -0
- package/dist/interpretation/index.d.ts +23 -0
- package/dist/interpretation/index.d.ts.map +1 -0
- package/dist/interpretation/index.js +23 -0
- package/dist/interpretation/index.js.map +1 -0
- package/dist/interpretation/limits.d.ts +20 -0
- package/dist/interpretation/limits.d.ts.map +1 -0
- package/dist/interpretation/limits.js +35 -0
- package/dist/interpretation/limits.js.map +1 -0
- package/dist/interpretation/parse-resume.d.ts +28 -0
- package/dist/interpretation/parse-resume.d.ts.map +1 -0
- package/dist/interpretation/parse-resume.js +91 -0
- package/dist/interpretation/parse-resume.js.map +1 -0
- package/dist/interpretation/presence.d.ts +16 -0
- package/dist/interpretation/presence.d.ts.map +1 -0
- package/dist/interpretation/presence.js +32 -0
- package/dist/interpretation/presence.js.map +1 -0
- package/dist/interpretation/resume-last.d.ts +32 -0
- package/dist/interpretation/resume-last.d.ts.map +1 -0
- package/dist/interpretation/resume-last.js +70 -0
- package/dist/interpretation/resume-last.js.map +1 -0
- package/dist/interpretation/session-id.d.ts +22 -0
- package/dist/interpretation/session-id.d.ts.map +1 -0
- package/dist/interpretation/session-id.js +29 -0
- package/dist/interpretation/session-id.js.map +1 -0
- package/dist/interpretation/session-input.d.ts +13 -0
- package/dist/interpretation/session-input.d.ts.map +1 -0
- package/dist/interpretation/session-input.js +32 -0
- package/dist/interpretation/session-input.js.map +1 -0
- package/dist/interpretation/shape.d.ts +17 -0
- package/dist/interpretation/shape.d.ts.map +1 -0
- package/dist/interpretation/shape.js +54 -0
- package/dist/interpretation/shape.js.map +1 -0
- package/dist/interpretation/store.d.ts +16 -0
- package/dist/interpretation/store.d.ts.map +1 -0
- package/dist/interpretation/store.js +27 -0
- package/dist/interpretation/store.js.map +1 -0
- package/dist/interpretation/versions.d.ts +16 -0
- package/dist/interpretation/versions.d.ts.map +1 -0
- package/dist/interpretation/versions.js +44 -0
- package/dist/interpretation/versions.js.map +1 -0
- package/dist/interpretation/vocabulary.d.ts +29 -0
- package/dist/interpretation/vocabulary.d.ts.map +1 -0
- package/dist/interpretation/vocabulary.js +55 -0
- package/dist/interpretation/vocabulary.js.map +1 -0
- package/dist/knowledge/claude-code.d.ts +8 -0
- package/dist/knowledge/claude-code.d.ts.map +1 -0
- package/dist/knowledge/claude-code.js +132 -0
- package/dist/knowledge/claude-code.js.map +1 -0
- package/dist/knowledge/codex.d.ts +9 -0
- package/dist/knowledge/codex.d.ts.map +1 -0
- package/dist/knowledge/codex.js +106 -0
- package/dist/knowledge/codex.js.map +1 -0
- package/dist/knowledge/descriptor.d.ts +211 -0
- package/dist/knowledge/descriptor.d.ts.map +1 -0
- package/dist/knowledge/descriptor.js +20 -0
- package/dist/knowledge/descriptor.js.map +1 -0
- package/dist/knowledge/index.d.ts +19 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +19 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/matchers.d.ts +10 -0
- package/dist/knowledge/matchers.d.ts.map +1 -0
- package/dist/knowledge/matchers.js +11 -0
- package/dist/knowledge/matchers.js.map +1 -0
- package/dist/knowledge/muse.d.ts +12 -0
- package/dist/knowledge/muse.d.ts.map +1 -0
- package/dist/knowledge/muse.js +94 -0
- package/dist/knowledge/muse.js.map +1 -0
- package/dist/knowledge/overrides.d.ts +11 -0
- package/dist/knowledge/overrides.d.ts.map +1 -0
- package/dist/knowledge/overrides.js +166 -0
- package/dist/knowledge/overrides.js.map +1 -0
- package/dist/knowledge/pi.d.ts +11 -0
- package/dist/knowledge/pi.d.ts.map +1 -0
- package/dist/knowledge/pi.js +97 -0
- package/dist/knowledge/pi.js.map +1 -0
- package/package.json +69 -0
- package/src/execution/channel.ts +86 -0
- package/src/execution/decode.ts +79 -0
- package/src/execution/deps.ts +59 -0
- package/src/execution/events.ts +37 -0
- package/src/execution/index.ts +18 -0
- package/src/execution/lines.ts +71 -0
- package/src/execution/node-deps.ts +179 -0
- package/src/execution/open-session.ts +392 -0
- package/src/execution/stream-turn.ts +310 -0
- package/src/index.ts +7 -0
- package/src/interpretation/argv.ts +188 -0
- package/src/interpretation/capabilities.ts +51 -0
- package/src/interpretation/content.ts +191 -0
- package/src/interpretation/context.ts +28 -0
- package/src/interpretation/dimensions.ts +20 -0
- package/src/interpretation/identity.ts +81 -0
- package/src/interpretation/index.ts +22 -0
- package/src/interpretation/limits.ts +63 -0
- package/src/interpretation/parse-resume.ts +117 -0
- package/src/interpretation/presence.ts +49 -0
- package/src/interpretation/resume-last.ts +93 -0
- package/src/interpretation/session-id.ts +35 -0
- package/src/interpretation/session-input.ts +45 -0
- package/src/interpretation/shape.ts +55 -0
- package/src/interpretation/store.ts +43 -0
- package/src/interpretation/versions.ts +43 -0
- package/src/interpretation/vocabulary.ts +74 -0
- package/src/knowledge/claude-code.ts +132 -0
- package/src/knowledge/codex.ts +106 -0
- package/src/knowledge/descriptor.ts +217 -0
- package/src/knowledge/index.ts +23 -0
- package/src/knowledge/matchers.ts +19 -0
- package/src/knowledge/muse.ts +94 -0
- package/src/knowledge/overrides.ts +182 -0
- package/src/knowledge/pi.ts +97 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { asRecord } from "./shape.js";
|
|
2
|
+
/** Text of an array of `{type:"text", text}` content blocks. */
|
|
3
|
+
const textOfBlocks = (content) => Array.isArray(content)
|
|
4
|
+
? content
|
|
5
|
+
.map((b) => asRecord(b))
|
|
6
|
+
.filter((b) => b !== null && b.type === "text")
|
|
7
|
+
.map((b) => (typeof b.text === "string" ? b.text : ""))
|
|
8
|
+
.join("")
|
|
9
|
+
: "";
|
|
10
|
+
const at = (record, path) => {
|
|
11
|
+
let cursor = record;
|
|
12
|
+
for (const seg of path.split(".")) {
|
|
13
|
+
const inner = asRecord(cursor);
|
|
14
|
+
if (inner === null)
|
|
15
|
+
return undefined;
|
|
16
|
+
cursor = inner[seg];
|
|
17
|
+
}
|
|
18
|
+
return cursor;
|
|
19
|
+
};
|
|
20
|
+
const claude = (r) => {
|
|
21
|
+
const events = [];
|
|
22
|
+
if (r.type === "assistant") {
|
|
23
|
+
const content = at(r, "message.content");
|
|
24
|
+
if (Array.isArray(content)) {
|
|
25
|
+
for (const raw of content) {
|
|
26
|
+
const block = asRecord(raw);
|
|
27
|
+
if (block?.type === "tool_use" && typeof block.name === "string") {
|
|
28
|
+
events.push({ kind: "tool", name: block.name, input: block.input });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const text = textOfBlocks(content);
|
|
33
|
+
if (text !== "")
|
|
34
|
+
events.push({ kind: "message", role: "assistant", text });
|
|
35
|
+
}
|
|
36
|
+
else if (r.type === "stream_event") {
|
|
37
|
+
const delta = at(r, "event.delta");
|
|
38
|
+
const d = asRecord(delta);
|
|
39
|
+
if (d?.type === "text_delta" && typeof d.text === "string") {
|
|
40
|
+
events.push({ kind: "token", text: d.text });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (r.type === "system" && r.subtype !== "init" && typeof r.subtype === "string") {
|
|
44
|
+
// Non-init system lines (hook_started etc.) surface as droppable
|
|
45
|
+
// progress, as the pre-refactor decoder did. The init line is the
|
|
46
|
+
// identity announcement, handled upstream.
|
|
47
|
+
events.push({ kind: "progress", label: r.subtype });
|
|
48
|
+
}
|
|
49
|
+
else if (r.type === "result" && r.is_error === true) {
|
|
50
|
+
// A result line marked is_error is a failed turn (max-turns, execution
|
|
51
|
+
// error) - surface it so a streamTurn consumer sees the failure, not a
|
|
52
|
+
// clean turn. (openSession handles result boundaries itself.)
|
|
53
|
+
const sub = typeof r.subtype === "string" ? r.subtype : "result error";
|
|
54
|
+
events.push({ kind: "error", message: `turn failed: ${sub}` });
|
|
55
|
+
}
|
|
56
|
+
return events;
|
|
57
|
+
};
|
|
58
|
+
// codex item types that are NOT tool activity - everything else on
|
|
59
|
+
// item.started is a tool of some kind (command_execution, file_change,
|
|
60
|
+
// mcp_tool_call, web_search, ...), surfaced generically by item.type.
|
|
61
|
+
const CODEX_NON_TOOL = new Set(["agent_message", "error", "reasoning", "todo_list"]);
|
|
62
|
+
const codex = (r) => {
|
|
63
|
+
const item = asRecord(r.item);
|
|
64
|
+
if (item === null)
|
|
65
|
+
return [];
|
|
66
|
+
// Tool activity is emitted once on start so it is not double-counted
|
|
67
|
+
// against the completion record. Any non-message/reasoning item is a tool;
|
|
68
|
+
// name it by its item.type, carry the most useful field as input.
|
|
69
|
+
if (r.type === "item.started" &&
|
|
70
|
+
typeof item.type === "string" &&
|
|
71
|
+
!CODEX_NON_TOOL.has(item.type)) {
|
|
72
|
+
const name = item.type === "command_execution" ? "shell" : item.type;
|
|
73
|
+
const input = item.command ?? item.changes ?? item.query ?? item.invocation ?? undefined;
|
|
74
|
+
return [{ kind: "tool", name, input }];
|
|
75
|
+
}
|
|
76
|
+
if (r.type !== "item.completed")
|
|
77
|
+
return [];
|
|
78
|
+
if (item.type === "agent_message" && typeof item.text === "string") {
|
|
79
|
+
return [{ kind: "message", role: "assistant", text: item.text }];
|
|
80
|
+
}
|
|
81
|
+
if (item.type === "error" && typeof item.message === "string") {
|
|
82
|
+
return [{ kind: "error", message: item.message }];
|
|
83
|
+
}
|
|
84
|
+
return [];
|
|
85
|
+
};
|
|
86
|
+
const pi = (r) => {
|
|
87
|
+
// One clean tool event per invocation (the toolcall_start/delta/end and
|
|
88
|
+
// tool_execution_update stream is noise; tool_execution_start fires once).
|
|
89
|
+
if (r.type === "tool_execution_start" && typeof r.toolName === "string") {
|
|
90
|
+
return [{ kind: "tool", name: r.toolName, input: r.args }];
|
|
91
|
+
}
|
|
92
|
+
if (r.type === "message_update") {
|
|
93
|
+
const ev = asRecord(r.assistantMessageEvent);
|
|
94
|
+
if (ev?.type === "text_delta" && typeof ev.delta === "string") {
|
|
95
|
+
return [{ kind: "token", text: ev.delta }];
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (r.type === "message_end") {
|
|
100
|
+
const message = asRecord(r.message);
|
|
101
|
+
if (message?.role === "assistant") {
|
|
102
|
+
// A turn that ends with stopReason "error" is a provider/auth/token
|
|
103
|
+
// failure pi does NOT print to stderr and exits 0 for (verified with
|
|
104
|
+
// an expired minimax token: empty content, stopReason error, clean
|
|
105
|
+
// exit). Without this the failure is invisible - a silent empty turn.
|
|
106
|
+
if (message.stopReason === "error") {
|
|
107
|
+
return [
|
|
108
|
+
{ kind: "error", message: "pi turn ended with stopReason error (provider/auth failure)" },
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
const text = textOfBlocks(message.content);
|
|
112
|
+
if (text !== "")
|
|
113
|
+
return [{ kind: "message", role: "assistant", text }];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return [];
|
|
117
|
+
};
|
|
118
|
+
const muse = (r) => {
|
|
119
|
+
const payload = asRecord(r.payload);
|
|
120
|
+
if (payload === null)
|
|
121
|
+
return [];
|
|
122
|
+
// Tool activity: muse emits a tool_result naming the tool in
|
|
123
|
+
// correlation_facts.tool_name, with the command inside the result text.
|
|
124
|
+
if (payload.kind === "tool_result") {
|
|
125
|
+
const facts = asRecord(payload.correlation_facts);
|
|
126
|
+
const name = typeof facts?.tool_name === "string" ? facts.tool_name : "tool";
|
|
127
|
+
// Shell tools carry a JSON result with a `command`; file tools carry
|
|
128
|
+
// plain prose. Surface the command when present, else leave input off
|
|
129
|
+
// (the tool name is the signal that matters).
|
|
130
|
+
let command;
|
|
131
|
+
if (typeof payload.text === "string") {
|
|
132
|
+
try {
|
|
133
|
+
command = JSON.parse(payload.text).command;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
command = undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return [{ kind: "tool", name, input: command }];
|
|
140
|
+
}
|
|
141
|
+
if (payload.kind === "run_output_delta" && typeof payload.text === "string") {
|
|
142
|
+
return [{ kind: "token", text: payload.text }];
|
|
143
|
+
}
|
|
144
|
+
if (payload.kind === "run_terminal") {
|
|
145
|
+
if (payload.terminal === "completed" &&
|
|
146
|
+
typeof payload.text === "string" &&
|
|
147
|
+
payload.text !== "") {
|
|
148
|
+
return [{ kind: "message", role: "assistant", text: payload.text }];
|
|
149
|
+
}
|
|
150
|
+
if (payload.terminal === "failed") {
|
|
151
|
+
const reason = typeof payload.reason === "string" ? payload.reason : "run failed";
|
|
152
|
+
return [{ kind: "error", message: `muse run failed: ${reason}` }];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
};
|
|
157
|
+
const READERS = {
|
|
158
|
+
claude,
|
|
159
|
+
codex,
|
|
160
|
+
pi,
|
|
161
|
+
muse,
|
|
162
|
+
};
|
|
163
|
+
export const contentEventsOf = (harness, raw) => {
|
|
164
|
+
const record = asRecord(raw);
|
|
165
|
+
if (record === null)
|
|
166
|
+
return [];
|
|
167
|
+
return READERS[harness](record);
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","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AC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,MAAM,EAAE,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAM,OAAO,GAAwE;IACnF,MAAM;IACN,KAAK;IACL,EAAE;IACF,IAAI;CACL,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAoB,EAAE,GAAY,EAAkB,EAAE;IACpF,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-hook decoding: recognizes the harness's context-window usage
|
|
3
|
+
* payload and surfaces it as a `context` HarnessEvent, the droppable
|
|
4
|
+
* gauge-class event the chat layer may coalesce under pressure. For claude
|
|
5
|
+
* the payload arrives on the STATUSLINE channel, never on stream-json
|
|
6
|
+
* stdout - route this at the channel level, do not call it per stdout line.
|
|
7
|
+
* Values are sanitized (v1 sanitizeContext): non-finite is rejected,
|
|
8
|
+
* out-of-range is clamped, so callers report nothing rather than a broken
|
|
9
|
+
* gauge.
|
|
10
|
+
*/
|
|
11
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
12
|
+
export interface ContextEvent {
|
|
13
|
+
readonly kind: "context";
|
|
14
|
+
readonly usedPct: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const contextEventFrom: (h: HarnessDescriptor, raw: unknown) => ContextEvent | null;
|
|
17
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/interpretation/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,gBAAgB,MAAO,iBAAiB,OAAO,OAAO,KAAG,YAAY,GAAG,IASpF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { asRecord } from "./shape.js";
|
|
2
|
+
export const contextEventFrom = (h, raw) => {
|
|
3
|
+
if (h.contextHook === null)
|
|
4
|
+
return null;
|
|
5
|
+
const record = asRecord(raw);
|
|
6
|
+
if (record === null)
|
|
7
|
+
return null;
|
|
8
|
+
const outer = asRecord(record[h.contextHook.object]);
|
|
9
|
+
if (outer === null)
|
|
10
|
+
return null;
|
|
11
|
+
const usedPct = outer[h.contextHook.usedPctField];
|
|
12
|
+
if (typeof usedPct !== "number" || !Number.isFinite(usedPct))
|
|
13
|
+
return null;
|
|
14
|
+
return { kind: "context", usedPct: Math.min(100, Math.max(0, usedPct)) };
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/interpretation/context.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAOtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAoB,EAAE,GAAY,EAAuB,EAAE;IAC1F,IAAI,CAAC,CAAC,WAAW,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAClD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1E,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;AAC3E,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small dimension accessors: one interpretation function per PLAN 3.1
|
|
3
|
+
* dimension whose value is a direct descriptor lookup. They exist so every
|
|
4
|
+
* dimension has a single named owner in the interpretation layer - callers
|
|
5
|
+
* never reach into descriptor internals.
|
|
6
|
+
*/
|
|
7
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
8
|
+
export declare const stdinPolicyOf: (h: HarnessDescriptor) => "inherit" | "close-required";
|
|
9
|
+
export declare const providerFlagOf: (h: HarnessDescriptor) => string | null;
|
|
10
|
+
export declare const toolsFlagOf: (h: HarnessDescriptor) => string | null;
|
|
11
|
+
export declare const discoveryDisableFlagsOf: (h: HarnessDescriptor) => readonly string[];
|
|
12
|
+
export declare const autonomyFlagOf: (h: HarnessDescriptor) => string | null;
|
|
13
|
+
//# sourceMappingURL=dimensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimensions.d.ts","sourceRoot":"","sources":["../../src/interpretation/dimensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,eAAO,MAAM,aAAa,MAAO,iBAAiB,KAAG,SAAS,GAAG,gBAA2B,CAAC;AAE7F,eAAO,MAAM,cAAc,MAAO,iBAAiB,KAAG,MAAM,GAAG,IACjB,CAAC;AAE/C,eAAO,MAAM,WAAW,MAAO,iBAAiB,KAAG,MAAM,GAAG,IAA0B,CAAC;AAEvF,eAAO,MAAM,uBAAuB,MAAO,iBAAiB,KAAG,SAAS,MAAM,EACrD,CAAC;AAE1B,eAAO,MAAM,cAAc,MAAO,iBAAiB,KAAG,MAAM,GAAG,IACjB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const stdinPolicyOf = (h) => h.stdin;
|
|
2
|
+
export const providerFlagOf = (h) => h.provider === null ? null : h.provider.flag;
|
|
3
|
+
export const toolsFlagOf = (h) => h.launch.toolsFlag;
|
|
4
|
+
export const discoveryDisableFlagsOf = (h) => h.discoveryDisableFlags;
|
|
5
|
+
export const autonomyFlagOf = (h) => h.autonomy === null ? null : h.autonomy.flag;
|
|
6
|
+
//# sourceMappingURL=dimensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dimensions.js","sourceRoot":"","sources":["../../src/interpretation/dimensions.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAoB,EAAgC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAE7F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAoB,EAAiB,EAAE,CACpE,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAoB,EAAiB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;AAEvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAoB,EAAqB,EAAE,CACjF,CAAC,CAAC,qBAAqB,CAAC;AAE1B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAoB,EAAiB,EAAE,CACpE,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity decoding: pure recognition of a harness's identity announcement
|
|
3
|
+
* inside its output stream. D-022: claude re-emits `system/init` with the
|
|
4
|
+
* same session_id at every turn start, so announcements are deduped against
|
|
5
|
+
* the last seen id - an identity is only "news" on first sight or change.
|
|
6
|
+
* Under caller-assigned authority an announcement that differs from the
|
|
7
|
+
* REQUESTED id is a rotation anomaly (v1 HSI005): binding it would silently
|
|
8
|
+
* attach the conversation to a context that never saw it, so the outcome is
|
|
9
|
+
* surfaced for the runner to refuse, never papered over.
|
|
10
|
+
*/
|
|
11
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
12
|
+
export type IdentityOutcome =
|
|
13
|
+
/** Not an identity announcement at all. */
|
|
14
|
+
"none"
|
|
15
|
+
/** First sight (or a changed id under harness-minted authority). */
|
|
16
|
+
| "announced"
|
|
17
|
+
/** Same id as last seen - turn-start metadata, not news. */
|
|
18
|
+
| "duplicate"
|
|
19
|
+
/** Caller-assigned authority, but the harness announced a DIFFERENT id
|
|
20
|
+
* than the one requested - refuse to bind, do not paper over. */
|
|
21
|
+
| "rotated"
|
|
22
|
+
/** Announcement present but the id fails the shape rule - not believed. */
|
|
23
|
+
| "malformed";
|
|
24
|
+
export interface DecodedIdentity {
|
|
25
|
+
/** The id this raw event announces, whether or not it is news. */
|
|
26
|
+
readonly sessionId: string | null;
|
|
27
|
+
/** The id to surface as an identity HarnessEvent, or null when not news. */
|
|
28
|
+
readonly identity: string | null;
|
|
29
|
+
readonly outcome: IdentityOutcome;
|
|
30
|
+
}
|
|
31
|
+
export declare const decodeIdentity: (h: HarnessDescriptor, raw: unknown, lastSeenId: string | null, requestedId?: string | null) => DecodedIdentity;
|
|
32
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/interpretation/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIpE,MAAM,MAAM,eAAe;AACzB,2CAA2C;AACzC,MAAM;AACR,oEAAoE;GAClE,WAAW;AACb,4DAA4D;GAC1D,WAAW;AACb;iEACiE;GAC/D,SAAS;AACX,2EAA2E;GACzE,WAAW,CAAC;AAEhB,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;CACnC;AAID,eAAO,MAAM,cAAc,MACtB,iBAAiB,OACf,OAAO,cACA,MAAM,GAAG,IAAI,gBACZ,MAAM,GAAG,IAAI,KACzB,eAsCF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isUsableSessionId } from "./session-id.js";
|
|
2
|
+
import { asRecord } from "./shape.js";
|
|
3
|
+
const NOT_ANNOUNCED = { sessionId: null, identity: null, outcome: "none" };
|
|
4
|
+
export const decodeIdentity = (h, raw, lastSeenId, requestedId = null) => {
|
|
5
|
+
const record = asRecord(raw);
|
|
6
|
+
if (record === null)
|
|
7
|
+
return NOT_ANNOUNCED;
|
|
8
|
+
const spec = h.identity.announce;
|
|
9
|
+
for (const [key, expected] of Object.entries(spec.match)) {
|
|
10
|
+
if (record[key] !== expected)
|
|
11
|
+
return NOT_ANNOUNCED;
|
|
12
|
+
}
|
|
13
|
+
// idField is a dot-path: muse nests its id at stream.id.
|
|
14
|
+
let cursor = record;
|
|
15
|
+
for (const segment of spec.idField.split(".")) {
|
|
16
|
+
const inner = asRecord(cursor);
|
|
17
|
+
if (inner === null)
|
|
18
|
+
return NOT_ANNOUNCED;
|
|
19
|
+
cursor = inner[segment];
|
|
20
|
+
}
|
|
21
|
+
const announced = cursor;
|
|
22
|
+
if (typeof announced !== "string" || !isUsableSessionId(announced)) {
|
|
23
|
+
// A record that matched a real discriminator (claude system/init) but
|
|
24
|
+
// carries a null/missing/garbage id is a MALFORMED announcement the
|
|
25
|
+
// runner must see - treating it as unrelated output leaves the runner
|
|
26
|
+
// waiting for an identity that already failed to arrive. Descriptors
|
|
27
|
+
// with an empty match (muse: any record) have no discriminator, so a
|
|
28
|
+
// record without the id path is ordinary output, not malformed.
|
|
29
|
+
const discriminated = Object.keys(spec.match).length > 0;
|
|
30
|
+
return discriminated
|
|
31
|
+
? { sessionId: null, identity: null, outcome: "malformed" }
|
|
32
|
+
: NOT_ANNOUNCED;
|
|
33
|
+
}
|
|
34
|
+
if (h.identity.authority === "caller-assigned" &&
|
|
35
|
+
requestedId !== null &&
|
|
36
|
+
announced !== requestedId) {
|
|
37
|
+
return { sessionId: announced, identity: null, outcome: "rotated" };
|
|
38
|
+
}
|
|
39
|
+
if (announced === lastSeenId) {
|
|
40
|
+
return { sessionId: announced, identity: null, outcome: "duplicate" };
|
|
41
|
+
}
|
|
42
|
+
return { sessionId: announced, identity: announced, outcome: "announced" };
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/interpretation/identity.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAuBtC,MAAM,aAAa,GAAoB,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;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AC3D,CAAC,CAAC,aAAa,CAAC;IACpB,CAAC;IACD,IACE,CAAC,CAAC,QAAQ,CAAC,SAAS,KAAK,iBAAiB;QAC1C,WAAW,KAAK,IAAI;QACpB,SAAS,KAAK,WAAW,EACzB,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACtE,CAAC;IACD,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IACxE,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAC7E,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpretation layer: owns pure functions that operate over descriptors.
|
|
3
|
+
*
|
|
4
|
+
* This includes argv building, identity decoding, limit detection, and
|
|
5
|
+
* capability queries. Every function here is total and side-effect free: it
|
|
6
|
+
* performs no I/O and imports no side-effecting Node builtins - purity is
|
|
7
|
+
* test-enforced. It is NOT responsible for spawning processes or handling
|
|
8
|
+
* streams; that is the execution layer's job.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./argv.js";
|
|
11
|
+
export * from "./capabilities.js";
|
|
12
|
+
export * from "./context.js";
|
|
13
|
+
export * from "./dimensions.js";
|
|
14
|
+
export * from "./identity.js";
|
|
15
|
+
export * from "./limits.js";
|
|
16
|
+
export * from "./parse-resume.js";
|
|
17
|
+
export * from "./presence.js";
|
|
18
|
+
export * from "./resume-last.js";
|
|
19
|
+
export * from "./session-id.js";
|
|
20
|
+
export * from "./session-input.js";
|
|
21
|
+
export * from "./store.js";
|
|
22
|
+
export * from "./vocabulary.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interpretation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interpretation layer: owns pure functions that operate over descriptors.
|
|
3
|
+
*
|
|
4
|
+
* This includes argv building, identity decoding, limit detection, and
|
|
5
|
+
* capability queries. Every function here is total and side-effect free: it
|
|
6
|
+
* performs no I/O and imports no side-effecting Node builtins - purity is
|
|
7
|
+
* test-enforced. It is NOT responsible for spawning processes or handling
|
|
8
|
+
* streams; that is the execution layer's job.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./argv.js";
|
|
11
|
+
export * from "./capabilities.js";
|
|
12
|
+
export * from "./context.js";
|
|
13
|
+
export * from "./dimensions.js";
|
|
14
|
+
export * from "./identity.js";
|
|
15
|
+
export * from "./limits.js";
|
|
16
|
+
export * from "./parse-resume.js";
|
|
17
|
+
export * from "./presence.js";
|
|
18
|
+
export * from "./resume-last.js";
|
|
19
|
+
export * from "./session-id.js";
|
|
20
|
+
export * from "./session-input.js";
|
|
21
|
+
export * from "./store.js";
|
|
22
|
+
export * from "./vocabulary.js";
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interpretation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wall detection: pure classification of harness output against the
|
|
3
|
+
* descriptor's limit and auth matchers. Returns the CODE, never the matched
|
|
4
|
+
* line - the consumers of a detection are a retained record and a viewer
|
|
5
|
+
* warning, and anything the harness printed on that line (a prompt, a
|
|
6
|
+
* filename, a customer's name) must not ride along (v1 D-005: records carry
|
|
7
|
+
* identifiers and outcomes, never content).
|
|
8
|
+
*
|
|
9
|
+
* Feed these wall-eligible output only - stderr and the non-JSON tail of a
|
|
10
|
+
* dying turn - never assistant message content, where the model merely
|
|
11
|
+
* TALKING about limits would match.
|
|
12
|
+
*/
|
|
13
|
+
import type { AuthFailureKind, HarnessDescriptor, LimitCode } from "../knowledge/descriptor.js";
|
|
14
|
+
/** Per-line entry point for streaming readers: O(1) per line, no rescans. */
|
|
15
|
+
export declare const detectLimitInLine: (h: HarnessDescriptor, line: string) => LimitCode | null;
|
|
16
|
+
/** Batch convenience over a turn's tail, bounded and bottom-up. */
|
|
17
|
+
export declare const detectLimit: (h: HarnessDescriptor, output: string) => LimitCode | null;
|
|
18
|
+
export declare const detectAuthFailureInLine: (h: HarnessDescriptor, line: string) => AuthFailureKind | null;
|
|
19
|
+
export declare const detectAuthFailure: (h: HarnessDescriptor, output: string) => AuthFailureKind | null;
|
|
20
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/interpretation/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAoChG,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,MAAO,iBAAiB,QAAQ,MAAM,KAAG,SAAS,GAAG,IAC3C,CAAC;AAEzC,mEAAmE;AACnE,eAAO,MAAM,WAAW,MAAO,iBAAiB,UAAU,MAAM,KAAG,SAAS,GAAG,IAC5C,CAAC;AAEpC,eAAO,MAAM,uBAAuB,MAC/B,iBAAiB,QACd,MAAM,KACX,eAAe,GAAG,IAA6C,CAAC;AAEnE,eAAO,MAAM,iBAAiB,MAAO,iBAAiB,UAAU,MAAM,KAAG,eAAe,GAAG,IACzD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Bottom-up batch scans stop after this many non-empty lines: the wall is
|
|
2
|
+
* virtually always the last thing a dying turn printed, and an unbounded
|
|
3
|
+
* scan over an accumulating session buffer is O(turns x output). */
|
|
4
|
+
const BATCH_SCAN_MAX_LINES = 200;
|
|
5
|
+
const scanLine = (line, matchers) => {
|
|
6
|
+
for (let i = 0; i < matchers.length; i++) {
|
|
7
|
+
const matcher = matchers[i];
|
|
8
|
+
if (matcher?.[0].test(line))
|
|
9
|
+
return matcher[1];
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
const scanTail = (output, matchers) => {
|
|
14
|
+
let end = output.length;
|
|
15
|
+
let scanned = 0;
|
|
16
|
+
while (end > 0 && scanned < BATCH_SCAN_MAX_LINES) {
|
|
17
|
+
const start = output.lastIndexOf("\n", end - 1);
|
|
18
|
+
const line = output.slice(start + 1, end).trim();
|
|
19
|
+
end = start;
|
|
20
|
+
if (line === "")
|
|
21
|
+
continue;
|
|
22
|
+
scanned++;
|
|
23
|
+
const code = scanLine(line, matchers);
|
|
24
|
+
if (code !== null)
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
/** Per-line entry point for streaming readers: O(1) per line, no rescans. */
|
|
30
|
+
export const detectLimitInLine = (h, line) => scanLine(line.trim(), h.limitMatchers);
|
|
31
|
+
/** Batch convenience over a turn's tail, bounded and bottom-up. */
|
|
32
|
+
export const detectLimit = (h, output) => scanTail(output, h.limitMatchers);
|
|
33
|
+
export const detectAuthFailureInLine = (h, line) => scanLine(line.trim(), h.authMatchers);
|
|
34
|
+
export const detectAuthFailure = (h, output) => scanTail(output, h.authMatchers);
|
|
35
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/interpretation/limits.ts"],"names":[],"mappings":"AAcA;;oEAEoE;AACpE,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,MAAM,QAAQ,GAAG,CACf,IAAY,EACZ,QAAgD,EACnC,EAAE;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CACf,MAAc,EACd,QAAgD,EACnC,EAAE;IACf,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,GAAG,GAAG,CAAC,IAAI,OAAO,GAAG,oBAAoB,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,GAAG,GAAG,KAAK,CAAC;QACZ,IAAI,IAAI,KAAK,EAAE;YAAE,SAAS;QAC1B,OAAO,EAAE,CAAC;QACV,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IACjC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAoB,EAAE,IAAY,EAAoB,EAAE,CACxF,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;AAEzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAoB,EAAE,MAAc,EAAoB,EAAE,CACpF,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC;AAEpC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,CAAoB,EACpB,IAAY,EACY,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAoB,EAAE,MAAc,EAA0B,EAAE,CAChG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resume-command parsing: recognizes a pasted "resume this session" shell
|
|
3
|
+
* command and recovers {harness, sessionId, autonomy} - or a resume-last
|
|
4
|
+
* request where the harness supports one. The inverse of buildResumeArgv,
|
|
5
|
+
* tolerant of what shell history actually carries (quoted ids, resolved
|
|
6
|
+
* bin paths, --flag=value, flag aliases, root options on either side of a
|
|
7
|
+
* subcommand). Anchoring rules ported from v1 (D-011): the id must follow
|
|
8
|
+
* the harness's own resume grammar, match its id shape, and be the ONLY
|
|
9
|
+
* id-shaped token - a UUID inside quoted prompt text must never be
|
|
10
|
+
* returned as the session id. Position independence is safe because
|
|
11
|
+
* tokenize collapses quoted text into single words: a bare resume word can
|
|
12
|
+
* only come from a real argv slot.
|
|
13
|
+
*/
|
|
14
|
+
import type { HarnessDescriptor, HarnessName } from "../knowledge/descriptor.js";
|
|
15
|
+
export interface ParsedResume {
|
|
16
|
+
readonly harness: HarnessName;
|
|
17
|
+
readonly sessionId: string;
|
|
18
|
+
readonly autonomy: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** A recorded `--last` resume: no id to anchor - corroboration ranking
|
|
21
|
+
* (rankResumeLast) decides what it names. */
|
|
22
|
+
export interface ParsedResumeLast {
|
|
23
|
+
readonly harness: HarnessName;
|
|
24
|
+
readonly resumeLast: true;
|
|
25
|
+
readonly autonomy: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const parseResumeCommand: (known: readonly HarnessDescriptor[], command: string) => ParsedResume | ParsedResumeLast | null;
|
|
28
|
+
//# sourceMappingURL=parse-resume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-resume.d.ts","sourceRoot":"","sources":["../../src/interpretation/parse-resume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;6CAC6C;AAC7C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AA+DD,eAAO,MAAM,kBAAkB,UACtB,SAAS,iBAAiB,EAAE,WAC1B,MAAM,KACd,YAAY,GAAG,gBAAgB,GAAG,IAqBpC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isUsableSessionId } from "./session-id.js";
|
|
2
|
+
import { basenameOf, tokenize } from "./shape.js";
|
|
3
|
+
const flagTokens = (h) => [
|
|
4
|
+
h.resume.flag,
|
|
5
|
+
...h.resume.aliases,
|
|
6
|
+
];
|
|
7
|
+
/** The id token per the descriptor's resume grammar, or null. */
|
|
8
|
+
const idTokenOf = (h, words) => {
|
|
9
|
+
const positionalWords = [];
|
|
10
|
+
if (h.resume.style === "positional")
|
|
11
|
+
positionalWords.push(h.resume.flag);
|
|
12
|
+
if (h.resume.positionalParseWord !== undefined) {
|
|
13
|
+
positionalWords.push(h.resume.positionalParseWord);
|
|
14
|
+
}
|
|
15
|
+
if (positionalWords.length > 0) {
|
|
16
|
+
// Walk consuming `--flag value` pairs so an option VALUE spelled
|
|
17
|
+
// "resume" (muse exec --workspace resume <uuid>) is never mistaken for
|
|
18
|
+
// the resume word. Root options may sit on either side of a subcommand,
|
|
19
|
+
// so position alone is not the anchor - a bare, unconsumed resume word
|
|
20
|
+
// followed by an id-shaped token is. Conservative direction: a boolean
|
|
21
|
+
// flag directly before the resume word reads as a pair and yields null
|
|
22
|
+
// (display-only false negative), never a stranger's session.
|
|
23
|
+
for (let i = 1; i < words.length; i++) {
|
|
24
|
+
const word = words[i];
|
|
25
|
+
if (word === undefined)
|
|
26
|
+
break;
|
|
27
|
+
if (word.startsWith("-")) {
|
|
28
|
+
const next = words[i + 1];
|
|
29
|
+
if (!word.includes("=") && next !== undefined && !next.startsWith("-"))
|
|
30
|
+
i++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (positionalWords.includes(word)) {
|
|
34
|
+
const candidate = words[i + 1];
|
|
35
|
+
if (candidate !== undefined && h.resume.idShape.test(candidate))
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (h.resume.style === "flag" || h.resume.positionalParseWord === undefined) {
|
|
41
|
+
for (const token of flagTokens(h)) {
|
|
42
|
+
if (h.resume.style === "positional")
|
|
43
|
+
break;
|
|
44
|
+
const at = words.indexOf(token, 1);
|
|
45
|
+
if (at !== -1)
|
|
46
|
+
return words[at + 1] ?? null;
|
|
47
|
+
const eqForm = words.find((w) => w.startsWith(`${token}=`));
|
|
48
|
+
if (eqForm !== undefined)
|
|
49
|
+
return eqForm.slice(token.length + 1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
54
|
+
/** True when the command asks for the harness's resume-most-recent form. */
|
|
55
|
+
const isResumeLast = (h, words) => {
|
|
56
|
+
if (h.resumeLast === null)
|
|
57
|
+
return false;
|
|
58
|
+
if (!words.includes(h.resumeLast.flag))
|
|
59
|
+
return false;
|
|
60
|
+
// --last only means "resume last" in the resume grammar's context: after
|
|
61
|
+
// the positional resume word, or anywhere for flag-style harnesses.
|
|
62
|
+
const anchor = h.resume.style === "positional" ? h.resume.flag : (h.resume.positionalParseWord ?? null);
|
|
63
|
+
if (anchor !== null) {
|
|
64
|
+
const at = words.indexOf(anchor, 1);
|
|
65
|
+
return at !== -1 && words.indexOf(h.resumeLast.flag) > at;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
export const parseResumeCommand = (known, command) => {
|
|
70
|
+
const words = tokenize(command);
|
|
71
|
+
const bin = words[0];
|
|
72
|
+
if (bin === undefined)
|
|
73
|
+
return null;
|
|
74
|
+
const h = known.find((d) => basenameOf(bin) === d.bin);
|
|
75
|
+
if (h === undefined)
|
|
76
|
+
return null;
|
|
77
|
+
const autonomy = h.autonomy !== null && words.includes(h.autonomy.flag);
|
|
78
|
+
const id = idTokenOf(h, words);
|
|
79
|
+
if (id === null) {
|
|
80
|
+
return isResumeLast(h, words) ? { harness: h.name, resumeLast: true, autonomy } : null;
|
|
81
|
+
}
|
|
82
|
+
if (!h.resume.idShape.test(id) || !isUsableSessionId(id))
|
|
83
|
+
return null;
|
|
84
|
+
// D-011: any OTHER id-shaped token means the command is ambiguous -
|
|
85
|
+
// refuse rather than resume a stranger.
|
|
86
|
+
const idShaped = words.filter((w) => w !== id && h.resume.idShape.test(w));
|
|
87
|
+
if (idShaped.length > 0)
|
|
88
|
+
return null;
|
|
89
|
+
return { harness: h.name, sessionId: id, autonomy };
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=parse-resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-resume.js","sourceRoot":"","sources":["../../src/interpretation/parse-resume.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgBlD,MAAM,UAAU,GAAG,CAAC,CAAoB,EAAqB,EAAE,CAAC;IAC9D,CAAC,CAAC,MAAM,CAAC,IAAI;IACb,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO;CACpB,CAAC;AAEF,iEAAiE;AACjE,MAAM,SAAS,GAAG,CAAC,CAAoB,EAAE,KAAwB,EAAiB,EAAE;IAClF,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,YAAY;QAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzE,IAAI,CAAC,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;QAC/C,e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CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAErC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AACtD,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presence: does an INTERACTIVE process for this session id exist in the
|
|
3
|
+
* given process listing? Pure over injected rows - the host polls `ps` and
|
|
4
|
+
* feeds rows in. Presence says a process exists; it never creates a tap,
|
|
5
|
+
* never proves a channel, and never decides attachment (that is the chat
|
|
6
|
+
* layer's liveness state machine). Known blind spot, inherent to argv
|
|
7
|
+
* matching and shared with v1: an interactive session whose argv carries no
|
|
8
|
+
* id (`claude --continue`) is invisible here - false-negative is the safe
|
|
9
|
+
* direction, because presence only ever corroborates.
|
|
10
|
+
*/
|
|
11
|
+
import type { HarnessDescriptor } from "../knowledge/descriptor.js";
|
|
12
|
+
export interface ProcessRow {
|
|
13
|
+
readonly argv: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const isInteractive: (h: HarnessDescriptor, sessionId: string, rows: readonly ProcessRow[]) => boolean;
|
|
16
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../src/interpretation/presence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAWD,eAAO,MAAM,aAAa,MACrB,iBAAiB,aACT,MAAM,QACX,SAAS,UAAU,EAAE,KAC1B,OAkBF,CAAC"}
|