@tnunamak/dalan 0.8.1 → 0.8.2
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 +59 -2
- package/CONTRIBUTING.md +2 -0
- package/README.md +8 -12
- package/bin/dalan.mjs +25 -4
- package/bin/dot-acp-agent.mjs +572 -76
- package/bin/dot-alert.mjs +9 -3
- package/bin/dot-deadman.mjs +3 -1
- package/bin/dot-heartbeat.mjs +14 -7
- package/bin/dot-pr-reviewer.mjs +3 -31
- package/bin/dot-worker.mjs +121 -34
- package/contracts/adapter-qualification.schema.json +94 -7
- package/docs/chatgpt-worker-onboarding.md +1 -1
- package/docs/codex-to-muse.md +2 -2
- package/docs/connect-chatgpt.md +1 -1
- package/docs/connection-longevity.md +2 -2
- package/docs/dalan-upgrade.md +8 -5
- package/docs/deadman.md +4 -0
- package/docs/design/authority-matrix.md +18 -0
- package/docs/design/failure-table.md +87 -0
- package/docs/design/identities.md +22 -0
- package/docs/design/pnpm-prepared-dependencies.md +64 -0
- package/docs/design/reuse-ledger.md +75 -0
- package/docs/design/target-architecture-v2.md +434 -0
- package/docs/local-agent-mcp.md +14 -0
- package/docs/local-agent-requester.md +2 -1
- package/docs/manual-setup.md +1 -1
- package/docs/operations.md +77 -14
- package/docs/pull-workers.md +11 -1
- package/docs/service-setup.md +10 -10
- package/docs/t3-integration.md +4 -2
- package/docs/t3-reverse-control.md +5 -5
- package/docs/test-suite-isolation.md +7 -6
- package/docs/trials/chatgpt-agent.md +47 -0
- package/docs/trials/claude-code-requester.md +68 -0
- package/docs/trials/muse.md +46 -0
- package/docs/usage.md +21 -7
- package/docs/worker-clients.md +1 -1
- package/integrations/t3/acp-kit/src/errors.mjs +6 -2
- package/integrations/t3/acp-kit/src/lock.mjs +46 -17
- package/integrations/t3/acp-kit/src/session-store.mjs +15 -3
- package/integrations/t3/acp-kit/src/t3-envelope.mjs +10 -2
- package/package.json +4 -3
- package/packages/job-core/protocol/canonical.mjs +45 -7
- package/packages/job-core/transitions.mjs +4 -2
- package/scripts/upgrade-drain.mjs +96 -8
- package/scripts/worker-bridge-setup.mjs +215 -120
- package/src/ack-ledger.mjs +7 -1
- package/src/acp-bridge.mjs +256 -28
- package/src/admin-socket.mjs +32 -3
- package/src/alerts.mjs +17 -8
- package/src/answer-journal-retention.mjs +82 -0
- package/src/answer-journal.mjs +6 -4
- package/src/as-store.mjs +51 -6
- package/src/as.mjs +27 -5
- package/src/catalog-switch-inventory.mjs +70 -0
- package/src/check-response.mjs +4 -1
- package/src/cli-help.mjs +14 -3
- package/src/cli-name.mjs +13 -1
- package/src/connect-cli.mjs +159 -4
- package/src/deadman.mjs +8 -5
- package/src/delivery.mjs +2 -19
- package/src/destinations/index.mjs +75 -14
- package/src/drain-runner.mjs +5 -1
- package/src/follow-current.mjs +3 -1
- package/src/get-summary.mjs +11 -2
- package/src/git-env.mjs +1 -1
- package/src/gozar-routes.mjs +313 -94
- package/src/host-budget-storage.py +56 -6
- package/src/host-budget.mjs +98 -15
- package/src/host-execution-policy.mjs +17 -6
- package/src/legacy-names.mjs +0 -2
- package/src/lifecycle.mjs +44 -9
- package/src/loopback-probe.mjs +46 -0
- package/src/mcp-outcome.mjs +3 -1
- package/src/mcp-sse.mjs +2 -1
- package/src/mcp-stdio.mjs +192 -30
- package/src/patch-apply.mjs +212 -7
- package/src/phase-trace.mjs +73 -0
- package/src/prepared-go-modules.mjs +127 -0
- package/src/prepared-node-modules.mjs +225 -38
- package/src/prepared-pnpm.mjs +276 -0
- package/src/prepared-store-prune.mjs +52 -0
- package/src/projects.mjs +59 -7
- package/src/protocol-artifact-commands.mjs +28 -0
- package/src/protocol-finish.mjs +3 -2
- package/src/publication-authority.mjs +22 -0
- package/src/publish-plan.mjs +2 -2
- package/src/pull-queue.mjs +55 -20
- package/src/read-api.mjs +127 -0
- package/src/redaction.mjs +173 -0
- package/src/rejections.mjs +19 -3
- package/src/route-custody.mjs +90 -0
- package/src/route-publication.mjs +50 -0
- package/src/route-setup.mjs +184 -0
- package/src/schema-subset.mjs +5 -3
- package/src/server.mjs +503 -98
- package/src/service-launchd.mjs +5 -1
- package/src/service-update-lock.mjs +7 -4
- package/src/service-update-runtime.mjs +64 -19
- package/src/service-update.mjs +193 -48
- package/src/service.mjs +276 -77
- package/src/setup.mjs +48 -25
- package/src/signal.mjs +1 -1
- package/src/status-evidence.mjs +18 -5
- package/src/store.mjs +876 -120
- package/src/submission-policy.mjs +257 -56
- package/src/t3-control.mjs +1 -1
- package/src/t3.mjs +14 -8
- package/src/terminal-safe.mjs +9 -7
- package/src/tool-registry.mjs +134 -41
- package/src/try-exposure.mjs +53 -86
- package/src/try-hosted.mjs +257 -70
- package/src/try.mjs +48 -22
- package/src/work-order.mjs +11 -6
- package/src/worker-instructions.mjs +26 -4
- package/src/worker-runs.mjs +35 -0
- package/src/workers.mjs +34 -7
- package/src/workspace.mjs +354 -54
- package/systemd/dot-deadman.service +3 -1
- package/docs/dot-pr-reviewer.config.example.json +0 -9
- package/docs/pr-head-reviewer.md +0 -70
- package/src/pr-head-reviewer.mjs +0 -596
- package/systemd/dot-pr-reviewer.service +0 -11
- package/systemd/dot-pr-reviewer.timer +0 -10
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { Writable } from 'node:stream';
|
|
6
|
+
import { writeAtomic } from './as-files.mjs';
|
|
7
|
+
import { describeFacts, OWNER } from './gozar-routes.mjs';
|
|
8
|
+
import { terminalSafe } from './terminal-safe.mjs';
|
|
9
|
+
|
|
10
|
+
const cleanupPurposes = new Set(['reconcile', 'stop-connector', 'remove-resource', 'revoke-credential', 'disconnect']);
|
|
11
|
+
const setupComplete = view => view.state === 'complete' &&
|
|
12
|
+
!view.resources.some(resource => !resource.presence.known && resource.ownership !== 'foreign');
|
|
13
|
+
const yes = answer => /^y(es)?$/i.test(String(answer ?? '').trim());
|
|
14
|
+
|
|
15
|
+
function refDirectory(env) {
|
|
16
|
+
return path.join(env.XDG_CONFIG_HOME || path.join(env.HOME || os.homedir(), '.config'), 'dalan', 'route-setup');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function referencePath(env, home, providerId) {
|
|
20
|
+
const key = createHash('sha256').update(JSON.stringify([home, providerId])).digest('hex');
|
|
21
|
+
return path.join(refDirectory(env), key + '.json');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function reserveReference(file, home, providerId) {
|
|
25
|
+
const dir = path.dirname(file);
|
|
26
|
+
fs.mkdirSync(dir, { mode: 0o700, recursive: true });
|
|
27
|
+
if (!fs.existsSync(file)) {
|
|
28
|
+
const staged = path.join(dir, randomUUID());
|
|
29
|
+
try {
|
|
30
|
+
writeAtomic(staged, JSON.stringify({ home, owner: OWNER, providerId, operationId: randomUUID() }));
|
|
31
|
+
try { fs.linkSync(staged, file); } catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
32
|
+
const fd = fs.openSync(dir, 'r');
|
|
33
|
+
try { fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
|
|
34
|
+
} finally { fs.rmSync(staged, { force: true }); }
|
|
35
|
+
}
|
|
36
|
+
const ref = readReference(file);
|
|
37
|
+
if (ref.home !== home || ref.providerId !== providerId) throw new Error('The saved Gozar setup reference has a different scope.');
|
|
38
|
+
return ref;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readReference(file) {
|
|
42
|
+
const ref = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
43
|
+
if (ref.owner !== OWNER || typeof ref.home !== 'string' || !path.isAbsolute(ref.home) ||
|
|
44
|
+
typeof ref.providerId !== 'string' || typeof ref.operationId !== 'string') throw new Error('Invalid Gozar setup reference.');
|
|
45
|
+
return ref;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function muteableTerminal(input, output) {
|
|
49
|
+
const terminal = Boolean(input.isTTY && output.isTTY);
|
|
50
|
+
let muted = false;
|
|
51
|
+
return {
|
|
52
|
+
terminal,
|
|
53
|
+
output: terminal ? Object.assign(new Writable({
|
|
54
|
+
write(chunk, _encoding, done) { if (!muted) output.write(chunk); done(); },
|
|
55
|
+
}), { columns: output.columns, isTTY: true }) : undefined,
|
|
56
|
+
mute(value) { muted = value; },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function showAction(view, say) {
|
|
61
|
+
const action = view.nextAction;
|
|
62
|
+
if (!action) return;
|
|
63
|
+
for (const line of [action.label, action.disclosure.text, action.instructions, action.help, action.obtainUrl,
|
|
64
|
+
!action.step.browser && action.href, action.step.permission.label,
|
|
65
|
+
...action.disclosure.links.map(link => link.href),
|
|
66
|
+
...describeFacts(action.consent.facts),
|
|
67
|
+
...(action.effects?.writes ?? []), ...(action.effects?.networkOrigins ?? []),
|
|
68
|
+
]) if (line) say(line);
|
|
69
|
+
if (action.artifact) say(`Software artifact SHA-256 ${action.artifact.sha256}`);
|
|
70
|
+
if (action.effects?.requiresPrivilege) say('This effect requires elevated privileges.');
|
|
71
|
+
if (action.effects?.restartRequired) say('This effect requires a restart.');
|
|
72
|
+
if (action.step.resourceHandle) say(`Resource reference ${action.step.resourceHandle}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function drive({ gozar, ref, view, say, ask, askSecret, handoff, cancelling }) {
|
|
76
|
+
// Cancellation offers are separate decisions, including disconnect versus remote revocation.
|
|
77
|
+
for (;;) {
|
|
78
|
+
say(`Gozar setup is ${view.state}.`);
|
|
79
|
+
say(view.evidence.known ? view.evidence.value.summary : `Evidence unknown (${view.evidence.reason}).`);
|
|
80
|
+
for (const resource of view.resources) {
|
|
81
|
+
say(`${resource.label} (${resource.ownership}): ${resource.presence.known ? resource.presence.value ? 'present' : 'absent' : 'presence unknown'}, removal ${resource.removal}.`);
|
|
82
|
+
}
|
|
83
|
+
const action = view.nextAction;
|
|
84
|
+
if (view.operationId !== ref.operationId || view.scope.providerId !== ref.providerId) throw new Error('The Gozar setup offer does not match the retained operation.');
|
|
85
|
+
if (!cancelling && setupComplete(view)) return view;
|
|
86
|
+
if (!action || (cancelling && !cleanupPurposes.has(action.step.purpose)) ||
|
|
87
|
+
(!cancelling && ['cancelled', 'expired', 'denied'].includes(view.state))) return view;
|
|
88
|
+
const scopeReview = action.consent.scope;
|
|
89
|
+
if (scopeReview.operation?.id !== ref.operationId || scopeReview.operation.revision !== view.revision ||
|
|
90
|
+
scopeReview.configurationRevision !== view.scope.configurationRevision || scopeReview.scopeId !== view.scope.scopeId ||
|
|
91
|
+
scopeReview.providerId !== view.scope.providerId || scopeReview.registryId !== view.scope.registryId || scopeReview.draftId !== view.scope.draftId) {
|
|
92
|
+
throw new Error('The Gozar approval does not match the current setup offer.');
|
|
93
|
+
}
|
|
94
|
+
showAction(view, say);
|
|
95
|
+
if (!ask || !yes(await ask(`Approve ${action.kind === 'open-url' && action.step.browser ? 'the browser handoff' : action.step.permission.label} for this setup step? [y/N] `))) return view;
|
|
96
|
+
const approval = { kind: 'setup', digest: action.digest, disclosureRevision: action.disclosure.revision, consentFactsDigest: action.consent.consentFactsDigest };
|
|
97
|
+
const scope = { ...ref, ...(view.scope.draftId && { draftId: view.scope.draftId }), expectedConfigurationRevision: view.scope.configurationRevision };
|
|
98
|
+
const command = { ...scope, expectedSetupRevision: view.revision, actionId: action.id, approval };
|
|
99
|
+
let next;
|
|
100
|
+
if (action.kind === 'open-url' && action.step.browser) {
|
|
101
|
+
if (!handoff) return view;
|
|
102
|
+
const interactive = await gozar.readSetupOperation({ ...ref, includeBrowserHandoff: true });
|
|
103
|
+
if (interactive.revision !== view.revision || interactive.nextAction?.consent.consentFactsDigest !== approval.consentFactsDigest) {
|
|
104
|
+
view = await gozar.readSetupOperation(ref);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (interactive.nextAction.href) await handoff(interactive.nextAction.href);
|
|
108
|
+
if (!yes(await ask('Check Gozar for current authorization evidence? [y/N] '))) return view;
|
|
109
|
+
next = await gozar.readSetupOperation(ref);
|
|
110
|
+
} else if (action.kind === 'provide-secret') {
|
|
111
|
+
if (!askSecret) { say('Open Dalan in a private interactive terminal to enter the credential.'); return view; }
|
|
112
|
+
const bytes = await askSecret(action.secretLabel ?? action.label);
|
|
113
|
+
if (!bytes?.length) return view;
|
|
114
|
+
let stored;
|
|
115
|
+
try {
|
|
116
|
+
stored = await gozar.storeSecret({ ...scope, inputId: action.inputId, scopeId: view.scope.scopeId, bytes });
|
|
117
|
+
} finally { bytes.fill(0); }
|
|
118
|
+
try { next = await gozar.runSetupAction({ ...command, secretHandle: stored.handle }); }
|
|
119
|
+
finally {
|
|
120
|
+
// Delete unused intake, including refusals. Gozar protects the handles already referenced by the operation or configuration.
|
|
121
|
+
try { await gozar.discardSecret({ home: ref.home, handle: stored.handle }); }
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error?.code !== 'secret_in_use') {
|
|
124
|
+
// Disposal is separate from the step result. Do not expose backend details or claim deletion.
|
|
125
|
+
try { say('Unused setup input cleanup is unconfirmed.'); } catch { /* Reporting cannot replace the step outcome. */ }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else if (action.kind === 'provide-value') {
|
|
130
|
+
const options = action.step.options;
|
|
131
|
+
for (const [index, option] of (options ?? []).entries()) say(`${index + 1}. ${option.label}`);
|
|
132
|
+
const answer = await ask(`${action.valueLabel ?? action.label}: `);
|
|
133
|
+
if (!answer) return view;
|
|
134
|
+
const value = options ? options[Number(answer) - 1]?.value : answer;
|
|
135
|
+
if (!value) return view;
|
|
136
|
+
next = await gozar.runSetupAction({ ...command, value });
|
|
137
|
+
} else {
|
|
138
|
+
// For instructions and documentation links the SDK observes; the owner's acknowledgement cannot complete setup.
|
|
139
|
+
next = await gozar.runSetupAction(command);
|
|
140
|
+
}
|
|
141
|
+
// An attempted effect can advance the revision even when it fails. Offer it again only on a new owner invocation.
|
|
142
|
+
if (next.nextAction?.id === action.id && next.nextAction.digest === action.digest && next.state === view.state) return next;
|
|
143
|
+
view = next;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function runRouteSetup({ gozar, candidate, home, env, ...interaction }) {
|
|
148
|
+
const file = referencePath(env, home, candidate.providerId);
|
|
149
|
+
if (candidate.setup.state === 'ready' && !fs.existsSync(file)) return true;
|
|
150
|
+
const ref = reserveReference(file, home, candidate.providerId);
|
|
151
|
+
let view;
|
|
152
|
+
try { view = await gozar.readSetupOperation(ref); }
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error.code !== 'route_not_found') throw error;
|
|
155
|
+
const initial = candidate.setup.actions[0];
|
|
156
|
+
if (!initial) throw Object.assign(new Error('No initial Gozar setup action is available; refresh the setup status before trying again.'),
|
|
157
|
+
{ code: 'setup_initial_action_unavailable' });
|
|
158
|
+
view = await gozar.runSetupAction({ ...ref, expectedSetupRevision: 0,
|
|
159
|
+
expectedConfigurationRevision: candidate.configuration.revision, actionId: initial.id });
|
|
160
|
+
}
|
|
161
|
+
interaction.say(`Setup operation ${ref.operationId}`);
|
|
162
|
+
view = await drive({ gozar, ref, view, ...interaction });
|
|
163
|
+
return setupComplete(view);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function cancelRouteSetup({ gozar, home, operationId, env, say, ask }) {
|
|
167
|
+
const dir = refDirectory(env);
|
|
168
|
+
const files = fs.readdirSync(dir, { throwIfNoEntry: false }) ?? [];
|
|
169
|
+
const found = files.filter(name => /^[a-f0-9]{64}\.json$/.test(name)).map(name => {
|
|
170
|
+
const file = path.join(dir, name);
|
|
171
|
+
return { file, ref: readReference(file) };
|
|
172
|
+
}).filter(({ ref }) => ref.home === home && ref.operationId === operationId);
|
|
173
|
+
if (found.length !== 1) throw new Error('No exact Dalan setup reference matches that operation.');
|
|
174
|
+
const { ref, file } = found[0];
|
|
175
|
+
if (!ask || !yes(await ask('Cancel this Gozar setup operation? [y/N] '))) return false;
|
|
176
|
+
const view = await drive({ gozar, ref, view: await gozar.cancelSetupOperation(ref), say, ask, cancelling: true });
|
|
177
|
+
const settled = view.evidence.known && !view.nextAction && view.resources.every(resource => resource.removal === 'retained' ||
|
|
178
|
+
(resource.ownership === 'owned' && resource.removal === 'confirmed' && resource.presence.known && !resource.presence.value));
|
|
179
|
+
if (settled) fs.unlinkSync(file);
|
|
180
|
+
else say(`Cleanup is unconfirmed. Resume operation ${ref.operationId} after following the current Gozar instructions.`);
|
|
181
|
+
return settled;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const safeRouteOutput = output => line => output.write(`${terminalSafe(line)}\n`);
|
package/src/schema-subset.mjs
CHANGED
|
@@ -161,12 +161,14 @@ function check(schema, value, path, errors) {
|
|
|
161
161
|
for (const [key, sub] of Object.entries(schema.properties)) if (Object.hasOwn(value, key)) check(sub, value[key], `${path}.${key}`, errors);
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
case 'string':
|
|
164
|
+
case 'string': {
|
|
165
165
|
if (typeof value !== 'string') return fail('must be a string');
|
|
166
|
-
|
|
167
|
-
if (
|
|
166
|
+
const length = [...value].length;
|
|
167
|
+
if (length > schema.maxLength) return fail(`longer than ${schema.maxLength}`);
|
|
168
|
+
if (schema.minLength !== undefined && length < schema.minLength) fail(`shorter than ${schema.minLength}`);
|
|
168
169
|
if (schema.pattern !== undefined && !compiledRegex(schema.pattern).test(value)) fail('does not match the required pattern');
|
|
169
170
|
break;
|
|
171
|
+
}
|
|
170
172
|
case 'integer': case 'number':
|
|
171
173
|
if (typeof value !== 'number' || !Number.isFinite(value) || (schema.type === 'integer' && !Number.isInteger(value))) return fail(`must be ${schema.type === 'integer' ? 'an integer' : 'a number'}`);
|
|
172
174
|
if (schema.minimum !== undefined && value < schema.minimum) fail(`below ${schema.minimum}`);
|