@namzu/cli 23.0.0 → 25.0.0
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/CHANGELOG.md +845 -0
- package/README.md +13 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +18 -10
- package/dist/cli.js.map +1 -1
- package/dist/commands/drain.d.ts +0 -23
- package/dist/commands/drain.d.ts.map +1 -1
- package/dist/commands/drain.js +23 -9
- package/dist/commands/drain.js.map +1 -1
- package/dist/commands/resident-flags.d.ts +24 -0
- package/dist/commands/resident-flags.d.ts.map +1 -0
- package/dist/commands/resident-flags.js +191 -0
- package/dist/commands/resident-flags.js.map +1 -0
- package/dist/commands/resident-learning.d.ts +6 -0
- package/dist/commands/resident-learning.d.ts.map +1 -0
- package/dist/commands/resident-learning.js +293 -0
- package/dist/commands/resident-learning.js.map +1 -0
- package/dist/commands/resident.d.ts +20 -0
- package/dist/commands/resident.d.ts.map +1 -0
- package/dist/commands/resident.js +418 -0
- package/dist/commands/resident.js.map +1 -0
- package/dist/commands/run-flags.d.ts +2 -2
- package/dist/commands/run-flags.d.ts.map +1 -1
- package/dist/commands/run-flags.js +6 -6
- package/dist/commands/run-flags.js.map +1 -1
- package/dist/commands/run-stream.d.ts.map +1 -1
- package/dist/commands/run-stream.js +9 -10
- package/dist/commands/run-stream.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +3 -2
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/upgrade.d.ts +1 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +6 -3
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +27 -4
- package/dist/config/load.js.map +1 -1
- package/dist/config/run-limits.d.ts +11 -0
- package/dist/config/run-limits.d.ts.map +1 -0
- package/dist/config/run-limits.js +64 -0
- package/dist/config/run-limits.js.map +1 -0
- package/dist/config/schema.d.ts +12 -4
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/context/runtime-message.d.ts.map +1 -1
- package/dist/context/runtime-message.js +2 -0
- package/dist/context/runtime-message.js.map +1 -1
- package/dist/integrations/npm-invocation.d.ts +10 -0
- package/dist/integrations/npm-invocation.d.ts.map +1 -0
- package/dist/integrations/npm-invocation.js +23 -0
- package/dist/integrations/npm-invocation.js.map +1 -0
- package/dist/integrations/plugins/runtime.d.ts +19 -1
- package/dist/integrations/plugins/runtime.d.ts.map +1 -1
- package/dist/integrations/plugins/runtime.js +89 -1
- package/dist/integrations/plugins/runtime.js.map +1 -1
- package/dist/integrations/plugins/settings.d.ts +15 -0
- package/dist/integrations/plugins/settings.d.ts.map +1 -0
- package/dist/integrations/plugins/settings.js +106 -0
- package/dist/integrations/plugins/settings.js.map +1 -0
- package/dist/integrations/providers/credential-store.d.ts +8 -7
- package/dist/integrations/providers/credential-store.d.ts.map +1 -1
- package/dist/integrations/providers/credential-store.js +44 -17
- package/dist/integrations/providers/credential-store.js.map +1 -1
- package/dist/integrations/providers/discover.d.ts.map +1 -1
- package/dist/integrations/providers/discover.js +7 -2
- package/dist/integrations/providers/discover.js.map +1 -1
- package/dist/integrations/providers/harness-credentials.d.ts +2 -2
- package/dist/integrations/providers/harness-credentials.d.ts.map +1 -1
- package/dist/integrations/providers/harness-credentials.js +13 -8
- package/dist/integrations/providers/harness-credentials.js.map +1 -1
- package/dist/integrations/providers/setup.d.ts.map +1 -1
- package/dist/integrations/providers/setup.js +52 -5
- package/dist/integrations/providers/setup.js.map +1 -1
- package/dist/integrations/resident/foreground.d.ts +19 -0
- package/dist/integrations/resident/foreground.d.ts.map +1 -0
- package/dist/integrations/resident/foreground.js +95 -0
- package/dist/integrations/resident/foreground.js.map +1 -0
- package/dist/integrations/resident/inspection.d.ts +10 -0
- package/dist/integrations/resident/inspection.d.ts.map +1 -0
- package/dist/integrations/resident/inspection.js +263 -0
- package/dist/integrations/resident/inspection.js.map +1 -0
- package/dist/integrations/resident/learning-sources.d.ts +4 -0
- package/dist/integrations/resident/learning-sources.d.ts.map +1 -0
- package/dist/integrations/resident/learning-sources.js +79 -0
- package/dist/integrations/resident/learning-sources.js.map +1 -0
- package/dist/integrations/resident/learning-storage.d.ts +5 -0
- package/dist/integrations/resident/learning-storage.d.ts.map +1 -0
- package/dist/integrations/resident/learning-storage.js +51 -0
- package/dist/integrations/resident/learning-storage.js.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts +9 -0
- package/dist/integrations/resident/lifecycle-errors.d.ts.map +1 -0
- package/dist/integrations/resident/lifecycle-errors.js +15 -0
- package/dist/integrations/resident/lifecycle-errors.js.map +1 -0
- package/dist/integrations/resident/owned-runner.d.ts +17 -0
- package/dist/integrations/resident/owned-runner.d.ts.map +1 -0
- package/dist/integrations/resident/owned-runner.js +91 -0
- package/dist/integrations/resident/owned-runner.js.map +1 -0
- package/dist/integrations/resident/runner-control.d.ts +47 -0
- package/dist/integrations/resident/runner-control.d.ts.map +1 -0
- package/dist/integrations/resident/runner-control.js +238 -0
- package/dist/integrations/resident/runner-control.js.map +1 -0
- package/dist/integrations/resident/runner-launch.d.ts +52 -0
- package/dist/integrations/resident/runner-launch.d.ts.map +1 -0
- package/dist/integrations/resident/runner-launch.js +142 -0
- package/dist/integrations/resident/runner-launch.js.map +1 -0
- package/dist/integrations/resident/runner-store.d.ts +44 -0
- package/dist/integrations/resident/runner-store.d.ts.map +1 -0
- package/dist/integrations/resident/runner-store.js +281 -0
- package/dist/integrations/resident/runner-store.js.map +1 -0
- package/dist/integrations/resident/runner-worker.d.ts +2 -0
- package/dist/integrations/resident/runner-worker.d.ts.map +1 -0
- package/dist/integrations/resident/runner-worker.js +146 -0
- package/dist/integrations/resident/runner-worker.js.map +1 -0
- package/dist/integrations/resident/session-step.d.ts +29 -0
- package/dist/integrations/resident/session-step.d.ts.map +1 -0
- package/dist/integrations/resident/session-step.js +462 -0
- package/dist/integrations/resident/session-step.js.map +1 -0
- package/dist/integrations/resident/storage.d.ts +17 -0
- package/dist/integrations/resident/storage.d.ts.map +1 -0
- package/dist/integrations/resident/storage.js +140 -0
- package/dist/integrations/resident/storage.js.map +1 -0
- package/dist/integrations/resident/tool-evidence.d.ts +6 -0
- package/dist/integrations/resident/tool-evidence.d.ts.map +1 -0
- package/dist/integrations/resident/tool-evidence.js +117 -0
- package/dist/integrations/resident/tool-evidence.js.map +1 -0
- package/dist/integrations/resident/verification.d.ts +11 -0
- package/dist/integrations/resident/verification.d.ts.map +1 -0
- package/dist/integrations/resident/verification.js +109 -0
- package/dist/integrations/resident/verification.js.map +1 -0
- package/dist/integrations/sessions/compaction-evidence.d.ts +5 -0
- package/dist/integrations/sessions/compaction-evidence.d.ts.map +1 -0
- package/dist/integrations/sessions/compaction-evidence.js +59 -0
- package/dist/integrations/sessions/compaction-evidence.js.map +1 -0
- package/dist/integrations/sessions/context-inventory.js +1 -1
- package/dist/integrations/sessions/context-inventory.js.map +1 -1
- package/dist/integrations/sessions/conversation-search.d.ts +56 -8
- package/dist/integrations/sessions/conversation-search.d.ts.map +1 -1
- package/dist/integrations/sessions/conversation-search.js +600 -63
- package/dist/integrations/sessions/conversation-search.js.map +1 -1
- package/dist/integrations/sessions/database.d.ts +5 -0
- package/dist/integrations/sessions/database.d.ts.map +1 -0
- package/dist/integrations/sessions/database.js +34 -0
- package/dist/integrations/sessions/database.js.map +1 -0
- package/dist/integrations/sessions/evidence-page-validation.d.ts +8 -0
- package/dist/integrations/sessions/evidence-page-validation.d.ts.map +1 -0
- package/dist/integrations/sessions/evidence-page-validation.js +74 -0
- package/dist/integrations/sessions/evidence-page-validation.js.map +1 -0
- package/dist/integrations/sessions/evidence-recall.d.ts +5 -0
- package/dist/integrations/sessions/evidence-recall.d.ts.map +1 -0
- package/dist/integrations/sessions/evidence-recall.js +173 -0
- package/dist/integrations/sessions/evidence-recall.js.map +1 -0
- package/dist/integrations/sessions/paths.d.ts +7 -0
- package/dist/integrations/sessions/paths.d.ts.map +1 -0
- package/dist/integrations/sessions/paths.js +14 -0
- package/dist/integrations/sessions/paths.js.map +1 -0
- package/dist/integrations/sessions/run-discovery.d.ts +24 -0
- package/dist/integrations/sessions/run-discovery.d.ts.map +1 -0
- package/dist/integrations/sessions/run-discovery.js +142 -0
- package/dist/integrations/sessions/run-discovery.js.map +1 -0
- package/dist/integrations/sessions/store.d.ts +8 -18
- package/dist/integrations/sessions/store.d.ts.map +1 -1
- package/dist/integrations/sessions/store.js +14 -39
- package/dist/integrations/sessions/store.js.map +1 -1
- package/dist/integrations/sessions/transcript-export.d.ts +0 -1
- package/dist/integrations/sessions/transcript-export.d.ts.map +1 -1
- package/dist/integrations/sessions/transcript-export.js +3 -2
- package/dist/integrations/sessions/transcript-export.js.map +1 -1
- package/dist/integrations/sessions/turn-evidence.d.ts +0 -9
- package/dist/integrations/sessions/turn-evidence.d.ts.map +1 -1
- package/dist/integrations/sessions/turn-evidence.js +5 -2
- package/dist/integrations/sessions/turn-evidence.js.map +1 -1
- package/dist/integrations/state/private-directory.d.ts +4 -2
- package/dist/integrations/state/private-directory.d.ts.map +1 -1
- package/dist/integrations/state/private-directory.js +6 -4
- package/dist/integrations/state/private-directory.js.map +1 -1
- package/dist/integrations/state/report.d.ts.map +1 -1
- package/dist/integrations/state/report.js +78 -21
- package/dist/integrations/state/report.js.map +1 -1
- package/dist/integrations/subagents/parent.d.ts +3 -2
- package/dist/integrations/subagents/parent.d.ts.map +1 -1
- package/dist/integrations/subagents/parent.js +11 -6
- package/dist/integrations/subagents/parent.js.map +1 -1
- package/dist/integrations/subagents/policy.d.ts +2 -5
- package/dist/integrations/subagents/policy.d.ts.map +1 -1
- package/dist/integrations/subagents/policy.js +2 -5
- package/dist/integrations/subagents/policy.js.map +1 -1
- package/dist/integrations/subagents/runtime.d.ts +7 -0
- package/dist/integrations/subagents/runtime.d.ts.map +1 -1
- package/dist/integrations/subagents/runtime.js +9 -7
- package/dist/integrations/subagents/runtime.js.map +1 -1
- package/dist/permissions/rules.d.ts +2 -8
- package/dist/permissions/rules.d.ts.map +1 -1
- package/dist/permissions/rules.js +19 -10
- package/dist/permissions/rules.js.map +1 -1
- package/dist/tui/App.d.ts +0 -12
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +235 -15
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/ChoicePicker.d.ts +2 -1
- package/dist/tui/ChoicePicker.d.ts.map +1 -1
- package/dist/tui/ChoicePicker.js +10 -8
- package/dist/tui/ChoicePicker.js.map +1 -1
- package/dist/tui/ToolOutputViewer.js +1 -1
- package/dist/tui/ToolOutputViewer.js.map +1 -1
- package/dist/tui/agent.d.ts +29 -3
- package/dist/tui/agent.d.ts.map +1 -1
- package/dist/tui/agent.js +233 -46
- package/dist/tui/agent.js.map +1 -1
- package/dist/tui/conversation-evidence-view.d.ts +6 -0
- package/dist/tui/conversation-evidence-view.d.ts.map +1 -0
- package/dist/tui/conversation-evidence-view.js +96 -0
- package/dist/tui/conversation-evidence-view.js.map +1 -0
- package/dist/tui/conversation-history.d.ts +3 -1
- package/dist/tui/conversation-history.d.ts.map +1 -1
- package/dist/tui/conversation-history.js +16 -1
- package/dist/tui/conversation-history.js.map +1 -1
- package/dist/tui/exit-summary.d.ts +1 -1
- package/dist/tui/exit-summary.d.ts.map +1 -1
- package/dist/tui/exit-summary.js +17 -5
- package/dist/tui/exit-summary.js.map +1 -1
- package/dist/tui/markdownParser.d.ts.map +1 -1
- package/dist/tui/markdownParser.js +2 -1
- package/dist/tui/markdownParser.js.map +1 -1
- package/dist/tui/plugin-view.d.ts +9 -0
- package/dist/tui/plugin-view.d.ts.map +1 -0
- package/dist/tui/plugin-view.js +59 -0
- package/dist/tui/plugin-view.js.map +1 -0
- package/dist/tui/run-interruption.d.ts +2 -2
- package/dist/tui/run-interruption.d.ts.map +1 -1
- package/dist/tui/run-interruption.js +5 -1
- package/dist/tui/run-interruption.js.map +1 -1
- package/dist/tui/run-limits-settings.d.ts +39 -0
- package/dist/tui/run-limits-settings.d.ts.map +1 -0
- package/dist/tui/run-limits-settings.js +88 -0
- package/dist/tui/run-limits-settings.js.map +1 -0
- package/dist/tui/slashCommands.d.ts +6 -1
- package/dist/tui/slashCommands.d.ts.map +1 -1
- package/dist/tui/slashCommands.js +40 -9
- package/dist/tui/slashCommands.js.map +1 -1
- package/dist/tui/types.d.ts +4 -2
- package/dist/tui/types.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isDeepStrictEqual, stripVTControlCharacters } from 'node:util';
|
|
3
|
+
import { inspectResidentConsumption, isEntityId, } from '@namzu/sdk';
|
|
4
|
+
import { readResidentAttemptReceipt } from './tool-evidence.js';
|
|
5
|
+
function object(value) {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
7
|
+
throw new Error('Invalid resident receipt object.');
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function count(value) {
|
|
11
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
|
|
12
|
+
throw new Error('Invalid receipt count.');
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function text(value) {
|
|
16
|
+
if (typeof value !== 'string')
|
|
17
|
+
throw new Error('Invalid receipt text.');
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function id(value) {
|
|
21
|
+
if (!isEntityId(value, 'run'))
|
|
22
|
+
throw new Error('Invalid receipt identity.');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function identity(value) {
|
|
26
|
+
const v = object(value);
|
|
27
|
+
if (v.version !== 1)
|
|
28
|
+
throw new Error('Unknown attempt receipt version.');
|
|
29
|
+
return {
|
|
30
|
+
version: 1,
|
|
31
|
+
pursuitId: id(v.pursuitId),
|
|
32
|
+
claimId: id(v.claimId),
|
|
33
|
+
sessionId: id(v.sessionId),
|
|
34
|
+
runId: id(v.runId),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function parseBudget(value) {
|
|
38
|
+
if (value === undefined)
|
|
39
|
+
return null;
|
|
40
|
+
const b = object(value);
|
|
41
|
+
if (typeof b.poisoned !== 'boolean')
|
|
42
|
+
throw new Error('Invalid budget state.');
|
|
43
|
+
return {
|
|
44
|
+
ownTokens: count(b.ownTokens),
|
|
45
|
+
treeTokens: count(b.treeTokens),
|
|
46
|
+
inFlightRequests: count(b.inFlightRequests),
|
|
47
|
+
unsettledChildren: count(b.unsettledChildren),
|
|
48
|
+
poisoned: b.poisoned,
|
|
49
|
+
unresolvedRequests: b.unresolvedRequests === undefined ? null : count(b.unresolvedRequests),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function parseFinish(value) {
|
|
53
|
+
const f = object(value);
|
|
54
|
+
if (f.cleanup !== 'confirmed' && f.cleanup !== 'unconfirmed')
|
|
55
|
+
throw new Error('Unknown cleanup state.');
|
|
56
|
+
if (f.error !== null)
|
|
57
|
+
text(f.error);
|
|
58
|
+
if (f.stopReason !== null)
|
|
59
|
+
text(f.stopReason);
|
|
60
|
+
const decision = f.decision === null ? null : object(f.decision);
|
|
61
|
+
if (decision && !['wait', 'complete', 'blocked'].includes(text(decision.kind)))
|
|
62
|
+
throw new Error('Invalid attempt outcome.');
|
|
63
|
+
const u = f.usage === null ? null : object(f.usage);
|
|
64
|
+
const cost = u ? object(u.cost) : null;
|
|
65
|
+
if (cost &&
|
|
66
|
+
(typeof cost.totalCost !== 'number' || !Number.isFinite(cost.totalCost) || cost.totalCost < 0))
|
|
67
|
+
throw new Error('Invalid cost.');
|
|
68
|
+
return {
|
|
69
|
+
...identity(f),
|
|
70
|
+
finishedAt: count(f.finishedAt),
|
|
71
|
+
cleanup: f.cleanup,
|
|
72
|
+
error: f.error,
|
|
73
|
+
decision,
|
|
74
|
+
budget: parseBudget(f.budget),
|
|
75
|
+
verificationPolicy: f.verificationPolicy,
|
|
76
|
+
verification: f.verification ? object(f.verification) : null,
|
|
77
|
+
usage: u && cost
|
|
78
|
+
? {
|
|
79
|
+
totalTokens: count(u.totalTokens),
|
|
80
|
+
cost: {
|
|
81
|
+
totalCost: cost.totalCost,
|
|
82
|
+
unpricedTokens: count(cost.unpricedTokens),
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
: null,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Uses only scoped attempt/run records. No provider discovery or session writes. */
|
|
89
|
+
export function residentConsumptionResolver(resident) {
|
|
90
|
+
const read = async (path, signal) => {
|
|
91
|
+
try {
|
|
92
|
+
return await readResidentAttemptReceipt(resident.root, path, signal);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error.code === 'ENOENT')
|
|
96
|
+
return null;
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
maxReadBytes: 3 * 65_536,
|
|
102
|
+
async resolve(admission, signal) {
|
|
103
|
+
id(admission.claimId);
|
|
104
|
+
const dir = join(resident.artifactsRoot, admission.claimId);
|
|
105
|
+
const rawStart = await read(join(dir, 'start.json'), signal);
|
|
106
|
+
if (!rawStart)
|
|
107
|
+
return null;
|
|
108
|
+
const start = { ...identity(rawStart), startedAt: count(object(rawStart).startedAt) };
|
|
109
|
+
if (start.claimId !== admission.claimId || start.pursuitId !== admission.pursuitId)
|
|
110
|
+
throw new Error('Attempt does not match the admitted claim.');
|
|
111
|
+
const rawRun = await read(join(resident.root, 'sessions', start.sessionId, 'runs', start.runId, 'run.json'), signal);
|
|
112
|
+
if (!rawRun)
|
|
113
|
+
return null;
|
|
114
|
+
const raw = object(rawRun);
|
|
115
|
+
const run = {
|
|
116
|
+
id: id(raw.id),
|
|
117
|
+
metadata: { scope: object(object(raw.metadata).scope) },
|
|
118
|
+
tokenUsage: { totalTokens: count(object(raw.tokenUsage).totalTokens) },
|
|
119
|
+
budget: parseBudget(raw.budget),
|
|
120
|
+
};
|
|
121
|
+
if (run.id !== start.runId ||
|
|
122
|
+
!isDeepStrictEqual(run.metadata.scope, {
|
|
123
|
+
tenantId: resident.tenantId,
|
|
124
|
+
projectId: resident.projectId,
|
|
125
|
+
sessionId: start.sessionId,
|
|
126
|
+
runId: start.runId,
|
|
127
|
+
}))
|
|
128
|
+
throw new Error('Attempt run is outside this resident project.');
|
|
129
|
+
const rawFinish = await read(join(dir, 'finish.json'), signal);
|
|
130
|
+
const finish = rawFinish === null ? null : parseFinish(rawFinish);
|
|
131
|
+
if (finish &&
|
|
132
|
+
(!isDeepStrictEqual(identity(start), identity(finish)) ||
|
|
133
|
+
finish.finishedAt < start.startedAt))
|
|
134
|
+
throw new Error('Attempt receipts disagree.');
|
|
135
|
+
if (finish?.usage && finish.usage.totalTokens !== run.tokenUsage.totalTokens)
|
|
136
|
+
throw new Error('Finish usage disagrees with the scoped run.');
|
|
137
|
+
const tree = finish?.budget ?? run.budget;
|
|
138
|
+
if (tree && tree.ownTokens !== run.tokenUsage.totalTokens)
|
|
139
|
+
throw new Error('Tree ledger disagrees with own usage.');
|
|
140
|
+
let verification = !finish || finish.verificationPolicy ? 'unconfirmed' : 'unconfigured';
|
|
141
|
+
if (finish?.verification) {
|
|
142
|
+
const receipt = object(finish.verification.receipt);
|
|
143
|
+
if (!/^[a-f0-9]{64}$/.test(text(finish.verification.answerSha256)) ||
|
|
144
|
+
!Array.isArray(receipt.observations) ||
|
|
145
|
+
receipt.observations.length < 1 ||
|
|
146
|
+
receipt.observations.length > 32)
|
|
147
|
+
throw new Error('Invalid verification receipt.');
|
|
148
|
+
const expectedScope = {
|
|
149
|
+
tenantId: resident.tenantId,
|
|
150
|
+
projectId: resident.projectId,
|
|
151
|
+
pursuitId: admission.pursuitId,
|
|
152
|
+
claimId: admission.claimId,
|
|
153
|
+
sessionId: start.sessionId,
|
|
154
|
+
runId: start.runId,
|
|
155
|
+
revision: admission.pursuitRevision,
|
|
156
|
+
};
|
|
157
|
+
if (!isDeepStrictEqual(JSON.parse(text(receipt.scope)), expectedScope) ||
|
|
158
|
+
receipt.runId !== start.runId ||
|
|
159
|
+
finish.decision?.kind !== 'complete' ||
|
|
160
|
+
finish.error !== null ||
|
|
161
|
+
finish.cleanup !== 'confirmed' ||
|
|
162
|
+
receipt.observations.some((item) => {
|
|
163
|
+
const o = object(item);
|
|
164
|
+
const at = count(o.observedAt);
|
|
165
|
+
count(o.bytes);
|
|
166
|
+
text(o.source);
|
|
167
|
+
return (!/^[a-f0-9]{64}$/.test(text(o.sha256)) ||
|
|
168
|
+
at < start.startedAt ||
|
|
169
|
+
at > finish.finishedAt);
|
|
170
|
+
}))
|
|
171
|
+
throw new Error('Verification receipt does not match this attempt.');
|
|
172
|
+
const policy = object(finish.verificationPolicy);
|
|
173
|
+
const claims = object(receipt.claims);
|
|
174
|
+
if (policy.version !== 1 ||
|
|
175
|
+
!Array.isArray(policy.claims) ||
|
|
176
|
+
policy.claims.length < 1 ||
|
|
177
|
+
policy.claims.length > 32 ||
|
|
178
|
+
Object.keys(claims).length !== policy.claims.length)
|
|
179
|
+
throw new Error('Invalid verification policy.');
|
|
180
|
+
const requirements = policy.claims.map(object);
|
|
181
|
+
const sources = new Set(requirements.map((r) => text(r.source)));
|
|
182
|
+
if (new Set(requirements.map((r) => text(r.id))).size !== requirements.length ||
|
|
183
|
+
requirements.some((r) => {
|
|
184
|
+
const key = text(r.id);
|
|
185
|
+
const value = claims[key];
|
|
186
|
+
return (!Object.hasOwn(claims, key) ||
|
|
187
|
+
!(value === null ||
|
|
188
|
+
typeof value === 'boolean' ||
|
|
189
|
+
(typeof value === 'string' && value.length <= 2000) ||
|
|
190
|
+
(typeof value === 'number' && Number.isSafeInteger(value))) ||
|
|
191
|
+
(Object.hasOwn(r, 'expected') && !isDeepStrictEqual(value, r.expected)));
|
|
192
|
+
}) ||
|
|
193
|
+
receipt.observations.length !== sources.size ||
|
|
194
|
+
new Set(receipt.observations.map((o) => text(object(o).source))).size !== sources.size ||
|
|
195
|
+
receipt.observations.some((o) => !sources.has(text(object(o).source))))
|
|
196
|
+
throw new Error('Incomplete verification evidence.');
|
|
197
|
+
verification = 'recorded';
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
runId: start.runId,
|
|
201
|
+
ownTokens: finish?.usage?.totalTokens ?? run.tokenUsage.totalTokens,
|
|
202
|
+
treeTokens: tree?.treeTokens ?? null,
|
|
203
|
+
ownCostUsd: finish?.usage?.cost.totalCost ?? null,
|
|
204
|
+
unpricedOwnTokens: finish?.usage?.cost.unpricedTokens ?? null,
|
|
205
|
+
usageFinal: !!finish?.usage &&
|
|
206
|
+
finish.error === null &&
|
|
207
|
+
finish.cleanup === 'confirmed' &&
|
|
208
|
+
!!tree &&
|
|
209
|
+
tree.inFlightRequests === 0 &&
|
|
210
|
+
tree.unsettledChildren === 0 &&
|
|
211
|
+
!tree.poisoned &&
|
|
212
|
+
tree.unresolvedRequests === 0,
|
|
213
|
+
cleanup: (finish?.cleanup ?? 'unknown'),
|
|
214
|
+
verification,
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const line = (value) => stripVTControlCharacters(value).replace(/[\p{Cc}\p{Cf}]/gu, ' ');
|
|
220
|
+
export function residentInspectionText(report) {
|
|
221
|
+
const { recorded, unknown } = report;
|
|
222
|
+
const deferred = report.attempts.filter((a) => a.receiptStatus === 'deferred');
|
|
223
|
+
const missing = report.attempts.filter((a) => a.receiptStatus === 'missing').length;
|
|
224
|
+
const invalid = report.attempts.filter((a) => a.receiptStatus === 'invalid' || a.receiptStatus === 'duplicate-run').length;
|
|
225
|
+
const settled = report.attempts.filter((a) => a.settlement).length;
|
|
226
|
+
const verified = report.attempts.filter((a) => a.settlement?.outcome === 'complete' && a.receipt?.verification === 'recorded').length;
|
|
227
|
+
return [
|
|
228
|
+
`Resident ${line(report.scope.agentKey)} · ${report.historyComplete ? 'lifetime history' : 'partial history'}`,
|
|
229
|
+
`Revisions ${report.fromRevision}–${report.throughRevision} of ${report.scope.throughRevision}${report.nextCursor === null ? '' : ` · next cursor ${report.nextCursor}`}`,
|
|
230
|
+
`${report.attempts.length} admitted · ${settled} settled · ${verified} ${verified === 1 ? 'completion' : 'completions'} with recorded verification · ${report.archivedPursuits.length} archived pursuits`,
|
|
231
|
+
`Recorded tokens: ${recorded.ownTokens} own · ${recorded.treeTokens} including descendants (separate totals)`,
|
|
232
|
+
`Known own cost: $${recorded.ownCostUsd.toFixed(6)}${unknown.ownPriceAttempts ? ' (partial)' : ''} · ${recorded.unpricedOwnTokens} unpriced own tokens · descendant prices not included`,
|
|
233
|
+
`Incomplete attempts: ${unknown.ownUsageAttempts} own usage · ${unknown.treeUsageAttempts} tree usage · ${unknown.ownPriceAttempts} own price`,
|
|
234
|
+
...(report.unavailableRevisions.length
|
|
235
|
+
? [`Unavailable history revisions: ${report.unavailableRevisions.join(', ')}`]
|
|
236
|
+
: []),
|
|
237
|
+
...(missing || invalid || deferred.length
|
|
238
|
+
? [
|
|
239
|
+
`Receipts: ${missing} missing · ${invalid} invalid · ${deferred.length} deferred by read allowance`,
|
|
240
|
+
]
|
|
241
|
+
: []),
|
|
242
|
+
...(deferred[0]
|
|
243
|
+
? [
|
|
244
|
+
`Continue deferred receipts: resident inspect --cursor ${deferred[0].revision} --through-revision ${report.scope.throughRevision}`,
|
|
245
|
+
]
|
|
246
|
+
: []),
|
|
247
|
+
'Accounting only; existing limits apply per step. Verification is historical, not a current-source check.',
|
|
248
|
+
'',
|
|
249
|
+
...report.attempts.slice(-20).map((a) => {
|
|
250
|
+
const state = a.settlement?.outcome ??
|
|
251
|
+
(report.historyComplete ? 'unsettled' : 'settlement outside this view or unresolved');
|
|
252
|
+
return `${a.claimId} · step ${a.step} · ${state} · ${a.receipt?.ownTokens ?? '?'} own tokens${a.receipt?.usageFinal ? '' : ' (partial/unknown)'}\n ${line(a.objective).slice(0, 180)}`;
|
|
253
|
+
}),
|
|
254
|
+
...(report.attempts.length > 20
|
|
255
|
+
? [`Showing latest 20 of ${report.attempts.length} inspected attempts; JSON includes all.`]
|
|
256
|
+
: []),
|
|
257
|
+
].join('\n');
|
|
258
|
+
}
|
|
259
|
+
export async function inspectCliResident(resident, throughRevision, options, signal) {
|
|
260
|
+
const inspection = await inspectResidentConsumption(resident.agenda.activity(throughRevision), residentConsumptionResolver(resident), options, signal);
|
|
261
|
+
return { inspection, text: residentInspectionText(inspection) };
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspection.js","sourceRoot":"","sources":["../../../src/integrations/resident/inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EAMN,0BAA0B,EAC1B,UAAU,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAE/D,SAAS,MAAM,CAAC,KAAc;IAC7B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC9D,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACpD,OAAO,KAAgC,CAAA;AACxC,CAAC;AACD,SAAS,KAAK,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QACzE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAA;AACb,CAAC;AACD,SAAS,IAAI,CAAC,KAAc;IAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACvE,OAAO,KAAK,CAAA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AAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;QACxL,CAAC,CAAC;QACF,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,EAAE;YAC9B,CAAC,CAAC,CAAC,wBAAwB,MAAM,CAAC,QAAQ,CAAC,MAAM,yCAAyC,CAAC;YAC3F,CAAC,CAAC,EAAE,CAAC;KACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,QAAqB,EACrB,eAAuB,EACvB,OAAoC,EACpC,MAAoB;IAEpB,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAClD,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,EACzC,2BAA2B,CAAC,QAAQ,CAAC,EACrC,OAAO,EACP,MAAM,CACN,CAAA;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,sBAAsB,CAAC,UAAU,CAAC,EAAE,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResidentLearningSource, ResidentLearningState } from '@namzu/sdk';
|
|
2
|
+
/** Resolve only declared local file dependencies; no credentials, network or model calls. */
|
|
3
|
+
export declare function residentLearningSources(cwd: string, learning?: ResidentLearningState): () => readonly ResidentLearningSource[];
|
|
4
|
+
//# sourceMappingURL=learning-sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-sources.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/learning-sources.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAM/E,6FAA6F;AAC7F,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,qBAAqB,GAC9B,MAAM,SAAS,sBAAsB,EAAE,CA4EzC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants, closeSync, fstatSync, openSync, readSync, realpathSync, statSync, } from 'node:fs';
|
|
3
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
4
|
+
const PREFIX = 'workspace-file:';
|
|
5
|
+
const MAX_BYTES = 256 * 1024;
|
|
6
|
+
const MAX_TOTAL_BYTES = 1024 * 1024;
|
|
7
|
+
/** Resolve only declared local file dependencies; no credentials, network or model calls. */
|
|
8
|
+
export function residentLearningSources(cwd, learning) {
|
|
9
|
+
const keys = [
|
|
10
|
+
...new Set(learning?.skills.flatMap((skill) => skill.sources?.map((source) => source.key) ?? []) ?? []),
|
|
11
|
+
];
|
|
12
|
+
return () => {
|
|
13
|
+
const observations = [];
|
|
14
|
+
let remaining = MAX_TOTAL_BYTES;
|
|
15
|
+
const root = realpathSync(cwd);
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
if (!key.startsWith(PREFIX))
|
|
18
|
+
continue;
|
|
19
|
+
const path = key.slice(PREFIX.length);
|
|
20
|
+
// Keys are portable, canonical, workspace-relative paths. No traversal or Windows ADS.
|
|
21
|
+
if (!path ||
|
|
22
|
+
path.includes('\\') ||
|
|
23
|
+
path.includes(':') ||
|
|
24
|
+
path.includes('\0') ||
|
|
25
|
+
isAbsolute(path) ||
|
|
26
|
+
path.split('/').some((part) => !part || part === '.' || part === '..'))
|
|
27
|
+
continue;
|
|
28
|
+
let fd;
|
|
29
|
+
try {
|
|
30
|
+
const target = resolve(root, path);
|
|
31
|
+
const actual = realpathSync(target);
|
|
32
|
+
const fromRoot = relative(root, actual);
|
|
33
|
+
if (!fromRoot ||
|
|
34
|
+
isAbsolute(fromRoot) ||
|
|
35
|
+
fromRoot === '..' ||
|
|
36
|
+
fromRoot.startsWith(`..${sep}`) ||
|
|
37
|
+
actual !== target)
|
|
38
|
+
continue;
|
|
39
|
+
fd = openSync(target, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
40
|
+
const before = fstatSync(fd, { bigint: true });
|
|
41
|
+
if (!before.isFile() || before.size > BigInt(MAX_BYTES) || before.size > BigInt(remaining))
|
|
42
|
+
continue;
|
|
43
|
+
const size = Number(before.size);
|
|
44
|
+
remaining -= size;
|
|
45
|
+
const bytes = Buffer.alloc(size + 1);
|
|
46
|
+
let length = 0;
|
|
47
|
+
while (length < bytes.length) {
|
|
48
|
+
const count = readSync(fd, bytes, length, bytes.length - length, length);
|
|
49
|
+
if (!count)
|
|
50
|
+
break;
|
|
51
|
+
length += count;
|
|
52
|
+
}
|
|
53
|
+
const after = fstatSync(fd, { bigint: true });
|
|
54
|
+
const current = statSync(target, { bigint: true });
|
|
55
|
+
if (length !== size ||
|
|
56
|
+
current.dev !== after.dev ||
|
|
57
|
+
current.ino !== after.ino ||
|
|
58
|
+
after.size !== before.size ||
|
|
59
|
+
after.mtimeNs !== before.mtimeNs ||
|
|
60
|
+
after.ctimeNs !== before.ctimeNs ||
|
|
61
|
+
realpathSync(target) !== actual)
|
|
62
|
+
continue;
|
|
63
|
+
observations.push({
|
|
64
|
+
key,
|
|
65
|
+
revision: createHash('sha256').update(bytes.subarray(0, size)).digest('hex'),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* Missing, changed or unreadable sources remain unverified. */
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
if (fd !== undefined)
|
|
73
|
+
closeSync(fd);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return observations;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=learning-sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-sources.js","sourceRoot":"","sources":["../../../src/integrations/resident/learning-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OA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identLearningStore } from '@namzu/sdk';
|
|
2
|
+
import type { CliResident } from './storage.js';
|
|
3
|
+
/** One installation database; SQL scope replaces a directory/index per experiment. */
|
|
4
|
+
export declare function residentLearningStore(resident: CliResident, readOnly?: boolean): SqliteResidentLearningStore | null;
|
|
5
|
+
//# sourceMappingURL=learning-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-storage.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/learning-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,sFAAsF;AACtF,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,WAAW,EACrB,QAAQ,UAAQ,GACd,2BAA2B,GAAG,IAAI,CAuCpC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { SqliteResidentLearningStore } from '@namzu/sdk';
|
|
4
|
+
import { ensurePrivateStateDirectory } from '../state/private-directory.js';
|
|
5
|
+
/** One installation database; SQL scope replaces a directory/index per experiment. */
|
|
6
|
+
export function residentLearningStore(resident, readOnly = false) {
|
|
7
|
+
const databasePath = join(resident.root, 'state', 'learning.sqlite');
|
|
8
|
+
const learningRoot = join(resident.root, 'learning');
|
|
9
|
+
const artifactsPath = join(learningRoot, 'artifacts');
|
|
10
|
+
if (readOnly) {
|
|
11
|
+
for (const directory of [join(resident.root, 'state'), learningRoot, artifactsPath]) {
|
|
12
|
+
if (!existsSync(directory))
|
|
13
|
+
continue;
|
|
14
|
+
const entry = lstatSync(directory);
|
|
15
|
+
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
16
|
+
throw new Error(`Learning state requires a real directory: ${directory}`);
|
|
17
|
+
}
|
|
18
|
+
if (!existsSync(databasePath))
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
ensurePrivateStateDirectory(resident.root, 'state');
|
|
23
|
+
ensurePrivateStateDirectory(resident.root, 'learning');
|
|
24
|
+
ensurePrivateStateDirectory(learningRoot, 'artifacts');
|
|
25
|
+
}
|
|
26
|
+
for (const file of [
|
|
27
|
+
databasePath,
|
|
28
|
+
`${databasePath}-journal`,
|
|
29
|
+
`${databasePath}-wal`,
|
|
30
|
+
`${databasePath}-shm`,
|
|
31
|
+
]) {
|
|
32
|
+
let entry;
|
|
33
|
+
try {
|
|
34
|
+
entry = lstatSync(file);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error.code === 'ENOENT')
|
|
38
|
+
continue;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
if (!entry.isFile() || entry.isSymbolicLink() || entry.nlink !== 1)
|
|
42
|
+
throw new Error(`Learning database requires a private regular file: ${file}`);
|
|
43
|
+
}
|
|
44
|
+
return new SqliteResidentLearningStore({
|
|
45
|
+
databasePath,
|
|
46
|
+
artifactsPath,
|
|
47
|
+
scope: resident,
|
|
48
|
+
readOnly,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=learning-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-storage.js","sourceRoot":"","sources":["../../../src/integrations/resident/learning-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAG3E,sFAAsF;AACtF,MAAM,UAAU,qBAAqB,CACpC,QAAqB,EACrB,QAAQ,GAAG,KAAK;IAEhB,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,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,CAAA;QACZ,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,cAAc,EAAE,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC;YACjE,MAAM,IAAI,KAAK,CAAC,sDAAsD,IAAI,EAAE,CAAC,CAAA;IAC/E,CAAC;IACD,OAAO,IAAI,2BAA2B,CAAC;QACtC,YAAY;QACZ,aAAa;QACb,KAAK,EAAE,QAAQ;QACf,QAAQ;KACR,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The callback has finished awaiting cleanup, but cannot certify that every
|
|
3
|
+
* owned resource drained. A managed runner must retain its ownership record.
|
|
4
|
+
* Latch this error at the step boundary: cancellation may hide it at the host.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResidentCleanupUnconfirmedError extends AggregateError {
|
|
7
|
+
constructor(errors: readonly unknown[]);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=lifecycle-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-errors.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/lifecycle-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,cAAc;gBACtD,MAAM,EAAE,SAAS,OAAO,EAAE;CAYtC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The callback has finished awaiting cleanup, but cannot certify that every
|
|
3
|
+
* owned resource drained. A managed runner must retain its ownership record.
|
|
4
|
+
* Latch this error at the step boundary: cancellation may hide it at the host.
|
|
5
|
+
*/
|
|
6
|
+
export class ResidentCleanupUnconfirmedError extends AggregateError {
|
|
7
|
+
constructor(errors) {
|
|
8
|
+
super(errors, [
|
|
9
|
+
'Resident cleanup is unconfirmed; runner ownership must be retained.',
|
|
10
|
+
...errors.map((error) => (error instanceof Error ? error.message : String(error)).slice(0, 4_000)),
|
|
11
|
+
].join('\n'));
|
|
12
|
+
this.name = 'ResidentCleanupUnconfirmedError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=lifecycle-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-errors.js","sourceRoot":"","sources":["../../../src/integrations/resident/lifecycle-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,+BAAgC,SAAQ,cAAc;IAClE,YAAY,MAA0B;QACrC,KAAK,CACJ,MAAM,EACN;YACC,qEAAqE;YACrE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACvB,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CACxE;SACD,CAAC,IAAI,CAAC,IAAI,CAAC,CACZ,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAA;IAC9C,CAAC;CACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ResidentContextualStep, ResidentHostResult } from '@namzu/sdk';
|
|
2
|
+
import { type RunnerRecord, publicRunner } from './runner-store.js';
|
|
3
|
+
import type { CliResident } from './storage.js';
|
|
4
|
+
export interface OwnedResidentOptions {
|
|
5
|
+
readonly resident: CliResident;
|
|
6
|
+
readonly owner: RunnerRecord;
|
|
7
|
+
readonly step: ResidentContextualStep;
|
|
8
|
+
readonly signal: AbortSignal;
|
|
9
|
+
readonly keepAlive: boolean;
|
|
10
|
+
readonly maxIdleMs: number;
|
|
11
|
+
/** Readiness means control and durable ownership are installed, not model availability. */
|
|
12
|
+
readonly ready?: (owner: ReturnType<typeof publicRunner>, signal: AbortSignal) => Promise<void>;
|
|
13
|
+
readonly pollIntervalMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/** Keep ownership until the SDK invocation, callback cleanup and control server drain. */
|
|
16
|
+
export declare function runOwnedResident(options: OwnedResidentOptions): Promise<ResidentHostResult>;
|
|
17
|
+
//# sourceMappingURL=owned-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owned-runner.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/owned-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAI5E,OAAO,EACN,KAAK,YAAY,EAGjB,YAAY,EAEZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAA;IACrC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,2FAA2F;IAC3F,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/F,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAChC;AAED,0FAA0F;AAC1F,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA+EjG"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { runResidentForeground } from './foreground.js';
|
|
2
|
+
import { ResidentCleanupUnconfirmedError } from './lifecycle-errors.js';
|
|
3
|
+
import { createRunnerControlServer } from './runner-control.js';
|
|
4
|
+
import { attachRunning, finishRunner, publicRunner, readRunner, } from './runner-store.js';
|
|
5
|
+
/** Keep ownership until the SDK invocation, callback cleanup and control server drain. */
|
|
6
|
+
export async function runOwnedResident(options) {
|
|
7
|
+
const { resident } = options;
|
|
8
|
+
let owner = options.owner;
|
|
9
|
+
let phase = 'starting';
|
|
10
|
+
let stepsStarted = 0;
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const signal = AbortSignal.any([options.signal, controller.signal]);
|
|
13
|
+
const abort = () => {
|
|
14
|
+
phase = 'stopping';
|
|
15
|
+
controller.abort(new Error('Resident runner stop requested.'));
|
|
16
|
+
};
|
|
17
|
+
const checkControl = async () => {
|
|
18
|
+
const current = readRunner(resident);
|
|
19
|
+
if (current?.instanceId !== owner.instanceId || current.phase !== 'running')
|
|
20
|
+
throw new Error('Resident runner ownership changed; this invocation is fenced.');
|
|
21
|
+
};
|
|
22
|
+
let server;
|
|
23
|
+
let outcome = 'startup_failed';
|
|
24
|
+
let cleanupConfirmed = true;
|
|
25
|
+
try {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const state = await resident.agenda.read();
|
|
28
|
+
if (!state || state.paused || (state.pauseGeneration ?? 0) !== owner.pauseGeneration)
|
|
29
|
+
throw new Error('Resident admission changed before runner startup. Resume and start a new invocation.');
|
|
30
|
+
if (state.pursuits.some((p) => p.state.phase === 'running'))
|
|
31
|
+
throw new Error('Inspect and reconcile unresolved work before starting a runner.');
|
|
32
|
+
server = await createRunnerControlServer({
|
|
33
|
+
instanceId: owner.instanceId,
|
|
34
|
+
token: owner.token,
|
|
35
|
+
getStatus: () => ({
|
|
36
|
+
pid: process.pid,
|
|
37
|
+
phase: signal.aborted ? 'stopping' : phase,
|
|
38
|
+
stepsStarted,
|
|
39
|
+
}),
|
|
40
|
+
onStop: abort,
|
|
41
|
+
});
|
|
42
|
+
owner = attachRunning(resident, owner, { pid: process.pid, port: server.port });
|
|
43
|
+
await checkControl();
|
|
44
|
+
await options.ready?.(publicRunner(owner), signal);
|
|
45
|
+
signal.throwIfAborted();
|
|
46
|
+
phase = 'idle';
|
|
47
|
+
const result = await runResidentForeground({
|
|
48
|
+
agenda: resident.agenda,
|
|
49
|
+
step: async (...args) => {
|
|
50
|
+
phase = 'working';
|
|
51
|
+
stepsStarted++;
|
|
52
|
+
try {
|
|
53
|
+
return await options.step(...args);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
// The SDK host turns aborted callbacks into a cancelled result.
|
|
57
|
+
// Latch failed drainage before that conversion can hide it.
|
|
58
|
+
if (error instanceof ResidentCleanupUnconfirmedError)
|
|
59
|
+
cleanupConfirmed = false;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
phase = signal.aborted ? 'stopping' : 'idle';
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
signal,
|
|
67
|
+
maxSteps: owner.maxSteps,
|
|
68
|
+
maxIdleMs: options.maxIdleMs,
|
|
69
|
+
keepAlive: options.keepAlive,
|
|
70
|
+
expectedPauseGeneration: owner.pauseGeneration,
|
|
71
|
+
checkControl,
|
|
72
|
+
...(options.pollIntervalMs ? { pollIntervalMs: options.pollIntervalMs } : {}),
|
|
73
|
+
});
|
|
74
|
+
outcome = result.status;
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof ResidentCleanupUnconfirmedError)
|
|
79
|
+
cleanupConfirmed = false;
|
|
80
|
+
outcome = signal.aborted ? 'cancelled' : 'failed';
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
phase = 'stopping';
|
|
85
|
+
// A stopped receipt is a drainage acknowledgement, never a PID-liveness guess.
|
|
86
|
+
await server?.close();
|
|
87
|
+
if (cleanupConfirmed)
|
|
88
|
+
finishRunner(resident, owner, outcome);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=owned-run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