blun-king-cli 9.1.642 → 9.1.644

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 (273) hide show
  1. package/LIESMICH.txt +18 -0
  2. package/README.md +20 -6
  3. package/bin/blun.js +3 -3
  4. package/bin/king.js +3 -3
  5. package/bin/launcher-mode.js +125 -126
  6. package/bin/launcher-runtime.js +603 -616
  7. package/bin/plugin-bootstrap.js +339 -405
  8. package/bin/rename-private-staging.cjs +2 -2
  9. package/bin/retired-bundled-plugins.cjs +84 -0
  10. package/bin/startup-security-host.cjs +105 -0
  11. package/bin/startup-security.cjs +9 -105
  12. package/bin/startup-warning-policy.cjs +22 -0
  13. package/bin/update-lease-installer.cjs +125 -0
  14. package/bin/update-lease-sockets.cjs +228 -0
  15. package/bin/update-lease.js +22 -327
  16. package/bin/verify-bundled-agent-sources.cjs +2 -4
  17. package/blun.mjs +78 -193
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +4 -6
  20. package/tool-liveness642/index.cjs +7 -0
  21. package/tool-liveness642/queue-delivery.cjs +109 -0
  22. package/tool-liveness642/receipt.json +40 -0
  23. package/tool-liveness642/shell-yield.cjs +43 -0
  24. package/tool-liveness642/task-wait.cjs +45 -0
  25. package/versionierung/BELEG.json +43 -0
  26. package/versionierung/LIESMICH.md +5 -0
  27. package/versionierung/urspruenglicher-overlay-beleg.json +39 -0
  28. package/worker-host.mjs +48 -128
  29. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  30. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  31. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  32. package/agent-spine-plugin/.mcp.json +0 -8
  33. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  34. package/agent-spine-plugin/LICENSE +0 -186
  35. package/agent-spine-plugin/README.md +0 -432
  36. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  37. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  38. package/agent-spine-plugin/bin/agentspine.js +0 -7
  39. package/agent-spine-plugin/blun.plugin.json +0 -68
  40. package/agent-spine-plugin/docs/acceptance.md +0 -61
  41. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  42. package/agent-spine-plugin/docs/host-integration.md +0 -193
  43. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  44. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  45. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  46. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  47. package/agent-spine-plugin/docs/source-roots.md +0 -113
  48. package/agent-spine-plugin/docs/world-model.md +0 -119
  49. package/agent-spine-plugin/hooks/codex.json +0 -47
  50. package/agent-spine-plugin/hooks/hooks.json +0 -106
  51. package/agent-spine-plugin/hooks/version.json +0 -5
  52. package/agent-spine-plugin/package.json +0 -77
  53. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  54. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  55. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  56. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  57. package/agent-spine-plugin/scripts/check-install.js +0 -478
  58. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  59. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  60. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  61. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  62. package/agent-spine-plugin/scripts/release-check.js +0 -150
  63. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  64. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  65. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  66. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  67. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  68. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  69. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  70. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  71. package/agent-spine-plugin/src/cli-agent.js +0 -315
  72. package/agent-spine-plugin/src/cli-attention.js +0 -95
  73. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  74. package/agent-spine-plugin/src/cli-common.js +0 -71
  75. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  76. package/agent-spine-plugin/src/cli-core.js +0 -128
  77. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  78. package/agent-spine-plugin/src/cli-host.js +0 -21
  79. package/agent-spine-plugin/src/cli-learning.js +0 -320
  80. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  81. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  82. package/agent-spine-plugin/src/cli.js +0 -181
  83. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  84. package/agent-spine-plugin/src/hook.js +0 -500
  85. package/agent-spine-plugin/src/index.js +0 -108
  86. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  87. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  88. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  89. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  90. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  91. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  92. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  93. package/agent-spine-plugin/src/lib/attention.js +0 -164
  94. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  95. package/agent-spine-plugin/src/lib/audit.js +0 -401
  96. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  97. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  98. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  99. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  100. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  101. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  102. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  103. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  104. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  105. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  106. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  107. package/agent-spine-plugin/src/lib/context.js +0 -156
  108. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  109. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  110. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  111. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  112. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  113. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  114. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  115. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  116. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  117. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  118. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  119. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  120. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  121. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  122. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  123. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  124. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  125. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  126. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  127. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  128. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  129. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  130. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  131. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  132. package/agent-spine-plugin/src/lib/documents.js +0 -239
  133. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  134. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  135. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  136. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  137. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  138. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  139. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  140. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  141. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  142. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  143. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  144. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  145. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  146. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  147. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  148. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  149. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  150. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  151. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  152. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  153. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  154. package/agent-spine-plugin/src/lib/graph.js +0 -337
  155. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  156. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  157. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  158. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  159. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  160. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  161. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  162. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  163. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  164. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  165. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  166. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  167. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  168. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  169. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  170. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  171. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  172. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  173. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  174. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  175. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  176. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  177. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  178. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  179. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  180. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  181. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  182. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  183. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  184. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  185. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  186. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  187. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  188. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  189. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  190. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  191. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  192. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  193. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  194. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  195. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  196. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  197. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  198. package/agent-spine-plugin/src/lib/learning.js +0 -36
  199. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  200. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  201. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  202. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  203. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  204. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  205. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  206. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  207. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  208. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  209. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  210. package/agent-spine-plugin/src/lib/paths.js +0 -109
  211. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  212. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  213. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  214. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  215. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  216. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  217. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  218. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  219. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  220. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  221. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  222. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  223. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  224. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  225. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  226. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  227. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  228. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  229. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  230. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  231. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  232. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  233. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  234. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  235. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  236. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  237. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  238. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  239. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  240. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  241. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  242. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  243. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  244. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  245. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  246. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  247. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  248. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  249. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  250. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  251. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  252. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  253. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  254. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  255. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  256. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  257. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  258. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  259. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  260. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  261. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  262. package/agent-spine-plugin/src/mcp.js +0 -456
  263. package/agent-spine-plugin/src/version.js +0 -1
  264. package/agent-spine-plugin/src/worker.js +0 -257
  265. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  266. package/bin/agentspine-king-goal-intake.mjs +0 -106
  267. package/bin/agentspine-king-host-runner.mjs +0 -109
  268. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  269. package/bin/agentspine-king-status-policy.mjs +0 -226
  270. package/bin/agentspine-king-worker-host.mjs +0 -160
  271. package/bin/managed-plugin-selection.cjs +0 -141
  272. package/bin/verify-agent-behavior.cjs +0 -122
  273. package/bin/verify-agent-components.cjs +0 -104
@@ -1,145 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { isAbsolute, join } from "node:path";
3
- import { readWindowsSidAcl } from "./session-timeline-sid-acl.js";
4
-
5
- const SID_RE = /\bS-\d+(?:-\d+)+\b/i;
6
- const WRITE_RIGHTS = new Set(["AD", "D", "DC", "DE", "F", "GA", "GW", "M", "W", "WA", "WD", "WDAC", "WEA", "WO"]);
7
- const SYSTEM_PRINCIPALS = new Set([
8
- "s-1-5-18", "s-1-5-32-544", "sddl:la"
9
- ]);
10
- const MANDATORY_LABEL_PREFIX = "mandatory label\\";
11
- const FILE_ROLES = new Set(["key", "state", "head", "private"]);
12
-
13
- function failure(message, result = null) {
14
- const detail = result?.error?.message || result?.stderr || result?.stdout || "no diagnostic";
15
- throw new Error(`session timeline Windows ACL ${message}: ${String(detail).trim().slice(0, 240)}`);
16
- }
17
-
18
- function executable(name, env) {
19
- const root = env.SystemRoot;
20
- if (typeof root !== "string" || !isAbsolute(root)) throw new Error("session timeline Windows system root is unavailable");
21
- return join(root, "System32", name);
22
- }
23
-
24
- function runCommand(run, binary, args, env) {
25
- const result = run(binary, args, { encoding: "utf8", env, shell: false, timeout: 1_500, windowsHide: true });
26
- if (!result || result.status !== 0 || result.error || result.signal) failure(`${binary} failed`, result);
27
- return `${result.stdout || ""}\n${result.stderr || ""}`;
28
- }
29
-
30
- function identityFrom(output) {
31
- const sid = output.match(SID_RE)?.[0]?.toLowerCase();
32
- const account = output.match(/^\s*"((?:[^"]|"")*)"\s*,/m)?.[1]?.replaceAll('""', '"').toLowerCase();
33
- if (!sid || !account) throw new Error("session timeline Windows identity is unavailable");
34
- return { sid, account };
35
- }
36
-
37
- function normalizedPrincipal(value) {
38
- return value.trim().replace(/^\*/, "").replaceAll("/", "\\").toLowerCase();
39
- }
40
-
41
- function entriesFrom(output, path) {
42
- const values = [];
43
- let first = true;
44
- for (const source of output.split(/\r?\n/)) {
45
- let line = source.trim();
46
- if (!line) continue;
47
- if (first && line.toLowerCase().startsWith(path.toLowerCase())) line = line.slice(path.length).trim();
48
- first = false;
49
- const match = line.match(/^(.+?):((?:\([^)]*\))+)/);
50
- if (!match) continue;
51
- values.push({ principal: normalizedPrincipal(match[1]), rights: [...match[2].matchAll(/\(([^)]*)\)/g)].map((item) => item[1].toUpperCase()) });
52
- }
53
- return values;
54
- }
55
-
56
- function canWrite(entry) { return entry.rights.some((right) => WRITE_RIGHTS.has(right)); }
57
- function isSelf(principal, identity) { return principal === identity.sid; }
58
- export function isTrustedWindowsWriter(principal, identity) {
59
- return isSelf(principal, identity) || SYSTEM_PRINCIPALS.has(principal);
60
- }
61
- function isMandatoryLabel(entry) {
62
- return entry.principal.startsWith(MANDATORY_LABEL_PREFIX)
63
- && entry.rights.every((right) => new Set(["I", "IO", "OI", "CI", "NW"]).has(right));
64
- }
65
- function isPrivatePrincipal(entry, identity) {
66
- return isTrustedWindowsWriter(entry.principal, identity) || isMandatoryLabel(entry);
67
- }
68
- function isTrustedParentWriter(entry, identity) {
69
- return isTrustedWindowsWriter(entry.principal, identity)
70
- || (entry.principal === "s-1-3-0" && entry.rights.includes("IO"));
71
- }
72
-
73
- function verifyParent(entries, identity) {
74
- if (!entries.length) throw new Error("session timeline Windows parent ACL has no readable entries");
75
- const unsafe = entries.find((entry) => canWrite(entry) && !isTrustedParentWriter(entry, identity));
76
- if (unsafe) throw new Error(`session timeline Windows parent ACL grants write access to ${unsafe.principal}`);
77
- }
78
-
79
- function verifyIntegrity(entries, identity) {
80
- const owner = entries.find((entry) => isSelf(entry.principal, identity)
81
- && entry.rights.includes("F") && !entry.rights.includes("I") && !entry.rights.includes("IO"));
82
- if (!owner || entries.some((entry) => !isPrivatePrincipal(entry, identity))) {
83
- throw new Error("session timeline Windows integrity ACL is not private to the current SID");
84
- }
85
- }
86
-
87
- function verifyFile(entries, identity, role) {
88
- const owner = entries.find((entry) => isSelf(entry.principal, identity)
89
- && entry.rights.includes("F") && !entry.rights.includes("IO"));
90
- if (!owner || entries.some((entry) => !isPrivatePrincipal(entry, identity))) {
91
- throw new Error(`session timeline Windows ${role} ACL is not private to the current SID`);
92
- }
93
- }
94
-
95
- function fingerprint(metadata) {
96
- if (!metadata) return null;
97
- return [metadata.dev, metadata.ino, metadata.mtimeNs, metadata.ctimeNs].map(String).join(":");
98
- }
99
-
100
- export function createWindowsTimelineAclVerifier({ platform = process.platform, env = process.env, run = spawnSync } = {}) {
101
- const cache = new Map();
102
- let identity = null;
103
- return async function verifyWindowsTimelineDirectoryAcl(path, { created = false, metadata = null, role = "integrity" } = {}) {
104
- if (platform !== "win32") return;
105
- if (!isAbsolute(path) || !["integrity", "parent"].includes(role)) {
106
- throw new Error("session timeline Windows ACL request is invalid");
107
- }
108
- const cached = `${role}:${path.toLowerCase()}:${fingerprint(metadata)}`;
109
- if (!created && fingerprint(metadata) && cache.has(cached)) return;
110
- const whoami = executable("whoami.exe", env);
111
- const icacls = executable("icacls.exe", env);
112
- identity ||= identityFrom(runCommand(run, whoami, ["/user", "/fo", "csv", "/nh"], env));
113
- if (role === "integrity" && created) {
114
- runCommand(run, icacls, [path, "/inheritance:r", "/grant:r", `*${identity.sid}:(OI)(CI)(F)`], env);
115
- }
116
- const entries = await readWindowsSidAcl(path, env, runCommand, run, identity);
117
- if (role === "integrity") verifyIntegrity(entries, identity); else verifyParent(entries, identity);
118
- if (!created && fingerprint(metadata)) cache.set(cached, true);
119
- };
120
- }
121
-
122
- export function createWindowsTimelineFileAclVerifier({ platform = process.platform, env = process.env, run = spawnSync } = {}) {
123
- const cache = new Map();
124
- let identity = null;
125
- return async function verifyWindowsTimelineFileAcl(path, { created = false, metadata = null, role = "private" } = {}) {
126
- if (platform !== "win32") return;
127
- if (!isAbsolute(path) || !FILE_ROLES.has(role)) {
128
- throw new Error("session timeline Windows file ACL request is invalid");
129
- }
130
- const cached = `${role}:${path.toLowerCase()}:${fingerprint(metadata)}`;
131
- if (!created && fingerprint(metadata) && cache.has(cached)) return;
132
- const whoami = executable("whoami.exe", env);
133
- const icacls = executable("icacls.exe", env);
134
- identity ||= identityFrom(runCommand(run, whoami, ["/user", "/fo", "csv", "/nh"], env));
135
- if (created) runCommand(run, icacls, [path, "/inheritance:r", "/grant:r", `*${identity.sid}:(F)`], env);
136
- verifyFile(await readWindowsSidAcl(path, env, runCommand, run, identity), identity, role);
137
- if (!created && fingerprint(metadata)) cache.set(cached, true);
138
- };
139
- }
140
-
141
- const verifyWindowsTimelineDirectoryAcl = createWindowsTimelineAclVerifier();
142
- const verifyWindowsTimelineFileAcl = createWindowsTimelineFileAclVerifier();
143
-
144
- export { entriesFrom as parseWindowsIcaclsEntries };
145
- export { verifyWindowsTimelineDirectoryAcl, verifyWindowsTimelineFileAcl };
@@ -1,462 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { mkdir } from "node:fs/promises";
3
- import { isAbsolute } from "node:path";
4
- import { withOwnedFileLock } from "./owned-file-lock.js";
5
- import {
6
- completeTimelineBinding, hasVerifiedTimelinePrivateScope, sameTimelineBinding, sessionTimelineBinding,
7
- TIMELINE_ID_RE, validTimelineBinding
8
- } from "./session-timeline-contract.js";
9
- import {
10
- ensureSessionTimelineTrust, sessionTimelineStatePaths
11
- } from "./session-timeline-auth.js";
12
- import { consumeSessionTimelineInvocation, issueSessionTimelineInvocation } from "./session-timeline-invocation.js";
13
- import {
14
- loadPrivateSessionTimelineEnrollment, resolvePrivateSessionTimelineEnrollment
15
- } from "./session-timeline-enrollment.js";
16
- import { timelineTransportEnrollmentMatches } from "./session-timeline-enrollment-transport.js";
17
- import { sameTimelineTransportDigest, timelineTransportDigest } from "./session-timeline-transport.js";
18
- import {
19
- matchesTimelineEvent, rankTimelineEvents, timelineQuery
20
- } from "./session-timeline-query.js";
21
- import { timelineContinuationCapsule, timelineSearchResult } from "./session-timeline-results.js";
22
- import { seekTimelineEvidence, verifyTimelineEvent } from "./session-timeline-search.js";
23
- import { eventFromTimelineLine, extractTimelineTimestamp } from "./session-timeline-event-extract.js";
24
- import { verifiedTimelineEventFromLine } from "./session-timeline-event-extract.js";
25
- import { pathMatchesSource } from "./session-timeline-source.js";
26
- import { readRange, unchangedHandle, validatedHandle } from "./session-timeline-source-open.js";
27
- import { readTimelineState, saveTimelineState } from "./session-timeline-state.js";
28
- import { sessionTimelineRootDigest } from "./session-timeline-root.js";
29
- import { priorTimelineHint, selectPriorTimelineSource, timelineSessionReference } from "./session-timeline-prior.js";
30
- import { crossProviderTimelineEnabled } from "./session-timeline-provider.js";
31
- export const SESSION_TIMELINE_SCHEMA = "agentspine.session-timeline/v1";
32
- const STATE_SCHEMA = "agentspine.session-timeline-state/v1";
33
- const AUTHORITY = "context-only";
34
- const MAX_STATE_BYTES = 16 * 1024 * 1024;
35
- const MAX_SOURCES = 64;
36
- const MAX_EVENTS = 4096;
37
- const MAX_LINE_BYTES = 1024 * 1024;
38
- const MAX_INDEX_BYTES = 16 * 1024 * 1024;
39
- const ROOM_BYTES = 1024 * 1024;
40
- const EVENT_OUTCOMES = new Set(["pass", "fail", "blocked", "timeout", "error", "skipped"]);
41
- const EVENT_LABEL_RE = /^(?:suite-(?:0|[1-9]\d{0,3})|acceptance|audit|npm-check|ci|test)$/;
42
- const EVENT_KEYS = new Set(["nativeMessageId", "id", "at", "offset", "bytes", "sha256", "kind", "outcome", "count", "testLabel", "nextStepSummary", "terms", "authority"]);
43
- function digest(value) { return createHash("sha256").update(value).digest("hex"); }
44
- function asDate(value) {
45
- const date = value instanceof Date ? value : new Date(value);
46
- if (!Number.isFinite(date.getTime())) throw new Error("session timeline timestamp is invalid");
47
- return date;
48
- }
49
- function date(value) { return Number.isFinite(new Date(value).getTime()); }
50
- function empty(root) { return { schema: STATE_SCHEMA, rootDigest: sessionTimelineRootDigest(root), sources: [], authority: AUTHORITY }; }
51
- function hasOnlyKeys(item, allowed) { return Object.keys(item).every((key) => allowed.has(key)); }
52
- function validCount(item) {
53
- return item === null || Boolean(item && typeof item === "object" && Object.keys(item).length === 2
54
- && Number.isSafeInteger(item.value) && item.value >= 0 && Number.isSafeInteger(item.total)
55
- && item.total > 0 && item.value <= item.total);
56
- }
57
- function validEvent(item) {
58
- const common = item && typeof item === "object" && hasOnlyKeys(item, EVENT_KEYS)
59
- && typeof item.id === "string" && TIMELINE_ID_RE.test(item.id) && date(item.at)
60
- && Number.isSafeInteger(item.offset) && item.offset >= 0 && Number.isSafeInteger(item.bytes) && item.bytes > 0
61
- && /^[a-f0-9]{64}$/.test(item.sha256 || "")
62
- && Array.isArray(item.terms) && item.terms.length <= 24 && item.terms.every((term) => /^[\p{L}\p{N}]{3,}$/u.test(term))
63
- && (item.nativeMessageId === undefined || typeof item.nativeMessageId === "string" && TIMELINE_ID_RE.test(item.nativeMessageId))
64
- && item.authority === AUTHORITY;
65
- if (!common) return false;
66
- if (item.kind === "user-message-candidate") return item.outcome === undefined
67
- && item.count === undefined && item.testLabel === undefined && item.nextStepSummary === undefined
68
- && item.terms.join(" ") === "user message";
69
- if (item.kind === "objective-result") {
70
- return EVENT_OUTCOMES.has(item.outcome) && validCount(item.count)
71
- && (item.testLabel === null || typeof item.testLabel === "string" && EVENT_LABEL_RE.test(item.testLabel))
72
- && item.nextStepSummary === undefined;
73
- }
74
- return item.kind === "explicit-next-step-correction" && item.outcome === undefined
75
- && item.count === undefined && item.testLabel === undefined
76
- && (item.nextStepSummary === undefined || typeof item.nextStepSummary === "string"
77
- && Boolean(item.nextStepSummary.trim()) && item.nextStepSummary.length <= 500);
78
- }
79
- function validSource(item) {
80
- return item && validTimelineBinding(item.binding) && typeof item.path === "string" && isAbsolute(item.path)
81
- && item.path.length > 0 && item.path.length <= 4096 && typeof item.profileRoot === "string" && isAbsolute(item.profileRoot)
82
- && item.profileRoot.length > 0 && item.profileRoot.length <= 4096 && typeof item.projectsRoot === "string" && isAbsolute(item.projectsRoot)
83
- && item.projectsRoot.length > 0 && item.projectsRoot.length <= 4096 && item.pathDigest === digest(item.path)
84
- && typeof item.identity === "string" && item.identity.length <= 256
85
- && /^[0-9]+$/.test(item.mtimeNs || "") && /^[0-9]+$/.test(item.ctimeNs || "")
86
- && Number.isInteger(item.indexedBytes) && item.indexedBytes >= 0 && Number.isInteger(item.size) && item.size >= 0
87
- && item.indexedBytes <= item.size && Array.isArray(item.events) && item.events.length <= MAX_EVENTS
88
- && item.events.every((event) => validEvent(event) && event.bytes <= MAX_LINE_BYTES && event.offset + event.bytes <= item.size)
89
- && (item.lessonDigest === null || /^[a-f0-9]{64}$/.test(item.lessonDigest || ""))
90
- && date(item.updatedAt) && item.authority === AUTHORITY;
91
- }
92
- function validate(value, root) {
93
- if (!value || value.schema !== STATE_SCHEMA || value.rootDigest !== sessionTimelineRootDigest(root) || value.authority !== AUTHORITY
94
- || !Array.isArray(value.sources) || value.sources.length > MAX_SOURCES || value.sources.some((item) => !validSource(item))) {
95
- throw new Error("session timeline state is invalid");
96
- }
97
- return value;
98
- }
99
- function paths(root) { return sessionTimelineStatePaths(root); }
100
- function readState(path, root, assertStable) {
101
- return readTimelineState({ path, root, maximumBytes: MAX_STATE_BYTES, empty, validate, assertStable });
102
- }
103
- function saveState(state, path, assertOwned, root, assertStable) {
104
- return saveTimelineState({ state, path, root, maximumBytes: MAX_STATE_BYTES, assertOwned, assertStable });
105
- }
106
- function status(value, extra = {}) { return { schema: SESSION_TIMELINE_SCHEMA, ...value, ...extra, authority: AUTHORITY }; }
107
- function hasExactPrivateTimelineScope(scope) { return scope?.groupId === null; }
108
- function sourceFor(state, scope) { return state.sources.find((item) => sameTimelineBinding(item.binding, scope)) || null; }
109
- function sourceMetadata(source) {
110
- const sourceDigest = digest(`${source.pathDigest}\0${source.identity}\0${source.size}\0${source.mtimeNs}\0${source.ctimeNs}`);
111
- return { sourceDigest, indexedBytes: source.indexedBytes, size: source.size, events: source.events.length,
112
- rooms: Math.ceil(source.size / ROOM_BYTES), continuation: timelineContinuationCapsule({ source, sourceDigest, roomBytes: ROOM_BYTES, authority: AUTHORITY }) };
113
- }
114
- function sameSourceSnapshot(left, right) {
115
- return Boolean(left && right) && ["path", "profileRoot", "projectsRoot", "pathDigest", "identity", "size", "mtimeNs", "ctimeNs"]
116
- .every((key) => left[key] === right[key]);
117
- }
118
- async function confirmedSourceEnrollment({ root, scoped, source, hostHome }) {
119
- const enrollment = await resolvePrivateSessionTimelineEnrollment({ root, host: scoped.host, sessionId: scoped.sessionId,
120
- transcriptPath: source.path, hostHome });
121
- if (enrollment.status !== "enrolled" || !sameTimelineBinding(enrollment.binding, scoped)
122
- || !sameSourceSnapshot(enrollment.source, source)) return false;
123
- return true;
124
- }
125
- async function bootstrapEnrollment(root, enrollmentDigest, environment) {
126
- const loaded = await loadPrivateSessionTimelineEnrollment({ root, enrollmentDigest });
127
- if (loaded.status !== "loaded") return null;
128
- const transportDigest = timelineTransportDigest({
129
- root: loaded.rootPath, binding: loaded.record.binding, environment
130
- });
131
- return transportDigest && sameTimelineTransportDigest(loaded.record.transportDigest, transportDigest) ? loaded : null;
132
- }
133
- function enrolledSource(record, previous, now) {
134
- const source = record.source;
135
- const unchanged = previous && sameSourceSnapshot(previous, source);
136
- return {
137
- binding: record.binding, path: source.path, profileRoot: source.profileRoot, projectsRoot: source.projectsRoot,
138
- pathDigest: source.pathDigest, identity: source.identity, size: source.size, mtimeNs: source.mtimeNs,
139
- ctimeNs: source.ctimeNs, lessonDigest: unchanged ? previous.lessonDigest : null,
140
- indexedBytes: unchanged ? previous.indexedBytes : 0, events: unchanged ? previous.events : [],
141
- updatedAt: asDate(now).toISOString(), authority: AUTHORITY
142
- };
143
- }
144
- export async function bootstrapSessionTimelineEnrollment({
145
- root, enrollmentDigest, environment = process.env, now = new Date()
146
- }) {
147
- const loaded = await bootstrapEnrollment(root, enrollmentDigest, environment);
148
- if (!loaded) return status({ status: "unavailable", reason: "private-enrollment-unavailable" });
149
- const { rootPath, record } = loaded;
150
- try { await ensureSessionTimelineTrust({ create: true }); }
151
- catch { return status({ status: "unavailable", reason: "timeline-state-unavailable" }); }
152
- try {
153
- const names = await paths(rootPath);
154
- await withOwnedFileLock(names.lock, async ({ assertOwned }) => {
155
- const state = await readState(names.path, rootPath, names.assertStable);
156
- const previous = sourceFor(state, record.binding);
157
- if (previous && sameSourceSnapshot(previous, record.source)) return;
158
- state.sources = state.sources.filter((item) => !sameTimelineBinding(item.binding, record.binding));
159
- state.sources.unshift(enrolledSource(record, previous, now));
160
- state.sources = state.sources.slice(0, MAX_SOURCES);
161
- await saveState(state, names.path, assertOwned, rootPath, names.assertStable);
162
- }, { assertPath: names.assertStable });
163
- } catch { return status({ status: "unavailable", reason: "timeline-state-unavailable" }); }
164
- return status({ status: "registered", bootstrap: "signed-enrollment-metadata" });
165
- }
166
- export async function sessionTimelineLifecycleHint({
167
- root, host, sessionId, scope, environment = process.env
168
- }) {
169
- const scoped = sessionTimelineBinding({ host, sessionId, scope });
170
- if (!hasExactPrivateTimelineScope(scope)) return status({ status: "group-suppressed" });
171
- if (!completeTimelineBinding(scoped)) {
172
- return status({ status: "unavailable", reason: "timeline-scope-unverified" });
173
- }
174
- const loaded = await loadPrivateSessionTimelineEnrollment({ root, host, sessionId, scope });
175
- if (loaded.status !== "loaded") return status({ status: "unavailable", reason: "private-enrollment-unavailable" });
176
- const transportDigest = timelineTransportDigest({ root: loaded.rootPath, binding: loaded.record.binding, environment });
177
- if (!transportDigest || !sameTimelineTransportDigest(loaded.record.transportDigest, transportDigest)) {
178
- return status({ status: "unavailable", reason: "private-enrollment-unavailable" });
179
- }
180
- try {
181
- await ensureSessionTimelineTrust();
182
- const names = await paths(loaded.rootPath);
183
- const state = await readState(names.path, loaded.rootPath, names.assertStable);
184
- const source = sourceFor(state, scoped);
185
- if (!source) return status({ status: "unavailable", reason: "timeline-not-registered" });
186
- return status({ status: source.indexedBytes >= source.size ? "indexed" : "partial", ...sourceMetadata(source),
187
- priorSessions: priorTimelineHint(state, scoped, (item) => sourceMetadata(item).sourceDigest,
188
- { includePriorProviders: crossProviderTimelineEnabled(environment) }),
189
- freshness: "source-not-read", instruction: "Use session_timeline_index before search when this snapshot is partial." });
190
- } catch {
191
- return status({ status: "unavailable", reason: "timeline-state-unavailable" });
192
- }
193
- }
194
- export async function registerSessionTimelineSource() {
195
- return status({ status: "unavailable", reason: "timeline-enrollment-bootstrap-required" });
196
- }
197
- function mergeEvents(existing, additions) {
198
- const byId = new Map(existing.map((item) => [item.id, item]));
199
- for (const item of additions) byId.set(item.id, item);
200
- const ordered = [...byId.values()].sort((left, right) => left.at.localeCompare(right.at) || left.offset - right.offset);
201
- const evidence = ordered.filter((item) => item.kind !== "user-message-candidate").slice(-MAX_EVENTS);
202
- const available = Math.min(256, MAX_EVENTS - evidence.length);
203
- const feedback = ordered.filter((item) => item.kind === "user-message-candidate")
204
- .slice(available ? -available : ordered.length);
205
- return [...evidence, ...feedback].sort((left, right) => left.at.localeCompare(right.at) || left.offset - right.offset);
206
- }
207
- function parsedEvents(buffer, start, dropFirst = false, host = "claude", includeUserMessages = false) {
208
- const result = [];
209
- let index = 0;
210
- while (index < buffer.byteLength) {
211
- const newline = buffer.indexOf(0x0a, index);
212
- const end = newline < 0 ? buffer.byteLength : newline + 1;
213
- const line = buffer.subarray(index, end);
214
- if (!(dropFirst && index === 0) && line.byteLength) {
215
- const event = eventFromTimelineLine(line.toString("utf8"), start + index, AUTHORITY, host);
216
- if (event && (includeUserMessages || event.kind !== "user-message-candidate")) {
217
- if (event.kind === "explicit-next-step-correction") delete event.nextStepSummary;
218
- delete event.sourceText;
219
- result.push(event);
220
- }
221
- }
222
- index = end;
223
- }
224
- return result;
225
- }
226
- async function indexRange(source, start, maximum, hostHome = null) {
227
- const opened = await validatedHandle(source, hostHome);
228
- if (opened.status !== "open") return opened;
229
- try {
230
- if (start >= opened.size) return { status: "indexed", next: opened.size, events: [], size: opened.size };
231
- const bytes = await readRange(opened.handle, start, Math.min(maximum, opened.size - start));
232
- const last = bytes.lastIndexOf(0x0a);
233
- const completeAtEnd = start + bytes.byteLength === opened.size;
234
- if (last < 0 && !completeAtEnd) return { status: "partial-line", events: [], size: opened.size };
235
- const selected = last < 0 || completeAtEnd ? bytes : bytes.subarray(0, last + 1);
236
- const before = start > 0 ? await readRange(opened.handle, start - 1, 1) : Buffer.alloc(0);
237
- if (!await unchangedHandle(opened.handle, source, hostHome)) return { status: "unavailable", reason: "transcript-changed" };
238
- return { status: "indexed", next: start + selected.byteLength,
239
- events: parsedEvents(selected, start, start > 0 && before[0] !== 0x0a, source.binding.host,
240
- Boolean(source.binding.portalRef && source.binding.threadRef)), size: opened.size };
241
- } finally { await opened.handle.close(); }
242
- }
243
- async function mutateSource(root, scoped, task) {
244
- try { await ensureSessionTimelineTrust(); }
245
- catch { return status({ status: "unavailable", reason: "timeline-state-unavailable" }); }
246
- let names;
247
- try { names = await paths(root); }
248
- catch { return status({ status: "unavailable", reason: "timeline-state-unavailable" }); }
249
- return withOwnedFileLock(names.lock, async ({ assertOwned }) => {
250
- let state;
251
- try { state = await readState(names.path, root, names.assertStable); }
252
- catch { return status({ status: "unavailable", reason: "timeline-state-unavailable" }); }
253
- const source = sourceFor(state, scoped);
254
- if (!source) return status({ status: "unavailable", reason: "timeline-not-registered" });
255
- const result = await task(source);
256
- if (result.status === "indexed") {
257
- source.size = result.size;
258
- if (!result.preserveCursor) source.indexedBytes = Math.max(source.indexedBytes, result.next);
259
- source.events = mergeEvents(source.events, result.events); source.updatedAt = new Date().toISOString();
260
- await saveState(state, names.path, assertOwned, root, names.assertStable);
261
- }
262
- return result.status === "indexed" ? status({ status: source.indexedBytes >= source.size ? "indexed"
263
- : result.preserveCursor ? "fresh-tail" : "partial", ...sourceMetadata(source), added: result.events.length })
264
- : status(result);
265
- }, { assertPath: names.assertStable }).catch(() =>
266
- status({ status: "unavailable", reason: "timeline-state-unavailable" }));
267
- }
268
- export async function indexSessionTimeline({
269
- root, host, sessionId, scope, maxBytes = 4 * 1024 * 1024,
270
- invocationRequest = null, transportDigest = null, enrollmentDigest = null, hostHome = null
271
- }) {
272
- const scoped = sessionTimelineBinding({ host, sessionId, scope });
273
- if (!hasExactPrivateTimelineScope(scope)) return status({ status: "group-suppressed" });
274
- if (!hasVerifiedTimelinePrivateScope(scope)) return status({ status: "unavailable", reason: "timeline-scope-unverified" });
275
- if (!completeTimelineBinding(scoped)) return status({ status: "unavailable", reason: "missing-session-scope" });
276
- if (!Number.isInteger(maxBytes) || maxBytes < 64 * 1024 || maxBytes > MAX_INDEX_BYTES) throw new Error("timeline index byte budget is invalid");
277
- return mutateSource(root, scoped, async (source) => {
278
- if (!await confirmedSourceEnrollment({ root, scoped, source, hostHome })) {
279
- return { status: "unavailable", reason: "private-enrollment-unavailable" };
280
- }
281
- const sourceDigest = sourceMetadata(source).sourceDigest;
282
- if (!invocationRequest || !await timelineTransportEnrollmentMatches({ root, binding: scoped, enrollmentDigest, transportDigest, hostHome })
283
- || !await consumeSessionTimelineInvocation({ root, tool: "index", binding: scoped, sourceDigest,
284
- request: invocationRequest, transportDigest })) {
285
- return { status: "unavailable", reason: "timeline-invocation-unavailable" };
286
- }
287
- return indexRange(source, source.indexedBytes, maxBytes, hostHome);
288
- });
289
- }
290
- export async function refreshSessionTimelineTail() {
291
- return status({ status: "unavailable", reason: "timeline-mcp-index-required" });
292
- }
293
- export async function sessionTimelineStatus({ root, host, sessionId, scope, environment = process.env }) {
294
- if (!hasExactPrivateTimelineScope(scope)) return status({ status: "group-suppressed" });
295
- if (!hasVerifiedTimelinePrivateScope(scope)) return status({ status: "unavailable", reason: "timeline-scope-unverified" });
296
- return sessionTimelineLifecycleHint({ root, host, sessionId, scope, environment });
297
- }
298
- export async function authorizeSessionTimelineInvocation({
299
- root, host, sessionId, scope, hostHome, tool, request, toolUseId, transportDigest, enrollmentDigest,
300
- environment = process.env
301
- }) {
302
- const scoped = sessionTimelineBinding({ host, sessionId, scope });
303
- if (!hasExactPrivateTimelineScope(scope) || !completeTimelineBinding(scoped) || !/^(index|search|capture)$/.test(tool || "")) return null;
304
- if (!hasVerifiedTimelinePrivateScope(scope)) return null;
305
- try {
306
- await ensureSessionTimelineTrust();
307
- const names = await paths(root);
308
- const state = await readState(names.path, root, names.assertStable);
309
- const currentSource = sourceFor(state, scoped);
310
- if (!currentSource || !await pathMatchesSource(currentSource, hostHome)
311
- || !await confirmedSourceEnrollment({ root, scoped, source: currentSource, hostHome })) return null;
312
- const includePriorProviders = request?.includePriorProviders === true;
313
- if (includePriorProviders && (request?.includePriorSessions !== true || !crossProviderTimelineEnabled(environment))) return null;
314
- const query = tool !== "index" ? timelineQuery({ at: request?.at, query: request?.query }) : null;
315
- const source = request?.includePriorSessions === true
316
- ? selectPriorTimelineSource(state, scoped, { ...query, windowMs: request.windowSeconds * 1000,
317
- includePriorProviders, sessionRef: request?.ref }) : currentSource;
318
- const sourceHome = source?.binding.host === scoped.host ? hostHome : source?.profileRoot;
319
- if (!source || !await pathMatchesSource(source, sourceHome)
320
- || !await confirmedSourceEnrollment({ root, scoped: source.binding, source, hostHome: sourceHome })) return null;
321
- const sourceDigest = sourceMetadata(source).sourceDigest;
322
- if (!await timelineTransportEnrollmentMatches({ root, binding: scoped, enrollmentDigest, transportDigest, hostHome })) return null;
323
- await issueSessionTimelineInvocation({
324
- root, tool, binding: scoped, sourceDigest, request, toolUseId, transportDigest
325
- });
326
- return { sourceDigest, authority: AUTHORITY };
327
- } catch { return null; }
328
- }
329
- export async function reverifyTimelineFeedbackSources({
330
- root, host, sessionId, scope, references, includePriorProviders = false,
331
- environment = process.env, hostHome = null
332
- }) {
333
- const scoped = sessionTimelineBinding({ host, sessionId, scope });
334
- if (!completeTimelineBinding(scoped) || !hasVerifiedTimelinePrivateScope(scope)
335
- || !Array.isArray(references) || !references.length || references.length > 3
336
- || includePriorProviders && !crossProviderTimelineEnabled(environment)) return null;
337
- try {
338
- await ensureSessionTimelineTrust();
339
- const names = await paths(root);
340
- const state = await readState(names.path, root, names.assertStable);
341
- const fields = ["entityId", "userId", "tenantId", "projectId", "taskId", "groupId", "portalRef", "threadRef"];
342
- const eligible = state.sources.filter((source) => fields.every((key) =>
343
- (source.binding[key] ?? null) === (scoped[key] ?? null))
344
- && (includePriorProviders || source.binding.host === scoped.host));
345
- const verified = [];
346
- for (const reference of references) {
347
- const source = eligible.find((item) => item.binding.host === reference.sourceProvider
348
- && timelineSessionReference(item.binding) === reference.sessionRef
349
- && sourceMetadata(item).sourceDigest === reference.sourceDigest);
350
- const sourceHome = source?.binding.host === scoped.host ? hostHome : source?.profileRoot;
351
- const indexed = source?.events.find((item) => item.id === reference.eventId
352
- && item.sha256 === reference.messageDigest && item.at === reference.observedAt);
353
- if (!source || !indexed || reference.messageRef !== reference.eventId
354
- || !await confirmedSourceEnrollment({ root, scoped: source.binding, source, hostHome: sourceHome })) return null;
355
- const opened = await validatedHandle(source, sourceHome);
356
- if (opened.status !== "open") return null;
357
- try {
358
- const current = await verifyTimelineEvent({ handle: opened.handle, event: indexed, readRange, digest,
359
- eventFromLine: (line, offset) => verifiedTimelineEventFromLine(line, offset, AUTHORITY, source.binding.host) });
360
- if (!current || current.kind !== "user-message-candidate"
361
- || !await unchangedHandle(opened.handle, source, sourceHome)) return null;
362
- verified.push({ ...current, sourceDigest: reference.sourceDigest,
363
- sourceProvider: reference.sourceProvider, sessionRef: reference.sessionRef });
364
- } finally { await opened.handle.close(); }
365
- }
366
- return verified;
367
- } catch { return null; }
368
- }
369
- function searchResult(source, target, wanted, mode, events, extra = {}, includeMessageDigest = false) {
370
- const index = sourceMetadata(source);
371
- return timelineSearchResult({ sourceDigest: index.sourceDigest, sessionRef: timelineSessionReference(source.binding),
372
- sourceProvider: source.binding.host, binding: source.binding, target, wanted, mode, events, index,
373
- roomBytes: ROOM_BYTES, authority: AUTHORITY, extra, includeMessageDigest });
374
- }
375
- export async function searchSessionTimeline({
376
- root, host, sessionId, scope, at, query, windowSeconds = undefined,
377
- includePriorSessions = false, includePriorProviders = false, environment = process.env,
378
- invocationRequest = null, invocationTool = "search", transportDigest = null, enrollmentDigest = null, hostHome = null
379
- }) {
380
- const scoped = sessionTimelineBinding({ host, sessionId, scope });
381
- if (!hasExactPrivateTimelineScope(scope) || !hasVerifiedTimelinePrivateScope(scope) || !completeTimelineBinding(scoped)) {
382
- return { blocked: true, reason: "session timeline scope is unavailable", authority: AUTHORITY };
383
- }
384
- const { target, wanted } = timelineQuery({ at, query });
385
- const boundedWindowSeconds = windowSeconds === undefined ? 0 : windowSeconds;
386
- if (!Number.isInteger(boundedWindowSeconds) || boundedWindowSeconds < 0 || boundedWindowSeconds > 900) {
387
- throw new Error("timeline window is invalid");
388
- }
389
- if (typeof includePriorSessions !== "boolean") throw new Error("prior session selection is invalid");
390
- if (typeof includePriorProviders !== "boolean") throw new Error("prior provider selection is invalid");
391
- if (includePriorProviders && (!includePriorSessions || !crossProviderTimelineEnabled(environment))) {
392
- return { blocked: true, reason: "cross-provider timeline recall is unavailable", authority: AUTHORITY };
393
- }
394
- try { await ensureSessionTimelineTrust(); }
395
- catch { return { blocked: true, reason: "session timeline is unavailable", authority: AUTHORITY }; }
396
- let names; let state;
397
- try {
398
- names = await paths(root);
399
- state = await readState(names.path, root, names.assertStable);
400
- }
401
- catch { return { blocked: true, reason: "session timeline is unavailable", authority: AUTHORITY }; }
402
- const currentSource = sourceFor(state, scoped);
403
- if (!currentSource) return { blocked: true, reason: "session timeline is unavailable", authority: AUTHORITY };
404
- if (!await confirmedSourceEnrollment({ root, scoped, source: currentSource, hostHome })) {
405
- return { blocked: true, reason: "session timeline is unavailable", authority: AUTHORITY };
406
- }
407
- const source=includePriorSessions
408
- ?selectPriorTimelineSource(state,scoped,{target,wanted,windowMs:boundedWindowSeconds*1000,
409
- includePriorProviders,sessionRef:invocationRequest?.ref})
410
- : currentSource;
411
- const sourceHome=source?.binding.host===scoped.host?hostHome:source?.profileRoot;
412
- if(!source||!await pathMatchesSource(source,sourceHome)
413
- ||!await confirmedSourceEnrollment({root,scoped:source.binding,source,hostHome:sourceHome})) {
414
- return { blocked: true, reason: "session timeline is unavailable", authority: AUTHORITY };
415
- }
416
- const sourceDigest=sourceMetadata(source).sourceDigest;
417
- if(!/^(search|capture)$/.test(invocationTool)||!invocationRequest
418
- ||!await timelineTransportEnrollmentMatches({root,binding:scoped,enrollmentDigest,transportDigest,hostHome})
419
- ||!await consumeSessionTimelineInvocation({root,tool:invocationTool,binding:scoped,sourceDigest,
420
- request:invocationRequest,transportDigest})) {
421
- return { blocked: true, reason: "session timeline invocation is unavailable", authority: AUTHORITY };
422
- }
423
- const matchAt=invocationRequest?.ref&&target&&query==="user message"?null:target;
424
- const indexed=rankTimelineEvents(source.events
425
- .filter(event=>matchesTimelineEvent(event,wanted,matchAt,boundedWindowSeconds*1000)),wanted,target).slice(0,8);
426
- if (includePriorSessions && !indexed.length) {
427
- return searchResult(source, target, wanted, "prior-index", [], { priorSession: true,
428
- priorProvider: source.binding.host !== scoped.host }, invocationTool === "capture");
429
- }
430
- const opened = await validatedHandle(source, sourceHome);
431
- if (opened.status !== "open") return { blocked: true, reason: opened.reason, authority: AUTHORITY };
432
- try {
433
- const verified = [];
434
- for (const event of indexed) {
435
- const current = await verifyTimelineEvent({ handle: opened.handle, event, readRange, digest,
436
- eventFromLine: (line, offset) => verifiedTimelineEventFromLine(line, offset, AUTHORITY, source.binding.host) });
437
- if(!current||!matchesTimelineEvent(current,wanted,matchAt,boundedWindowSeconds*1000)) return { blocked: true, reason: "timeline evidence changed", authority: AUTHORITY };
438
- verified.push(current);
439
- }
440
- if (verified.length) {
441
- if (!await unchangedHandle(opened.handle, source, sourceHome)) return { blocked: true, reason: "transcript-changed", authority: AUTHORITY };
442
- return searchResult(source, target, wanted, includePriorSessions ? "prior-verified-index" : "verified-index", verified,
443
- includePriorSessions ? { priorSession: true, priorProvider: source.binding.host !== scoped.host } : {},
444
- invocationTool === "capture");
445
- }
446
- if (!target) return searchResult(source, target, wanted, "verified-index", [], {}, invocationTool === "capture");
447
- const sought = await seekTimelineEvidence({ handle: opened.handle, size: opened.size, target, wanted,
448
- windowMs: boundedWindowSeconds * 1000, readRange,
449
- eventFromLine: (line, offset) => verifiedTimelineEventFromLine(line, offset, AUTHORITY, source.binding.host),
450
- extractTimestamp: extractTimelineTimestamp,
451
- matches: matchesTimelineEvent, rank: rankTimelineEvents });
452
- if (sought.status === "searched") {
453
- if (!await unchangedHandle(opened.handle, source, sourceHome)) return { blocked: true, reason: "transcript-changed", authority: AUTHORITY };
454
- return searchResult(source, target, wanted, "timestamp-seek", sought.events,
455
- { budgetExhausted: sought.budgetExhausted }, invocationTool === "capture");
456
- }
457
- if (sought.status === "out-of-range") {
458
- return searchResult(source, target, wanted, "timestamp-seek", [], {}, invocationTool === "capture");
459
- }
460
- return { blocked: true, reason: sought.reason, authority: AUTHORITY };
461
- } finally { await opened.handle.close(); }
462
- }