@tnunamak/dalan 0.8.0 → 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 +70 -1
- package/CONTRIBUTING.md +2 -0
- package/PROTOCOL.md +6 -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 +215 -40
- 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 +3 -2
- package/docs/manual-setup.md +1 -1
- package/docs/operations.md +78 -14
- package/docs/pull-workers.md +11 -0
- package/docs/relationships.md +13 -0
- package/docs/service-setup.md +10 -10
- package/docs/t3-integration.md +6 -2
- package/docs/t3-reverse-control.md +5 -5
- package/docs/t3-wake-fence-r4.md +1 -1
- package/docs/test-suite-isolation.md +8 -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 +35 -9
- 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/claim-command-ledger.mjs +3 -2
- package/src/cli-help.mjs +29 -10
- 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/inbox.mjs +13 -3
- package/src/legacy-names.mjs +0 -2
- package/src/lifecycle.mjs +104 -11
- 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 +285 -19
- 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 +619 -88
- 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/status-summary.mjs +3 -0
- package/src/store.mjs +1086 -127
- 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 +49 -4
- 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
package/src/setup.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
// and saves only the requirements, the opaque route name and the pinned origin (route-setting.mjs, version 2).
|
|
1
|
+
// Choose a durable public route for a subsequent bridge start, and drive any setup Gozar offers.
|
|
3
2
|
import readline from 'node:readline';
|
|
4
3
|
import {
|
|
5
|
-
RouteError, buildQuery, dalanRequirements, describeCandidate, describeDisclosure,
|
|
4
|
+
RouteError, buildQuery, chooseRoute, dalanRequirements, describeCandidate, describeDisclosure, explainRouteError, gozarHomeFor, resolveGozar, resolveRouteWord, targetFor,
|
|
6
5
|
} from './gozar-routes.mjs';
|
|
6
|
+
import { cancelRouteSetup, muteableTerminal, runRouteSetup, safeRouteOutput } from './route-setup.mjs';
|
|
7
7
|
import { inspectRouteSetting, writeRouteSetting } from './route-setting.mjs';
|
|
8
8
|
|
|
9
9
|
export const SWITCH_NOTE = 'Next: run `dalan try --public`, then in your MCP client remove the trial connector and add the new URL it prints; a new address cannot reuse the trial sign-in.';
|
|
@@ -11,27 +11,30 @@ export const ROUTE_ID = 'dalan-main';
|
|
|
11
11
|
const DEFAULT_PORT = 8789;
|
|
12
12
|
|
|
13
13
|
export function parseSetupArgs(argv) {
|
|
14
|
-
const out = { route: undefined };
|
|
14
|
+
const out = { route: undefined, cancel: undefined };
|
|
15
15
|
for (let i = 0; i < argv.length; i++) {
|
|
16
16
|
const arg = argv[i];
|
|
17
17
|
if (arg === '--route') { out.route = argv[++i]; if (out.route === undefined) throw new Error('--route needs a name'); } else if (arg.startsWith('--route=')) out.route = arg.slice(8);
|
|
18
|
-
else
|
|
18
|
+
else if (arg === '--cancel') { out.cancel = argv[++i]; if (!out.cancel) throw new Error('--cancel needs the setup operation ID'); }
|
|
19
|
+
else throw new Error(`unknown option ${arg}; usage: dalan setup [--route NAME | --cancel OPERATION_ID]`);
|
|
19
20
|
}
|
|
21
|
+
if (out.cancel && out.route !== undefined) throw new Error('Choose either --cancel or --route.');
|
|
20
22
|
return out;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export async function runSetup({
|
|
24
26
|
argv = [], env = process.env, out = process.stdout, input = process.stdin, interactive = Boolean(process.stdin.isTTY), gozar, gozarHome, answers, port = DEFAULT_PORT,
|
|
25
27
|
} = {}) {
|
|
26
|
-
const say =
|
|
27
|
-
const { route: routeName } = parseSetupArgs(argv);
|
|
28
|
+
const say = safeRouteOutput(out);
|
|
29
|
+
const { route: routeName, cancel } = parseSetupArgs(argv);
|
|
28
30
|
const found = inspectRouteSetting(env);
|
|
29
|
-
if (found.state === 'legacy') {
|
|
31
|
+
if (!cancel && found.state === 'legacy') {
|
|
30
32
|
say('A saved 0.6 route setting exists. It is left untouched. Moving it to Gozar is a separate, journaled step that keeps the same address; setup never rewrites it.');
|
|
31
33
|
return { route: null, changed: false, legacy: true };
|
|
32
34
|
}
|
|
33
|
-
if (found.state === 'unreadable') { say(`The saved route setting could not be read (${found.reason}). It was left untouched.`); return { route: null, changed: false }; }
|
|
34
|
-
const
|
|
35
|
+
if (!cancel && found.state === 'unreadable') { say(`The saved route setting could not be read (${found.reason}). It was left untouched.`); return { route: null, changed: false }; }
|
|
36
|
+
const terminal = muteableTerminal(input, out);
|
|
37
|
+
const lines = !answers && interactive ? readline.createInterface({ input, terminal: terminal.terminal, output: terminal.output }) : null;
|
|
35
38
|
const queued = answers ? [...answers] : null;
|
|
36
39
|
const ask = question => new Promise(resolve => {
|
|
37
40
|
if (queued) { out.write(question); return resolve(queued.shift() ?? null); }
|
|
@@ -42,25 +45,45 @@ export async function runSetup({
|
|
|
42
45
|
out.write(question); lines.once('line', finish); lines.once('close', onClose);
|
|
43
46
|
});
|
|
44
47
|
try {
|
|
45
|
-
const runtime = gozar ?? await resolveGozar();
|
|
46
48
|
const home = gozarHome ?? gozarHomeFor(env);
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const runtime = gozar ?? await resolveGozar({ env, home });
|
|
50
|
+
if (cancel) return { cancelled: await cancelRouteSetup({ gozar: runtime, home, operationId: cancel, env, say, ask }) };
|
|
51
|
+
const interaction = {
|
|
52
|
+
say, ask,
|
|
53
|
+
...(terminal.terminal && {
|
|
54
|
+
async askSecret(label) {
|
|
55
|
+
terminal.mute(true);
|
|
56
|
+
try { return Buffer.from(await ask(`${label} (hidden): `) ?? ''); }
|
|
57
|
+
finally { terminal.mute(false); out.write('\n'); }
|
|
58
|
+
},
|
|
59
|
+
handoff(href) { out.write(`${href}\n`); },
|
|
60
|
+
}),
|
|
54
61
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
const wanted = buildQuery({ home, target: targetFor(port), usage: { kind: 'durable', routeId: ROUTE_ID }, address: 'stable', ...(routeName !== undefined ? { route: routeName } : {}) });
|
|
63
|
+
if (!interactive && !answers) { say('Run `dalan setup` in a terminal to choose a public route.'); return { route: found.setting ?? null, changed: false }; }
|
|
64
|
+
const { query, pick } = await resolveRouteWord({ gozar: runtime, query: wanted });
|
|
65
|
+
const setup = candidate => runRouteSetup({ gozar: runtime, candidate, home, env, ...interaction });
|
|
66
|
+
let candidate;
|
|
67
|
+
try { ({ candidate } = await chooseRoute({ gozar: runtime, query, pick, setup })); }
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error?.code !== 'setup_required' && !error?.nextAction) throw error;
|
|
70
|
+
const e = explainRouteError(error);
|
|
71
|
+
say(e.line);
|
|
72
|
+
if (e.fix) say(`Next: ${e.fix}`);
|
|
73
|
+
return { route: found.setting ?? null, changed: false };
|
|
74
|
+
}
|
|
75
|
+
for (const line of describeCandidate(candidate)) say(line);
|
|
76
|
+
for (const line of describeDisclosure(candidate)) say(line);
|
|
77
|
+
if (!/^y(es)?$/i.test(String(await ask('Save this route choice? [y/N] ') ?? '').trim())) {
|
|
78
|
+
say('Nothing saved.');
|
|
79
|
+
return { route: found.setting ?? null, changed: false };
|
|
60
80
|
}
|
|
61
|
-
const
|
|
81
|
+
const name = routeName ?? candidate.providerId ?? null;
|
|
82
|
+
const pinned = found.setting?.routeName === name && found.setting?.gozarHome === home ? found.setting.origin : null;
|
|
83
|
+
const setting = { version: 2, requirements: dalanRequirements({ address: 'stable' }), gozarHome: home,
|
|
84
|
+
routeName: name, routeId: ROUTE_ID, origin: pinned, bridgeHome: null };
|
|
62
85
|
writeRouteSetting(setting, env);
|
|
63
|
-
say(
|
|
86
|
+
say('Saved the route choice. Dalan checks the route when the bridge starts.');
|
|
64
87
|
say(SWITCH_NOTE);
|
|
65
88
|
return { route: setting, changed: found.state !== 'current' || found.setting.origin !== setting.origin || found.setting.routeName !== setting.routeName };
|
|
66
89
|
} finally { lines?.close(); }
|
package/src/signal.mjs
CHANGED
|
@@ -109,7 +109,7 @@ export function createSignal({ dir, store, workerNames, publicUrl, log, now = Da
|
|
|
109
109
|
if (wait) { log({ kind: 'signal', status: 429 }); res.writeHead(429, { 'retry-after': String(wait), 'cache-control': 'no-store' }); res.end(); return true; }
|
|
110
110
|
const answer = work(worker);
|
|
111
111
|
const body = JSON.stringify({ work: answer });
|
|
112
|
-
log({ kind: 'signal', status: 200, work: answer });
|
|
112
|
+
log({ kind: 'signal', status: 200, worker, work: answer });
|
|
113
113
|
res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', 'content-length': Buffer.byteLength(body) });
|
|
114
114
|
res.end(body);
|
|
115
115
|
return true;
|
package/src/status-evidence.mjs
CHANGED
|
@@ -2,12 +2,25 @@
|
|
|
2
2
|
const denial = /auto-?review|guardian|denied|not approved|paused out of precaution/i;
|
|
3
3
|
const waiting = /auto.?stop|paused out of precaution|(?:resume|confirmation|approval).*(?:required|requested|needed)|(?:waiting|wait).*(?:guardian|confirmation|approval)/i;
|
|
4
4
|
|
|
5
|
+
// progress, reports and late_evidence only ever gain rows, so each status call reads only the rows added since the last one and keeps
|
|
6
|
+
// the ones that look like a denial. The first call on a store reads every row once; reading them on each call cost 100 MB per call.
|
|
7
|
+
const seen = new WeakMap();
|
|
8
|
+
const SOURCES = [
|
|
9
|
+
['progress', 'SELECT request_id,id row_id,created_at at,note text FROM progress WHERE id>? ORDER BY id'],
|
|
10
|
+
['report', 'SELECT request_id,rowid row_id,created_at at,summary text FROM reports WHERE rowid>? ORDER BY rowid'],
|
|
11
|
+
['late_evidence', 'SELECT request_id,rowid row_id,created_at at,summary text FROM late_evidence WHERE rowid>? ORDER BY rowid'],
|
|
12
|
+
];
|
|
13
|
+
|
|
5
14
|
export function statusEvidence(store) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
let state = seen.get(store);
|
|
16
|
+
if (!state) seen.set(store, state = SOURCES.map(([source, sql]) => ({ source, sql, last: 0, matches: [] })));
|
|
17
|
+
for (const part of state) {
|
|
18
|
+
for (const row of store.db.prepare(part.sql).all(part.last)) {
|
|
19
|
+
part.last = row.row_id;
|
|
20
|
+
if (denial.test(row.text)) part.matches.push({ request_id: row.request_id, row_id: row.row_id, at: row.at, source: part.source, text: row.text });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const observations = state.flatMap(part => part.matches);
|
|
11
24
|
const summarize = predicate => {
|
|
12
25
|
const matches = observations.filter(row => predicate(row.text)).sort((a, b) => b.at.localeCompare(a.at));
|
|
13
26
|
return {
|
package/src/status-summary.mjs
CHANGED
|
@@ -41,6 +41,9 @@ export function formatStatusSummary(status, { home, url = null, trial = false, n
|
|
|
41
41
|
const paused = status?.paused === true;
|
|
42
42
|
const lines = [`Bridge: ${paused ? 'running, paused' : 'running'}${url ? ` on ${url}` : ''} (${trial ? 'trial home' : 'home'} ${home})${paused && status.pause_reason ? `. Pause reason: ${status.pause_reason}` : ''}`,
|
|
43
43
|
...(workers.length ? workers.map(w => w.text) : ['Workers: none yet'])];
|
|
44
|
+
// A wake held because its parent stopped is invisible in the queue counts: it left the send queue and waits for the parent.
|
|
45
|
+
const held = Number.isInteger(status?.held_wakes) ? status.held_wakes : 0;
|
|
46
|
+
if (held > 0) lines.push(`${held} held wake${held === 1 ? '' : 's'}: the parent thread stopped, so the wake waits until it runs again (see: ${cli} inbox --all)`);
|
|
44
47
|
const total = workers.reduce((n, w) => n + w.total, 0) || (status?.counts ?? []).reduce((n, c) => n + c.count, 0);
|
|
45
48
|
const next = paused ? `resume handing out jobs: ${cli} resume`
|
|
46
49
|
: workers.some(w => w.queued) ? `send your worker the queued job (to connect a worker first, see ${CONNECT_URL}); list your jobs: ${cli} inbox --all`
|