sigild 0.0.7 → 0.0.9

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.
Files changed (145) hide show
  1. package/README.md +80 -27
  2. package/THREAT_MODEL.md +6 -4
  3. package/dist/src/audit/log.d.ts +1 -1
  4. package/dist/src/audit/log.js +1 -1
  5. package/dist/src/bin/sigil-mcp.js +60 -16
  6. package/dist/src/bin/sigil-mcp.js.map +1 -1
  7. package/dist/src/cli/index.d.ts +2 -2
  8. package/dist/src/cli/index.d.ts.map +1 -1
  9. package/dist/src/cli/index.js.map +1 -1
  10. package/dist/src/cli/main.d.ts.map +1 -1
  11. package/dist/src/cli/main.js +35 -9
  12. package/dist/src/cli/main.js.map +1 -1
  13. package/dist/src/cli/paths.d.ts +15 -5
  14. package/dist/src/cli/paths.d.ts.map +1 -1
  15. package/dist/src/cli/paths.js +11 -1
  16. package/dist/src/cli/paths.js.map +1 -1
  17. package/dist/src/cli/portal.d.ts +14 -1
  18. package/dist/src/cli/portal.d.ts.map +1 -1
  19. package/dist/src/cli/portal.js +31 -1
  20. package/dist/src/cli/portal.js.map +1 -1
  21. package/dist/src/cli/status.d.ts +15 -12
  22. package/dist/src/cli/status.d.ts.map +1 -1
  23. package/dist/src/cli/status.js +17 -30
  24. package/dist/src/cli/status.js.map +1 -1
  25. package/dist/src/cli/unlock.d.ts +15 -15
  26. package/dist/src/cli/unlock.d.ts.map +1 -1
  27. package/dist/src/cli/unlock.js +83 -60
  28. package/dist/src/cli/unlock.js.map +1 -1
  29. package/dist/src/confirm/ack-server.d.ts +53 -0
  30. package/dist/src/confirm/ack-server.d.ts.map +1 -0
  31. package/dist/src/confirm/ack-server.js +87 -0
  32. package/dist/src/confirm/ack-server.js.map +1 -0
  33. package/dist/src/confirm/config.d.ts +54 -0
  34. package/dist/src/confirm/config.d.ts.map +1 -0
  35. package/dist/src/confirm/config.js +139 -0
  36. package/dist/src/confirm/config.js.map +1 -0
  37. package/dist/src/confirm/gate.d.ts +38 -0
  38. package/dist/src/confirm/gate.d.ts.map +1 -0
  39. package/dist/src/confirm/gate.js +66 -0
  40. package/dist/src/confirm/gate.js.map +1 -0
  41. package/dist/src/confirm/index.d.ts +6 -0
  42. package/dist/src/confirm/index.d.ts.map +1 -0
  43. package/dist/src/confirm/index.js +5 -0
  44. package/dist/src/confirm/index.js.map +1 -0
  45. package/dist/src/confirm/ntfy.d.ts +38 -0
  46. package/dist/src/confirm/ntfy.d.ts.map +1 -0
  47. package/dist/src/confirm/ntfy.js +47 -0
  48. package/dist/src/confirm/ntfy.js.map +1 -0
  49. package/dist/src/confirm/types.d.ts +66 -0
  50. package/dist/src/confirm/types.d.ts.map +1 -0
  51. package/dist/src/confirm/types.js +12 -0
  52. package/dist/src/confirm/types.js.map +1 -0
  53. package/dist/src/control/broadcast.d.ts +29 -0
  54. package/dist/src/control/broadcast.d.ts.map +1 -0
  55. package/dist/src/control/broadcast.js +88 -0
  56. package/dist/src/control/broadcast.js.map +1 -0
  57. package/dist/src/control/client.d.ts.map +1 -1
  58. package/dist/src/control/client.js +4 -1
  59. package/dist/src/control/client.js.map +1 -1
  60. package/dist/src/control/index.d.ts +1 -0
  61. package/dist/src/control/index.d.ts.map +1 -1
  62. package/dist/src/control/index.js +1 -0
  63. package/dist/src/control/index.js.map +1 -1
  64. package/dist/src/control/protocol.d.ts +6 -2
  65. package/dist/src/control/protocol.d.ts.map +1 -1
  66. package/dist/src/control/protocol.js +2 -1
  67. package/dist/src/control/protocol.js.map +1 -1
  68. package/dist/src/control/server.d.ts +10 -0
  69. package/dist/src/control/server.d.ts.map +1 -1
  70. package/dist/src/control/server.js +60 -7
  71. package/dist/src/control/server.js.map +1 -1
  72. package/dist/src/daemon/handles.d.ts +5 -2
  73. package/dist/src/daemon/handles.d.ts.map +1 -1
  74. package/dist/src/daemon/handles.js +11 -3
  75. package/dist/src/daemon/handles.js.map +1 -1
  76. package/dist/src/daemon/methods.d.ts +13 -3
  77. package/dist/src/daemon/methods.d.ts.map +1 -1
  78. package/dist/src/daemon/methods.js +121 -16
  79. package/dist/src/daemon/methods.js.map +1 -1
  80. package/dist/src/eth/secp.d.ts.map +1 -1
  81. package/dist/src/eth/secp.js +6 -2
  82. package/dist/src/eth/secp.js.map +1 -1
  83. package/dist/src/hooks/command-scanner.d.ts.map +1 -1
  84. package/dist/src/hooks/command-scanner.js +57 -13
  85. package/dist/src/hooks/command-scanner.js.map +1 -1
  86. package/dist/src/hooks/glob.js +1 -1
  87. package/dist/src/hooks/glob.js.map +1 -1
  88. package/dist/src/hooks/path-blocker.d.ts.map +1 -1
  89. package/dist/src/hooks/path-blocker.js +1 -8
  90. package/dist/src/hooks/path-blocker.js.map +1 -1
  91. package/dist/src/mcp/server.d.ts +14 -2
  92. package/dist/src/mcp/server.d.ts.map +1 -1
  93. package/dist/src/mcp/server.js +28 -14
  94. package/dist/src/mcp/server.js.map +1 -1
  95. package/dist/src/mcp/tools.d.ts +1 -1
  96. package/dist/src/mcp/tools.d.ts.map +1 -1
  97. package/dist/src/mcp/tools.js +38 -4
  98. package/dist/src/mcp/tools.js.map +1 -1
  99. package/dist/src/policy/evaluate.d.ts +10 -4
  100. package/dist/src/policy/evaluate.d.ts.map +1 -1
  101. package/dist/src/policy/evaluate.js +161 -20
  102. package/dist/src/policy/evaluate.js.map +1 -1
  103. package/dist/src/policy/loader.d.ts.map +1 -1
  104. package/dist/src/policy/loader.js +70 -0
  105. package/dist/src/policy/loader.js.map +1 -1
  106. package/dist/src/policy/template.d.ts +1 -1
  107. package/dist/src/policy/template.d.ts.map +1 -1
  108. package/dist/src/policy/template.js +30 -0
  109. package/dist/src/policy/template.js.map +1 -1
  110. package/dist/src/policy/types.d.ts +53 -3
  111. package/dist/src/policy/types.d.ts.map +1 -1
  112. package/dist/src/policy/types.js.map +1 -1
  113. package/dist/src/qr/encode.d.ts +36 -0
  114. package/dist/src/qr/encode.d.ts.map +1 -0
  115. package/dist/src/qr/encode.js +44 -0
  116. package/dist/src/qr/encode.js.map +1 -0
  117. package/dist/src/qr/index.d.ts +3 -0
  118. package/dist/src/qr/index.d.ts.map +1 -0
  119. package/dist/src/qr/index.js +3 -0
  120. package/dist/src/qr/index.js.map +1 -0
  121. package/dist/src/qr/render.d.ts +34 -0
  122. package/dist/src/qr/render.d.ts.map +1 -0
  123. package/dist/src/qr/render.js +43 -0
  124. package/dist/src/qr/render.js.map +1 -0
  125. package/dist/src/svm/address.d.ts +14 -0
  126. package/dist/src/svm/address.d.ts.map +1 -0
  127. package/dist/src/svm/address.js +18 -0
  128. package/dist/src/svm/address.js.map +1 -0
  129. package/dist/src/svm/base58.d.ts +15 -0
  130. package/dist/src/svm/base58.d.ts.map +1 -0
  131. package/dist/src/svm/base58.js +60 -0
  132. package/dist/src/svm/base58.js.map +1 -0
  133. package/dist/src/svm/ed25519.d.ts +19 -0
  134. package/dist/src/svm/ed25519.d.ts.map +1 -0
  135. package/dist/src/svm/ed25519.js +32 -0
  136. package/dist/src/svm/ed25519.js.map +1 -0
  137. package/dist/src/svm/index.d.ts +5 -0
  138. package/dist/src/svm/index.d.ts.map +1 -0
  139. package/dist/src/svm/index.js +5 -0
  140. package/dist/src/svm/index.js.map +1 -0
  141. package/dist/src/svm/transaction.d.ts +56 -0
  142. package/dist/src/svm/transaction.d.ts.map +1 -0
  143. package/dist/src/svm/transaction.js +182 -0
  144. package/dist/src/svm/transaction.js.map +1 -0
  145. package/package.json +4 -2
@@ -0,0 +1,87 @@
1
+ import { createServer } from 'node:http';
2
+ import { randomBytes } from 'node:crypto';
3
+ /**
4
+ * Start a local ack server on 127.0.0.1 and resolve when it's listening.
5
+ * The chosen port is observable via `baseUrl`.
6
+ */
7
+ export function startAckServer() {
8
+ const pending = new Map();
9
+ const handle = (req, res) => {
10
+ // Strip query, route on path. We accept GET and POST equivalently — the
11
+ // ntfy "http,Approve,..." button POSTs, but a fallback SMS link a human
12
+ // taps would be a GET.
13
+ const url = new URL(req.url ?? '/', 'http://127.0.0.1');
14
+ let outcome;
15
+ if (url.pathname === '/approve')
16
+ outcome = 'approve';
17
+ else if (url.pathname === '/deny')
18
+ outcome = 'deny';
19
+ else {
20
+ reply(res, 404, 'unknown path\n');
21
+ return;
22
+ }
23
+ const token = url.searchParams.get('t');
24
+ if (!token) {
25
+ reply(res, 400, 'missing token\n');
26
+ return;
27
+ }
28
+ const entry = pending.get(token);
29
+ if (!entry) {
30
+ // Either never existed, or already settled, or cancelled by timeout.
31
+ reply(res, 410, 'token expired or already used\n');
32
+ return;
33
+ }
34
+ pending.delete(token);
35
+ entry.resolve(outcome);
36
+ reply(res, 200, outcome === 'approve'
37
+ ? 'approved — you can close this tab\n'
38
+ : 'denied — you can close this tab\n');
39
+ };
40
+ const server = createServer(handle);
41
+ return new Promise((resolve, reject) => {
42
+ server.once('error', reject);
43
+ server.listen(0, '127.0.0.1', () => {
44
+ server.removeListener('error', reject);
45
+ const addr = server.address();
46
+ const baseUrl = `http://127.0.0.1:${addr.port}`;
47
+ resolve(makeApi(server, baseUrl, pending));
48
+ });
49
+ });
50
+ }
51
+ function makeApi(server, baseUrl, pending) {
52
+ return {
53
+ baseUrl,
54
+ pending() {
55
+ const token = randomBytes(32).toString('base64url');
56
+ let resolveFn;
57
+ const settled = new Promise((res) => {
58
+ resolveFn = res;
59
+ });
60
+ pending.set(token, { resolve: resolveFn, cancelled: false });
61
+ const approveUrl = `${baseUrl}/approve?t=${token}`;
62
+ const denyUrl = `${baseUrl}/deny?t=${token}`;
63
+ return { token, approveUrl, denyUrl, settled };
64
+ },
65
+ cancel(token) {
66
+ const entry = pending.get(token);
67
+ if (!entry)
68
+ return;
69
+ entry.cancelled = true;
70
+ pending.delete(token);
71
+ // Note: we deliberately do not resolve `settled`. The gate owns the
72
+ // timeout race and will already have moved on by the time it calls
73
+ // cancel(). A settled-after-timeout resolution would cause the gate
74
+ // to double-decide.
75
+ },
76
+ close() {
77
+ return new Promise((resolve, reject) => {
78
+ server.close((err) => (err ? reject(err) : resolve()));
79
+ });
80
+ },
81
+ };
82
+ }
83
+ function reply(res, status, body) {
84
+ res.writeHead(status, { 'Content-Type': 'text/plain; charset=utf-8' });
85
+ res.end(body);
86
+ }
87
+ //# sourceMappingURL=ack-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ack-server.js","sourceRoot":"","sources":["../../../src/confirm/ack-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA4D1C;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE3C,MAAM,MAAM,GAAG,CAAC,GAAoB,EAAE,GAAmB,EAAQ,EAAE;QACjE,wEAAwE;QACxE,wEAAwE;QACxE,uBAAuB;QACvB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,kBAAkB,CAAC,CAAC;QACxD,IAAI,OAAmB,CAAC;QACxB,IAAI,GAAG,CAAC,QAAQ,KAAK,UAAU;YAAE,OAAO,GAAG,SAAS,CAAC;aAChD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;YAAE,OAAO,GAAG,MAAM,CAAC;aAC/C,CAAC;YACJ,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;YACnC,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,qEAAqE;YACrE,KAAK,CAAC,GAAG,EAAE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EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7D,MAAM,UAAU,GAAG,GAAG,OAAO,cAAc,KAAK,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,GAAG,OAAO,WAAW,KAAK,EAAE,CAAC;YAC7C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QACjD,CAAC;QACD,MAAM,CAAC,KAAK;YACV,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK;gBAAE,OAAO;YACnB,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;YACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtB,oEAAoE;YACpE,mEAAmE;YACnE,oEAAoE;YACpE,oBAAoB;QACtB,CAAC;QACD,KAAK;YACH,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC3C,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,GAAmB,EAAE,MAAc,EAAE,IAAY;IAC9D,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,CAAC,CAAC;IACvE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * sigil config at ~/.sigil/config.toml. Today this only carries the OOB
3
+ * confirm transport block; will grow over time.
4
+ *
5
+ * [confirm.ntfy]
6
+ * topic = "an-unguessable-string"
7
+ * server = "https://ntfy.sh" # optional, default https://ntfy.sh
8
+ *
9
+ * Missing file → SigilConfig with no transport configured. That's fine on
10
+ * its own; we only fail closed at startup if some policy actually depends
11
+ * on a transport (see `enforceConfirmTransportPresence`).
12
+ */
13
+ export interface SigilConfig {
14
+ confirm?: ConfirmConfig;
15
+ }
16
+ export interface ConfirmConfig {
17
+ /** Default timeout for any OOB confirm round-trip, in milliseconds.
18
+ * Defaults to 60_000. Per-portal overrides come later. */
19
+ timeoutMs?: number;
20
+ ntfy?: NtfyConfigToml;
21
+ }
22
+ export interface NtfyConfigToml {
23
+ topic: string;
24
+ server?: string;
25
+ }
26
+ export declare class SigilConfigError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /**
30
+ * Parse the file contents (an empty string is treated as "no file").
31
+ * Exported for tests; production loaders should use `loadConfig` so the
32
+ * file-not-found case is handled uniformly.
33
+ */
34
+ export declare function parseConfig(source: string): SigilConfig;
35
+ /**
36
+ * Load + parse the file at ~/.sigil/config.toml. Returns an empty config if
37
+ * the file is absent. Throws SigilConfigError on parse/schema errors.
38
+ */
39
+ export declare function loadConfig(path: string): SigilConfig;
40
+ /**
41
+ * Walk every *.toml under the policy dir, parse each, and return true if
42
+ * any of them sets require_confirm_above_wei. A malformed policy file is
43
+ * skipped (it'll surface its own error at sign time); we only need to know
44
+ * whether some portal is *trying* to gate on confirm.
45
+ */
46
+ export declare function anyPolicyRequiresConfirm(policyDir: string): boolean;
47
+ /**
48
+ * Fail-closed check called at sigil-mcp boot: if any policy on disk uses
49
+ * require_confirm_above_wei but the config has no transport, the process
50
+ * cannot honour that policy — bail with a clear message instead of running
51
+ * with a half-built safety net.
52
+ */
53
+ export declare function enforceConfirmTransportPresence(config: SigilConfig, policyDir: string): void;
54
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/confirm/config.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B;+DAC2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CA2CvD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CASpD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CA2BnE;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,GAChB,IAAI,CAWN"}
@@ -0,0 +1,139 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import toml from '@iarna/toml';
4
+ import { parsePolicy, PolicyLoadError } from '../policy/index.js';
5
+ export class SigilConfigError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = 'SigilConfigError';
9
+ }
10
+ }
11
+ /**
12
+ * Parse the file contents (an empty string is treated as "no file").
13
+ * Exported for tests; production loaders should use `loadConfig` so the
14
+ * file-not-found case is handled uniformly.
15
+ */
16
+ export function parseConfig(source) {
17
+ if (source.trim() === '')
18
+ return {};
19
+ let raw;
20
+ try {
21
+ raw = toml.parse(source);
22
+ }
23
+ catch (err) {
24
+ throw new SigilConfigError(`config: invalid TOML — ${err.message}`);
25
+ }
26
+ const out = {};
27
+ const confirmRaw = raw['confirm'];
28
+ if (confirmRaw === undefined)
29
+ return out;
30
+ if (!isObject(confirmRaw)) {
31
+ throw new SigilConfigError(`config.confirm must be a table`);
32
+ }
33
+ const confirm = {};
34
+ const timeoutMs = confirmRaw['timeout_ms'];
35
+ if (timeoutMs !== undefined) {
36
+ if (typeof timeoutMs !== 'number' || !Number.isInteger(timeoutMs) || timeoutMs <= 0) {
37
+ throw new SigilConfigError(`config.confirm.timeout_ms must be a positive integer (got ${JSON.stringify(timeoutMs)})`);
38
+ }
39
+ confirm.timeoutMs = timeoutMs;
40
+ }
41
+ const ntfyRaw = confirmRaw['ntfy'];
42
+ if (ntfyRaw !== undefined) {
43
+ if (!isObject(ntfyRaw)) {
44
+ throw new SigilConfigError(`config.confirm.ntfy must be a table`);
45
+ }
46
+ const topic = ntfyRaw['topic'];
47
+ if (typeof topic !== 'string' || topic.length === 0) {
48
+ throw new SigilConfigError(`config.confirm.ntfy.topic is required and must be a string`);
49
+ }
50
+ const server = ntfyRaw['server'];
51
+ if (server !== undefined && typeof server !== 'string') {
52
+ throw new SigilConfigError(`config.confirm.ntfy.server must be a string if set`);
53
+ }
54
+ confirm.ntfy = server !== undefined ? { topic, server } : { topic };
55
+ }
56
+ if (confirm.timeoutMs !== undefined || confirm.ntfy !== undefined) {
57
+ out.confirm = confirm;
58
+ }
59
+ return out;
60
+ }
61
+ /**
62
+ * Load + parse the file at ~/.sigil/config.toml. Returns an empty config if
63
+ * the file is absent. Throws SigilConfigError on parse/schema errors.
64
+ */
65
+ export function loadConfig(path) {
66
+ let source;
67
+ try {
68
+ source = readFileSync(path, 'utf8');
69
+ }
70
+ catch (err) {
71
+ if (err.code === 'ENOENT')
72
+ return {};
73
+ throw new SigilConfigError(`config: failed to read ${path}: ${err.message}`);
74
+ }
75
+ return parseConfig(source);
76
+ }
77
+ /**
78
+ * Walk every *.toml under the policy dir, parse each, and return true if
79
+ * any of them sets require_confirm_above_wei. A malformed policy file is
80
+ * skipped (it'll surface its own error at sign time); we only need to know
81
+ * whether some portal is *trying* to gate on confirm.
82
+ */
83
+ export function anyPolicyRequiresConfirm(policyDir) {
84
+ let entries;
85
+ try {
86
+ entries = readdirSync(policyDir);
87
+ }
88
+ catch (err) {
89
+ if (err.code === 'ENOENT')
90
+ return false;
91
+ throw err;
92
+ }
93
+ for (const f of entries) {
94
+ if (!f.endsWith('.toml'))
95
+ continue;
96
+ let source;
97
+ try {
98
+ source = readFileSync(join(policyDir, f), 'utf8');
99
+ }
100
+ catch {
101
+ continue;
102
+ }
103
+ try {
104
+ const p = parsePolicy(source);
105
+ if (p.requireConfirmAboveWei !== undefined)
106
+ return true;
107
+ }
108
+ catch (err) {
109
+ // Malformed policy file — not our problem here; the sign path will
110
+ // raise PolicyLoadError when this portal is used. Skip.
111
+ if (err instanceof PolicyLoadError)
112
+ continue;
113
+ throw err;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Fail-closed check called at sigil-mcp boot: if any policy on disk uses
120
+ * require_confirm_above_wei but the config has no transport, the process
121
+ * cannot honour that policy — bail with a clear message instead of running
122
+ * with a half-built safety net.
123
+ */
124
+ export function enforceConfirmTransportPresence(config, policyDir) {
125
+ const needsTransport = anyPolicyRequiresConfirm(policyDir);
126
+ if (!needsTransport)
127
+ return;
128
+ const haveTransport = config.confirm?.ntfy !== undefined;
129
+ if (haveTransport)
130
+ return;
131
+ throw new SigilConfigError(`at least one portal policy in ${policyDir} sets require_confirm_above_wei, ` +
132
+ `but no OOB confirm transport is configured. ` +
133
+ `Add a [confirm.ntfy] block to ~/.sigil/config.toml with a topic, ` +
134
+ `or remove require_confirm_above_wei from the affected policy files.`);
135
+ }
136
+ function isObject(v) {
137
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
138
+ }
139
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/confirm/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,IA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IAAI,CAAC,cAAc;QAAE,OAAO;IAC5B,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,EAAE,IAAI,KAAK,SAAS,CAAC;IACzD,IAAI,aAAa;QAAE,OAAO;IAC1B,MAAM,IAAI,gBAAgB,CACxB,iCAAiC,SAAS,mCAAmC;QAC7E,8CAA8C;QAC9C,mEAAmE;QACnE,qEAAqE,CACtE,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { AckServer } from './ack-server.js';
2
+ import type { ConfirmDecision, ConfirmTransport } from './types.js';
3
+ export interface ConfirmGateOpts {
4
+ /** Pluggable transport — ntfy in production; mock in tests. */
5
+ transport: ConfirmTransport;
6
+ /** Shared local ack server (one per process). */
7
+ ackServer: AckServer;
8
+ /** Per-portal override comes from policy; this is the cross-portal default.
9
+ * Configurable so tests can use ms-scale timeouts without slowing the suite. */
10
+ timeoutMs?: number;
11
+ }
12
+ /**
13
+ * The OOB confirm gate. Mints a token, pushes the prompt over the transport,
14
+ * races the human's click against a timeout, returns the decision.
15
+ *
16
+ * Failure modes (all map to a final ConfirmDecision):
17
+ * - transport.send() throws → `transport_error` (gate doesn't fall
18
+ * back to silently allowing the sign;
19
+ * the caller maps this to RPC_POLICY_DENIED)
20
+ * - human clicks Approve / Deny → `approved` / `denied`
21
+ * - clock runs out → `timeout` (cancels the token so a late
22
+ * click returns 410 Gone instead of being
23
+ * silently absorbed)
24
+ *
25
+ * Concurrent requests are isolated: each call mints its own token, the ack
26
+ * server matches by token, so two pending confirms cannot cross-resolve.
27
+ */
28
+ export declare class ConfirmGate {
29
+ #private;
30
+ constructor(opts: ConfirmGateOpts);
31
+ /** Transport name — used for audit log + startup banner. */
32
+ get transportName(): string;
33
+ request(input: {
34
+ portal: string;
35
+ summary: string;
36
+ }): Promise<ConfirmDecision>;
37
+ }
38
+ //# sourceMappingURL=gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../../../src/confirm/gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,SAAS,EAAE,gBAAgB,CAAC;IAC5B,iDAAiD;IACjD,SAAS,EAAE,SAAS,CAAC;IACrB;qFACiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAW;;gBAKV,IAAI,EAAE,eAAe;IAMjC,4DAA4D;IAC5D,IAAI,aAAa,IAAI,MAAM,CAE1B;IAEK,OAAO,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAmCpF"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The OOB confirm gate. Mints a token, pushes the prompt over the transport,
3
+ * races the human's click against a timeout, returns the decision.
4
+ *
5
+ * Failure modes (all map to a final ConfirmDecision):
6
+ * - transport.send() throws → `transport_error` (gate doesn't fall
7
+ * back to silently allowing the sign;
8
+ * the caller maps this to RPC_POLICY_DENIED)
9
+ * - human clicks Approve / Deny → `approved` / `denied`
10
+ * - clock runs out → `timeout` (cancels the token so a late
11
+ * click returns 410 Gone instead of being
12
+ * silently absorbed)
13
+ *
14
+ * Concurrent requests are isolated: each call mints its own token, the ack
15
+ * server matches by token, so two pending confirms cannot cross-resolve.
16
+ */
17
+ export class ConfirmGate {
18
+ #transport;
19
+ #ackServer;
20
+ #timeoutMs;
21
+ constructor(opts) {
22
+ this.#transport = opts.transport;
23
+ this.#ackServer = opts.ackServer;
24
+ this.#timeoutMs = opts.timeoutMs ?? 60_000;
25
+ }
26
+ /** Transport name — used for audit log + startup banner. */
27
+ get transportName() {
28
+ return this.#transport.name;
29
+ }
30
+ async request(input) {
31
+ const { token, approveUrl, denyUrl, settled } = this.#ackServer.pending();
32
+ try {
33
+ await this.#transport.send({
34
+ portal: input.portal,
35
+ summary: input.summary,
36
+ approveUrl,
37
+ denyUrl,
38
+ token,
39
+ });
40
+ }
41
+ catch (err) {
42
+ this.#ackServer.cancel(token);
43
+ return { kind: 'transport_error', message: err.message };
44
+ }
45
+ // Race the click against the timeout. We use a unique sentinel rather
46
+ // than null so that an Outcome of falsy value (no such thing today, but
47
+ // future-proofing) doesn't get misread as a timeout.
48
+ const TIMEOUT = Symbol('confirm-timeout');
49
+ let timer;
50
+ const timeoutP = new Promise((resolve) => {
51
+ timer = setTimeout(() => resolve(TIMEOUT), this.#timeoutMs);
52
+ // Don't keep the event loop alive just for the timeout — sigil-mcp
53
+ // exits when stdin closes, and a hanging timeout would prevent that.
54
+ timer.unref?.();
55
+ });
56
+ const winner = await Promise.race([settled, timeoutP]);
57
+ if (timer)
58
+ clearTimeout(timer);
59
+ if (winner === TIMEOUT) {
60
+ this.#ackServer.cancel(token);
61
+ return { kind: 'timeout' };
62
+ }
63
+ return winner === 'approve' ? { kind: 'approved' } : { kind: 'denied' };
64
+ }
65
+ }
66
+ //# sourceMappingURL=gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate.js","sourceRoot":"","sources":["../../../src/confirm/gate.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,WAAW;IACb,UAAU,CAAmB;IAC7B,UAAU,CAAY;IACtB,UAAU,CAAS;IAE5B,YAAY,IAAqB;QAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SA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,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAE/B,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC1E,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { type ConfirmRequest, type ConfirmDecision, type ConfirmTransport, } from './types.js';
2
+ export { NtfyTransport, type NtfyConfig, type FetchLike } from './ntfy.js';
3
+ export { startAckServer, type AckServer, type AckOutcome, } from './ack-server.js';
4
+ export { ConfirmGate, type ConfirmGateOpts } from './gate.js';
5
+ export { type SigilConfig, type ConfirmConfig, type NtfyConfigToml, SigilConfigError, parseConfig, loadConfig, anyPolicyRequiresConfirm, enforceConfirmTransportPresence, } from './config.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/confirm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,cAAc,EACd,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { NtfyTransport } from './ntfy.js';
2
+ export { startAckServer, } from './ack-server.js';
3
+ export { ConfirmGate } from './gate.js';
4
+ export { SigilConfigError, parseConfig, loadConfig, anyPolicyRequiresConfirm, enforceConfirmTransportPresence, } from './config.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/confirm/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAmC,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,cAAc,GAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAwB,MAAM,WAAW,CAAC;AAC9D,OAAO,EAIL,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ConfirmRequest, ConfirmTransport } from './types.js';
2
+ export interface NtfyConfig {
3
+ /** Topic name — appears as the last path segment of the ntfy URL. The
4
+ * topic name IS the credential on ntfy.sh; pick something unguessable. */
5
+ topic: string;
6
+ /** Base URL, default https://ntfy.sh. Override to point at a self-hosted
7
+ * ntfy instance (e.g. https://ntfy.example.com). No trailing slash. */
8
+ server?: string;
9
+ }
10
+ /** Minimal subset of the fetch API surface we use. Lets tests inject a stub
11
+ * without dragging in undici/MSW. */
12
+ export type FetchLike = (url: string, init: {
13
+ method: 'POST';
14
+ headers: Record<string, string>;
15
+ body?: string;
16
+ }) => Promise<{
17
+ ok: boolean;
18
+ status: number;
19
+ statusText: string;
20
+ }>;
21
+ /**
22
+ * ntfy.sh transport. Publish-only — the user's phone subscribes through the
23
+ * ntfy app, taps an action button, and the click round-trips to sigil's
24
+ * local ack server. We never read from ntfy.
25
+ *
26
+ * Headers we use (all per ntfy docs):
27
+ * Title: portal handle
28
+ * Priority: high (default 4) — bypasses Android Doze + iOS quiet hours
29
+ * Click: approveUrl — tapping the body of the notification approves
30
+ * Actions: http,Approve,<approveUrl>; http,Deny,<denyUrl>
31
+ */
32
+ export declare class NtfyTransport implements ConfirmTransport {
33
+ #private;
34
+ readonly name = "ntfy";
35
+ constructor(config: NtfyConfig, fetchImpl?: FetchLike);
36
+ send(req: ConfirmRequest): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=ntfy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ntfy.d.ts","sourceRoot":"","sources":["../../../src/confirm/ntfy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB;+EAC2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd;4EACwE;IACxE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;sCACsC;AACtC,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACrE,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAElE;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,gBAAgB;;IACpD,QAAQ,CAAC,IAAI,UAAU;gBAIX,MAAM,EAAE,UAAU,EAAE,SAAS,GAAE,SAAoD;IAazF,IAAI,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB/C"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * ntfy.sh transport. Publish-only — the user's phone subscribes through the
3
+ * ntfy app, taps an action button, and the click round-trips to sigil's
4
+ * local ack server. We never read from ntfy.
5
+ *
6
+ * Headers we use (all per ntfy docs):
7
+ * Title: portal handle
8
+ * Priority: high (default 4) — bypasses Android Doze + iOS quiet hours
9
+ * Click: approveUrl — tapping the body of the notification approves
10
+ * Actions: http,Approve,<approveUrl>; http,Deny,<denyUrl>
11
+ */
12
+ export class NtfyTransport {
13
+ name = 'ntfy';
14
+ #url;
15
+ #fetch;
16
+ constructor(config, fetchImpl = globalThis.fetch) {
17
+ const server = (config.server ?? 'https://ntfy.sh').replace(/\/+$/, '');
18
+ if (!/^[A-Za-z0-9_\-]+$/.test(config.topic)) {
19
+ // ntfy permits more, but a stricter pattern catches "user pasted the full
20
+ // URL into the topic field" right at construction time.
21
+ throw new Error(`ntfy topic must match [A-Za-z0-9_-]+ (got ${JSON.stringify(config.topic)})`);
22
+ }
23
+ this.#url = `${server}/${config.topic}`;
24
+ this.#fetch = fetchImpl;
25
+ }
26
+ async send(req) {
27
+ const actions = [
28
+ `http, Approve, ${req.approveUrl}, method=POST, clear=true`,
29
+ `http, Deny, ${req.denyUrl}, method=POST, clear=true`,
30
+ ].join('; ');
31
+ const resp = await this.#fetch(this.#url, {
32
+ method: 'POST',
33
+ headers: {
34
+ 'Title': `sigil — ${req.portal}`,
35
+ 'Priority': 'high',
36
+ 'Click': req.approveUrl,
37
+ 'Actions': actions,
38
+ 'Content-Type': 'text/plain; charset=utf-8',
39
+ },
40
+ body: req.summary,
41
+ });
42
+ if (!resp.ok) {
43
+ throw new Error(`ntfy push failed: HTTP ${resp.status} ${resp.statusText}`);
44
+ }
45
+ }
46
+ }
47
+ //# sourceMappingURL=ntfy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ntfy.js","sourceRoot":"","sources":["../../../src/confirm/ntfy.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IACf,IAAI,GAAG,MAAM,CAAC;IACd,IAAI,CAAS;IACb,MAAM,CAAY;IAE3B,YAAY,MAAkB,E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+ /**
2
+ * Out-of-band confirmation: when a sign request crosses the policy's confirm
3
+ * threshold, sigil pushes a notification to a channel the human controls
4
+ * (not the agent) and waits for an explicit human ack before signing.
5
+ *
6
+ * The transport interface is intentionally tiny. The shared ack mechanism
7
+ * (a localhost HTTP listener that resolves clicks) lives in ack-server.ts
8
+ * and isn't a per-transport concern — every transport just emits a
9
+ * notification carrying the two URLs.
10
+ */
11
+ /**
12
+ * A pending sign request that needs an out-of-band human ack. The transport
13
+ * is told about it via `send`; the human resolves it by hitting one of the
14
+ * two URLs from a device the agent process can't reach.
15
+ *
16
+ * `token` is opaque to the transport — it's already baked into approveUrl
17
+ * and denyUrl. The transport may surface it (e.g. for logging) but should
18
+ * not transmit it separately, since the URLs are the only thing the ack
19
+ * server matches against.
20
+ */
21
+ export interface ConfirmRequest {
22
+ /** Portal handle, e.g. "evm:executor". Used as the notification title. */
23
+ portal: string;
24
+ /** One-line description of what's about to be signed. Comes from the policy
25
+ * evaluator. Safe to put in the push body — does not include key material. */
26
+ summary: string;
27
+ /** Full URL the human clicks (or taps) to approve. Hits the ack server on
28
+ * 127.0.0.1; the token in the query string is single-use + request-bound. */
29
+ approveUrl: string;
30
+ /** Same shape, deny path. */
31
+ denyUrl: string;
32
+ /** Token (also embedded in the URLs above). Exposed for transports that
33
+ * want to log/correlate without parsing URLs. */
34
+ token: string;
35
+ }
36
+ /**
37
+ * Implementation contract. Transports just push the prompt — the ack
38
+ * round-trips back through the local HTTP server, not through the transport.
39
+ *
40
+ * Implementations should reject with a thrown Error on transport failure
41
+ * (network down, push provider 5xx, etc). The gate treats any throw as a
42
+ * push failure and surfaces it as a deny (fail-closed): we'd rather decline
43
+ * the sign than silently let it through because the notification didn't
44
+ * reach the human's phone.
45
+ */
46
+ export interface ConfirmTransport {
47
+ /** Short identifier — used in audit log + startup banner. */
48
+ readonly name: string;
49
+ send(req: ConfirmRequest): Promise<void>;
50
+ }
51
+ /**
52
+ * Outcome of a confirm round-trip. The gate returns one of these; the sign
53
+ * method then either proceeds (approved) or throws RPC_POLICY_DENIED with
54
+ * the appropriate reason (denied | timeout | transport_error).
55
+ */
56
+ export type ConfirmDecision = {
57
+ kind: 'approved';
58
+ } | {
59
+ kind: 'denied';
60
+ } | {
61
+ kind: 'timeout';
62
+ } | {
63
+ kind: 'transport_error';
64
+ message: string;
65
+ };
66
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/confirm/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf;mFAC+E;IAC/E,OAAO,EAAE,MAAM,CAAC;IAChB;kFAC8E;IAC9E,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB;sDACkD;IAClD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Out-of-band confirmation: when a sign request crosses the policy's confirm
3
+ * threshold, sigil pushes a notification to a channel the human controls
4
+ * (not the agent) and waits for an explicit human ack before signing.
5
+ *
6
+ * The transport interface is intentionally tiny. The shared ack mechanism
7
+ * (a localhost HTTP listener that resolves clicks) lives in ack-server.ts
8
+ * and isn't a per-transport concern — every transport just emits a
9
+ * notification carrying the two URLs.
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/confirm/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
@@ -0,0 +1,29 @@
1
+ import { ControlClientError } from './client.js';
2
+ import type { ControlRequest, ControlResponse } from './protocol.js';
3
+ export interface SessionSocket {
4
+ /** PID parsed from the socket filename. */
5
+ pid: number;
6
+ socketPath: string;
7
+ }
8
+ export interface SessionResult extends SessionSocket {
9
+ /** Server response, or null if the socket was unreachable. */
10
+ response: ControlResponse | null;
11
+ /** Set when the socket couldn't be reached. */
12
+ clientError?: ControlClientError;
13
+ /** True when the socket was stale (refused / missing) and got unlinked. */
14
+ reaped: boolean;
15
+ }
16
+ /**
17
+ * List the `<pid>.sock` entries in `controlDir`, sorted by PID for stable
18
+ * output. Returns `[]` if the directory is missing. Ignores anything that
19
+ * isn't a `<digits>.sock` name.
20
+ */
21
+ export declare function listSessionSockets(controlDir: string): SessionSocket[];
22
+ /**
23
+ * Send `request` to every live session socket in parallel and collect the
24
+ * per-session outcomes. Sockets that refuse the connection or have vanished
25
+ * are treated as stale: they're unlinked and reported with `reaped: true`.
26
+ * Never throws — transport failures land in each result's `clientError`.
27
+ */
28
+ export declare function broadcast(controlDir: string, request: ControlRequest, timeoutMs?: number): Promise<SessionResult[]>;
29
+ //# sourceMappingURL=broadcast.d.ts.map