@ai-ecoverse/slicc-agent 7.31.0 → 7.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +28 -8
  2. package/dist/agent.js +4 -0
  3. package/dist/agent.js.map +2 -2
  4. package/dist/approvals/policy.js +27 -5
  5. package/dist/approvals/policy.js.map +2 -2
  6. package/dist/approvals/published.js +18 -0
  7. package/dist/approvals/published.js.map +7 -0
  8. package/dist/approvals/record.js +4 -1
  9. package/dist/approvals/record.js.map +2 -2
  10. package/dist/approvals/run-licks.js +137 -0
  11. package/dist/approvals/run-licks.js.map +7 -0
  12. package/dist/approvals/run-procs.js +127 -0
  13. package/dist/approvals/run-procs.js.map +7 -0
  14. package/dist/approvals/run.js +468 -0
  15. package/dist/approvals/run.js.map +7 -0
  16. package/dist/approvals/runnable.js +125 -0
  17. package/dist/approvals/runnable.js.map +7 -0
  18. package/dist/approvals/sudo.js +29 -1
  19. package/dist/approvals/sudo.js.map +2 -2
  20. package/dist/client.js +1 -0
  21. package/dist/client.js.map +2 -2
  22. package/dist/control.js +7 -1
  23. package/dist/control.js.map +2 -2
  24. package/dist/guests/view.js +8 -0
  25. package/dist/guests/view.js.map +2 -2
  26. package/dist/host.js +69 -16
  27. package/dist/host.js.map +2 -2
  28. package/dist/index.js +14 -0
  29. package/dist/index.js.map +2 -2
  30. package/dist/kernel/exec.js +42 -6
  31. package/dist/kernel/exec.js.map +2 -2
  32. package/dist/kernel/trace.js +203 -0
  33. package/dist/kernel/trace.js.map +7 -0
  34. package/dist/licks/extension.js +1 -0
  35. package/dist/licks/extension.js.map +2 -2
  36. package/dist/licks/lick.js +1 -0
  37. package/dist/licks/lick.js.map +2 -2
  38. package/dist/main.js +3 -0
  39. package/dist/main.js.map +2 -2
  40. package/dist/ran/index.js +55 -0
  41. package/dist/ran/index.js.map +7 -0
  42. package/dist/ran/shown.js +62 -0
  43. package/dist/ran/shown.js.map +7 -0
  44. package/dist/services.js +7 -2
  45. package/dist/services.js.map +2 -2
  46. package/dist/spectrum/approvals-port.js +69 -0
  47. package/dist/spectrum/approvals-port.js.map +2 -2
  48. package/dist/spectrum/messages.js +36 -9
  49. package/dist/spectrum/messages.js.map +3 -3
  50. package/dist/spectrum/monitor-port.js +2 -1
  51. package/dist/spectrum/monitor-port.js.map +2 -2
  52. package/dist/spectrum/tool-title.js +10 -12
  53. package/dist/spectrum/tool-title.js.map +3 -3
  54. package/dist/titles/cluster.js +15 -5
  55. package/dist/titles/cluster.js.map +2 -2
  56. package/dist/types/agent.d.ts +2 -0
  57. package/dist/types/approvals/policy.d.ts +10 -1
  58. package/dist/types/approvals/published.d.ts +3 -0
  59. package/dist/types/approvals/record.d.ts +44 -1
  60. package/dist/types/approvals/run-licks.d.ts +18 -0
  61. package/dist/types/approvals/run-procs.d.ts +40 -0
  62. package/dist/types/approvals/run.d.ts +60 -0
  63. package/dist/types/approvals/runnable.d.ts +55 -0
  64. package/dist/types/approvals/sudo.d.ts +3 -1
  65. package/dist/types/client.d.ts +2 -0
  66. package/dist/types/host.d.ts +10 -0
  67. package/dist/types/index.d.ts +4 -1
  68. package/dist/types/kernel/client.d.ts +47 -1
  69. package/dist/types/kernel/exec.d.ts +4 -0
  70. package/dist/types/kernel/trace.d.ts +45 -0
  71. package/dist/types/licks/lick.d.ts +1 -1
  72. package/dist/types/licks/triage.d.ts +1 -1
  73. package/dist/types/main.d.ts +2 -1
  74. package/dist/types/ran/index.d.ts +3 -0
  75. package/dist/types/ran/shown.d.ts +12 -0
  76. package/dist/types/services.d.ts +7 -2
  77. package/dist/types/spectrum/approvals-port.d.ts +10 -2
  78. package/dist/types/spectrum/messages.d.ts +1 -0
  79. package/dist/types/spectrum/tool-title.d.ts +1 -0
  80. package/dist/types/titles/cluster.d.ts +1 -0
  81. package/package.json +4 -4
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/spectrum/tool-title.ts"],
4
- "sourcesContent": ["import { intentOf } from '../intent/said.ts';\nimport { mcpLabel } from '../mcp/label.ts';\nimport { redactSecrets } from '../memory/format.ts';\n\ntype Json = Record<string, unknown>;\n\nconst TITLE_LENGTH = 60;\n\nfunction leaf(path: string): string {\n return path.replace(/\\\\/g, '/').split('/').filter(Boolean).at(-1) ?? '';\n}\n\nfunction shown(text: string): string {\n const flat = redactSecrets(text).text.replace(/\\s+/g, ' ').trim();\n return flat.length > TITLE_LENGTH ? `${flat.slice(0, TITLE_LENGTH - 1)}\u2026` : flat;\n}\n\nfunction file(verb: string, path: string): string {\n const name = leaf(path);\n return shown(name ? `${verb} ${name}` : verb);\n}\n\nconst PROGRAMS_SHOWN = 3;\n\nfunction program(segment: string): string | undefined {\n const words = segment.trim().split(/\\s+/);\n const word = words.find((each) => !/^\\w+=/.test(each) && each !== 'sudo' && each !== 'env');\n const name = leaf(word ?? '');\n return /^[\\w.+-]+$/.test(name) ? name : undefined;\n}\n\nfunction listed(names: readonly string[]): string {\n if (names.length < 2) return names.join('');\n return `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;\n}\n\nexport function commandTitle(command: string): string {\n const head = command.replace(/<<[\\s\\S]*/, '');\n const names = [\n ...new Set(\n head\n .split(/&&|\\|\\||[;|&\\n()]/)\n .map(program)\n .filter((name) => name !== undefined)\n ),\n ];\n if (!names.length) return 'Running a command';\n const shown = names.slice(0, PROGRAMS_SHOWN);\n const more = names.length > PROGRAMS_SHOWN ? [...shown, 'more'] : shown;\n return `Running ${listed(more)}`;\n}\n\nexport function toolTitle(name: string, args: Json | undefined, trusted = false): string {\n const said = trusted ? intentOf(name, args) : '';\n if (said) return shown(said);\n const labeled = mcpLabel(name);\n if (labeled) return `Calling ${labeled}`;\n const path = typeof args?.path === 'string' ? args.path : '';\n const command = typeof args?.command === 'string' ? args.command : '';\n if (name === 'bash') return shown(commandTitle(command));\n if (name === 'read') return file('Reading', path);\n if (name === 'write') return file('Writing', path);\n if (name === 'edit') return file('Editing', path);\n if (name === 'codemode') return 'Running code';\n if (path) {\n const fileName = leaf(path);\n return shown(fileName ? `${name} ${fileName}` : name);\n }\n if (command) return shown(command) || name;\n return name;\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAI9B,MAAM,eAAe;AAErB,SAAS,KAAK,MAAsB;AAClC,SAAO,KAAK,QAAQ,OAAO,GAAG,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,GAAG,EAAE,KAAK;AACvE;AAEA,SAAS,MAAM,MAAsB;AACnC,QAAM,OAAO,cAAc,IAAI,EAAE,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAChE,SAAO,KAAK,SAAS,eAAe,GAAG,KAAK,MAAM,GAAG,eAAe,CAAC,CAAC,WAAM;AAC9E;AAEA,SAAS,KAAK,MAAc,MAAsB;AAChD,QAAM,OAAO,KAAK,IAAI;AACtB,SAAO,MAAM,OAAO,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI;AAC9C;AAEA,MAAM,iBAAiB;AAEvB,SAAS,QAAQ,SAAqC;AACpD,QAAM,QAAQ,QAAQ,KAAK,EAAE,MAAM,KAAK;AACxC,QAAM,OAAO,MAAM,KAAK,CAAC,SAAS,CAAC,QAAQ,KAAK,IAAI,KAAK,SAAS,UAAU,SAAS,KAAK;AAC1F,QAAM,OAAO,KAAK,QAAQ,EAAE;AAC5B,SAAO,aAAa,KAAK,IAAI,IAAI,OAAO;AAC1C;AAEA,SAAS,OAAO,OAAkC;AAChD,MAAI,MAAM,SAAS,EAAG,QAAO,MAAM,KAAK,EAAE;AAC1C,SAAO,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC,QAAQ,MAAM,GAAG,EAAE,CAAC;AAC7D;AAEO,SAAS,aAAa,SAAyB;AACpD,QAAM,OAAO,QAAQ,QAAQ,aAAa,EAAE;AAC5C,QAAM,QAAQ;AAAA,IACZ,GAAG,IAAI;AAAA,MACL,KACG,MAAM,mBAAmB,EACzB,IAAI,OAAO,EACX,OAAO,CAAC,SAAS,SAAS,MAAS;AAAA,IACxC;AAAA,EACF;AACA,MAAI,CAAC,MAAM,OAAQ,QAAO;AAC1B,QAAMA,SAAQ,MAAM,MAAM,GAAG,cAAc;AAC3C,QAAM,OAAO,MAAM,SAAS,iBAAiB,CAAC,GAAGA,QAAO,MAAM,IAAIA;AAClE,SAAO,WAAW,OAAO,IAAI,CAAC;AAChC;AAEO,SAAS,UAAU,MAAc,MAAwB,UAAU,OAAe;AACvF,QAAM,OAAO,UAAU,SAAS,MAAM,IAAI,IAAI;AAC9C,MAAI,KAAM,QAAO,MAAM,IAAI;AAC3B,QAAM,UAAU,SAAS,IAAI;AAC7B,MAAI,QAAS,QAAO,WAAW,OAAO;AACtC,QAAM,OAAO,OAAO,MAAM,SAAS,WAAW,KAAK,OAAO;AAC1D,QAAM,UAAU,OAAO,MAAM,YAAY,WAAW,KAAK,UAAU;AACnE,MAAI,SAAS,OAAQ,QAAO,MAAM,aAAa,OAAO,CAAC;AACvD,MAAI,SAAS,OAAQ,QAAO,KAAK,WAAW,IAAI;AAChD,MAAI,SAAS,QAAS,QAAO,KAAK,WAAW,IAAI;AACjD,MAAI,SAAS,OAAQ,QAAO,KAAK,WAAW,IAAI;AAChD,MAAI,SAAS,WAAY,QAAO;AAChC,MAAI,MAAM;AACR,UAAM,WAAW,KAAK,IAAI;AAC1B,WAAO,MAAM,WAAW,GAAG,IAAI,IAAI,QAAQ,KAAK,IAAI;AAAA,EACtD;AACA,MAAI,QAAS,QAAO,MAAM,OAAO,KAAK;AACtC,SAAO;AACT;",
6
- "names": ["shown"]
4
+ "sourcesContent": ["import { intentOf } from '../intent/said.ts';\nimport { mcpLabel } from '../mcp/label.ts';\nimport { redactSecrets } from '../memory/format.ts';\nimport { listed } from '../ran/shown.ts';\n\ntype Json = Record<string, unknown>;\n\nconst TITLE_LENGTH = 60;\n\nfunction leaf(path: string): string {\n return path.replace(/\\\\/g, '/').split('/').filter(Boolean).at(-1) ?? '';\n}\n\nexport function shownTitle(text: string): string {\n const flat = redactSecrets(text).text.replace(/\\s+/g, ' ').trim();\n return flat.length > TITLE_LENGTH ? `${flat.slice(0, TITLE_LENGTH - 1)}\u2026` : flat;\n}\n\nfunction file(verb: string, path: string): string {\n const name = leaf(path);\n return shownTitle(name ? `${verb} ${name}` : verb);\n}\n\nconst PROGRAMS_SHOWN = 3;\n\nfunction program(segment: string): string | undefined {\n const words = segment.trim().split(/\\s+/);\n const word = words.find((each) => !/^\\w+=/.test(each) && each !== 'sudo' && each !== 'env');\n const name = leaf(word ?? '');\n return /^[\\w.+-]+$/.test(name) ? name : undefined;\n}\n\nexport function commandTitle(command: string): string {\n const head = command.replace(/<<[\\s\\S]*/, '');\n const names = [\n ...new Set(\n head\n .split(/&&|\\|\\||[;|&\\n()]/)\n .map(program)\n .filter((name) => name !== undefined)\n ),\n ];\n if (!names.length) return 'Running a command';\n const shown = names.slice(0, PROGRAMS_SHOWN);\n const more = names.length > PROGRAMS_SHOWN ? [...shown, 'more'] : shown;\n return `Running ${listed(more)}`;\n}\n\nexport function toolTitle(name: string, args: Json | undefined, trusted = false): string {\n const said = trusted ? intentOf(name, args) : '';\n if (said) return shownTitle(said);\n const labeled = mcpLabel(name);\n if (labeled) return `Calling ${labeled}`;\n const path = typeof args?.path === 'string' ? args.path : '';\n const command = typeof args?.command === 'string' ? args.command : '';\n if (name === 'bash') return shownTitle(commandTitle(command));\n if (name === 'read') return file('Reading', path);\n if (name === 'write') return file('Writing', path);\n if (name === 'edit') return file('Editing', path);\n if (name === 'codemode') return 'Running code';\n if (path) {\n const fileName = leaf(path);\n return shownTitle(fileName ? `${name} ${fileName}` : name);\n }\n if (command) return shownTitle(command) || name;\n return name;\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AAIvB,MAAM,eAAe;AAEr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9C,MAAI,KAAM,QAAO,WAAW,IAAI;AAChC,QAAM,UAAU,SAAS,IAAI;AAC7B,MAAI,QAAS,QAAO,WAAW,OAAO;AACtC,QAAM,OAAO,OAAO,MAAM,SAAS,WAAW,KAAK,OAAO;AAC1D,QAAM,UAAU,OAAO,MAAM,YAAY,WAAW,KAAK,UAAU;AACnE,MAAI,SAAS,OAAQ,QAAO,WAAW,aAAa,OAAO,CAAC;AAC5D,MAAI,SAAS,OAAQ,QAAO,KAAK,WAAW,IAAI;AAChD,MAAI,SAAS,QAAS,QAAO,KAAK,WAAW,IAAI;AACjD,MAAI,SAAS,OAAQ,QAAO,KAAK,WAAW,IAAI;AAChD,MAAI,SAAS,WAAY,QAAO;AAChC,MAAI,MAAM;AACR,UAAM,WAAW,KAAK,IAAI;AAC1B,WAAO,WAAW,WAAW,GAAG,IAAI,IAAI,QAAQ,KAAK,IAAI;AAAA,EAC3D;AACA,MAAI,QAAS,QAAO,WAAW,OAAO,KAAK;AAC3C,SAAO;AACT;",
6
+ "names": []
7
7
  }
@@ -1,5 +1,6 @@
1
1
  import { answerText } from "../agent.js";
2
2
  import { intentOf, withoutIntent } from "../intent/said.js";
3
+ import { ranLine, ranOf, saidIntent } from "../ran/shown.js";
3
4
  const OUTPUT_LENGTH = 600;
4
5
  function blocks(entry) {
5
6
  const content = entry.model?.[0]?.content;
@@ -35,8 +36,15 @@ function clusterOf(entries, callIds) {
35
36
  at: said?.timestamp ?? 0
36
37
  });
37
38
  }
38
- if (entry.kind === "pi.tool-result" && said?.toolCallId)
39
- results.set(said.toolCallId, { output: answerText(said.content), index });
39
+ if (entry.kind === "pi.tool-result" && said?.toolCallId) {
40
+ const ran = ranOf(said.details);
41
+ results.set(said.toolCallId, {
42
+ output: answerText(said.content),
43
+ index,
44
+ ran: ranLine(ran),
45
+ intent: saidIntent(ran?.intent)
46
+ });
47
+ }
40
48
  });
41
49
  const runs = [];
42
50
  let at = 0;
@@ -50,7 +58,8 @@ function clusterOf(entries, callIds) {
50
58
  input: call.input,
51
59
  output: result?.output ?? "",
52
60
  done: !!result,
53
- intent: call.intent
61
+ intent: call.intent || (call.name === "bash" ? result?.intent ?? "" : ""),
62
+ ran: call.name === "bash" ? result?.ran ?? "" : ""
54
63
  });
55
64
  at = Math.max(at, call.at);
56
65
  last = Math.max(last, result?.index ?? Number.POSITIVE_INFINITY);
@@ -59,11 +68,12 @@ function clusterOf(entries, callIds) {
59
68
  return { runs, at, settled };
60
69
  }
61
70
  function describeStep(run) {
62
- return `${run.name}: ${run.input}`;
71
+ return run.ran ? `${run.name}: ${run.input}
72
+ ${run.ran}` : `${run.name}: ${run.input}`;
63
73
  }
64
74
  function describe(runs) {
65
75
  return runs.map(
66
- (run) => `${run.name}: ${run.input}
76
+ (run) => `${describeStep(run)}
67
77
  => ${run.done ? run.output.slice(0, OUTPUT_LENGTH) : "(running)"}`
68
78
  ).join("\n\n");
69
79
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/titles/cluster.ts"],
4
- "sourcesContent": ["import type { ConversationView, EntryRecord } from '@earendil-works/pi-durable';\nimport { answerText } from '../agent.ts';\nimport { intentOf, withoutIntent } from '../intent/said.ts';\n\nconst OUTPUT_LENGTH = 600;\n\nexport type Run = { name: string; input: string; output: string; done: boolean; intent: string };\n\nexport type Cluster = { runs: Run[]; at: number; settled: boolean };\n\ntype Block = { type?: string; id?: string; name?: string; arguments?: unknown; text?: string };\n\ntype Said = {\n content?: unknown;\n toolCallId?: string;\n timestamp?: number;\n stopReason?: string;\n};\n\nfunction blocks(entry: EntryRecord): Block[] {\n const content = (entry.model?.[0] as Said | undefined)?.content;\n return entry.kind === 'pi.assistant' && Array.isArray(content) ? (content as Block[]) : [];\n}\n\nexport function callIdsOf(views: readonly ConversationView[]): Set<string> {\n const ids = new Set<string>();\n for (const view of views)\n for (const entry of view.entries)\n for (const block of blocks(entry))\n if (block.type === 'toolCall' && block.id) ids.add(block.id);\n return ids;\n}\n\nfunction movedOn(entry: EntryRecord): boolean {\n if (entry.kind === 'pi.user') return true;\n if (entry.kind !== 'pi.assistant') return false;\n const said = entry.model?.[0] as Said | undefined;\n return (\n said?.stopReason !== 'toolUse' ||\n blocks(entry).some((block) => block.type === 'text' && block.text?.trim())\n );\n}\n\nexport function clusterOf(\n entries: readonly EntryRecord[],\n callIds: readonly string[]\n): Cluster | undefined {\n const calls = new Map<string, Pick<Run, 'name' | 'input' | 'intent'> & { at: number }>();\n const results = new Map<string, { output: string; index: number }>();\n entries.forEach((entry, index) => {\n const said = entry.model?.[0] as Said | undefined;\n for (const block of blocks(entry))\n if (block.type === 'toolCall' && block.id) {\n const name = block.name ?? 'tool';\n const args = (block.arguments ?? {}) as object;\n calls.set(block.id, {\n name,\n input: JSON.stringify(withoutIntent(name, args)),\n intent: intentOf(name, args),\n at: said?.timestamp ?? 0,\n });\n }\n if (entry.kind === 'pi.tool-result' && said?.toolCallId)\n results.set(said.toolCallId, { output: answerText(said.content), index });\n });\n const runs: Run[] = [];\n let at = 0;\n let last = -1;\n for (const id of callIds) {\n const call = calls.get(id);\n if (!call) return undefined;\n const result = results.get(id);\n runs.push({\n name: call.name,\n input: call.input,\n output: result?.output ?? '',\n done: !!result,\n intent: call.intent,\n });\n at = Math.max(at, call.at);\n last = Math.max(last, result?.index ?? Number.POSITIVE_INFINITY);\n }\n const settled = entries.slice(last + 1).some(movedOn);\n return { runs, at, settled };\n}\n\nexport function describeStep(run: Run): string {\n return `${run.name}: ${run.input}`;\n}\n\nexport function describe(runs: readonly Run[]): string {\n return runs\n .map(\n (run) =>\n `${run.name}: ${run.input}\\n=> ${run.done ? run.output.slice(0, OUTPUT_LENGTH) : '(running)'}`\n )\n .join('\\n\\n');\n}\n"],
5
- "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,qBAAqB;AAExC,MAAM,gBAAgB;AAetB,SAAS,OAAO,OAA6B;AAC3C,QAAM,UAAW,MAAM,QAAQ,CAAC,GAAwB;AACxD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AACT,MAAI,OAAO;AACX,aAAW,MAAM,SAAS;AACxB,UAAM,OAAO,MAAM,IAAI,EAAE;AACzB,QAAI,CAAC,KAAM,QAAO;AAClB,UAAM,SAAS,QAAQ,IAAI,EAAE;AAC7B,SAAK,KAAK;AAAA,MACR,MAAM,KAAK;AAAA,MACX,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,UAAU;AAAA,MAC1B,MAAM,CAAC,CAAC;AAAA,MACR,QAAQ,KAAK;AAAA,IACf,CAAC;AACD,SAAK,KAAK,IAAI,IAAI,KAAK,EAAE;AACzB,WAAO,KAAK,IAAI,MAAM,QAAQ,SAAS,OAAO,iBAAiB;AAAA,EACjE;AACA,QAAM,UAAU,QAAQ,MAAM,OAAO,CAAC,EAAE,KAAK,OAAO;AACpD,SAAO,EAAE,MAAM,IAAI,QAAQ;AAC7B;AAEO,SAAS,aAAa,KAAkB;AAC7C,SAAO,GAAG,IAAI,IAAI,KAAK,IAAI,KAAK;AAClC;AAEO,SAAS,SAAS,MAA8B;AACrD,SAAO,KACJ;AAAA,IACC,CAAC,QACC,GAAG,IAAI,IAAI,KAAK,IAAI,KAAK;AAAA,KAAQ,IAAI,OAAO,IAAI,OAAO,MAAM,GAAG,aAAa,IAAI,WAAW;AAAA,EAChG,EACC,KAAK,MAAM;AAChB;",
4
+ "sourcesContent": ["import type { ConversationView, EntryRecord } from '@earendil-works/pi-durable';\nimport { answerText } from '../agent.ts';\nimport { intentOf, withoutIntent } from '../intent/said.ts';\nimport { ranLine, ranOf, saidIntent } from '../ran/shown.ts';\n\nconst OUTPUT_LENGTH = 600;\n\nexport type Run = {\n name: string;\n input: string;\n output: string;\n done: boolean;\n intent: string;\n ran: string;\n};\n\nexport type Cluster = { runs: Run[]; at: number; settled: boolean };\n\ntype Block = { type?: string; id?: string; name?: string; arguments?: unknown; text?: string };\n\ntype Said = {\n content?: unknown;\n toolCallId?: string;\n details?: unknown;\n timestamp?: number;\n stopReason?: string;\n};\n\nfunction blocks(entry: EntryRecord): Block[] {\n const content = (entry.model?.[0] as Said | undefined)?.content;\n return entry.kind === 'pi.assistant' && Array.isArray(content) ? (content as Block[]) : [];\n}\n\nexport function callIdsOf(views: readonly ConversationView[]): Set<string> {\n const ids = new Set<string>();\n for (const view of views)\n for (const entry of view.entries)\n for (const block of blocks(entry))\n if (block.type === 'toolCall' && block.id) ids.add(block.id);\n return ids;\n}\n\nfunction movedOn(entry: EntryRecord): boolean {\n if (entry.kind === 'pi.user') return true;\n if (entry.kind !== 'pi.assistant') return false;\n const said = entry.model?.[0] as Said | undefined;\n return (\n said?.stopReason !== 'toolUse' ||\n blocks(entry).some((block) => block.type === 'text' && block.text?.trim())\n );\n}\n\nexport function clusterOf(\n entries: readonly EntryRecord[],\n callIds: readonly string[]\n): Cluster | undefined {\n const calls = new Map<string, Pick<Run, 'name' | 'input' | 'intent'> & { at: number }>();\n const results = new Map<string, { output: string; index: number; ran: string; intent: string }>();\n entries.forEach((entry, index) => {\n const said = entry.model?.[0] as Said | undefined;\n for (const block of blocks(entry))\n if (block.type === 'toolCall' && block.id) {\n const name = block.name ?? 'tool';\n const args = (block.arguments ?? {}) as object;\n calls.set(block.id, {\n name,\n input: JSON.stringify(withoutIntent(name, args)),\n intent: intentOf(name, args),\n at: said?.timestamp ?? 0,\n });\n }\n if (entry.kind === 'pi.tool-result' && said?.toolCallId) {\n const ran = ranOf(said.details);\n results.set(said.toolCallId, {\n output: answerText(said.content),\n index,\n ran: ranLine(ran),\n intent: saidIntent(ran?.intent),\n });\n }\n });\n const runs: Run[] = [];\n let at = 0;\n let last = -1;\n for (const id of callIds) {\n const call = calls.get(id);\n if (!call) return undefined;\n const result = results.get(id);\n runs.push({\n name: call.name,\n input: call.input,\n output: result?.output ?? '',\n done: !!result,\n intent: call.intent || (call.name === 'bash' ? (result?.intent ?? '') : ''),\n ran: call.name === 'bash' ? (result?.ran ?? '') : '',\n });\n at = Math.max(at, call.at);\n last = Math.max(last, result?.index ?? Number.POSITIVE_INFINITY);\n }\n const settled = entries.slice(last + 1).some(movedOn);\n return { runs, at, settled };\n}\n\nexport function describeStep(run: Run): string {\n return run.ran ? `${run.name}: ${run.input}\\n${run.ran}` : `${run.name}: ${run.input}`;\n}\n\nexport function describe(runs: readonly Run[]): string {\n return runs\n .map(\n (run) =>\n `${describeStep(run)}\\n=> ${run.done ? run.output.slice(0, OUTPUT_LENGTH) : '(running)'}`\n )\n .join('\\n\\n');\n}\n"],
5
+ "mappings": "AACA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,qBAAqB;AACxC,SAAS,SAAS,OAAO,kBAAkB;AAE3C,MAAM,gBAAgB;AAuBtB,SAAS,OAAO,OAA6B;AAC3C,QAAM,UAAW,MAAM,QAAQ,CAAC,GAAwB;AACxD,SAAO,MAAM,SAAS,kBAAkB,MAAM,QAAQ,OAAO,IAAK,UAAsB,CAAC;AAC3F;AAEO,SAAS,UAAU,OAAiD;AACzE,QAAM,MAAM,oBAAI,IAAY;AAC5B,aAAW,QAAQ;AACjB,eAAW,SAAS,KAAK;AACvB,iBAAW,SAAS,OAAO,KAAK;AAC9B,YAAI,MAAM,SAAS,cAAc,MAAM,GAAI,KAAI,IAAI,MAAM,EAAE;AACjE,SAAO;AACT;AAEA,SAAS,QAAQ,OAA6B;AAC5C,MAAI,MAAM,SAAS,UAAW,QAAO;AACrC,MAAI,MAAM,SAAS,eAAgB,QAAO;AAC1C,QAAM,OAAO,MAAM,QAAQ,CAAC;AAC5B,SACE,MAAM,eAAe,aACrB,OAAO,KAAK,EAAE,KAAK,CAAC,UAAU,MAAM,SAAS,UAAU,MAAM,MAAM,KAAK,CAAC;AAE7E;AAEO,SAAS,UACd,SACA,SACqB;AACrB,QAAM,QAAQ,oBAAI,IAAqE;AACvF,QAAM,UAAU,oBAAI,IAA4E;AAChG,UAAQ,QAAQ,CAAC,OAAO,UAAU;AAChC,UAAM,OAAO,MAAM,QAAQ,CAAC;AAC5B,eAAW,SAAS,OAAO,KAAK;AAC9B,UAAI,MAAM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B;AAEO,SAAS,aAAa,KAAkB;AAC7C,SAAO,IAAI,MAAM,GAAG,IAAI,IAAI,KAAK,IAAI,KAAK;AAAA,EAAK,IAAI,GAAG,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,KAAK;AACtF;AAEO,SAAS,SAAS,MAA8B;AACrD,SAAO,KACJ;AAAA,IACC,CAAC,QACC,GAAG,aAAa,GAAG,CAAC;AAAA,KAAQ,IAAI,OAAO,IAAI,OAAO,MAAM,GAAG,aAAa,IAAI,WAAW;AAAA,EAC3F,EACC,KAAK,MAAM;AAChB;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,7 @@ import type { Context } from '@earendil-works/chord';
2
2
  import type { Models } from '@earendil-works/pi-ai/models';
3
3
  import { type Conversation, Harness, type HarnessOptions, type ModelRef, type Registry, type Storage } from '@earendil-works/pi-durable';
4
4
  import { type Agents } from './agents.ts';
5
+ import { type SudoRuns } from './approvals/run.ts';
5
6
  import type { Clock } from './clock.ts';
6
7
  import type { Cones } from './cone.ts';
7
8
  import { type GuestToolGate } from './guests/guard.ts';
@@ -29,6 +30,7 @@ export interface Agent extends Cones {
29
30
  readonly reviews: GuestReviews;
30
31
  readonly gate: GuestToolGate;
31
32
  readonly scoopReviews: ScoopReviews;
33
+ readonly sudoRuns: SudoRuns;
32
34
  readonly reports: Reports;
33
35
  readonly timings: Timings;
34
36
  onCone(listener: (conversation: Conversation) => void | Promise<void>): () => void;
@@ -2,16 +2,24 @@ import { type Context, type ReplicatedState } from '@earendil-works/chord';
2
2
  import { type Harness, type JsonObject } from '@earendil-works/pi-durable';
3
3
  import { type GuestPolicy, type GuestPolicyChange } from '../guests/policy.ts';
4
4
  import type { ApprovalKind } from './record.ts';
5
+ export type RunLatePolicy = {
6
+ maxAgeMinutes: number;
7
+ };
5
8
  export type SudoPolicy = {
6
9
  approver: 'user' | 'agent';
10
+ runLate: RunLatePolicy;
7
11
  };
8
12
  export type ApprovalPolicy = {
9
13
  guests: GuestPolicy;
10
14
  sudo: SudoPolicy;
11
15
  };
16
+ export type SudoPolicyChange = {
17
+ approver?: SudoPolicy['approver'];
18
+ runLate?: Partial<RunLatePolicy>;
19
+ };
12
20
  export type ApprovalPolicyChange = {
13
21
  guests?: GuestPolicyChange;
14
- sudo?: Partial<SudoPolicy>;
22
+ sudo?: SudoPolicyChange;
15
23
  };
16
24
  export type ApprovalPolicySet = {
17
25
  policy: ApprovalPolicy;
@@ -21,6 +29,7 @@ export type ApprovalPolicySet = {
21
29
  error: string;
22
30
  };
23
31
  export declare const DEFAULT_APPROVAL_POLICY: ApprovalPolicy;
32
+ export declare const MAX_RUN_LATE_MINUTES = 10080;
24
33
  type Overrides = Partial<Record<keyof ApprovalPolicy, JsonObject>>;
25
34
  export declare const ApprovalPolicyDoc: import("@earendil-works/pi-durable").SessionDocToken<{
26
35
  overrides: Overrides;
@@ -0,0 +1,3 @@
1
+ import { type ReplicatedState } from '@earendil-works/chord';
2
+ import type { Approval } from './record.ts';
3
+ export declare function publishedApprovals(state: ReplicatedState<Approval[]>, view: boolean): ReplicatedState<Approval[]>;
@@ -57,6 +57,44 @@ export type SudoDetail = {
57
57
  writable?: boolean;
58
58
  validate?: true;
59
59
  };
60
+ export type SudoFile = {
61
+ path: string;
62
+ sha256: string;
63
+ };
64
+ export type SudoReplay = {
65
+ id: string;
66
+ user: string;
67
+ uid?: number;
68
+ target?: string;
69
+ argv: string[];
70
+ path?: string;
71
+ cwd?: string;
72
+ stdin?: SudoStdin;
73
+ rootOnly?: Record<string, boolean>;
74
+ userWritable?: SudoFile[];
75
+ tag?: string;
76
+ tags?: string[];
77
+ validate?: boolean;
78
+ };
79
+ export type SudoRunState = 'starting' | 'running' | 'done' | 'failed' | 'stopped';
80
+ export type SudoRun = {
81
+ state: SudoRunState;
82
+ by: DecidedBy;
83
+ device?: string;
84
+ at: number;
85
+ pid?: number;
86
+ pgid?: number;
87
+ status?: number;
88
+ signal?: string;
89
+ endedAt?: number;
90
+ error?: string;
91
+ stdout?: string;
92
+ stderr?: string;
93
+ stopBy?: DecidedBy;
94
+ survivors?: number[];
95
+ capped?: number;
96
+ removed?: true;
97
+ };
60
98
  export type CaptureWhat = 'screen' | 'camera' | 'microphone';
61
99
  export type CaptureMode = 'still' | 'video' | 'audio';
62
100
  export type CaptureDetail = {
@@ -99,6 +137,8 @@ export type GuestToolApproval = Base & {
99
137
  export type SudoApproval = Base & {
100
138
  kind: 'sudo';
101
139
  detail: SudoDetail;
140
+ replay?: SudoReplay;
141
+ run?: SudoRun;
102
142
  };
103
143
  export type CaptureApproval = Base & {
104
144
  kind: 'capture';
@@ -111,7 +151,9 @@ type DraftOf<T extends Approval> = Pick<T, 'kind' | 'detail' | 'agentId' | 'requ
111
151
  always?: boolean;
112
152
  expiresAt?: number;
113
153
  };
114
- export type ApprovalDraft = DraftOf<GuestMessageApproval> | DraftOf<GuestToolApproval> | DraftOf<SudoApproval> | DraftOf<CaptureApproval>;
154
+ export type ApprovalDraft = DraftOf<GuestMessageApproval> | DraftOf<GuestToolApproval> | (DraftOf<SudoApproval> & {
155
+ replay?: SudoReplay;
156
+ }) | DraftOf<CaptureApproval>;
115
157
  export type ApprovalsState = {
116
158
  items: Approval[];
117
159
  };
@@ -140,6 +182,7 @@ export declare function route(verdict: ApprovalVerdict | undefined, requester: P
140
182
  export declare function alwaysOffered(item: Approval): boolean;
141
183
  export declare function gone(state: ApprovalState): string;
142
184
  export declare function cleanReason(reason: unknown): string | undefined;
185
+ export declare const runLive: (item: Approval) => boolean;
143
186
  export declare function prune(items: Approval[], kept?: number): Approval[];
144
187
  export type Settle = {
145
188
  state: Exclude<ApprovalState, 'pending'>;
@@ -0,0 +1,18 @@
1
+ import type { Harness } from '@earendil-works/pi-durable';
2
+ import { type AgentsState } from '../agents.ts';
3
+ import type { LickEvent } from '../licks/licks.ts';
4
+ import type { SudoApproval } from './record.ts';
5
+ export declare const KEEP_HOURS = 24;
6
+ export declare const MIB: number;
7
+ export type LickHost = {
8
+ harness: Pick<Harness, 'commit' | 'snapshot'>;
9
+ agents: {
10
+ state(): Readonly<AgentsState>;
11
+ };
12
+ now?: () => number;
13
+ };
14
+ export declare const sized: (bytes: number) => string;
15
+ export declare function clock(at: number, now: number): string;
16
+ export declare function duration(ms: number): string;
17
+ export declare function startLick(host: LickHost, item: SudoApproval): Promise<LickEvent>;
18
+ export declare function endLick(host: LickHost, item: SudoApproval): Promise<LickEvent>;
@@ -0,0 +1,40 @@
1
+ import type { KernelClient } from '../kernel/client.ts';
2
+ export type RunKernel = Pick<KernelClient, 'fs' | 'spawn' | 'ps' | 'kill' | 'sudoRun' | 'trace'>;
3
+ export type Exit = {
4
+ status?: number;
5
+ signal?: string;
6
+ };
7
+ export declare const RUN_TAG = "sudo-run:";
8
+ export declare const RUNS_DIR = ".slicc/sudo-runs";
9
+ export declare const GRACE_MS = 1000;
10
+ export declare const runTag: (id: string) => string;
11
+ type Row = NonNullable<Awaited<ReturnType<NonNullable<RunKernel['ps']>>>>[number];
12
+ export declare function uidOf(kernel: RunKernel, user: string): Promise<number | undefined>;
13
+ export declare function aborted(signal: AbortSignal | undefined): Promise<never>;
14
+ export declare function outputOf(kernel: RunKernel, user: string, id: string, signal?: AbortSignal): Promise<{
15
+ stdout: string;
16
+ stderr: string;
17
+ }>;
18
+ export declare function removeOutput(kernel: RunKernel, user: string, paths: string[]): Promise<void>;
19
+ export declare function outputSize(kernel: RunKernel, paths: string[]): Promise<number>;
20
+ export type Watcher = {
21
+ waitFor(pid: number): Promise<Exit>;
22
+ close(): void;
23
+ };
24
+ export declare function watchExits(kernel: RunKernel, tag: string): Promise<Watcher>;
25
+ export declare const sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
26
+ export declare function gone(kernel: RunKernel, pid: number, ms: number, signal: AbortSignal): Promise<Exit>;
27
+ export declare function tagged(kernel: RunKernel, tag: string): Promise<Row[] | null>;
28
+ export type Signalled = 'sent' | 'none' | 'unknown';
29
+ export declare function signalTree(kernel: RunKernel, tag: string, killMs: number): Promise<Signalled>;
30
+ export declare function adoptable(kernel: RunKernel, tag: string, target: string): Promise<{
31
+ pid: number;
32
+ ppid?: number;
33
+ pgid?: number;
34
+ state?: string;
35
+ argv?: readonly string[];
36
+ uid?: number;
37
+ tag?: string;
38
+ tags?: readonly string[];
39
+ }>;
40
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { Context } from '@earendil-works/chord';
2
+ import { type Extension, type Harness } from '@earendil-works/pi-durable';
3
+ import type { AgentsState } from '../agents.ts';
4
+ import type { Licks } from '../licks/licks.ts';
5
+ import { type DecidedBy } from './record.ts';
6
+ import { type RunKernel } from './run-procs.ts';
7
+ import { type RunGates } from './runnable.ts';
8
+ export { clock, duration, endLick, startLick } from './run-licks.ts';
9
+ export { outputOf, RUN_TAG, RUNS_DIR, type RunKernel, runTag } from './run-procs.ts';
10
+ export declare const SUDO_RUN_TASK = "slicc.sudo-run";
11
+ export declare const SUDO_RUNS = "slicc-sudo-runs";
12
+ export declare const POLL_MS = 5000;
13
+ export declare const KILL_MS = 5000;
14
+ export declare const ADOPT_MS = 250;
15
+ export declare const ADOPT_TRIES = 5;
16
+ export declare const OUTPUT_CAP: number;
17
+ export declare const KEEP_MS: number;
18
+ export declare const RUN_ERRORS: {
19
+ readonly interrupted: 'interrupted before it started';
20
+ readonly reloaded: 'the page reloaded while it ran';
21
+ readonly idle: "This request isn't running.";
22
+ readonly gone: 'Its processes are already gone.';
23
+ readonly unseen: "The kernel's process list isn't available, so it can't be stopped.";
24
+ };
25
+ export interface SudoRunHost {
26
+ kernel: RunKernel;
27
+ harness: Pick<Harness, 'commit' | 'snapshot'>;
28
+ agents: {
29
+ state(): Readonly<AgentsState>;
30
+ };
31
+ licks?: Pick<Licks, 'deliver'>;
32
+ boot: string | null;
33
+ server: string;
34
+ conversation: number;
35
+ now?: () => number;
36
+ pollMs?: number;
37
+ killMs?: number;
38
+ adoptMs?: number;
39
+ outputCap?: number;
40
+ keepMs?: number;
41
+ }
42
+ export type RunAnswer = {
43
+ done: true;
44
+ error: null;
45
+ } | {
46
+ done: false;
47
+ error: string;
48
+ };
49
+ export type Runner = {
50
+ by: DecidedBy;
51
+ device?: string;
52
+ };
53
+ export interface SudoRuns {
54
+ readonly extension: Extension;
55
+ bind(host: SudoRunHost): void;
56
+ claim(id: string, runner: Runner, gates: RunGates, context: Context): Promise<RunAnswer>;
57
+ stop(id: string, runner: Runner, context: Context): Promise<RunAnswer>;
58
+ }
59
+ export declare function messageOf(error: unknown): string;
60
+ export declare function sudoRuns(): SudoRuns;
@@ -0,0 +1,55 @@
1
+ import { type ReplicatedState } from '@earendil-works/chord';
2
+ import { type AgentsState } from '../agents.ts';
3
+ import type { LickTarget } from '../licks/lick.ts';
4
+ import { type Approval } from './record.ts';
5
+ export type Runnable = true | {
6
+ reason: string;
7
+ };
8
+ export type RunGates = {
9
+ maxAgeMinutes: number;
10
+ kernel: true | string;
11
+ frozen?: (agentId: string) => string | undefined;
12
+ gone?: (agentId: string) => boolean;
13
+ };
14
+ export declare const SUDO_RUN_PROTOCOL: readonly [number, number];
15
+ export declare const RUN_REASONS: {
16
+ readonly kind: 'Only a sudo request can run now.';
17
+ readonly open: 'This request is still open: answer it instead.';
18
+ readonly untimed: 'Only a request that timed out can run now.';
19
+ readonly running: 'This request is already running.';
20
+ readonly ran: 'This request already ran.';
21
+ readonly terminal: 'Run it again in the terminal.';
22
+ readonly validate: 'sudo -v has no command to run.';
23
+ readonly stdin: 'Its input is gone, so it must be asked again.';
24
+ readonly old: 'This request is from before Run now, so it must be asked again.';
25
+ readonly off: 'Run now is off in the approval policy.';
26
+ readonly gone: 'The agent that asked is gone, so it must be asked again.';
27
+ readonly kernel: `Needs slicc-kernel protocol ${string} or later.`;
28
+ };
29
+ export declare function tooOld(minutes: number): string;
30
+ export declare const thawFirst: (cone: string) => string;
31
+ export declare function runnable(item: Approval, now: number, gates: RunGates): Runnable;
32
+ export declare function runEnds(item: Approval, maxAgeMinutes: number): number | undefined;
33
+ export declare function agentTarget(state: Readonly<AgentsState>, agentId: string): LickTarget;
34
+ export declare const frozenOf: (state: () => Readonly<AgentsState>) => (agentId: string) => string | undefined;
35
+ export declare const goneOf: (state: () => Readonly<AgentsState>) => (agentId: string) => boolean;
36
+ type Protocol = {
37
+ protocol?: readonly number[];
38
+ sudoRun?: unknown;
39
+ };
40
+ export declare function kernelGate(client: Protocol | undefined): true | string;
41
+ type Watched = {
42
+ subscribe(listener: () => void): () => void;
43
+ };
44
+ export interface RunnableWatch {
45
+ readonly state: ReplicatedState<Record<string, Runnable>>;
46
+ refresh(): void;
47
+ dispose(): void;
48
+ }
49
+ export declare function watchRunnable(approvals: Watched & {
50
+ readonly value: readonly Approval[] | undefined;
51
+ }, changes: readonly Watched[], gates: () => RunGates, clock?: {
52
+ now?: () => number;
53
+ setTimer?: (callback: () => void, ms: number) => () => void;
54
+ }): RunnableWatch;
55
+ export {};
@@ -3,7 +3,7 @@ import type { AgentsState } from '../agents.ts';
3
3
  import type { AgentCapture } from '../guests/capture.ts';
4
4
  import type { Licks } from '../licks/licks.ts';
5
5
  import type { Approvals } from './index.ts';
6
- import { type Approval, type ApprovalRequester, type SudoDetail, type SudoStdin } from './record.ts';
6
+ import { type Approval, type ApprovalRequester, type SudoDetail, type SudoFile, type SudoReplay, type SudoStdin } from './record.ts';
7
7
  export type SudoAnswer = 'once' | 'always' | 'deny';
8
8
  export type SudoDenial = {
9
9
  answer: 'deny';
@@ -32,6 +32,7 @@ export interface SudoRequest {
32
32
  always?: boolean;
33
33
  stdin?: SudoStdin;
34
34
  rootOnly?: Record<string, boolean>;
35
+ userWritable?: SudoFile[];
35
36
  timestamp?: boolean;
36
37
  validate?: boolean;
37
38
  }
@@ -56,6 +57,7 @@ export declare function sudoRequester(request: SudoRequest, agents: Readonly<Age
56
57
  export declare const validating: (request: Pick<SudoRequest, 'validate'>) => boolean;
57
58
  export declare const timestampFor: (user: string) => string;
58
59
  export declare function sudoDetail(request: SudoRequest): SudoDetail;
60
+ export declare function sudoReplay(request: SudoRequest): SudoReplay;
59
61
  export interface SudoAttach {
60
62
  approvals: Approvals;
61
63
  capture: AgentCapture;
@@ -2,6 +2,7 @@ import { type Context, type Host, type ReplicatedState } from '@earendil-works/c
2
2
  import type { ConversationView } from '@earendil-works/pi-durable';
3
3
  import type { ApprovalPolicy } from './approvals/policy.ts';
4
4
  import type { Approval } from './approvals/record.ts';
5
+ import type { Runnable } from './approvals/runnable.ts';
5
6
  import type { ChangesView } from './changes/git.ts';
6
7
  import type { FrozenCone } from './freezer/index.ts';
7
8
  import type { ImportProgress } from './freezer/v6.ts';
@@ -39,6 +40,7 @@ export interface AgentConnection {
39
40
  readonly owner?: boolean;
40
41
  readonly approvals?: ReplicatedState<Approval[]>;
41
42
  readonly approvalPolicy?: ReplicatedState<ApprovalPolicy>;
43
+ readonly approvalRunnable?: ReplicatedState<Record<string, Runnable>>;
42
44
  readonly settings: AgentSettings;
43
45
  readonly remote?: AgentRemote;
44
46
  readonly history?: boolean;
@@ -3,6 +3,7 @@ import type { ConversationView } from '@earendil-works/pi-durable';
3
3
  import type { Agent } from './agent.ts';
4
4
  import { type ApprovalJudge, type Approvals, type Attendance, type Decider } from './approvals/index.ts';
5
5
  import { type ApprovalPolicies } from './approvals/policy.ts';
6
+ import type { RunKernel, Runner, SudoRunHost } from './approvals/run.ts';
6
7
  import { type AgentSudo } from './approvals/sudo.ts';
7
8
  import type { ChangesRuntime } from './changes/index.ts';
8
9
  import { type HostLicks, type HostScoops } from './control.ts';
@@ -95,13 +96,21 @@ export type HostOptions = {
95
96
  uploads?: Uploads;
96
97
  thumbnail?: Thumbnail;
97
98
  labels?: LabelsRuntime;
99
+ runs?: {
100
+ kernel: RunKernel & {
101
+ protocol?: readonly number[];
102
+ };
103
+ boot: string | null;
104
+ } & RunTimes;
98
105
  } & ApprovalOptions;
106
+ export type RunTimes = Partial<Pick<SudoRunHost, 'pollMs' | 'killMs' | 'adoptMs' | 'outputCap' | 'keepMs'>>;
99
107
  export declare function hostAgent(agent: Agent, options?: HostOptions): Promise<AgentHost>;
100
108
  interface Served {
101
109
  trusted: AgentControl;
102
110
  viewed: () => AgentControl;
103
111
  transcript: Record<keyof AgentTranscript, ReplicatedState<unknown>>;
104
112
  viewMonitor: ReplicatedState<unknown>;
113
+ viewApprovals: ReplicatedState<unknown>;
105
114
  sudo?: AgentSudo;
106
115
  settings: AgentSettings;
107
116
  remote: AgentRemote;
@@ -112,6 +121,7 @@ interface Served {
112
121
  dispose(): void;
113
122
  } | undefined;
114
123
  decide: (by: Decider) => AgentControl['decide'];
124
+ runs: (runner: Runner) => Pick<AgentControl, 'approvalRun' | 'approvalRunStop'>;
115
125
  owners?: Attendance;
116
126
  }
117
127
  export declare const CLOSED_TO_GUESTS = "a guest seat has only its transcript and propose";
@@ -1,7 +1,10 @@
1
1
  export { ADOBE, ADOBE_PROXY, type AdobeConfig, type AdobeModelInfo, adobeClassifiers, adobeConfig, adobeIdentity, adobeModel, adobeProvider, adobeUsage, type Budget, SESSION_HEADER, VERSION_HEADER, withAdobeIdentity, } from './adobe.ts';
2
2
  export { type Agent, type AgentOptions, answerText, openAgent } from './agent.ts';
3
3
  export { APPROVAL_MS, type Approval, type ApprovalAnswer, type ApprovalDecided, type ApprovalDecision, type ApprovalDraft, type ApprovalJudge, type ApprovalKind, type ApprovalRequester, type ApprovalState, type Approvals, ApprovalsDoc, type ApprovalTier, type ApprovalVerdict, ASK_MIN_MS, approvalJudge, attachApprovals, type CaptureApproval, type CaptureDetail, DEFAULT_POLICY, type DecidedBy, type Decider, JUDGE_ALLOW, JUDGE_KIND, JUDGE_MODEL, JUDGE_QUESTIONS, type Judgement, judgeModelOf, judgeSpender, judgeState, type OwnerIntent, ownerIntent, POLICY_FILE, REASONS, route, seedPolicy, VERDICT_REASONS, verdictOf, verdictRecorder, } from './approvals/index.ts';
4
- export { type ApprovalPolicy, type ApprovalPolicyChange, type ApprovalPolicySet, DEFAULT_APPROVAL_POLICY, type SudoPolicy, } from './approvals/policy.ts';
4
+ export { type ApprovalPolicy, type ApprovalPolicyChange, type ApprovalPolicySet, DEFAULT_APPROVAL_POLICY, type RunLatePolicy, type SudoPolicy, type SudoPolicyChange, } from './approvals/policy.ts';
5
+ export type { SudoFile, SudoReplay, SudoRun, SudoRunState } from './approvals/record.ts';
6
+ export { RUN_ERRORS, type RunAnswer, SUDO_RUN_TASK, } from './approvals/run.ts';
7
+ export { RUN_REASONS, type RunGates, type Runnable, runnable, SUDO_RUN_PROTOCOL, } from './approvals/runnable.ts';
5
8
  export type { AgentSudo, SudoAnswer, SudoDenial, SudoReply, SudoRequest, SudoTimestamp, } from './approvals/sudo.ts';
6
9
  export type { CaptureAsk } from './approvals/sudo-client.ts';
7
10
  export { FILE_LIMIT, IMAGE_LIMIT, type SendAttachment, type ShownAttachment, splitUser, TOTAL_LIMIT, userParts, } from './attachments.ts';
@@ -40,15 +40,61 @@ export interface KernelProcess {
40
40
  }
41
41
  export interface SpawnOptions {
42
42
  cwd?: string;
43
+ user?: string | number;
43
44
  env?: Record<string, string>;
44
45
  pgid?: number;
45
- tag?: string;
46
+ tag?: string | readonly string[];
46
47
  stdin?: Uint8Array;
47
48
  onStdout?(bytes: Uint8Array): void;
48
49
  onStderr?(bytes: Uint8Array): void;
49
50
  }
51
+ export interface TraceExit {
52
+ type: 'exit';
53
+ seq?: number;
54
+ pid: number;
55
+ status: number;
56
+ signal?: string;
57
+ utime?: number;
58
+ stime?: number;
59
+ at?: number;
60
+ }
61
+ export type TraceEvent = {
62
+ type: 'exec' | 'fork';
63
+ seq: number;
64
+ pid: number;
65
+ ppid: number;
66
+ pgid?: number;
67
+ argv: readonly string[];
68
+ exe?: string;
69
+ at?: number;
70
+ replaced?: boolean;
71
+ } | TraceExit;
72
+ export interface TraceBatch {
73
+ events: readonly TraceEvent[];
74
+ dropped: number;
75
+ }
76
+ export interface SudoRunOptions {
77
+ stdout?: string;
78
+ stderr?: string;
79
+ tag?: string | string[];
80
+ }
81
+ export interface SudoRunning {
82
+ pid: number;
83
+ pgid: number;
84
+ ended: Promise<{
85
+ status: number;
86
+ signal?: string;
87
+ }>;
88
+ }
50
89
  export interface KernelClient {
51
90
  fs: KernelFs;
91
+ protocol?: readonly number[];
92
+ sudoRun?(request: object, options: SudoRunOptions): Promise<SudoRunning>;
93
+ trace?(tag: string, onEvents: (batch: TraceBatch) => void | Promise<unknown>, options?: {
94
+ limit?: number;
95
+ }): Promise<{
96
+ close(): void;
97
+ }>;
52
98
  spawn(argv: readonly string[], options: SpawnOptions): Promise<KernelProcess>;
53
99
  kill?(pid: number, signal?: string): Promise<void>;
54
100
  ps?(): Promise<readonly {
@@ -2,10 +2,14 @@ import type { Context } from '@earendil-works/chord';
2
2
  import { ExecutionError, type Result, type ShellExecOptions, type ShellExecResult } from '@earendil-works/pi-durable/env';
3
3
  import type { ScrubStream } from '../secrets/scrub.ts';
4
4
  import type { KernelClient, KernelProcess } from './client.ts';
5
+ import { type CallTrace } from './trace.ts';
5
6
  export declare const SHELL: readonly ['bash', '-c'];
6
7
  export declare const HELD_LIMIT: number;
7
8
  export declare const HELD = "output held: waiting for the vault";
8
9
  export declare const GONE = "the kernel went away mid-run, so the command may have partly run";
10
+ export type TracedExecOptions = ShellExecOptions & {
11
+ trace?: CallTrace;
12
+ };
9
13
  export interface ExecHooks {
10
14
  scrub?: () => ScrubStream;
11
15
  spawn?: (argv: readonly string[]) => readonly string[];
@@ -0,0 +1,45 @@
1
+ import type { KernelClient, TraceBatch } from './client.ts';
2
+ export declare const CALL_TAG = "call:";
3
+ export declare const PROGRAMS_KEPT = 16;
4
+ export declare const NAMES_HELD = 64;
5
+ export declare const PIDS_HELD = 1024;
6
+ export declare const QUEUE_HELD = 4096;
7
+ export declare const LINGER_MS = 2000;
8
+ export declare const TRACE_LIMIT = 4096;
9
+ export declare const INTENT_HELD = 1000;
10
+ export interface RanProgram {
11
+ name: string;
12
+ status?: number;
13
+ signal?: string;
14
+ quiet?: true;
15
+ }
16
+ export interface Ran {
17
+ programs: RanProgram[];
18
+ ms: number;
19
+ more?: number;
20
+ dropped?: number;
21
+ intent?: string;
22
+ }
23
+ export interface CallTrace {
24
+ tag: string;
25
+ report(ran: Ran): void;
26
+ }
27
+ export declare function programOf(argv: readonly string[], exe?: string): {
28
+ name: string;
29
+ args: readonly string[];
30
+ } | undefined;
31
+ export declare function argvIntent(args: readonly string[]): string | undefined;
32
+ export declare class Collector {
33
+ #private;
34
+ constructor(argv: readonly string[], launchers: number);
35
+ feed(batch: TraceBatch): void;
36
+ begin(pid: number): void;
37
+ get done(): boolean;
38
+ settled(ms: number): Promise<void>;
39
+ facts(ms: number, killed: boolean): Ran;
40
+ }
41
+ export interface Tracer {
42
+ collector: Collector;
43
+ close(): void;
44
+ }
45
+ export declare function follow(client: KernelClient, tag: string, argv: readonly string[], launchers: number): Promise<Tracer | undefined>;
@@ -1,4 +1,4 @@
1
- export declare const LICK_CHANNELS: readonly ['webhook', 'cron', 'sprinkle', 'fswatch', 'session-reload', 'navigate', 'discovery', 'upgrade', 'workflow', 'bash', 'jshd', 'preview', 'cherry', 'scoop-notify', 'scoop-idle', 'scoop-wait', 'sudo-request', 'cone-message'];
1
+ export declare const LICK_CHANNELS: readonly ['webhook', 'cron', 'sprinkle', 'fswatch', 'session-reload', 'navigate', 'discovery', 'upgrade', 'workflow', 'bash', 'jshd', 'preview', 'cherry', 'scoop-notify', 'scoop-idle', 'scoop-wait', 'sudo-request', 'sudo-run', 'cone-message'];
2
2
  export type LickChannel = (typeof LICK_CHANNELS)[number];
3
3
  export type LickAction = 'confirm' | 'dismiss';
4
4
  export type LickSeverity = 'warn' | 'error';