strands-darwin 0.0.37 → 0.0.40
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/README.md +17 -2
- package/README.zh-CN.md +12 -2
- package/dist/src/agent/permission-rules.js +1 -1
- package/dist/src/agent/permission-rules.js.map +1 -1
- package/dist/src/agent/permission.d.ts +4 -1
- package/dist/src/agent/permission.js +21 -4
- package/dist/src/agent/permission.js.map +1 -1
- package/dist/src/agent/runtime.d.ts +6 -2
- package/dist/src/agent/runtime.js +37 -6
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/session-lease.d.ts +31 -0
- package/dist/src/agent/session-lease.js +42 -0
- package/dist/src/agent/session-lease.js.map +1 -0
- package/dist/src/agent/session.d.ts +2 -47
- package/dist/src/agent/session.js +3 -50
- package/dist/src/agent/session.js.map +1 -1
- package/dist/src/agent/stream-idle.d.ts +1 -1
- package/dist/src/agent/stream-idle.js +1 -1
- package/dist/src/cli-list-agents.d.ts +1 -0
- package/dist/src/cli-list-agents.js +12 -0
- package/dist/src/cli-list-agents.js.map +1 -0
- package/dist/src/cli-usage.d.ts +1 -1
- package/dist/src/cli-usage.js +7 -0
- package/dist/src/cli-usage.js.map +1 -1
- package/dist/src/cli.js +9 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/collaboration/command.d.ts +5 -0
- package/dist/src/collaboration/command.js +84 -0
- package/dist/src/collaboration/command.js.map +1 -0
- package/dist/src/collaboration/grammar.d.ts +3 -0
- package/dist/src/collaboration/grammar.js +9 -0
- package/dist/src/collaboration/grammar.js.map +1 -0
- package/dist/src/collaboration/hub-command.d.ts +21 -0
- package/dist/src/collaboration/hub-command.js +129 -0
- package/dist/src/collaboration/hub-command.js.map +1 -0
- package/dist/src/collaboration/hub-store.d.ts +58 -0
- package/dist/src/collaboration/hub-store.js +108 -0
- package/dist/src/collaboration/hub-store.js.map +1 -0
- package/dist/src/collaboration/hub-transport.d.ts +86 -0
- package/dist/src/collaboration/hub-transport.js +456 -0
- package/dist/src/collaboration/hub-transport.js.map +1 -0
- package/dist/src/collaboration/hub-wire.d.ts +356 -0
- package/dist/src/collaboration/hub-wire.js +192 -0
- package/dist/src/collaboration/hub-wire.js.map +1 -0
- package/dist/src/collaboration/local.d.ts +78 -0
- package/dist/src/collaboration/local.js +464 -0
- package/dist/src/collaboration/local.js.map +1 -0
- package/dist/src/collaboration/protocol.d.ts +113 -0
- package/dist/src/collaboration/protocol.js +27 -0
- package/dist/src/collaboration/protocol.js.map +1 -0
- package/dist/src/collaboration/storage.d.ts +37 -0
- package/dist/src/collaboration/storage.js +246 -0
- package/dist/src/collaboration/storage.js.map +1 -0
- package/dist/src/collaboration/tools.d.ts +5 -0
- package/dist/src/collaboration/tools.js +10 -0
- package/dist/src/collaboration/tools.js.map +1 -0
- package/dist/src/commands/custom-commands.d.ts +1 -1
- package/dist/src/commands/custom-commands.js +3 -1
- package/dist/src/commands/custom-commands.js.map +1 -1
- package/dist/src/commands/review-command.d.ts +8 -3
- package/dist/src/commands/review-command.js +17 -3
- package/dist/src/commands/review-command.js.map +1 -1
- package/dist/src/config.d.ts +7 -5
- package/dist/src/config.js +5 -3
- package/dist/src/config.js.map +1 -1
- package/dist/src/dev-repl.js +8 -1
- package/dist/src/dev-repl.js.map +1 -1
- package/dist/src/headless-protocol.d.ts +6 -2
- package/dist/src/headless-protocol.js +32 -8
- package/dist/src/headless-protocol.js.map +1 -1
- package/dist/src/headless-runner.js +45 -1
- package/dist/src/headless-runner.js.map +1 -1
- package/dist/src/headless.d.ts +2 -1
- package/dist/src/headless.js +5 -5
- package/dist/src/headless.js.map +1 -1
- package/dist/src/list-agents.d.ts +21 -0
- package/dist/src/list-agents.js +219 -0
- package/dist/src/list-agents.js.map +1 -0
- package/dist/src/paths.d.ts +5 -0
- package/dist/src/paths.js +14 -2
- package/dist/src/paths.js.map +1 -1
- package/dist/src/trajectory/record.d.ts +8 -3
- package/dist/src/trajectory/record.js +3 -0
- package/dist/src/trajectory/record.js.map +1 -1
- package/dist/src/trajectory/replay.js +13 -0
- package/dist/src/trajectory/replay.js.map +1 -1
- package/dist/src/trajectory/rewind-history.js +1 -1
- package/dist/src/trajectory/rewind-history.js.map +1 -1
- package/dist/src/trajectory/writer.d.ts +3 -2
- package/dist/src/trajectory/writer.js +4 -0
- package/dist/src/trajectory/writer.js.map +1 -1
- package/dist/src/tui/App.js +83 -1
- package/dist/src/tui/App.js.map +1 -1
- package/dist/src/tui/InputBox.d.ts +1 -1
- package/dist/src/tui/InputBox.js +1 -1
- package/dist/src/tui/help-format.d.ts +2 -2
- package/dist/src/tui/help-format.js +4 -3
- package/dist/src/tui/help-format.js.map +1 -1
- package/package.json +1 -1
package/dist/src/cli-usage.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const HELP_FLAGS: readonly ['--help', '-h'];
|
|
2
2
|
export declare const VERSION_FLAGS: readonly ['--version', '-V'];
|
|
3
3
|
/** The complete grammar, exactly as `darwin --help` prints it (trailing newline included). */
|
|
4
|
-
export declare const CLI_USAGE = "Usage: darwin [--resume [<id>]|--session <id>] [--permission-mode <default|auto|plan|yolo>] [--yolo]\n darwin -p <message> [--output-format text|json|stream-json]\n [--continue|--resume [<id>]|--session <id>] [permission flags]\n [--max-model-calls <n>] [--context-offload] [--compact-before]\n darwin sessions\n darwin permissions test <rule>\n darwin import --from claude-code [--apply]\n darwin doctor\n darwin cloud-memory [status|preferences|list|inspect|pending|preview] \u2026\n darwin trajectory <list|search|replay|fork> \u2026\n darwin --help | -h\n darwin --version | -V\n\n--context-offload force-enables the default-on offloader for this process; it never persists.\nPrint-only flags: --output-format, --max-model-calls, --context-offload, --compact-before, --continue.\nWith -p, piped (non-TTY) stdin is read to EOF and appended to <message> as one delimited block (256 KiB cap).\n";
|
|
4
|
+
export declare const CLI_USAGE = "Usage: darwin [--resume [<id>]|--session <id>] [--permission-mode <default|auto|plan|yolo>] [--yolo]\n darwin -p <message> [--output-format text|json|stream-json]\n [--continue|--resume [<id>]|--session <id>] [permission flags]\n [--max-model-calls <n>] [--context-offload] [--compact-before]\n darwin sessions\n darwin list-agents\n darwin collaborate [status|list|pending|relations|on|off]\n darwin collaborate send <endpoint-uuid> <literal text>\n darwin collaborate confirm <pending-id> --persist\n darwin collaborate revoke <pair-id>\n darwin collaborate hub enroll <url> <token> [--name <label>]\n darwin collaborate hub status|nodes|leave|publish on|off|block <node>|unblock <node>\n darwin permissions test <rule>\n darwin import --from claude-code [--apply]\n darwin doctor\n darwin cloud-memory [status|preferences|list|inspect|pending|preview] \u2026\n darwin trajectory <list|search|replay|fork> \u2026\n darwin --help | -h\n darwin --version | -V\n\n--context-offload force-enables the default-on offloader for this process; it never persists.\nPrint-only flags: --output-format, --max-model-calls, --context-offload, --compact-before, --continue.\nWith -p, piped (non-TTY) stdin is read to EOF and appended to <message> as one delimited block (256 KiB cap).\n";
|
|
5
5
|
/** The one hint every usage error appends after its `error:` line. */
|
|
6
6
|
export declare const CLI_HELP_HINT = "Run `darwin --help` for usage.";
|
|
7
7
|
/**
|
package/dist/src/cli-usage.js
CHANGED
|
@@ -19,6 +19,13 @@ export const CLI_USAGE = `Usage: darwin [--resume [<id>]|--session <id>] [--perm
|
|
|
19
19
|
[--continue|--resume [<id>]|--session <id>] [permission flags]
|
|
20
20
|
[--max-model-calls <n>] [--context-offload] [--compact-before]
|
|
21
21
|
darwin sessions
|
|
22
|
+
darwin list-agents
|
|
23
|
+
darwin collaborate [status|list|pending|relations|on|off]
|
|
24
|
+
darwin collaborate send <endpoint-uuid> <literal text>
|
|
25
|
+
darwin collaborate confirm <pending-id> --persist
|
|
26
|
+
darwin collaborate revoke <pair-id>
|
|
27
|
+
darwin collaborate hub enroll <url> <token> [--name <label>]
|
|
28
|
+
darwin collaborate hub status|nodes|leave|publish on|off|block <node>|unblock <node>
|
|
22
29
|
darwin permissions test <rule>
|
|
23
30
|
darwin import --from claude-code [--apply]
|
|
24
31
|
darwin doctor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-usage.js","sourceRoot":"","sources":["../../src/cli-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAU,CAAC;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,IAAI,CAAU,CAAC;AAE1D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,SAAS,GAAG
|
|
1
|
+
{"version":3,"file":"cli-usage.js","sourceRoot":"","sources":["../../src/cli-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAU,CAAC;AACpD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,IAAI,CAAU,CAAC;AAE1D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBxB,CAAC;AAEF,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAE9D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,UAAU,OAAO,KAAK,aAAa,IAAI,CAAC;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,OAAO,WAAW,SAAS,8BAA8B,SAAS,IAAI,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAuB;IACpD,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACrE,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,UAAU,cAAc,IAAI,CAAC;IAC3F,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/src/cli.js
CHANGED
|
@@ -26,7 +26,15 @@ else {
|
|
|
26
26
|
const args = process.argv.slice(2);
|
|
27
27
|
if (args[0] === '--')
|
|
28
28
|
args.shift();
|
|
29
|
-
if (args[0] === '
|
|
29
|
+
if (args[0] === 'collaborate') {
|
|
30
|
+
const { runCollaborationCli } = await import('./collaboration/command.js');
|
|
31
|
+
await runCollaborationCli(process.cwd(), args.slice(1));
|
|
32
|
+
}
|
|
33
|
+
else if (args[0] === 'list-agents') {
|
|
34
|
+
const { runListAgentsCli } = await import('./cli-list-agents.js');
|
|
35
|
+
await runListAgentsCli(process.cwd(), args.slice(1));
|
|
36
|
+
}
|
|
37
|
+
else if (args[0] === 'import') {
|
|
30
38
|
const { runImportCli } = await import('./cli-import.js');
|
|
31
39
|
await runImportCli(process.cwd(), args.slice(1));
|
|
32
40
|
}
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE5F,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;AACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,QAAQ,GAAG,6BAA6B,CAAC;AACnD,CAAC;KAAM,CAAC;IACN,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KA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H,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LocalCollaboration } from './local.js';
|
|
2
|
+
export { COLLABORATE_USAGE } from './grammar.js';
|
|
3
|
+
/** Literal user-only command. No invocation, expansion or model-granted trust. */
|
|
4
|
+
export declare function collaborationCommand(local: LocalCollaboration, text: string): Promise<string>;
|
|
5
|
+
export declare function runCollaborationCli(root: string, args: readonly string[]): Promise<void>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { discoverPeers, LocalCollaboration } from './local.js';
|
|
3
|
+
import { idSchema, policyCommand } from './storage.js';
|
|
4
|
+
import { hubCommand, parseHubArgs } from './hub-command.js';
|
|
5
|
+
import { COLLABORATE_USAGE } from './grammar.js';
|
|
6
|
+
export { COLLABORATE_USAGE } from './grammar.js';
|
|
7
|
+
/** Pure preflight shared by CLI and TUI: no policy, registration or probe on bad grammar. */
|
|
8
|
+
function validateCommand(args) {
|
|
9
|
+
const [verb, id, flag] = args;
|
|
10
|
+
if (verb === 'hub') {
|
|
11
|
+
parseHubArgs(args.slice(1));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (args.length === 1 && ['status', 'list', 'pending', 'relations', 'on', 'off'].includes(verb))
|
|
15
|
+
return;
|
|
16
|
+
if (verb === 'confirm' && args.length === 3 && flag === '--persist' && idSchema.safeParse(id).success)
|
|
17
|
+
return;
|
|
18
|
+
if (verb === 'revoke' && args.length === 2 && /^[a-f0-9]{64}$/.test(id ?? ''))
|
|
19
|
+
return;
|
|
20
|
+
if (verb === 'send' && args.length >= 3 && idSchema.safeParse(id).success) {
|
|
21
|
+
const bytes = Buffer.byteLength(args.slice(2).join(' '));
|
|
22
|
+
if (bytes > 0 && bytes <= 4096)
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(COLLABORATE_USAGE);
|
|
26
|
+
}
|
|
27
|
+
/** Literal user-only command. No invocation, expansion or model-granted trust. */
|
|
28
|
+
export async function collaborationCommand(local, text) {
|
|
29
|
+
const command = text.trim();
|
|
30
|
+
const send = /^send\s+(\S+)\s+([\s\S]+)$/.exec(text.trimStart());
|
|
31
|
+
validateCommand(send ? ['send', send[1], send[2]] : (command || 'status').split(/\s+/));
|
|
32
|
+
if (send) {
|
|
33
|
+
local.beginHumanTurn();
|
|
34
|
+
return local.send(send[1], send[2]);
|
|
35
|
+
}
|
|
36
|
+
if (/^hub(?:\s|$)/.test(command))
|
|
37
|
+
return hubCommand(local, local.root, command.split(/\s+/).slice(1), false);
|
|
38
|
+
if (command === 'list')
|
|
39
|
+
return JSON.stringify(await local.discover(), null, 2);
|
|
40
|
+
const result = await policyCommand((command || 'status').split(/\s+/));
|
|
41
|
+
if (command === 'off')
|
|
42
|
+
local.close('collaboration off');
|
|
43
|
+
if (command === 'on') {
|
|
44
|
+
local.close('new endpoint requested');
|
|
45
|
+
await local.start();
|
|
46
|
+
}
|
|
47
|
+
const hub = `${local.hub.state}${local.hub.reason ? ` (${local.hub.reason})` : ''}${local.hub.address ? ` endpoint ${local.hub.address.endpoint}` : ''}`;
|
|
48
|
+
return `${result}\nThis endpoint: ${JSON.stringify(local.address ?? null)}; queued: ${local.pending}\nHub: ${hub}\n${COLLABORATE_USAGE}`;
|
|
49
|
+
}
|
|
50
|
+
export async function runCollaborationCli(root, args) {
|
|
51
|
+
try {
|
|
52
|
+
// CLI registration exists only for an explicit send. Read projections do not
|
|
53
|
+
// create policy; first startup/on initializes it with no cross-project grants.
|
|
54
|
+
validateCommand(args.length ? args : ['status']);
|
|
55
|
+
if (args[0] === 'hub') {
|
|
56
|
+
console.log(await hubCommand(undefined, root, args.slice(1), true));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (args[0] === 'list') {
|
|
60
|
+
console.log(JSON.stringify(await discoverPeers(), null, 2));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (args[0] !== 'send') {
|
|
64
|
+
console.log(await policyCommand(args.length ? args : ['status']));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const local = new LocalCollaboration(root, `cli-${randomUUID()}`);
|
|
68
|
+
await local.start();
|
|
69
|
+
// argv already separates the target from literal text; do not reparse it as
|
|
70
|
+
// TUI command whitespace and lose leading spaces/newlines in a quoted body.
|
|
71
|
+
try {
|
|
72
|
+
local.beginHumanTurn();
|
|
73
|
+
console.log(await local.send(args[1], args.slice(2).join(' ')));
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
local.close('CLI send finished');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(`collaborate: ${error instanceof Error ? error.message : 'local operation failed'}`);
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/collaboration/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,6FAA6F;AAC7F,SAAS,eAAe,CAAC,IAAuB;IAC9C,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9B,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IA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I,CAAC;YAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAAC,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC;gBACzF,CAAC;YAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gBAAgB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,EAAE,CAAC,CAAC;QACnG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Pure canonical user grammar; safe to import from bounded local help. */
|
|
2
|
+
export declare const COLLABORATION_GRAMMAR: readonly ['/collaborate [status|list|pending|relations|on|off]', '/collaborate send <endpoint-uuid> <literal text>', '/collaborate confirm <pending-id> --persist; /collaborate revoke <pair-id>', '/collaborate hub status|nodes|leave|publish on|off|block <node>|unblock <node>; enroll: CLI only'];
|
|
3
|
+
export declare const COLLABORATE_USAGE: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Pure canonical user grammar; safe to import from bounded local help. */
|
|
2
|
+
export const COLLABORATION_GRAMMAR = [
|
|
3
|
+
'/collaborate [status|list|pending|relations|on|off]',
|
|
4
|
+
'/collaborate send <endpoint-uuid> <literal text>',
|
|
5
|
+
'/collaborate confirm <pending-id> --persist; /collaborate revoke <pair-id>',
|
|
6
|
+
'/collaborate hub status|nodes|leave|publish on|off|block <node>|unblock <node>; enroll: CLI only',
|
|
7
|
+
];
|
|
8
|
+
export const COLLABORATE_USAGE = COLLABORATION_GRAMMAR.join('; ');
|
|
9
|
+
//# sourceMappingURL=grammar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../../src/collaboration/grammar.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,qDAAqD;IACrD,kDAAkD;IAClD,4EAA4E;IAC5E,kGAAkG;CAC1F,CAAC;AACX,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { LocalCollaboration } from './local.js';
|
|
2
|
+
export declare const HUB_GRAMMAR = "collaborate hub status|nodes|leave|publish on|publish off|block <node>|unblock <node>; CLI only: hub enroll <url> <token> [--name <label>]";
|
|
3
|
+
type HubArgs = {
|
|
4
|
+
verb: 'status' | 'nodes' | 'leave';
|
|
5
|
+
} | {
|
|
6
|
+
verb: 'publish';
|
|
7
|
+
on: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
verb: 'block' | 'unblock';
|
|
10
|
+
node: string;
|
|
11
|
+
} | {
|
|
12
|
+
verb: 'enroll';
|
|
13
|
+
url: string;
|
|
14
|
+
token: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Pure grammar preflight: nothing is read, written or contacted on a malformed command. */
|
|
18
|
+
export declare function parseHubArgs(args: readonly string[]): HubArgs;
|
|
19
|
+
/** `local` is the live session (TUI) or undefined (standalone CLI). */
|
|
20
|
+
export declare function hubCommand(local: LocalCollaboration | undefined, root: string, args: readonly string[], cli: boolean): Promise<string>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-only hub controls: `darwin collaborate hub …` and `/collaborate hub …` (hub/README.md §5,
|
|
3
|
+
* §7, §9). Never a model tool; the gate denies model-issued `collaborate` controls and reads of
|
|
4
|
+
* the collaboration directory before rules and hooks. `enroll` is CLI-only so a token never enters
|
|
5
|
+
* a session transcript, trajectory or prompt recall.
|
|
6
|
+
*/
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { enrollResponseSchema, fingerprint, generateNodeKeys, nodeNameSchema, shortFingerprint, tokenSchema, uuidSchema } from './hub-wire.js';
|
|
10
|
+
import { readHubNode, readHubState, removeHubNode, updateHubState, writeHubNode } from './hub-store.js';
|
|
11
|
+
import { canonicalProject, checkStore } from './storage.js';
|
|
12
|
+
export const HUB_GRAMMAR = 'collaborate hub status|nodes|leave|publish on|publish off|block <node>|unblock <node>; CLI only: hub enroll <url> <token> [--name <label>]';
|
|
13
|
+
/** Pure grammar preflight: nothing is read, written or contacted on a malformed command. */
|
|
14
|
+
export function parseHubArgs(args) {
|
|
15
|
+
const [verb, a, b, c, d] = args;
|
|
16
|
+
const fail = () => { throw new Error(`Usage: ${HUB_GRAMMAR}`); };
|
|
17
|
+
if ((verb === 'status' || verb === 'nodes' || verb === 'leave') && args.length === 1)
|
|
18
|
+
return { verb };
|
|
19
|
+
if (verb === 'publish' && args.length === 2 && (a === 'on' || a === 'off'))
|
|
20
|
+
return { verb, on: a === 'on' };
|
|
21
|
+
if ((verb === 'block' || verb === 'unblock') && args.length === 2 && uuidSchema.safeParse(a).success)
|
|
22
|
+
return { verb, node: a };
|
|
23
|
+
if (verb === 'enroll' && (args.length === 3 || (args.length === 5 && c === '--name')) && tokenSchema.safeParse(b).success && a && a.length <= 512) {
|
|
24
|
+
if (args.length === 5 && !nodeNameSchema.safeParse(d).success)
|
|
25
|
+
fail();
|
|
26
|
+
return { verb, url: a, token: b, ...(args.length === 5 ? { name: d } : {}) };
|
|
27
|
+
}
|
|
28
|
+
return fail();
|
|
29
|
+
}
|
|
30
|
+
/** https, or plain http/ws only to a loopback host (the local hub). */
|
|
31
|
+
function safeUrl(value, kinds) {
|
|
32
|
+
const url = new URL(value);
|
|
33
|
+
const loopback = ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname);
|
|
34
|
+
const secure = kinds === 'http' ? 'https:' : 'wss:';
|
|
35
|
+
const plain = kinds === 'http' ? 'http:' : 'ws:';
|
|
36
|
+
if (url.protocol !== secure && !(url.protocol === plain && loopback))
|
|
37
|
+
throw new Error(`hub ${kinds} URL must use ${secure} (plain ${plain} only to loopback)`);
|
|
38
|
+
if (url.username || url.password)
|
|
39
|
+
throw new Error('hub URL must not carry credentials');
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
function defaultName() {
|
|
43
|
+
const name = os.hostname().replace(/[^A-Za-z0-9._-]/g, '-').slice(0, 64) || 'darwin';
|
|
44
|
+
return nodeNameSchema.safeParse(name).success ? name : 'darwin';
|
|
45
|
+
}
|
|
46
|
+
async function enroll(url, token, name) {
|
|
47
|
+
checkStore(true); // same owner-private creation as first collaboration startup
|
|
48
|
+
if (readHubNode())
|
|
49
|
+
throw new Error('This HOME is already enrolled; run darwin collaborate hub leave first');
|
|
50
|
+
const base = safeUrl(url, 'http');
|
|
51
|
+
const keys = generateNodeKeys();
|
|
52
|
+
const node = randomUUID();
|
|
53
|
+
const response = await fetch(new URL('/enroll', base), { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ token, node, name, publicKey: keys.publicKey }), signal: AbortSignal.timeout(15_000), redirect: 'error' });
|
|
54
|
+
const parsed = enrollResponseSchema.safeParse(await response.json().catch(() => undefined));
|
|
55
|
+
if (!response.ok || !parsed.success || parsed.data.node !== node || parsed.data.fingerprint !== fingerprint(keys.publicKey))
|
|
56
|
+
throw new Error('enrollment refused (token expired, already used, or not for this hub)');
|
|
57
|
+
const wsUrl = safeUrl(parsed.data.wsUrl, 'ws').toString();
|
|
58
|
+
await writeHubNode({ version: 1, hubUrl: base.origin, wsUrl, audience: parsed.data.audience, node, name, publicKey: keys.publicKey, privateKey: keys.privateKey, fingerprint: parsed.data.fingerprint, enrolledAt: Date.now() });
|
|
59
|
+
return [
|
|
60
|
+
`Enrolled node ${node} (${name}) at ${base.origin}.`,
|
|
61
|
+
`Fingerprint ${shortFingerprint(parsed.data.fingerprint)} (full ${parsed.data.fingerprint}).`,
|
|
62
|
+
'Every enrolled, active node collaborates with this one without per-pair confirmation. New sessions publish to the hub',
|
|
63
|
+
'when their project has a network git origin; opt a project out with: darwin collaborate hub publish off',
|
|
64
|
+
].join('\n');
|
|
65
|
+
}
|
|
66
|
+
function status(local, root) {
|
|
67
|
+
const node = readHubNode();
|
|
68
|
+
const state = readHubState();
|
|
69
|
+
let project;
|
|
70
|
+
try {
|
|
71
|
+
project = canonicalProject(root);
|
|
72
|
+
}
|
|
73
|
+
catch { /* reported as unknown */ }
|
|
74
|
+
return JSON.stringify({
|
|
75
|
+
enrolled: node !== undefined,
|
|
76
|
+
...(node ? { node: node.node, name: node.name, hub: node.hubUrl, fingerprint: shortFingerprint(node.fingerprint), fullFingerprint: node.fingerprint } : {}),
|
|
77
|
+
...(local ? { session: { state: local.hub.state, ...(local.hub.reason ? { reason: local.hub.reason } : {}), endpoint: local.hub.address ?? null } } : {}),
|
|
78
|
+
thisProjectPublishes: project === undefined ? 'unknown' : !state.unpublished.includes(project),
|
|
79
|
+
pinnedNodes: state.pins.length,
|
|
80
|
+
blockedNodes: state.blocked,
|
|
81
|
+
rule: 'Enrolled, active, not blocked nodes collaborate without confirmation; keys are pinned on first sight and never re-keyed.',
|
|
82
|
+
}, null, 2);
|
|
83
|
+
}
|
|
84
|
+
function nodes() {
|
|
85
|
+
const state = readHubState();
|
|
86
|
+
return JSON.stringify({ nodes: state.pins.map(pin => ({ node: pin.node, name: pin.name, fingerprint: shortFingerprint(pin.fingerprint), firstSeen: new Date(pin.firstSeen).toISOString(), blocked: state.blocked.includes(pin.node) })), note: 'Pinned on first sight. Compare fingerprints with `darwin collaborate hub status` on the other machine.' }, null, 2);
|
|
87
|
+
}
|
|
88
|
+
/** `local` is the live session (TUI) or undefined (standalone CLI). */
|
|
89
|
+
export async function hubCommand(local, root, args, cli) {
|
|
90
|
+
const parsed = parseHubArgs(args);
|
|
91
|
+
switch (parsed.verb) {
|
|
92
|
+
case 'status': return status(local, root);
|
|
93
|
+
case 'nodes': return nodes();
|
|
94
|
+
case 'enroll':
|
|
95
|
+
if (!cli)
|
|
96
|
+
throw new Error('hub enroll is CLI-only so the token never enters a session transcript: run darwin collaborate hub enroll <url> <token> in a shell');
|
|
97
|
+
return enroll(parsed.url, parsed.token, parsed.name ?? defaultName());
|
|
98
|
+
case 'leave': {
|
|
99
|
+
local?.hub.close();
|
|
100
|
+
const removed = await removeHubNode();
|
|
101
|
+
return removed ? 'Left the hub on this HOME: identity and private key removed. The hub row stays until the operator runs revoke-node; re-enrolling issues a new node id.' : 'Not enrolled.';
|
|
102
|
+
}
|
|
103
|
+
case 'publish': {
|
|
104
|
+
const project = canonicalProject(root);
|
|
105
|
+
await updateHubState(state => {
|
|
106
|
+
state.unpublished = state.unpublished.filter(entry => entry !== project);
|
|
107
|
+
if (!parsed.on)
|
|
108
|
+
state.unpublished.push(project);
|
|
109
|
+
});
|
|
110
|
+
if (local && !parsed.on)
|
|
111
|
+
local.hub.close();
|
|
112
|
+
if (local && parsed.on && local.active)
|
|
113
|
+
local.hub.start(local.project, true);
|
|
114
|
+
return `Hub publishing ${parsed.on ? 'on' : 'off'} for ${project}${local ? '; applied to this session' : '; applies to new sessions'}.`;
|
|
115
|
+
}
|
|
116
|
+
case 'block':
|
|
117
|
+
case 'unblock': {
|
|
118
|
+
await updateHubState(state => {
|
|
119
|
+
state.blocked = state.blocked.filter(node => node !== parsed.node);
|
|
120
|
+
if (parsed.verb === 'block')
|
|
121
|
+
state.blocked.push(parsed.node);
|
|
122
|
+
});
|
|
123
|
+
if (parsed.verb === 'block')
|
|
124
|
+
local?.dropHubNode(parsed.node, 'node blocked by the user');
|
|
125
|
+
return parsed.verb === 'block' ? `Blocked ${parsed.node}: its messages are refused and queued ones dropped, whatever the hub says.` : `Unblocked ${parsed.node}.`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=hub-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub-command.js","sourceRoot":"","sources":["../../../src/collaboration/hub-command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/I,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG5D,MAAM,CAAC,MAAM,WAAW,GAAG,4IAA4I,CAAC;AAQxK,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,IAAuB;IAClD,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAChC,MAAM,IAAI,GAAG,GAAU,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,UAAU,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACtG,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,KAAK,IAA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AM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;gBACnE,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;oBAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;gBAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;YACzF,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,IAAI,4EAA4E,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,IAAI,GAAG,CAAC;QACpK,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const MAX_PINS = 256;
|
|
3
|
+
export declare const hubNodeSchema: z.ZodObject<{
|
|
4
|
+
version: z.ZodLiteral<1>;
|
|
5
|
+
hubUrl: z.ZodString;
|
|
6
|
+
wsUrl: z.ZodString;
|
|
7
|
+
audience: z.ZodString;
|
|
8
|
+
node: z.ZodString;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
publicKey: z.ZodString;
|
|
11
|
+
privateKey: z.ZodString;
|
|
12
|
+
fingerprint: z.ZodString;
|
|
13
|
+
enrolledAt: z.ZodNumber;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export type HubNode = z.infer<typeof hubNodeSchema>;
|
|
16
|
+
declare const pinSchema: z.ZodObject<{
|
|
17
|
+
node: z.ZodString;
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
publicKey: z.ZodString;
|
|
20
|
+
fingerprint: z.ZodString;
|
|
21
|
+
firstSeen: z.ZodNumber;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
export type HubPin = z.infer<typeof pinSchema>;
|
|
24
|
+
declare const stateSchema: z.ZodObject<{
|
|
25
|
+
version: z.ZodLiteral<1>;
|
|
26
|
+
pins: z.ZodArray<z.ZodObject<{
|
|
27
|
+
node: z.ZodString;
|
|
28
|
+
name: z.ZodString;
|
|
29
|
+
publicKey: z.ZodString;
|
|
30
|
+
fingerprint: z.ZodString;
|
|
31
|
+
firstSeen: z.ZodNumber;
|
|
32
|
+
}, z.core.$strict>>;
|
|
33
|
+
blocked: z.ZodArray<z.ZodString>;
|
|
34
|
+
unpublished: z.ZodArray<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type HubState = z.infer<typeof stateSchema>;
|
|
37
|
+
export declare function readHubNode(): HubNode | undefined;
|
|
38
|
+
/** Enrollment writes the identity exactly once; an existing file must be removed by `leave`. */
|
|
39
|
+
export declare function writeHubNode(node: HubNode): Promise<void>;
|
|
40
|
+
export declare function removeHubNode(): Promise<boolean>;
|
|
41
|
+
export declare function readHubState(): HubState;
|
|
42
|
+
export declare function updateHubState<T>(change: (state: HubState) => T): Promise<T>;
|
|
43
|
+
export type PinResult = 'pinned' | 'match' | 'mismatch' | 'full';
|
|
44
|
+
/** Pin once, never re-key (§7.1): a different key for a known node id is refused forever. */
|
|
45
|
+
export declare function pinNode(node: string, name: string, publicKey: string, fingerprint: string, now?: number): Promise<PinResult>;
|
|
46
|
+
export declare function pinnedKey(node: string): string | undefined;
|
|
47
|
+
export declare function isBlocked(node: string): boolean;
|
|
48
|
+
export declare function isPublished(canonicalRoot: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Automatic cross-machine project identity (§4): `git remote get-url origin`, normalized.
|
|
51
|
+
* Argument array, no shell, bounded time. Any failure disables the hub for that project.
|
|
52
|
+
*/
|
|
53
|
+
export declare function remoteIdentity(canonicalRoot: string): {
|
|
54
|
+
project: string;
|
|
55
|
+
} | {
|
|
56
|
+
problem: string;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hub state on this machine (hub/README.md §5, §7). Lives in the owner-private collaboration
|
|
3
|
+
* directory, so the gate's existing protection covers it: sensitive read path, un-ruleable,
|
|
4
|
+
* model access to the directory and to `collaborate` controls denied before rules and hooks.
|
|
5
|
+
* Writes share the policy lock; reads validate strictly and fail closed.
|
|
6
|
+
*/
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { collaborationDir } from '../paths.js';
|
|
12
|
+
import { fingerprintSchema, nodeNameSchema, normalizeRemote, publicKeySchema, uuidSchema } from './hub-wire.js';
|
|
13
|
+
import { checkStore, readPrivate, withLock, writePrivate } from './storage.js';
|
|
14
|
+
const NODE_FILE = 'hub-node.json';
|
|
15
|
+
const STATE_FILE = 'hub-state.json';
|
|
16
|
+
export const MAX_PINS = 256;
|
|
17
|
+
const urlSchema = z.string().max(512).refine(value => { try {
|
|
18
|
+
return /^(https|wss|http|ws):$/.test(new URL(value).protocol);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
} });
|
|
23
|
+
export const hubNodeSchema = z.object({
|
|
24
|
+
version: z.literal(1), hubUrl: urlSchema, wsUrl: urlSchema, audience: z.string().min(1).max(256),
|
|
25
|
+
node: uuidSchema, name: nodeNameSchema, publicKey: publicKeySchema, privateKey: z.string().min(40).max(256), fingerprint: fingerprintSchema, enrolledAt: z.number().int(),
|
|
26
|
+
}).strict();
|
|
27
|
+
const pinSchema = z.object({ node: uuidSchema, name: nodeNameSchema, publicKey: publicKeySchema, fingerprint: fingerprintSchema, firstSeen: z.number().int() }).strict();
|
|
28
|
+
const stateSchema = z.object({
|
|
29
|
+
version: z.literal(1),
|
|
30
|
+
pins: z.array(pinSchema).max(MAX_PINS),
|
|
31
|
+
blocked: z.array(uuidSchema).max(MAX_PINS),
|
|
32
|
+
/** Canonical project roots whose sessions do not publish to the hub. */
|
|
33
|
+
unpublished: z.array(z.string().min(1).max(1024)).max(64),
|
|
34
|
+
}).strict();
|
|
35
|
+
const EMPTY = { version: 1, pins: [], blocked: [], unpublished: [] };
|
|
36
|
+
export function readHubNode() {
|
|
37
|
+
if (!existsSync(collaborationDir()))
|
|
38
|
+
return undefined;
|
|
39
|
+
const raw = readPrivate(NODE_FILE);
|
|
40
|
+
return raw === undefined ? undefined : hubNodeSchema.parse(raw);
|
|
41
|
+
}
|
|
42
|
+
/** Enrollment writes the identity exactly once; an existing file must be removed by `leave`. */
|
|
43
|
+
export async function writeHubNode(node) {
|
|
44
|
+
await withLock(() => {
|
|
45
|
+
if (readPrivate(NODE_FILE) !== undefined)
|
|
46
|
+
throw new Error('This HOME is already enrolled; run collaborate hub leave first');
|
|
47
|
+
writePrivate(NODE_FILE, hubNodeSchema.parse(node));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export async function removeHubNode() {
|
|
51
|
+
return withLock(() => {
|
|
52
|
+
if (readPrivate(NODE_FILE) === undefined)
|
|
53
|
+
return false;
|
|
54
|
+
unlinkSync(path.join(checkStore(), NODE_FILE));
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function readHubState() {
|
|
59
|
+
if (!existsSync(collaborationDir()))
|
|
60
|
+
return structuredClone(EMPTY);
|
|
61
|
+
const raw = readPrivate(STATE_FILE);
|
|
62
|
+
return raw === undefined ? structuredClone(EMPTY) : stateSchema.parse(raw);
|
|
63
|
+
}
|
|
64
|
+
export async function updateHubState(change) {
|
|
65
|
+
return withLock(() => {
|
|
66
|
+
const raw = readPrivate(STATE_FILE);
|
|
67
|
+
const state = raw === undefined ? structuredClone(EMPTY) : stateSchema.parse(raw);
|
|
68
|
+
const result = change(state);
|
|
69
|
+
writePrivate(STATE_FILE, stateSchema.parse(state));
|
|
70
|
+
return result;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Pin once, never re-key (§7.1): a different key for a known node id is refused forever. */
|
|
74
|
+
export async function pinNode(node, name, publicKey, fingerprint, now = Date.now()) {
|
|
75
|
+
const known = readHubState().pins.find(pin => pin.node === node);
|
|
76
|
+
if (known)
|
|
77
|
+
return known.publicKey === publicKey ? 'match' : 'mismatch';
|
|
78
|
+
return updateHubState(state => {
|
|
79
|
+
const current = state.pins.find(pin => pin.node === node);
|
|
80
|
+
if (current)
|
|
81
|
+
return current.publicKey === publicKey ? 'match' : 'mismatch';
|
|
82
|
+
if (state.pins.length >= MAX_PINS)
|
|
83
|
+
return 'full';
|
|
84
|
+
state.pins.push({ node, name, publicKey, fingerprint, firstSeen: now });
|
|
85
|
+
return 'pinned';
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export function pinnedKey(node) {
|
|
89
|
+
return readHubState().pins.find(pin => pin.node === node)?.publicKey;
|
|
90
|
+
}
|
|
91
|
+
export function isBlocked(node) { return readHubState().blocked.includes(node); }
|
|
92
|
+
export function isPublished(canonicalRoot) { return !readHubState().unpublished.includes(canonicalRoot); }
|
|
93
|
+
/**
|
|
94
|
+
* Automatic cross-machine project identity (§4): `git remote get-url origin`, normalized.
|
|
95
|
+
* Argument array, no shell, bounded time. Any failure disables the hub for that project.
|
|
96
|
+
*/
|
|
97
|
+
export function remoteIdentity(canonicalRoot) {
|
|
98
|
+
const result = spawnSync('git', ['-C', canonicalRoot, 'remote', 'get-url', 'origin'], { encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } });
|
|
99
|
+
if (result.error || result.status !== 0)
|
|
100
|
+
return { problem: 'no git origin remote' };
|
|
101
|
+
try {
|
|
102
|
+
return { project: normalizeRemote(result.stdout) };
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return { problem: error instanceof Error ? error.message : 'unrecognized origin remote' };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sour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,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,4BAA4B,EAAE,CAAC;IAAC,CAAC;AAC9G,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type HubAddress, type HubEnvelope, type PeerChain } from './hub-wire.js';
|
|
2
|
+
import { type HubNode } from './hub-store.js';
|
|
3
|
+
export declare const HEARTBEAT_MS: number;
|
|
4
|
+
export declare const ROTATE_MS: number;
|
|
5
|
+
export declare const REQUEST_TIMEOUT_MS = 10000;
|
|
6
|
+
export declare const MAX_REFUSALS = 3;
|
|
7
|
+
/** ~25 minutes of capped backoff against an unreachable hub, then pause with a notice. */
|
|
8
|
+
export declare const MAX_UNREACHABLE_ATTEMPTS = 30;
|
|
9
|
+
export interface HubHooks {
|
|
10
|
+
/** Shared admission (freshness, dedupe, chain, caps); returns the local queue result text. */
|
|
11
|
+
admit(envelope: HubEnvelope): Promise<string> | string;
|
|
12
|
+
/** Drop queued input from a revoked or blocked node. */
|
|
13
|
+
drop(node: string, reason: string): void;
|
|
14
|
+
notice(text: string): void;
|
|
15
|
+
}
|
|
16
|
+
export type HubState = 'off' | 'not-enrolled' | 'unpublished' | 'unavailable' | 'connecting' | 'connected' | 'paused' | 'closed';
|
|
17
|
+
interface Socket {
|
|
18
|
+
ws: WebSocket;
|
|
19
|
+
opened: boolean;
|
|
20
|
+
ended: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare class HubTransport {
|
|
23
|
+
private readonly hooks;
|
|
24
|
+
private readonly session;
|
|
25
|
+
private node;
|
|
26
|
+
private own;
|
|
27
|
+
private socket;
|
|
28
|
+
private rotating;
|
|
29
|
+
private attempt;
|
|
30
|
+
private refusals;
|
|
31
|
+
private timers;
|
|
32
|
+
private rows;
|
|
33
|
+
private revoked;
|
|
34
|
+
private requests;
|
|
35
|
+
private stopped;
|
|
36
|
+
state: HubState;
|
|
37
|
+
reason: string;
|
|
38
|
+
/** Changes on every start; validates queued input against this incarnation. */
|
|
39
|
+
generation: `${string}-${string}-${string}-${string}-${string}`;
|
|
40
|
+
constructor(hooks: HubHooks, session: string);
|
|
41
|
+
get address(): HubAddress | undefined;
|
|
42
|
+
get identity(): HubNode | undefined;
|
|
43
|
+
/** Test hook: run the two-hour rotation now (open successor, re-register, close old). */
|
|
44
|
+
rotateNow(): void;
|
|
45
|
+
/** Guarded like local startup: any problem disables only the hub transport, with one notice. */
|
|
46
|
+
start(canonicalRoot: string, published: boolean): void;
|
|
47
|
+
private disable;
|
|
48
|
+
close(): void;
|
|
49
|
+
private later;
|
|
50
|
+
private open;
|
|
51
|
+
private connect;
|
|
52
|
+
private heartbeat;
|
|
53
|
+
/** API Gateway caps a connection at two hours: open the successor first, then close the old one. */
|
|
54
|
+
private rotate;
|
|
55
|
+
private register;
|
|
56
|
+
private lost;
|
|
57
|
+
/** Server minus local clock in ms, or undefined when the hub's HTTP API is unreachable. */
|
|
58
|
+
private skew;
|
|
59
|
+
private request;
|
|
60
|
+
private settle;
|
|
61
|
+
private abandon;
|
|
62
|
+
private frame;
|
|
63
|
+
private receive;
|
|
64
|
+
discover(): Promise<{
|
|
65
|
+
state: HubState;
|
|
66
|
+
reason?: string;
|
|
67
|
+
endpoints: Array<{
|
|
68
|
+
address: HubAddress;
|
|
69
|
+
name: string;
|
|
70
|
+
fingerprint: string;
|
|
71
|
+
}>;
|
|
72
|
+
omitted: number;
|
|
73
|
+
}>;
|
|
74
|
+
knows(endpoint: string): boolean;
|
|
75
|
+
/** Synchronous checks and signing; throws before the caller reserves outgoing budget. */
|
|
76
|
+
prepare(target: string, chain: PeerChain, text: string): {
|
|
77
|
+
socket: Socket;
|
|
78
|
+
target: string;
|
|
79
|
+
envelope: HubEnvelope;
|
|
80
|
+
value: unknown;
|
|
81
|
+
};
|
|
82
|
+
transmit({ socket, target, envelope, value }: ReturnType<HubTransport['prepare']>): Promise<string>;
|
|
83
|
+
/** Delivery re-check (admission, dequeue, pre-invoke): same incarnation, sender still admissible. */
|
|
84
|
+
deliverable(envelope: HubEnvelope, authorization: string): boolean;
|
|
85
|
+
}
|
|
86
|
+
export {};
|