@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,462 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
import { BOOT_EVENT_NAMES, EVENT_NAME_ATTRIBUTE, createResidentEvidenceRecallStep, generateRunId, generateSessionId, projectResidentLearning, } from '@namzu/sdk';
|
|
6
|
+
import { applyProviderFlags, buildGate, loadSkillsContext, unknownOptionMessage, } from '../../commands/run-flags.js';
|
|
7
|
+
import { cliLogger } from '../../logging.js';
|
|
8
|
+
import { resolvePermissionMode } from '../../permissions/mode.js';
|
|
9
|
+
import { compilePermissions } from '../../permissions/rules.js';
|
|
10
|
+
import { describeRunInterruption } from '../../tui/run-interruption.js';
|
|
11
|
+
import { publishPrivateJsonIfAbsent } from '../state/immutable-json.js';
|
|
12
|
+
import { ensurePrivateStateDirectory } from '../state/private-directory.js';
|
|
13
|
+
import { attachSessionExport } from '../telemetry/session-export.js';
|
|
14
|
+
import { residentLearningSources } from './learning-sources.js';
|
|
15
|
+
import { ResidentCleanupUnconfirmedError } from './lifecycle-errors.js';
|
|
16
|
+
import { residentToolEvidence } from './tool-evidence.js';
|
|
17
|
+
import { residentClaimVerifier, verificationInstructions, } from './verification.js';
|
|
18
|
+
const MAX_DECISION_CHARS = 32_000;
|
|
19
|
+
const MAX_SUMMARY_CHARS = 8_000;
|
|
20
|
+
const MAX_WAKE_DELAY_MS = 86_400_000;
|
|
21
|
+
// SDK settlement requires a future wake time. A zero-delay request means the
|
|
22
|
+
// next local continuation, with a short scheduling margin for the durable write.
|
|
23
|
+
const MIN_WAKE_DELAY_MS = 1_000;
|
|
24
|
+
const DECISION_CONTRACT = 'Return only one JSON object, without Markdown: {"kind":"complete"|"blocked","summary":"..."} or {"kind":"wait","summary":"...","wakeAfterMs":number|null}. ' +
|
|
25
|
+
'The summary must contain 1 to 8000 characters of useful retained evidence and next steps. ' +
|
|
26
|
+
'wakeAfterMs is null to rest until new evidence, or a whole number from 0 to 86400000 to continue later. ' +
|
|
27
|
+
'Zero requests the next local continuation (at least one second later). ' +
|
|
28
|
+
'Use complete only when the authorized objective is achieved, blocked when a prerequisite is missing, and wait when useful authorized work remains. Do not include other fields.';
|
|
29
|
+
function parseDecision(answer, verification = false) {
|
|
30
|
+
if (answer.length > MAX_DECISION_CHARS)
|
|
31
|
+
throw new Error(`Resident decision exceeds ${MAX_DECISION_CHARS} characters.`);
|
|
32
|
+
let value;
|
|
33
|
+
try {
|
|
34
|
+
value = JSON.parse(answer);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error('Resident decision must be one JSON object without Markdown.');
|
|
38
|
+
}
|
|
39
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
40
|
+
throw new Error('Resident decision must be a JSON object.');
|
|
41
|
+
const input = value;
|
|
42
|
+
if (input.kind !== 'complete' && input.kind !== 'blocked' && input.kind !== 'wait')
|
|
43
|
+
throw new Error('Resident decision kind must be complete, blocked or wait.');
|
|
44
|
+
if (typeof input.summary !== 'string' ||
|
|
45
|
+
input.summary.trim().length === 0 ||
|
|
46
|
+
input.summary.trim().length > MAX_SUMMARY_CHARS)
|
|
47
|
+
throw new Error('Resident decision summary must contain 1 to 8000 characters.');
|
|
48
|
+
const allowed = input.kind === 'wait'
|
|
49
|
+
? ['kind', 'summary', 'wakeAfterMs']
|
|
50
|
+
: input.kind === 'complete' && verification
|
|
51
|
+
? ['kind', 'summary', 'claims']
|
|
52
|
+
: ['kind', 'summary'];
|
|
53
|
+
if (Object.keys(input).some((key) => !allowed.includes(key)))
|
|
54
|
+
throw new Error('Resident decision contains unsupported fields.');
|
|
55
|
+
const summary = input.summary.trim();
|
|
56
|
+
if (input.kind !== 'wait')
|
|
57
|
+
return { kind: input.kind, summary };
|
|
58
|
+
const delay = input.wakeAfterMs;
|
|
59
|
+
if (delay !== null &&
|
|
60
|
+
(typeof delay !== 'number' ||
|
|
61
|
+
!Number.isSafeInteger(delay) ||
|
|
62
|
+
delay < 0 ||
|
|
63
|
+
delay > MAX_WAKE_DELAY_MS))
|
|
64
|
+
throw new Error('Resident wait requires wakeAfterMs: null or a whole number from 0 to 86400000.');
|
|
65
|
+
return { kind: 'wait', summary, wakeAfterMs: delay };
|
|
66
|
+
}
|
|
67
|
+
function defaultPrefs(detected) {
|
|
68
|
+
const first = detected[0];
|
|
69
|
+
return first
|
|
70
|
+
? { version: 3, providers: [{ id: first.entry.id }], subagents: { active: [] } }
|
|
71
|
+
: null;
|
|
72
|
+
}
|
|
73
|
+
function errorText(error) {
|
|
74
|
+
return (error instanceof Error ? error.message : String(error)).slice(0, 4_000);
|
|
75
|
+
}
|
|
76
|
+
function validateFlags({ ctx, flags }) {
|
|
77
|
+
if (flags.unknown.length)
|
|
78
|
+
throw new Error(unknownOptionMessage(flags.unknown));
|
|
79
|
+
if (flags.session || flags.resume || flags.continueLast)
|
|
80
|
+
throw new Error('Resident steps own isolated sessions; --session, --resume and --continue are unsupported.');
|
|
81
|
+
if (flags.waitForProviderMs !== null || (ctx.config.limits?.waitForProviderMs ?? 0) > 0)
|
|
82
|
+
throw new Error('Resident steps do not replay provider checkpoints; remove --wait-for-provider and limits.waitForProviderMs.');
|
|
83
|
+
if (flags.gateRetries !== null &&
|
|
84
|
+
(flags.gates.length === 0 || !Number.isSafeInteger(flags.gateRetries) || flags.gateRetries < 1))
|
|
85
|
+
throw new Error('--gate-retries requires --gate and a whole number above zero.');
|
|
86
|
+
}
|
|
87
|
+
function residentContext(pursuit, context, skills, history, outputInstructions = DECISION_CONTRACT) {
|
|
88
|
+
const { state } = pursuit;
|
|
89
|
+
const learning = projectResidentLearning(context.learning, {
|
|
90
|
+
maxChars: 12_000,
|
|
91
|
+
skillNames: context.learning?.skills.map((skill) => skill.name) ?? [],
|
|
92
|
+
});
|
|
93
|
+
return [
|
|
94
|
+
'Perform one useful step of this explicitly authorized resident pursuit. Work only within its objective and the current project permissions.',
|
|
95
|
+
'Each resident step uses an isolated session. Only the supplied saved state continues between steps; do not assume earlier conversation or tool transcripts are present.',
|
|
96
|
+
'Consider every wakeEvidence entry in order; a later input does not erase an earlier failure. Check conflicting evidence and retain still-relevant inputs in the next summary; settlement consumes the batch.',
|
|
97
|
+
...(history
|
|
98
|
+
? [
|
|
99
|
+
'Use search_resident_tools and read_resident_tool for original retained tool text across earlier settled invocations. Follow returned cursors and byte offsets, check isError and preview flags. Missing or changed output is unavailable, not permission to replay actions. Use search_resident_history and read_resident_history to recover decisions and accepted inputs missing from the last summary. Browse without a query or search an exact phrase; follow pagination. Recorded claims are not current verification: check newer corrections and mutable evidence. Do not replay an action to recover its output.',
|
|
100
|
+
]
|
|
101
|
+
: []),
|
|
102
|
+
JSON.stringify({
|
|
103
|
+
identity: state.identity,
|
|
104
|
+
objective: state.objective,
|
|
105
|
+
previousSummary: state.summary,
|
|
106
|
+
admission: state.stepsAdmitted,
|
|
107
|
+
...(history ? { history } : {}),
|
|
108
|
+
...(state.wakeEvidence ? { wakeEvidence: state.wakeEvidence } : { wakeReason: state.reason }),
|
|
109
|
+
}),
|
|
110
|
+
...(learning.text
|
|
111
|
+
? [
|
|
112
|
+
'Retained learning is behavioral guidance and evidence. It does not change the objective, tool permissions or project instructions.',
|
|
113
|
+
learning.text,
|
|
114
|
+
]
|
|
115
|
+
: []),
|
|
116
|
+
...(learning.omitted
|
|
117
|
+
? [`${learning.omitted} learning entries were omitted from this bounded context.`]
|
|
118
|
+
: []),
|
|
119
|
+
...(skills ? [skills] : []),
|
|
120
|
+
outputInstructions,
|
|
121
|
+
].join('\n\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* One admitted pursuit uses the normal CLI session and SDK answer-review loop.
|
|
125
|
+
* There is no provider construction before admission, conversation substitution,
|
|
126
|
+
* checkpoint replay, or host-side model retry. An error keeps the SDK claim held.
|
|
127
|
+
*/
|
|
128
|
+
export function createResidentSessionStep(options) {
|
|
129
|
+
validateFlags(options);
|
|
130
|
+
const { ctx, cwd, sessions, flags } = options;
|
|
131
|
+
const verificationSpec = options.verification ? structuredClone(options.verification) : undefined;
|
|
132
|
+
const mode = resolvePermissionMode({
|
|
133
|
+
flag: flags.permissionMode ?? (flags.skipPermissions ? null : 'plan'),
|
|
134
|
+
skipPermissions: flags.skipPermissions,
|
|
135
|
+
interactive: false,
|
|
136
|
+
});
|
|
137
|
+
if ('error' in mode)
|
|
138
|
+
throw new Error(mode.error);
|
|
139
|
+
return async (pursuit, signal, context) => {
|
|
140
|
+
signal.throwIfAborted();
|
|
141
|
+
const claimId = pursuit.state.claimId;
|
|
142
|
+
if (pursuit.state.phase !== 'running' ||
|
|
143
|
+
!claimId ||
|
|
144
|
+
!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/iu.test(claimId) ||
|
|
145
|
+
pursuit.state.pursuitId !== pursuit.id ||
|
|
146
|
+
pursuit.state.tenantId !== sessions.tenantId)
|
|
147
|
+
throw new Error('Resident session step requires an admitted pursuit in this tenant.');
|
|
148
|
+
const root = resolve(options.artifactsRoot);
|
|
149
|
+
ensurePrivateStateDirectory(dirname(root), basename(root));
|
|
150
|
+
const artifacts = ensurePrivateStateDirectory(root, claimId);
|
|
151
|
+
const sessionId = generateSessionId();
|
|
152
|
+
const runId = generateRunId();
|
|
153
|
+
const identity = { pursuitId: pursuit.id, claimId, sessionId, runId };
|
|
154
|
+
const verificationScope = JSON.stringify({
|
|
155
|
+
tenantId: sessions.tenantId,
|
|
156
|
+
projectId: sessions.projectId,
|
|
157
|
+
...identity,
|
|
158
|
+
revision: pursuit.state.revision,
|
|
159
|
+
});
|
|
160
|
+
const verifier = verificationSpec
|
|
161
|
+
? residentClaimVerifier(verificationSpec, cwd, verificationScope, runId)
|
|
162
|
+
: undefined;
|
|
163
|
+
const outputInstructions = verificationSpec
|
|
164
|
+
? DECISION_CONTRACT.replace('Do not include other fields.', '') +
|
|
165
|
+
verificationInstructions(verificationSpec)
|
|
166
|
+
: DECISION_CONTRACT;
|
|
167
|
+
let verification;
|
|
168
|
+
const history = options.agenda?.history(pursuit.state, context.agendaRevision);
|
|
169
|
+
const toolEvidence = history ? residentToolEvidence(history, sessions, root) : undefined;
|
|
170
|
+
const startedAt = Date.now();
|
|
171
|
+
let session;
|
|
172
|
+
let sessionExport;
|
|
173
|
+
let sessionCreationAttempted = false;
|
|
174
|
+
let cleanupUnconfirmed = false;
|
|
175
|
+
let started = false;
|
|
176
|
+
let decision;
|
|
177
|
+
let done;
|
|
178
|
+
let usage;
|
|
179
|
+
let budget;
|
|
180
|
+
const errors = [];
|
|
181
|
+
const start = () => {
|
|
182
|
+
const receipt = {
|
|
183
|
+
version: 1,
|
|
184
|
+
...identity,
|
|
185
|
+
startedAt,
|
|
186
|
+
cwd,
|
|
187
|
+
provider: session?.providerSummary ?? null,
|
|
188
|
+
model: session?.modelSummary ?? null,
|
|
189
|
+
};
|
|
190
|
+
const path = join(artifacts, 'start.json');
|
|
191
|
+
publishPrivateJsonIfAbsent(path, receipt);
|
|
192
|
+
if (!isDeepStrictEqual(JSON.parse(readFileSync(path, 'utf8')), receipt))
|
|
193
|
+
throw new Error('This resident claim already has a different execution receipt; refusing replay.');
|
|
194
|
+
started = true;
|
|
195
|
+
};
|
|
196
|
+
try {
|
|
197
|
+
const { probeAgentSession, createAgentSession } = await import('../../tui/agent.js');
|
|
198
|
+
signal.throwIfAborted();
|
|
199
|
+
const probe = await probeAgentSession();
|
|
200
|
+
const configured = probe.preferences ?? defaultPrefs(probe.detected);
|
|
201
|
+
if (!configured)
|
|
202
|
+
throw new Error('No LLM provider available for this resident step; configure one with namzu.');
|
|
203
|
+
const prefs = applyProviderFlags(configured, flags);
|
|
204
|
+
const permissions = compilePermissions(ctx.config.permissions, ctx.config.permissionChecks);
|
|
205
|
+
for (const diagnostic of permissions.diagnostics)
|
|
206
|
+
ctx.formatter.error({ message: `permissions.${diagnostic.tool}: ${diagnostic.message}` });
|
|
207
|
+
const gate = buildGate(flags, cwd);
|
|
208
|
+
const reviewAnswer = async (answer, reviewContext) => {
|
|
209
|
+
verification = undefined;
|
|
210
|
+
let parsed;
|
|
211
|
+
try {
|
|
212
|
+
parsed = parseDecision(answer, !!verifier);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
return { accept: false, feedback: `${errorText(error)}\n${outputInstructions}` };
|
|
216
|
+
}
|
|
217
|
+
// Commands may modify the sources; check claims after the gate completes.
|
|
218
|
+
const gated = gate
|
|
219
|
+
? await gate.reviewAnswer(answer, reviewContext)
|
|
220
|
+
: { accept: true };
|
|
221
|
+
if (!gated.accept)
|
|
222
|
+
return gated;
|
|
223
|
+
if (verifier && parsed.kind === 'complete') {
|
|
224
|
+
const checked = await verifier.verify(JSON.parse(answer).claims, reviewContext);
|
|
225
|
+
if (!checked.accept)
|
|
226
|
+
return checked;
|
|
227
|
+
verification = {
|
|
228
|
+
answerSha256: createHash('sha256').update(answer).digest('hex'),
|
|
229
|
+
receipt: checked.receipt,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return { accept: true };
|
|
233
|
+
};
|
|
234
|
+
if (ctx.config.telemetry?.sessionExport) {
|
|
235
|
+
sessionExport = await attachSessionExport({ config: ctx.config.telemetry.sessionExport });
|
|
236
|
+
cliLogger().info(sessionExport.disclosure, {
|
|
237
|
+
[EVENT_NAME_ATTRIBUTE]: BOOT_EVENT_NAMES.TELEMETRY_STATUS,
|
|
238
|
+
'namzu.telemetry.session_export': true,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
signal.throwIfAborted();
|
|
242
|
+
const limits = {
|
|
243
|
+
...ctx.config.limits,
|
|
244
|
+
...(flags.maxIterations !== null ? { maxIterations: flags.maxIterations } : {}),
|
|
245
|
+
...(flags.tokenBudget !== null ? { tokenBudget: flags.tokenBudget } : {}),
|
|
246
|
+
};
|
|
247
|
+
sessionCreationAttempted = true;
|
|
248
|
+
session = await createAgentSession(prefs, probe.detected, {
|
|
249
|
+
cwd,
|
|
250
|
+
toolLoading: options.toolLoading,
|
|
251
|
+
// Foreground and managed resident hosts already own signal cancellation
|
|
252
|
+
// and must confirm drainage before releasing durable ownership.
|
|
253
|
+
emergencySave: false,
|
|
254
|
+
scope: {
|
|
255
|
+
sessionId,
|
|
256
|
+
topicId: sessions.topicId,
|
|
257
|
+
projectId: sessions.projectId,
|
|
258
|
+
tenantId: sessions.tenantId,
|
|
259
|
+
},
|
|
260
|
+
stateRoot: sessions.root,
|
|
261
|
+
...(history ? { residentHistory: history } : {}),
|
|
262
|
+
...(toolEvidence ? { residentToolEvidence: toolEvidence } : {}),
|
|
263
|
+
...(toolEvidence && ctx.config.compaction?.recallEvidence !== false
|
|
264
|
+
? {
|
|
265
|
+
residentEvidenceRecall: createResidentEvidenceRecallStep({
|
|
266
|
+
source: toolEvidence,
|
|
267
|
+
state: pursuit.state,
|
|
268
|
+
scope: {
|
|
269
|
+
tenantId: sessions.tenantId,
|
|
270
|
+
projectId: sessions.projectId,
|
|
271
|
+
sessionId,
|
|
272
|
+
runId,
|
|
273
|
+
},
|
|
274
|
+
excludeSuccessfulTools: [
|
|
275
|
+
'search_resident_tools',
|
|
276
|
+
'read_resident_tool',
|
|
277
|
+
'search_resident_history',
|
|
278
|
+
'read_resident_history',
|
|
279
|
+
],
|
|
280
|
+
}),
|
|
281
|
+
}
|
|
282
|
+
: {}),
|
|
283
|
+
rules: permissions.rules,
|
|
284
|
+
permissionMode: mode.mode,
|
|
285
|
+
reviewAnswer,
|
|
286
|
+
maxAnswerReviews: gate?.maxAnswerReviews ?? 3,
|
|
287
|
+
...(sessionExport ? { onRunEvent: sessionExport.listener } : {}),
|
|
288
|
+
...(ctx.config.mcpServers ? { mcpServers: ctx.config.mcpServers } : {}),
|
|
289
|
+
...(ctx.config.plugins ? { plugins: ctx.config.plugins } : {}),
|
|
290
|
+
...(ctx.config.web ? { web: ctx.config.web } : {}),
|
|
291
|
+
...(ctx.config.hooks ? { hooks: ctx.config.hooks } : {}),
|
|
292
|
+
...(ctx.config.compaction ? { compaction: ctx.config.compaction } : {}),
|
|
293
|
+
...(ctx.config.memory ? { memory: ctx.config.memory } : {}),
|
|
294
|
+
...(Object.keys(limits).length ? { limits } : {}),
|
|
295
|
+
...(ctx.config.sandbox ? { sandbox: ctx.config.sandbox } : {}),
|
|
296
|
+
...(ctx.config.additionalDirectories
|
|
297
|
+
? {
|
|
298
|
+
additionalDirectories: ctx.config.additionalDirectories.map((directory) => resolve(cwd, directory)),
|
|
299
|
+
}
|
|
300
|
+
: {}),
|
|
301
|
+
});
|
|
302
|
+
// Startup can return an inert refusal after ignoring failed resource
|
|
303
|
+
// cleanup. Its no-op close cannot establish that those resources drained.
|
|
304
|
+
// There is no public marker distinguishing that path from an early refusal.
|
|
305
|
+
if (!session.hasProvider)
|
|
306
|
+
cleanupUnconfirmed = true;
|
|
307
|
+
start();
|
|
308
|
+
if (!session.hasProvider)
|
|
309
|
+
throw new Error(session.errorHint ?? 'Resident agent is not ready.');
|
|
310
|
+
if (session.mcpFailed.length)
|
|
311
|
+
throw new Error(session.mcpFailed
|
|
312
|
+
.map((failure) => `Tool server ${failure.name} is unavailable: ${failure.reason}`)
|
|
313
|
+
.join('\n'));
|
|
314
|
+
for (const notice of session.configNotices)
|
|
315
|
+
ctx.formatter.info(notice);
|
|
316
|
+
ctx.formatter.info(`resident step ${pursuit.state.stepsAdmitted} · ${session.providerSummary} · ${session.modelSummary} · ${mode.mode}`);
|
|
317
|
+
if (session.instructionFiles.length)
|
|
318
|
+
ctx.formatter.info(`project instructions: ${session.instructionFiles.map((path) => relative(cwd, path) || path).join(', ')}`);
|
|
319
|
+
for (const skipped of session.skippedInstructionFiles)
|
|
320
|
+
ctx.formatter.error({
|
|
321
|
+
message: `skipped ${relative(cwd, skipped.path) || skipped.path}: ${skipped.reason}`,
|
|
322
|
+
});
|
|
323
|
+
const skills = await loadSkillsContext(cwd, flags.skills);
|
|
324
|
+
signal.throwIfAborted();
|
|
325
|
+
for await (const event of session.send([
|
|
326
|
+
{
|
|
327
|
+
role: 'user',
|
|
328
|
+
content: `Continue this authorized pursuit: ${pursuit.state.objective}`,
|
|
329
|
+
timestamp: Date.now(),
|
|
330
|
+
},
|
|
331
|
+
], {
|
|
332
|
+
signal,
|
|
333
|
+
runId,
|
|
334
|
+
permissionMode: mode.mode,
|
|
335
|
+
...(options.contextProfile === 'interactive'
|
|
336
|
+
? {
|
|
337
|
+
extraSystem: residentContext(pursuit, context, skills, history?.scope, outputInstructions),
|
|
338
|
+
}
|
|
339
|
+
: {
|
|
340
|
+
residentLearningDisclosure: options.learningDisclosure ?? 'on-demand',
|
|
341
|
+
residentContext: {
|
|
342
|
+
state: pursuit.state,
|
|
343
|
+
learning: context.learning,
|
|
344
|
+
resolveLearningSources: residentLearningSources(cwd, context.learning),
|
|
345
|
+
history: history?.scope,
|
|
346
|
+
toolEvidence: !!toolEvidence,
|
|
347
|
+
readOnly: mode.mode === 'plan',
|
|
348
|
+
skillsContext: skills,
|
|
349
|
+
outputInstructions,
|
|
350
|
+
},
|
|
351
|
+
}),
|
|
352
|
+
...(flags.effort !== null ? { effort: flags.effort } : {}),
|
|
353
|
+
})) {
|
|
354
|
+
if (event.kind === 'done') {
|
|
355
|
+
if (done)
|
|
356
|
+
errors.push(new Error('Resident session emitted more than one settled result.'));
|
|
357
|
+
done = event;
|
|
358
|
+
}
|
|
359
|
+
else if (event.kind === 'error' || event.kind === 'paused') {
|
|
360
|
+
errors.push(new Error(describeRunInterruption(event)));
|
|
361
|
+
}
|
|
362
|
+
else if (event.kind === 'usage')
|
|
363
|
+
usage = event;
|
|
364
|
+
else if (event.kind === 'context')
|
|
365
|
+
ctx.formatter.info(event.text);
|
|
366
|
+
else if (event.kind === 'tool-start')
|
|
367
|
+
ctx.formatter.info(`${event.toolName} ${event.summary}`);
|
|
368
|
+
if ('budget' in event && event.budget)
|
|
369
|
+
budget = event.budget;
|
|
370
|
+
}
|
|
371
|
+
signal.throwIfAborted();
|
|
372
|
+
if (done?.stopReason !== 'end_turn')
|
|
373
|
+
throw new Error(`Resident step did not finish normally (${done?.stopReason ?? 'no settled result'}); its claim remains unresolved.`);
|
|
374
|
+
if (typeof done.text !== 'string')
|
|
375
|
+
throw new Error('Resident step has no settled answer; its claim remains unresolved.');
|
|
376
|
+
if (!errors.length) {
|
|
377
|
+
decision = parseDecision(done.text, !!verifier);
|
|
378
|
+
if (verifier &&
|
|
379
|
+
decision.kind === 'complete' &&
|
|
380
|
+
(!verification ||
|
|
381
|
+
verification.answerSha256 !== createHash('sha256').update(done.text).digest('hex')))
|
|
382
|
+
throw new Error('Resident completion has no matching verification receipt; its claim remains unresolved.');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
errors.push(error);
|
|
387
|
+
// A rejected constructor provides no session handle with which to close
|
|
388
|
+
// resources it may already have opened. Do not infer a clean shutdown.
|
|
389
|
+
if (sessionCreationAttempted && !session)
|
|
390
|
+
cleanupUnconfirmed = true;
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
try {
|
|
394
|
+
await session?.close();
|
|
395
|
+
}
|
|
396
|
+
catch (error) {
|
|
397
|
+
errors.push(error);
|
|
398
|
+
cleanupUnconfirmed = true;
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
await sessionExport?.shutdown();
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
errors.push(error);
|
|
405
|
+
cleanupUnconfirmed = true;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (verifier && !verifier.isDrained()) {
|
|
409
|
+
cleanupUnconfirmed = true;
|
|
410
|
+
errors.push(new Error('A verification observation has not drained.'));
|
|
411
|
+
}
|
|
412
|
+
if (signal.aborted && !errors.includes(signal.reason))
|
|
413
|
+
errors.push(signal.reason);
|
|
414
|
+
try {
|
|
415
|
+
if (!started)
|
|
416
|
+
start();
|
|
417
|
+
// This receipt records the callback outcome and whether cleanup could be
|
|
418
|
+
// confirmed, not durable agenda settlement. It retains no provider history,
|
|
419
|
+
// reasoning blocks, tool inputs or credentials.
|
|
420
|
+
publishPrivateJsonIfAbsent(join(artifacts, 'finish.json'), {
|
|
421
|
+
version: 1,
|
|
422
|
+
...identity,
|
|
423
|
+
finishedAt: Date.now(),
|
|
424
|
+
stopReason: done?.stopReason ?? null,
|
|
425
|
+
decision: errors.length ? null : (decision ?? null),
|
|
426
|
+
error: errors.length ? errors.map(errorText).join('\n').slice(0, 8_000) : null,
|
|
427
|
+
cleanup: cleanupUnconfirmed ? 'unconfirmed' : 'confirmed',
|
|
428
|
+
...(verifier
|
|
429
|
+
? {
|
|
430
|
+
verificationPolicy: verificationSpec,
|
|
431
|
+
verification: errors.length ? null : (verification ?? null),
|
|
432
|
+
}
|
|
433
|
+
: {}),
|
|
434
|
+
usage: usage ? { totalTokens: usage.totalTokens, cost: usage.cost } : null,
|
|
435
|
+
...(budget ? { budget } : {}),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
// A receipt failure must not replace the signal to retain runner ownership.
|
|
440
|
+
errors.push(error);
|
|
441
|
+
}
|
|
442
|
+
if (cleanupUnconfirmed)
|
|
443
|
+
throw new ResidentCleanupUnconfirmedError(errors);
|
|
444
|
+
if (errors.length === 1)
|
|
445
|
+
throw errors[0];
|
|
446
|
+
if (errors.length)
|
|
447
|
+
throw new AggregateError(errors, errors.map(errorText).join('\n'));
|
|
448
|
+
if (!decision)
|
|
449
|
+
throw new Error('Resident step returned no decision.');
|
|
450
|
+
// Compute after cleanup and receipt publication so they do not consume the delay.
|
|
451
|
+
return decision.kind === 'wait'
|
|
452
|
+
? {
|
|
453
|
+
kind: 'wait',
|
|
454
|
+
summary: decision.summary,
|
|
455
|
+
wakeAt: decision.wakeAfterMs === null
|
|
456
|
+
? null
|
|
457
|
+
: Date.now() + Math.max(MIN_WAKE_DELAY_MS, decision.wakeAfterMs),
|
|
458
|
+
}
|
|
459
|
+
: decision;
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
//# sourceMappingURL=session-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-step.js","sourceRoot":"","sources":["../../../src/integrations/resident/session-step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EACN,gBAAgB,EAEhB,oBAAoB,EAQpB,gCAAgC,EAChC,aAAa,EACb,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEN,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,oBAAoB,GACpB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAGvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,EAAE,2BAA2B,EAAE,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AAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC;aAClE;YACF,CAAC,CAAE,QAAoC,CAAA;IACzC,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DiskResidentAgenda, type ProjectId, type TenantId } from '@namzu/sdk';
|
|
2
|
+
export interface CliResident {
|
|
3
|
+
readonly agenda: DiskResidentAgenda;
|
|
4
|
+
/** Canonical execution directory chosen by the first creator. */
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly agentKey: string;
|
|
7
|
+
readonly artifactsRoot: string;
|
|
8
|
+
readonly projectId: ProjectId;
|
|
9
|
+
readonly tenantId: TenantId;
|
|
10
|
+
/** Installation state root, never a second resident-specific hierarchy. */
|
|
11
|
+
readonly root: string;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve existing state only; a status request never mints identity or state. */
|
|
14
|
+
export declare function lookupResident(cwd: string, agentKey: string): Promise<CliResident | null>;
|
|
15
|
+
/** Initialize an explicit operator mutation, reusing the first creator's cwd. */
|
|
16
|
+
export declare function createResident(cwd: string, agentKey: string): Promise<CliResident>;
|
|
17
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/integrations/resident/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,kBAAkB,EAClB,KAAK,SAAS,EAEd,KAAK,QAAQ,EACb,MAAM,YAAY,CAAA;AAYnB,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACrB;AA+FD,mFAAmF;AACnF,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAgB/F;AAED,iFAAiF;AACjF,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAsCxF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { lstatSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { realpath } from 'node:fs/promises';
|
|
4
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { DiskResidentAgenda, ResidentConflictError, } from '@namzu/sdk';
|
|
6
|
+
import { sessionDatabasePath, sessionStore } from '../sessions/database.js';
|
|
7
|
+
import { resolveNamzuHome } from '../state/home.js';
|
|
8
|
+
import { readIdentity } from '../state/identity.js';
|
|
9
|
+
import { publishPrivateJsonIfAbsent } from '../state/immutable-json.js';
|
|
10
|
+
import { ensurePrivateStateDirectory } from '../state/private-directory.js';
|
|
11
|
+
import { cliProjectRoot, findCliProject } from '../state/project.js';
|
|
12
|
+
const MANDATE = 'Pursue only objectives explicitly added by this project’s operator. Respect project instructions and current tool permissions.';
|
|
13
|
+
function validateAgentKey(agentKey) {
|
|
14
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/u.test(agentKey)) {
|
|
15
|
+
throw new Error('Resident agent key must contain 1–64 lowercase letters, digits, underscores or hyphens, starting with a letter or digit.');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Check state boundaries without creating directories or changing their modes. */
|
|
19
|
+
function existingDirectory(path) {
|
|
20
|
+
try {
|
|
21
|
+
const entry = lstatSync(path);
|
|
22
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) {
|
|
23
|
+
throw new Error(`Resident state must use a real directory: ${path}`);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error.code === 'ENOENT')
|
|
29
|
+
return false;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function readBinding(residentsRoot, expected, projectRoot) {
|
|
34
|
+
const agentRoot = join(residentsRoot, expected.agentKey);
|
|
35
|
+
if (!existingDirectory(residentsRoot) || !existingDirectory(agentRoot))
|
|
36
|
+
return null;
|
|
37
|
+
const path = join(agentRoot, 'binding.json');
|
|
38
|
+
try {
|
|
39
|
+
const entry = lstatSync(path);
|
|
40
|
+
if (!entry.isFile() || entry.isSymbolicLink()) {
|
|
41
|
+
throw new Error('expected a regular file, without a symbolic link');
|
|
42
|
+
}
|
|
43
|
+
const raw = JSON.parse(readFileSync(path, 'utf8'));
|
|
44
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
45
|
+
throw new Error('expected an object');
|
|
46
|
+
}
|
|
47
|
+
const value = raw;
|
|
48
|
+
if (value.version !== 1 ||
|
|
49
|
+
value.tenantId !== expected.tenantId ||
|
|
50
|
+
value.projectId !== expected.projectId ||
|
|
51
|
+
value.agentKey !== expected.agentKey) {
|
|
52
|
+
throw new Error('version, tenant, project or agent key does not match this resident');
|
|
53
|
+
}
|
|
54
|
+
const cwd = value.cwd;
|
|
55
|
+
if (typeof cwd !== 'string' || cwd.includes('\0') || !isAbsolute(cwd) || resolve(cwd) !== cwd) {
|
|
56
|
+
throw new Error('expected an absolute canonical execution directory');
|
|
57
|
+
}
|
|
58
|
+
const withinProject = relative(projectRoot, cwd);
|
|
59
|
+
if (withinProject === '..' ||
|
|
60
|
+
withinProject.startsWith(`..${sep}`) ||
|
|
61
|
+
isAbsolute(withinProject)) {
|
|
62
|
+
throw new Error('execution directory is outside the bound project');
|
|
63
|
+
}
|
|
64
|
+
return { version: 1, ...expected, cwd };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (error.code === 'ENOENT')
|
|
68
|
+
return null;
|
|
69
|
+
throw new Error(`${path} is not a valid resident binding: ${error instanceof Error ? error.message : String(error)}. Refusing to replace it.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function residentHandle(root, residentsRoot, binding) {
|
|
73
|
+
return {
|
|
74
|
+
agenda: new DiskResidentAgenda(residentsRoot, binding),
|
|
75
|
+
cwd: binding.cwd,
|
|
76
|
+
agentKey: binding.agentKey,
|
|
77
|
+
artifactsRoot: join(residentsRoot, binding.agentKey, 'attempts'),
|
|
78
|
+
projectId: binding.projectId,
|
|
79
|
+
tenantId: binding.tenantId,
|
|
80
|
+
root,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Resolve existing state only; a status request never mints identity or state. */
|
|
84
|
+
export async function lookupResident(cwd, agentKey) {
|
|
85
|
+
validateAgentKey(agentKey);
|
|
86
|
+
const root = resolveNamzuHome();
|
|
87
|
+
const identity = readIdentity(root);
|
|
88
|
+
if (!identity || !existsSync(sessionDatabasePath(root)))
|
|
89
|
+
return null;
|
|
90
|
+
const workingDirectory = await realpath(resolve(cwd));
|
|
91
|
+
const store = sessionStore(root, true);
|
|
92
|
+
const project = await findCliProject(store, workingDirectory, identity.tenantId);
|
|
93
|
+
if (!project)
|
|
94
|
+
return null;
|
|
95
|
+
const residentsRoot = join(root, 'residents', project.id);
|
|
96
|
+
const binding = readBinding(residentsRoot, { tenantId: identity.tenantId, projectId: project.id, agentKey }, cliProjectRoot(workingDirectory));
|
|
97
|
+
return binding ? residentHandle(root, residentsRoot, binding) : null;
|
|
98
|
+
}
|
|
99
|
+
/** Initialize an explicit operator mutation, reusing the first creator's cwd. */
|
|
100
|
+
export async function createResident(cwd, agentKey) {
|
|
101
|
+
validateAgentKey(agentKey);
|
|
102
|
+
const workingDirectory = await realpath(resolve(cwd));
|
|
103
|
+
const { openSessions } = await import('../sessions/store.js');
|
|
104
|
+
const sessions = await openSessions(workingDirectory);
|
|
105
|
+
const residentsRoot = ensurePrivateStateDirectory(ensurePrivateStateDirectory(sessions.root, 'residents'), sessions.projectId);
|
|
106
|
+
const agentRoot = ensurePrivateStateDirectory(residentsRoot, agentKey);
|
|
107
|
+
const expected = { tenantId: sessions.tenantId, projectId: sessions.projectId, agentKey };
|
|
108
|
+
const projectRoot = cliProjectRoot(workingDirectory);
|
|
109
|
+
let binding = readBinding(residentsRoot, expected, projectRoot);
|
|
110
|
+
if (!binding) {
|
|
111
|
+
publishPrivateJsonIfAbsent(join(agentRoot, 'binding.json'), {
|
|
112
|
+
version: 1,
|
|
113
|
+
...expected,
|
|
114
|
+
cwd: workingDirectory,
|
|
115
|
+
});
|
|
116
|
+
binding = readBinding(residentsRoot, expected, projectRoot);
|
|
117
|
+
if (!binding)
|
|
118
|
+
throw new Error('Resident binding disappeared while it was being initialized.');
|
|
119
|
+
}
|
|
120
|
+
const resident = residentHandle(sessions.root, residentsRoot, binding);
|
|
121
|
+
let agenda = await resident.agenda.read();
|
|
122
|
+
if (!agenda) {
|
|
123
|
+
try {
|
|
124
|
+
agenda = await resident.agenda.create(MANDATE);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (!(error instanceof ResidentConflictError))
|
|
128
|
+
throw error;
|
|
129
|
+
agenda = await resident.agenda.read();
|
|
130
|
+
if (!agenda)
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (agenda.identity !== MANDATE) {
|
|
135
|
+
throw new Error('Resident agenda mandate does not match the CLI operator mandate.');
|
|
136
|
+
}
|
|
137
|
+
ensurePrivateStateDirectory(agentRoot, 'attempts');
|
|
138
|
+
return resident;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=storage.js.map
|