@temmo/cli 0.0.0-stage → 0.19.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 (445) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.claude-plugin/plugin.json +16 -0
  3. package/.codex-plugin/plugin.json +30 -0
  4. package/.cursor-plugin/plugin.json +22 -0
  5. package/.mcp.json +18 -0
  6. package/LICENSE +202 -0
  7. package/README.md +82 -2
  8. package/THIRD_PARTY_NOTICES +32 -0
  9. package/commands/afk.md +17 -0
  10. package/deploy/build-ui.mjs +65 -0
  11. package/deploy/claude/README.md +16 -0
  12. package/deploy/claude/auto-mode.json +31 -0
  13. package/deploy/postgres/compose.yaml +26 -0
  14. package/deploy/temmo-runner.service +24 -0
  15. package/deploy/verify-ui.mjs +15 -0
  16. package/harness-core/README.md +27 -0
  17. package/harness-core/bin/harness.mjs +17 -0
  18. package/harness-core/package.json +10 -0
  19. package/harness-core/stage.mjs +108 -0
  20. package/harness-core/stages/commit.md +7 -0
  21. package/harness-core/stages/pr.md +7 -0
  22. package/harness-core/stages/push.md +7 -0
  23. package/hooks/codex-hooks.json +14 -0
  24. package/hooks/cursor-hooks.json +17 -0
  25. package/hooks/hooks.json +27 -0
  26. package/lib/acp/permission.js +72 -0
  27. package/lib/acp/sessionConfig.js +109 -0
  28. package/lib/activity.js +244 -0
  29. package/lib/agent-guard.js +72 -0
  30. package/lib/agents-route.js +55 -0
  31. package/lib/agents.js +213 -0
  32. package/lib/agui.js +255 -0
  33. package/lib/alerts.js +36 -0
  34. package/lib/analyze-otlp.js +46 -0
  35. package/lib/analyze-run-code.js +397 -0
  36. package/lib/analyze-sources.js +372 -0
  37. package/lib/approval-card.js +54 -0
  38. package/lib/approval-cli.js +53 -0
  39. package/lib/approval-request.js +81 -0
  40. package/lib/approval-signer.js +48 -0
  41. package/lib/approvals.js +295 -0
  42. package/lib/attachment-cache.js +236 -0
  43. package/lib/attachment.js +63 -0
  44. package/lib/blocked.js +20 -0
  45. package/lib/build-review.js +90 -0
  46. package/lib/builder/cli.js +90 -0
  47. package/lib/builder/policy.js +176 -0
  48. package/lib/builder/recover.js +189 -0
  49. package/lib/builder/run.js +240 -0
  50. package/lib/builder/settle.js +198 -0
  51. package/lib/builder/stage.js +240 -0
  52. package/lib/builder/state.js +73 -0
  53. package/lib/builder/supervisor.js +289 -0
  54. package/lib/builder-clean.js +223 -0
  55. package/lib/builder-code.cjs +67 -0
  56. package/lib/builder.js +9 -0
  57. package/lib/bus-postgres.js +281 -0
  58. package/lib/bus.js +349 -0
  59. package/lib/catalog/author.js +278 -0
  60. package/lib/catalog/dot.js +426 -0
  61. package/lib/catalog/pattern-model.js +193 -0
  62. package/lib/catalog/patterns.js +324 -0
  63. package/lib/catalog/projects.js +83 -0
  64. package/lib/catalog/records.js +2 -0
  65. package/lib/catalog/roster.js +70 -0
  66. package/lib/catalog/team-files.js +49 -0
  67. package/lib/catalog/teams.js +109 -0
  68. package/lib/claude-socket.js +333 -0
  69. package/lib/cli.js +741 -0
  70. package/lib/code-mode.js +45 -0
  71. package/lib/code-read-policy.yaml +9 -0
  72. package/lib/code-run.js +461 -0
  73. package/lib/codex-compact.js +141 -0
  74. package/lib/compaction.js +21 -0
  75. package/lib/config.js +424 -0
  76. package/lib/cursor-trace.js +248 -0
  77. package/lib/deep-link.js +20 -0
  78. package/lib/deliver-push.js +120 -0
  79. package/lib/delivery.js +28 -0
  80. package/lib/deploy-tree.js +227 -0
  81. package/lib/durable.js +404 -0
  82. package/lib/factory-tick.js +32 -0
  83. package/lib/family.js +63 -0
  84. package/lib/fetch-origin.js +53 -0
  85. package/lib/format.js +133 -0
  86. package/lib/harness-surface-cli.js +153 -0
  87. package/lib/harness-surface.js +486 -0
  88. package/lib/harness.js +271 -0
  89. package/lib/hook.mjs +291 -0
  90. package/lib/idle.js +40 -0
  91. package/lib/install-cursor.js +115 -0
  92. package/lib/install-opencode.js +105 -0
  93. package/lib/job.js +82 -0
  94. package/lib/land-cli.js +319 -0
  95. package/lib/land-member.js +64 -0
  96. package/lib/land.js +320 -0
  97. package/lib/lessons.js +223 -0
  98. package/lib/limit-alert.js +423 -0
  99. package/lib/limits.js +284 -0
  100. package/lib/machine-prompt.js +19 -0
  101. package/lib/merge-sweep.js +149 -0
  102. package/lib/messaging.js +1002 -0
  103. package/lib/mission-cli.js +103 -0
  104. package/lib/mission.js +241 -0
  105. package/lib/mode.js +215 -0
  106. package/lib/models.js +114 -0
  107. package/lib/names.js +86 -0
  108. package/lib/opencode-api.js +57 -0
  109. package/lib/opencode-plugin.mjs +313 -0
  110. package/lib/operator-token.js +78 -0
  111. package/lib/operator.js +187 -0
  112. package/lib/pad-activity.js +143 -0
  113. package/lib/pad-fresh.js +44 -0
  114. package/lib/pad.js +198 -0
  115. package/lib/pattern-cli.js +120 -0
  116. package/lib/pattern-compiler.js +68 -0
  117. package/lib/pattern-runs.js +795 -0
  118. package/lib/pattern-stall.js +58 -0
  119. package/lib/pattern-tick.js +45 -0
  120. package/lib/pattern-workflow.js +69 -0
  121. package/lib/pi-extension.mjs +98 -0
  122. package/lib/pi.js +57 -0
  123. package/lib/plugin-copy.js +76 -0
  124. package/lib/pm-review.js +32 -0
  125. package/lib/pm-workspace.js +87 -0
  126. package/lib/postgres.js +115 -0
  127. package/lib/pr-card.js +34 -0
  128. package/lib/probe.js +295 -0
  129. package/lib/process.js +67 -0
  130. package/lib/project-pause.js +23 -0
  131. package/lib/prune.js +793 -0
  132. package/lib/questions.js +250 -0
  133. package/lib/receipts.js +63 -0
  134. package/lib/reflect.js +962 -0
  135. package/lib/rename-migration.js +118 -0
  136. package/lib/run-terminal.js +437 -0
  137. package/lib/runner-request.js +33 -0
  138. package/lib/sandbox-app.js +120 -0
  139. package/lib/sandbox-claims.js +258 -0
  140. package/lib/sandbox-cli.js +188 -0
  141. package/lib/sandbox-hosts-cli.js +68 -0
  142. package/lib/sandbox-hosts.js +94 -0
  143. package/lib/sandbox-pr.js +102 -0
  144. package/lib/sandbox-proposal.js +367 -0
  145. package/lib/sandbox-tools.js +143 -0
  146. package/lib/sandbox.js +501 -0
  147. package/lib/schedule-session.js +68 -0
  148. package/lib/session-activity.js +67 -0
  149. package/lib/session-events.js +94 -0
  150. package/lib/sessions/control.js +244 -0
  151. package/lib/sessions/git-refs.js +265 -0
  152. package/lib/sessions/launch.js +359 -0
  153. package/lib/sessions/registry.js +450 -0
  154. package/lib/sessions/scope.js +111 -0
  155. package/lib/setup.js +377 -0
  156. package/lib/signed-approval.js +225 -0
  157. package/lib/slash.js +167 -0
  158. package/lib/spawn-cli.js +45 -0
  159. package/lib/spawn.js +107 -0
  160. package/lib/start-limit.js +58 -0
  161. package/lib/state.js +24 -0
  162. package/lib/stop.js +308 -0
  163. package/lib/store-read.js +62 -0
  164. package/lib/store.js +252 -0
  165. package/lib/subagent-guard.js +240 -0
  166. package/lib/surfaces/channel-post.js +43 -0
  167. package/lib/surfaces/instructions.js +15 -0
  168. package/lib/surfaces/mcp-reload.js +144 -0
  169. package/lib/surfaces/ops.js +629 -0
  170. package/lib/surfaces/render-mcp.js +33 -0
  171. package/lib/surfaces/run-terminal-ops.js +40 -0
  172. package/lib/surfaces/sandbox-ops.js +36 -0
  173. package/lib/surfaces/schema.js +7 -0
  174. package/lib/surfaces/task-view.js +90 -0
  175. package/lib/surfaces/types.js +4 -0
  176. package/lib/task-cli.js +274 -0
  177. package/lib/task-order.js +34 -0
  178. package/lib/task-order.mjs +2 -0
  179. package/lib/task-route.js +125 -0
  180. package/lib/tasks.js +631 -0
  181. package/lib/team-permission.js +34 -0
  182. package/lib/team-templates/blitz/team.dot +9 -0
  183. package/lib/team-templates/factory/team.dot +26 -0
  184. package/lib/team-templates/feature/team.dot +14 -0
  185. package/lib/team-templates/fix-and-review/team.dot +12 -0
  186. package/lib/team-templates/product/team.dot +16 -0
  187. package/lib/team-templates/release/team.dot +7 -0
  188. package/lib/team-templates/review/team.dot +6 -0
  189. package/lib/terminal-draft.js +42 -0
  190. package/lib/thread-branch.js +82 -0
  191. package/lib/thread-channel-store.js +181 -0
  192. package/lib/thread-channels.js +116 -0
  193. package/lib/thread-listening.js +20 -0
  194. package/lib/thread-routes.js +91 -0
  195. package/lib/threads.js +441 -0
  196. package/lib/tool-api.js +33 -0
  197. package/lib/transcript.js +98 -0
  198. package/lib/ui-build-output.js +19 -0
  199. package/lib/ui-capabilities.js +90 -0
  200. package/lib/usage.js +182 -0
  201. package/lib/vendor/mcp-sdk.d.mts +4 -0
  202. package/lib/vendor/mcp-sdk.mjs +17046 -0
  203. package/lib/waiter.js +127 -0
  204. package/lib/workflows.js +546 -0
  205. package/lib/worktree-setup.js +86 -0
  206. package/package.json +110 -4
  207. package/runner/adapters/claude.js +465 -0
  208. package/runner/adapters/cli-sandbox.js +277 -0
  209. package/runner/adapters/codex.js +675 -0
  210. package/runner/adapters/cursor.mjs +937 -0
  211. package/runner/adapters/fake.js +119 -0
  212. package/runner/adapters/opencode-sandbox.js +370 -0
  213. package/runner/adapters/opencode.js +486 -0
  214. package/runner/adapters/pi-sandbox.js +134 -0
  215. package/runner/adapters/pi.js +364 -0
  216. package/runner/client.js +40 -0
  217. package/runner/contract.js +129 -0
  218. package/runner/control.js +178 -0
  219. package/runner/delivery.js +184 -0
  220. package/runner/factory-tick.mjs +10 -0
  221. package/runner/lock.js +41 -0
  222. package/runner/main.mjs +118 -0
  223. package/runner/pattern-tick.mjs +16 -0
  224. package/runner/publish.js +113 -0
  225. package/runner/runner.js +2612 -0
  226. package/runner/sandbox-run.mjs +239 -0
  227. package/runner/schedules.js +294 -0
  228. package/runner/task-wake.js +59 -0
  229. package/scripts/ai-collab +3 -0
  230. package/scripts/ai-collab-bus.mjs +4 -0
  231. package/scripts/ai-collab-code-mcp.mjs +3 -0
  232. package/scripts/ai-collab-hook +3 -0
  233. package/scripts/ai-collab-hook.mjs +3 -0
  234. package/scripts/ai-collab-mcp-tools.mjs +2 -0
  235. package/scripts/ai-collab-mcp.mjs +3 -0
  236. package/scripts/ai-collab.mjs +3 -0
  237. package/scripts/install-cursor.mjs +11 -0
  238. package/scripts/install-opencode.mjs +10 -0
  239. package/scripts/temmo +3 -0
  240. package/scripts/temmo-bus.mjs +151 -0
  241. package/scripts/temmo-code-mcp.mjs +63 -0
  242. package/scripts/temmo-hook +3 -0
  243. package/scripts/temmo-hook.mjs +201 -0
  244. package/scripts/temmo-mcp-tools.mjs +22 -0
  245. package/scripts/temmo-mcp.mjs +27 -0
  246. package/scripts/temmo.mjs +4 -0
  247. package/skills/antislop/SKILL.md +701 -0
  248. package/skills/antislop/VERSION +1 -0
  249. package/skills/antislop-code/SKILL.md +128 -0
  250. package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
  251. package/skills/antislop-human/SKILL.md +204 -0
  252. package/skills/antislop-human/contrast-check.py +168 -0
  253. package/skills/antislop-human/contrast-mcp.py +125 -0
  254. package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
  255. package/skills/antislop-human/references/WCAG.md +127 -0
  256. package/skills/antislop-layoutmobile/SKILL.md +170 -0
  257. package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
  258. package/skills/antislop-ui/SKILL.md +351 -0
  259. package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
  260. package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
  261. package/skills/harness-surface/SKILL.md +42 -0
  262. package/skills/land/SKILL.md +32 -0
  263. package/skills/memory-file/SKILL.md +39 -0
  264. package/skills/temmo/SKILL.md +101 -0
  265. package/skills/temmo/references/role-programs.md +47 -0
  266. package/skills/ui-sdk/SKILL.md +56 -0
  267. package/skills/ui-sdk/references/agent-ready.md +136 -0
  268. package/skills/ui-sdk/references/build-interface.md +187 -0
  269. package/skills/ui-sdk/references/create-component.md +88 -0
  270. package/skills/ui-sdk/references/patterns.md +246 -0
  271. package/skills/ui-sdk/references/styles.md +66 -0
  272. package/skills/ui-sdk/references/testing.md +172 -0
  273. package/skills/ui-sdk/references/web-components.md +78 -0
  274. package/tools/screen-state.mjs +119 -0
  275. package/tools/smoke-ui.mjs +540 -0
  276. package/web/app/activity.jsx +251 -0
  277. package/web/app/agent-mark.tsx +43 -0
  278. package/web/app/alert-level.jsx +16 -0
  279. package/web/app/api/[action]/route.js +8 -0
  280. package/web/app/api/auth/[step]/route.js +12 -0
  281. package/web/app/api/events/route.js +8 -0
  282. package/web/app/api/file/[name]/route.js +8 -0
  283. package/web/app/api/land/route.js +12 -0
  284. package/web/app/api/lessons/route.js +8 -0
  285. package/web/app/api/push/key/route.js +8 -0
  286. package/web/app/api/push/subscribe/route.js +12 -0
  287. package/web/app/api/push/test/route.js +8 -0
  288. package/web/app/api/refs/route.js +8 -0
  289. package/web/app/api/review-diff/route.js +8 -0
  290. package/web/app/api/schedules/route.js +8 -0
  291. package/web/app/api/thread-diff/route.js +8 -0
  292. package/web/app/api/version/route.js +6 -0
  293. package/web/app/cards.jsx +189 -0
  294. package/web/app/chat-api.js +82 -0
  295. package/web/app/chat-composer.jsx +313 -0
  296. package/web/app/chat-console.jsx +691 -0
  297. package/web/app/chat-image.tsx +61 -0
  298. package/web/app/chat-message.jsx +122 -0
  299. package/web/app/chat-shared.jsx +59 -0
  300. package/web/app/chat-sidebar.jsx +25 -0
  301. package/web/app/chat-stream.js +127 -0
  302. package/web/app/chat.jsx +31 -0
  303. package/web/app/compactions.jsx +57 -0
  304. package/web/app/composer-actions.tsx +87 -0
  305. package/web/app/decisions.jsx +53 -0
  306. package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
  307. package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
  308. package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
  309. package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  310. package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  311. package/web/app/globals.css +199 -0
  312. package/web/app/home.jsx +246 -0
  313. package/web/app/icon.svg +1 -0
  314. package/web/app/land-panel.jsx +63 -0
  315. package/web/app/land-reviews.jsx +20 -0
  316. package/web/app/layout.jsx +17 -0
  317. package/web/app/lessons.tsx +76 -0
  318. package/web/app/logo.tsx +13 -0
  319. package/web/app/logos.jsx +16 -0
  320. package/web/app/manifest.js +8 -0
  321. package/web/app/mode-menu.tsx +46 -0
  322. package/web/app/new-session.jsx +275 -0
  323. package/web/app/notify.jsx +180 -0
  324. package/web/app/outcomes.tsx +94 -0
  325. package/web/app/page.jsx +9 -0
  326. package/web/app/pattern-graph.jsx +75 -0
  327. package/web/app/patterns-page.jsx +293 -0
  328. package/web/app/phone-nav.tsx +36 -0
  329. package/web/app/progress-feed.tsx +33 -0
  330. package/web/app/providers.tsx +27 -0
  331. package/web/app/quote.jsx +15 -0
  332. package/web/app/run-card.tsx +200 -0
  333. package/web/app/run-requests.tsx +148 -0
  334. package/web/app/scheduled.jsx +105 -0
  335. package/web/app/session-panel.tsx +174 -0
  336. package/web/app/session-toolbar.tsx +180 -0
  337. package/web/app/shadcn.css +638 -0
  338. package/web/app/shipped.jsx +49 -0
  339. package/web/app/subagent-runs.jsx +31 -0
  340. package/web/app/task-graph.jsx +67 -0
  341. package/web/app/tasks-strip.tsx +36 -0
  342. package/web/app/tasks.jsx +375 -0
  343. package/web/app/team-author.jsx +145 -0
  344. package/web/app/team-editor.jsx +88 -0
  345. package/web/app/thread-agents.tsx +32 -0
  346. package/web/app/thread-place.tsx +9 -0
  347. package/web/app/thread-sessions.tsx +149 -0
  348. package/web/app/thread-sidebar.tsx +418 -0
  349. package/web/app/thread-switcher.tsx +27 -0
  350. package/web/app/tool-diff.jsx +94 -0
  351. package/web/components/a2ui/controls.jsx +36 -0
  352. package/web/components/a2ui/option-picker.jsx +23 -0
  353. package/web/components/a2ui/script.tsx +121 -0
  354. package/web/components/a2ui/surface.jsx +81 -0
  355. package/web/components/chat/thread.jsx +50 -0
  356. package/web/components/script-text.tsx +42 -0
  357. package/web/components/ui/avatar.jsx +115 -0
  358. package/web/components/ui/badge.jsx +47 -0
  359. package/web/components/ui/button.jsx +63 -0
  360. package/web/components/ui/chat-container.jsx +52 -0
  361. package/web/components/ui/choice-list.tsx +72 -0
  362. package/web/components/ui/code-block.jsx +60 -0
  363. package/web/components/ui/copy-button.tsx +41 -0
  364. package/web/components/ui/dropdown-menu.jsx +257 -0
  365. package/web/components/ui/markdown.jsx +84 -0
  366. package/web/components/ui/message.jsx +28 -0
  367. package/web/components/ui/popover.jsx +33 -0
  368. package/web/components/ui/scroll-button.jsx +34 -0
  369. package/web/components/ui/select.jsx +189 -0
  370. package/web/components/ui/sheet.jsx +152 -0
  371. package/web/components/ui/sonner.jsx +10 -0
  372. package/web/components/ui/tabs.jsx +88 -0
  373. package/web/components/ui/textarea.jsx +20 -0
  374. package/web/components/ui/tooltip.jsx +56 -0
  375. package/web/components.json +24 -0
  376. package/web/instrumentation.js +8 -0
  377. package/web/lib/a2ui-catalog.js +34 -0
  378. package/web/lib/a2ui-pr.js +76 -0
  379. package/web/lib/a2ui-run-catalog.js +18 -0
  380. package/web/lib/a2ui-run.js +93 -0
  381. package/web/lib/a2ui.js +262 -0
  382. package/web/lib/activity-rows.js +275 -0
  383. package/web/lib/agent-detail.js +5 -0
  384. package/web/lib/alert-level.js +44 -0
  385. package/web/lib/approval-mode.js +22 -0
  386. package/web/lib/chat-turns.js +174 -0
  387. package/web/lib/child-subagents.js +16 -0
  388. package/web/lib/compaction-view.js +48 -0
  389. package/web/lib/composer-actions.js +40 -0
  390. package/web/lib/context-view.js +57 -0
  391. package/web/lib/fuzzy.js +26 -0
  392. package/web/lib/highlight.js +44 -0
  393. package/web/lib/lessons-view.js +23 -0
  394. package/web/lib/mentions.js +16 -0
  395. package/web/lib/message-routing.js +105 -0
  396. package/web/lib/new-session.js +85 -0
  397. package/web/lib/operator-messages.js +28 -0
  398. package/web/lib/pattern-graph.js +165 -0
  399. package/web/lib/pattern-view.js +33 -0
  400. package/web/lib/pending-summary.js +18 -0
  401. package/web/lib/permission-modes.js +30 -0
  402. package/web/lib/project-feed.js +107 -0
  403. package/web/lib/quote.js +7 -0
  404. package/web/lib/reply-quote.js +31 -0
  405. package/web/lib/scheduled.js +79 -0
  406. package/web/lib/selection.js +110 -0
  407. package/web/lib/send-confirmation.js +22 -0
  408. package/web/lib/session-dead.js +10 -0
  409. package/web/lib/session-state.js +132 -0
  410. package/web/lib/sidebar.js +15 -0
  411. package/web/lib/slash-commands.js +164 -0
  412. package/web/lib/start-default.js +35 -0
  413. package/web/lib/start-mode.js +35 -0
  414. package/web/lib/stream-views.js +49 -0
  415. package/web/lib/subagent-state.js +20 -0
  416. package/web/lib/task-board.js +54 -0
  417. package/web/lib/task-graph.js +183 -0
  418. package/web/lib/task-tags.js +41 -0
  419. package/web/lib/team-editor.js +10 -0
  420. package/web/lib/thread-groups.js +86 -0
  421. package/web/lib/threads.js +28 -0
  422. package/web/lib/tool-diff.js +273 -0
  423. package/web/lib/ui-events.js +58 -0
  424. package/web/lib/utils.js +5 -0
  425. package/web/lib/view-memory.js +25 -0
  426. package/web/next.config.mjs +37 -0
  427. package/web/postcss.config.mjs +1 -0
  428. package/web/proxy.js +25 -0
  429. package/web/public/sw.js +39 -0
  430. package/web/server/auth.js +178 -0
  431. package/web/server/dispatch.js +293 -0
  432. package/web/server/history.js +56 -0
  433. package/web/server/hosted.js +58 -0
  434. package/web/server/hub.js +126 -0
  435. package/web/server/instance.js +5 -0
  436. package/web/server/land-reviews.js +64 -0
  437. package/web/server/push.js +148 -0
  438. package/web/server/run-terminal.js +79 -0
  439. package/web/server/schedules.js +38 -0
  440. package/web/server/shipped.js +51 -0
  441. package/web/server/task-board.js +71 -0
  442. package/web/server/threads.js +209 -0
  443. package/web/server/ui.js +2937 -0
  444. package/web/tsconfig.base.json +16 -0
  445. package/web/tsconfig.json +9 -0
@@ -0,0 +1,486 @@
1
+ /**
2
+ * Editable Harness² surfaces for a project (docs/harness-improvement.md), at standard paths inside
3
+ * the project root: `AGENTS.local.md` (system overlay), `.ai-collab/memory/` (OKF bundle),
4
+ * `.ai-collab/tool-guidance.md`, `.ai-collab/scripts/` and `.agents/skills/`. Memory is an OKF
5
+ * bundle (Open Knowledge Format v0.3): `memory/index.md` catalogs one-fact-per-file concepts whose
6
+ * YAML frontmatter requires only `type`. SessionStart injects a capped note; overlay, memory and
7
+ * tool-guidance edits take effect on the next UserPromptSubmit (and on the next start).
8
+ * Regenerating notes never invents content beyond stubs.
9
+ */
10
+ import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
11
+ import { dirname, join } from "node:path";
12
+ import { writeFileAtomic } from "./store.js";
13
+ export const SURFACE_TAG = "temmo-harness";
14
+ export const ALWAYS_ON = ["AGENTS.local.md", "memory/index.md", "tool-guidance.md"];
15
+ export const SURFACE_NOTE_MAX = 4_000;
16
+ export const ALWAYS_ON_NOTE_MAX = 2_400;
17
+ export const FILE_MAX_CHARS = 12_000;
18
+ const NAME_RE = /^[a-z0-9][a-z0-9_-]*$/;
19
+ // OKF reserves index.md and log.md at any level: they organize a bundle, they are not concepts.
20
+ const MEMORY_CONCEPT = /^memory\/(?!index\.md$|log\.md$)([a-z0-9][a-z0-9_-]*)\.md$/;
21
+ const STUBS = {
22
+ "AGENTS.local.md": "<!-- c1: project system prompt overlay. Edits apply on the next turn. -->\n",
23
+ "memory/index.md": "---\nokf_version: \"0.3\"\ntitle: Project memory\ndescription: Durable project facts as OKF concepts, one verified fact per file.\n---\n\n<!-- c3: durable project facts. memory/ is an OKF bundle: one fact per file as memory/<name>.md with YAML frontmatter whose only required key is type; add title, description, tags, sources, verified or stale_after when they help. Keep this index current: * [Title](file.md) - one-line summary, or file a fact in one call with harness_surface action=memory_add. -->\n",
24
+ "tool-guidance.md": "<!-- c4: tool parameter contracts and failure-avoidance tips. -->\n",
25
+ "skills/README.md": "<!-- c6: skills as skills/<name>/SKILL.md with YAML name + description. -->\n",
26
+ "scripts/README.md": "<!-- c7: deterministic helpers as scripts/<name>.mjs; run with node. -->\n",
27
+ };
28
+ // The surface is project knowledge: commit it. Runtime artifacts stay local, in these defaults.
29
+ // surface-log.jsonl is ignored because the reflector appends to it on the deployed host: a tracked,
30
+ // always-dirty file would make auto-deploy skip its pull.
31
+ const GITIGNORE_DEFAULT = "# temmo surface defaults: runtime history and the edit log stay local; the rest is project knowledge — commit it.\n.history/\nsurface-log.jsonl\n";
32
+ /**
33
+ * The surface edit log (MemPro's evaluation log, docs/harness-improvement.md): one JSON line per
34
+ * edit or verdict, appended on every write. Edits record op/path/by/note; reflector verdicts record
35
+ * op="verdict" with the path, verdict and evidence, so an edit accumulates hit/miss evidence.
36
+ */
37
+ export const SURFACE_LOG = "surface-log.jsonl";
38
+ /** Log ops that record an edit (as opposed to a verdict about one). */
39
+ export const SURFACE_EDIT_OPS = new Set(["write", "memory_add", "memory_edit", "restore"]);
40
+ /** Previous bodies kept per surface file under .history/. */
41
+ const HISTORY_KEEP = 20;
42
+ /** Appends one line to the surface edit log; a failed append never fails the edit it records. */
43
+ export function logSurfaceEdit(root, entry) {
44
+ if (!root)
45
+ return;
46
+ try {
47
+ mkdirSync(join(root, ".ai-collab"), { recursive: true, mode: 0o700 });
48
+ appendFileSync(join(root, ".ai-collab", SURFACE_LOG), `${JSON.stringify(entry)}\n`);
49
+ }
50
+ catch { /* the log is evidence when it can be */ }
51
+ }
52
+ /** The last `limit` log entries, oldest first; unreadable lines are skipped. */
53
+ export function readSurfaceLog(root, limit = 50) {
54
+ let text = "";
55
+ try {
56
+ text = readFileSync(join(root, ".ai-collab", SURFACE_LOG), "utf8");
57
+ }
58
+ catch {
59
+ return [];
60
+ }
61
+ const entries = text
62
+ .split("\n")
63
+ .filter((line) => line.trim())
64
+ .map((line) => { try {
65
+ return JSON.parse(line);
66
+ }
67
+ catch {
68
+ return null;
69
+ } })
70
+ .filter((e) => e !== null && Number.isSafeInteger(e.t) && typeof e.op === "string");
71
+ return entries.slice(-limit);
72
+ }
73
+ /** The last `limit` edit entries (verdicts excluded), oldest first: what the reflector asks to judge. */
74
+ export function recentSurfaceEdits(root, limit = 5) {
75
+ return readSurfaceLog(root, 500).filter((e) => SURFACE_EDIT_OPS.has(e.op)).slice(-limit);
76
+ }
77
+ function historyDir(root, rel) {
78
+ return join(root, ".ai-collab", ".history", rel.replace(/\//g, "__"));
79
+ }
80
+ // Keeps the previous body under .history/<path>/<epoch-ms>-<nnn>.<ext>; the fixed-width counter keeps
81
+ // names lexicographically ordered by time even within one millisecond. Newest HISTORY_KEEP kept.
82
+ // A body that is only the stub comment is not worth keeping.
83
+ function archiveSurfaceFile(root, rel) {
84
+ let body;
85
+ try {
86
+ body = readFileSync(surfacePath(root, rel), "utf8");
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ if (!hasContent(body))
92
+ return null;
93
+ const dir = historyDir(root, rel);
94
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
95
+ const ext = /\.[a-z0-9]+$/i.exec(rel)?.[0] ?? "";
96
+ let name = `${Date.now()}-000${ext}`;
97
+ for (let n = 1; existsSync(join(dir, name)); n++)
98
+ name = `${Date.now()}-${String(n).padStart(3, "0")}${ext}`;
99
+ writeFileSync(join(dir, name), body);
100
+ try {
101
+ const all = readdirSync(dir).sort();
102
+ for (const stale of all.slice(0, Math.max(0, all.length - HISTORY_KEEP)))
103
+ rmSync(join(dir, stale), { force: true });
104
+ }
105
+ catch { /* pruning is best effort */ }
106
+ return name;
107
+ }
108
+ /** Archived versions of one surface file, newest first: [{id, bytes}]. */
109
+ export function listSurfaceHistory(root, rel) {
110
+ const path = normalizeSurfacePath(rel);
111
+ if (!path)
112
+ return { error: `"${rel}" is not on the harness surface` };
113
+ let names;
114
+ try {
115
+ names = readdirSync(historyDir(root, path));
116
+ }
117
+ catch {
118
+ names = [];
119
+ }
120
+ const versions = names
121
+ .filter((name) => /^\d+-\d{3}(\.[a-z0-9]+)?$/.test(name))
122
+ .sort()
123
+ .reverse()
124
+ .map((id) => ({ id, bytes: (() => { try {
125
+ return statSync(join(historyDir(root, path), id)).size;
126
+ }
127
+ catch {
128
+ return 0;
129
+ } })() }));
130
+ return { path, versions };
131
+ }
132
+ /** Puts one archived version back: the current body is archived first, and the log records the restore. */
133
+ export function restoreSurfaceFile(root, rel, id) {
134
+ const path = normalizeSurfacePath(rel);
135
+ if (!path)
136
+ return { error: `"${rel}" is not on the harness surface` };
137
+ if (!/^\d+-\d{3}(\.[a-z0-9]+)?$/.test(String(id ?? "")))
138
+ return { error: `unknown history id "${id}"` };
139
+ let content;
140
+ try {
141
+ content = readFileSync(join(historyDir(root, path), id), "utf8");
142
+ }
143
+ catch {
144
+ return { error: `no archived version "${id}" of ${path}` };
145
+ }
146
+ const written = writeSurfaceFile(root, path, content, { op: "restore", note: `restored from ${id}` });
147
+ if ("error" in written)
148
+ return written;
149
+ return { path, bytes: written.bytes, from: id };
150
+ }
151
+ /** Absolute path of one surface file: skills live under `.agents/`, the rest under `.ai-collab/`. */
152
+ export function surfacePath(root, rel) {
153
+ if (rel === "AGENTS.local.md")
154
+ return join(root, rel);
155
+ if (rel.startsWith("skills/"))
156
+ return join(root, ".agents", rel);
157
+ return join(root, ".ai-collab", rel);
158
+ }
159
+ function isCommentOnly(text) {
160
+ return text.split("\n").every((line) => {
161
+ const t = line.trim();
162
+ return !t || t.startsWith("<!--") || t.endsWith("-->") || /^<!--.*-->$/.test(t);
163
+ });
164
+ }
165
+ /** Frontmatter is structure, not content: an index whose body is only the stub comment reads as empty. */
166
+ function stripFrontmatter(text) {
167
+ const block = /^---\n[\s\S]*?\n---\n?/.exec(text);
168
+ return block ? text.slice(block[0].length) : text;
169
+ }
170
+ /** True when the body has operator/agent content beyond the HTML-comment stub and any frontmatter block. */
171
+ export function hasContent(text) {
172
+ const body = stripFrontmatter(text);
173
+ return Boolean(body.trim()) && !isCommentOnly(body);
174
+ }
175
+ /** Creates the surface directories, stub files and the default .gitignore when missing; never overwrites. */
176
+ export function ensureSurface(root) {
177
+ if (!root)
178
+ throw new Error("harness-surface needs a project root");
179
+ mkdirSync(join(root, ".ai-collab", "memory"), { recursive: true, mode: 0o700 });
180
+ mkdirSync(join(root, ".ai-collab", "scripts"), { recursive: true, mode: 0o700 });
181
+ mkdirSync(join(root, ".agents", "skills"), { recursive: true, mode: 0o700 });
182
+ const gitignore = join(root, ".ai-collab", ".gitignore");
183
+ if (!existsSync(gitignore))
184
+ writeFileSync(gitignore, GITIGNORE_DEFAULT);
185
+ for (const [rel, body] of Object.entries(STUBS)) {
186
+ const file = surfacePath(root, rel);
187
+ if (!existsSync(file))
188
+ writeFileAtomic(file, body);
189
+ }
190
+ return root;
191
+ }
192
+ /**
193
+ * A relative path on the editable surface, or null when it escapes. Allows the always-on files
194
+ * (AGENTS.local.md, memory/index.md, tool-guidance.md), memory concepts (memory/log.md,
195
+ * memory/<name>.md), skills/<name>/SKILL.md and scripts/<name>.mjs.
196
+ */
197
+ export function normalizeSurfacePath(rel) {
198
+ const raw = rel.trim().replace(/\\/g, "/").replace(/^\.\//, "");
199
+ if (!raw || raw.startsWith("/") || raw.split("/").includes(".."))
200
+ return null;
201
+ if (ALWAYS_ON.includes(raw))
202
+ return raw;
203
+ if (raw === "memory/log.md" || MEMORY_CONCEPT.test(raw))
204
+ return raw;
205
+ const skill = /^skills\/([a-z0-9][a-z0-9_-]*)\/SKILL\.md$/.exec(raw);
206
+ if (skill && NAME_RE.test(skill[1]))
207
+ return raw;
208
+ const script = /^scripts\/([a-z0-9][a-z0-9_-]*)\.mjs$/.exec(raw);
209
+ if (script && NAME_RE.test(script[1]))
210
+ return raw;
211
+ return null;
212
+ }
213
+ /**
214
+ * The OKF concept rule for memory files: a memory/<name>.md must open with a YAML frontmatter block
215
+ * whose `type` is non-empty (OKF v0.3 §4.1). "" when the path is not a memory concept or the body conforms.
216
+ */
217
+ export function memoryConceptError(rel, content) {
218
+ if (!MEMORY_CONCEPT.test(rel))
219
+ return "";
220
+ const block = /^---\n([\s\S]*?)\n---(\n|$)/.exec(content);
221
+ if (!block)
222
+ return `${rel} needs an OKF frontmatter block between --- lines; type is the only required key`;
223
+ if (!/^type:\s*\S+/m.test(block[1]))
224
+ return `${rel} frontmatter needs a non-empty type (OKF v0.3)`;
225
+ return "";
226
+ }
227
+ function frontField(body, key) {
228
+ const block = /^---\n([\s\S]*?)\n---/.exec(body);
229
+ const m = block && new RegExp(`^${key}:\\s*(.+)$`, "m").exec(block[1]);
230
+ return m ? m[1].trim().replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1") : "";
231
+ }
232
+ function readFile(root, rel) {
233
+ try {
234
+ return readFileSync(surfacePath(root, rel), "utf8");
235
+ }
236
+ catch {
237
+ return "";
238
+ }
239
+ }
240
+ /** Memory concepts under root: memory/<name>.md files whose frontmatter has a type; index and log are not concepts. */
241
+ function memoryConcepts(root) {
242
+ let names;
243
+ try {
244
+ names = readdirSync(join(root, ".ai-collab", "memory")).sort();
245
+ }
246
+ catch {
247
+ return [];
248
+ }
249
+ const out = [];
250
+ for (const name of names) {
251
+ const path = `memory/${name}`;
252
+ if (!MEMORY_CONCEPT.test(path))
253
+ continue;
254
+ const body = readFile(root, path);
255
+ if (!frontField(body, "type"))
256
+ continue;
257
+ out.push({ path, title: frontField(body, "title") || name.replace(/\.md$/, ""), description: frontField(body, "description") });
258
+ }
259
+ return out;
260
+ }
261
+ /** Skill names present as skills/<name>/SKILL.md, sorted. */
262
+ export function listSkills(root) {
263
+ const dir = join(root, ".agents", "skills");
264
+ try {
265
+ return readdirSync(dir).filter((name) => NAME_RE.test(name) && existsSync(join(dir, name, "SKILL.md"))).sort();
266
+ }
267
+ catch {
268
+ return [];
269
+ }
270
+ }
271
+ /** Script basenames (`foo.mjs`) under scripts/, sorted. */
272
+ export function listScripts(root) {
273
+ const dir = join(root, ".ai-collab", "scripts");
274
+ try {
275
+ return readdirSync(dir).filter((name) => /^[a-z0-9][a-z0-9_-]*\.mjs$/.test(name) && statSync(join(dir, name)).isFile()).sort();
276
+ }
277
+ catch {
278
+ return [];
279
+ }
280
+ }
281
+ /** Reads one surface file; "" when missing. Ensures stubs exist first. */
282
+ export function readSurfaceFile(root, rel) {
283
+ const path = normalizeSurfacePath(rel);
284
+ if (!path)
285
+ return { error: `"${rel}" is not on the harness surface` };
286
+ ensureSurface(root);
287
+ return { path, content: readFile(root, path) };
288
+ }
289
+ /**
290
+ * Writes one surface file (creates parents). Caps length; memory concepts must carry OKF frontmatter.
291
+ * The previous body is archived under .history/ and the edit appended to the surface log, so any
292
+ * write is comparable and restorable (opts.op names the operation for callers like restore).
293
+ */
294
+ export function writeSurfaceFile(root, rel, content, opts = {}) {
295
+ const path = normalizeSurfacePath(rel);
296
+ if (!path)
297
+ return { error: `"${rel}" is not on the harness surface` };
298
+ if (typeof content !== "string")
299
+ return { error: "content must be a string" };
300
+ const conceptError = memoryConceptError(path, content);
301
+ if (conceptError)
302
+ return { error: conceptError };
303
+ if (content.length > FILE_MAX_CHARS)
304
+ return { error: `content exceeds ${FILE_MAX_CHARS} characters` };
305
+ ensureSurface(root);
306
+ archiveSurfaceFile(root, path);
307
+ const file = surfacePath(root, path);
308
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
309
+ const body = content.endsWith("\n") ? content : `${content}\n`;
310
+ writeFileAtomic(file, body);
311
+ logSurfaceEdit(root, { t: Date.now(), op: opts.op || "write", path, ...(opts.by ? { by: opts.by } : {}), ...(opts.note ? { note: opts.note } : {}) });
312
+ return { path, bytes: Buffer.byteLength(body) };
313
+ }
314
+ function yamlQuote(value) {
315
+ return `"${value.replace(/"/g, "'").trim()}"`;
316
+ }
317
+ function conceptFile({ type, title, description, body }) {
318
+ return `---\ntype: ${type}\ntitle: ${yamlQuote(title)}\n${description ? `description: ${yamlQuote(description)}\n` : ""}---\n\n${body}\n`;
319
+ }
320
+ /** Body of a concept after its frontmatter block. */
321
+ function conceptBody(text) {
322
+ const block = /^---\n[\s\S]*?\n---\n?/.exec(text);
323
+ return (block ? text.slice(block[0].length) : text).trim();
324
+ }
325
+ /** Write or replace `* [Title](name.md) - description` in memory/index.md; true when it changed. */
326
+ function upsertIndexLine(root, name, title, description) {
327
+ const current = readFile(root, "memory/index.md");
328
+ const line = `* [${title}](${name}.md)${description ? ` - ${description}` : ""}`;
329
+ const listed = new RegExp(`^\\* \\[[^\\]]*\\]\\(${name}\\.md\\).*$`, "m");
330
+ const next = listed.test(current) ? current.replace(listed, line) : `${current.trimEnd()}\n${line}\n`;
331
+ if (next === current)
332
+ return false;
333
+ writeFileAtomic(surfacePath(root, "memory/index.md"), next);
334
+ return true;
335
+ }
336
+ /** Appends `* [Title](name.md) - description` to memory/index.md unless the concept is already listed. */
337
+ function indexFact(root, name, title, description) {
338
+ const current = readFile(root, "memory/index.md");
339
+ if (current.includes(`(${name}.md)`))
340
+ return false;
341
+ const line = `* [${title}](${name}.md) - ${description}`;
342
+ const file = surfacePath(root, "memory/index.md");
343
+ writeFileAtomic(file, current.trim() ? `${current.trimEnd()}\n${line}\n` : `${line}\n`);
344
+ return true;
345
+ }
346
+ /**
347
+ * Files one memory fact as an OKF concept (`.ai-collab/memory/<name>.md`) and adds its index line,
348
+ * so an agent can record a fact without hand-writing frontmatter. Fails when the concept exists.
349
+ */
350
+ export function memoryAdd(root, { name, text, type = "Note", title = "", description = "", by = "" }) {
351
+ if (!root)
352
+ return { error: "harness-surface needs a project root" };
353
+ if (!NAME_RE.test(String(name ?? "")))
354
+ return { error: "name must be lowercase letters, digits, hyphens or underscores" };
355
+ const body = String(text ?? "").trim();
356
+ if (!body)
357
+ return { error: "memory_add needs text: the fact itself" };
358
+ ensureSurface(root);
359
+ const path = `memory/${name}.md`;
360
+ const file = surfacePath(root, path);
361
+ if (existsSync(file))
362
+ return { error: `${path} already exists; read and write it to change the fact` };
363
+ const factTitle = (title || name.replace(/[-_]/g, " ")).trim();
364
+ const firstLine = body.split("\n").map((l) => l.trim()).find(Boolean) || factTitle;
365
+ const desc = (description || firstLine).slice(0, 160);
366
+ const content = conceptFile({ type: (type || "Note").trim(), title: factTitle, description: desc, body });
367
+ writeFileAtomic(file, content);
368
+ logSurfaceEdit(root, { t: Date.now(), op: "memory_add", path, ...(by ? { by } : {}), note: factTitle });
369
+ return { path, bytes: Buffer.byteLength(content), index: indexFact(root, name, factTitle, desc) ? "updated" : "unchanged" };
370
+ }
371
+ /**
372
+ * Edits an existing memory concept in place: new body and/or frontmatter fields (omitted fields keep
373
+ * their value) and refreshes its index line. Fails when the concept does not exist — use memory_add.
374
+ */
375
+ export function memoryEdit(root, { name, text, type, title, description, by = "" }) {
376
+ if (!root)
377
+ return { error: "harness-surface needs a project root" };
378
+ if (!NAME_RE.test(String(name ?? "")))
379
+ return { error: "name must be lowercase letters, digits, hyphens or underscores" };
380
+ const path = `memory/${name}.md`;
381
+ const current = readFile(root, path);
382
+ if (!current)
383
+ return { error: `${path} not found; use memory_add to file a new fact` };
384
+ const body = text !== undefined && String(text).trim() ? String(text).trim() : conceptBody(current);
385
+ if (!body)
386
+ return { error: "memory_edit needs text or a field to change" };
387
+ const nextType = (type || frontField(current, "type") || "Note").trim();
388
+ const nextTitle = (title || frontField(current, "title") || name.replace(/[-_]/g, " ")).trim();
389
+ const nextDesc = (description !== undefined ? String(description) : frontField(current, "description")).trim().slice(0, 160);
390
+ const content = conceptFile({ type: nextType, title: nextTitle, description: nextDesc, body });
391
+ archiveSurfaceFile(root, path);
392
+ writeFileAtomic(surfacePath(root, path), content);
393
+ logSurfaceEdit(root, { t: Date.now(), op: "memory_edit", path, ...(by ? { by } : {}), note: nextTitle });
394
+ return { path, bytes: Buffer.byteLength(content), index: upsertIndexLine(root, name, nextTitle, nextDesc) ? "updated" : "unchanged" };
395
+ }
396
+ /** Inventory for list (read-only): always-on flags, memory concepts, skill and script names. */
397
+ export function listSurface(root) {
398
+ return {
399
+ root,
400
+ alwaysOn: ALWAYS_ON.map((path) => ({ path, empty: !hasContent(readFile(root, path)) })),
401
+ memory: memoryConcepts(root),
402
+ skills: listSkills(root),
403
+ scripts: listScripts(root),
404
+ };
405
+ }
406
+ function skillDesc(body) {
407
+ const m = /^description:\s*(.+)$/m.exec(body.slice(0, 600));
408
+ return m ? m[1].trim() : "(no description)";
409
+ }
410
+ function scriptDesc(body) {
411
+ const line = body.split("\n").map((l) => l.trim()).find((l) => l.startsWith("//") || l.startsWith("*") || l.startsWith("#"));
412
+ return line ? line.replace(/^\/\/\s*|^#\s*|\*\s*/g, "").trim() : "(helper)";
413
+ }
414
+ function section(title, body) {
415
+ const text = body.trim();
416
+ return text ? `## ${title}\n${text}` : "";
417
+ }
418
+ /** Index prose without structure: frontmatter block and HTML comments out, blank lines collapsed. */
419
+ function indexProse(text) {
420
+ return stripFrontmatter(text)
421
+ .replace(/<!--[\s\S]*?-->/g, "")
422
+ .split("\n").filter((line) => line.trim())
423
+ .join("\n");
424
+ }
425
+ /** The Memory section: the OKF index prose (when filled) plus one line per concept file. */
426
+ function memorySection(root) {
427
+ const index = readFile(root, "memory/index.md");
428
+ const concepts = memoryConcepts(root).map((c) => `- ${c.title} (${c.path})${c.description ? `: ${c.description}` : ""}`);
429
+ const prose = indexProse(index);
430
+ return section("Memory (.ai-collab/memory: OKF bundle, one fact per file)", [prose, concepts.join("\n")].filter(Boolean).join("\n\n"));
431
+ }
432
+ function buildNote(parts, max) {
433
+ const open = `<${SURFACE_TAG}>\nHarness surface for this project (advisory overlays): system AGENTS.local.md, memory .ai-collab/memory/ (file a fact: harness_surface action=memory_add), guidance .ai-collab/tool-guidance.md, skills .agents/skills/, scripts .ai-collab/scripts/.`;
434
+ const close = `</${SURFACE_TAG}>`;
435
+ const kept = [];
436
+ let used = open.length + close.length + 2;
437
+ for (const part of parts.filter(Boolean)) {
438
+ if (used + part.length + 2 > max) {
439
+ const room = max - used - 20;
440
+ if (room > 40)
441
+ kept.push(`${part.slice(0, room)}\n…`);
442
+ break;
443
+ }
444
+ kept.push(part);
445
+ used += part.length + 2;
446
+ }
447
+ return kept.length ? `\n\n${open}\n${kept.join("\n\n")}\n${close}` : "";
448
+ }
449
+ /** True when any surface location exists; nothing is created by the note functions. */
450
+ function surfaceExists(root) {
451
+ return Boolean(root) && (existsSync(join(root, ".ai-collab")) || existsSync(join(root, ".agents")) || existsSync(surfacePath(root, "AGENTS.local.md")));
452
+ }
453
+ /** Always-on bodies only (for UserPromptSubmit so mid-session AGENTS.local.md edits land). */
454
+ export function surfaceAlwaysOnNote(root) {
455
+ if (!surfaceExists(root))
456
+ return "";
457
+ const parts = [
458
+ section("System", hasContent(readFile(root, "AGENTS.local.md")) ? readFile(root, "AGENTS.local.md") : ""),
459
+ memorySection(root),
460
+ section("Tool guidance", hasContent(readFile(root, "tool-guidance.md")) ? readFile(root, "tool-guidance.md") : ""),
461
+ ];
462
+ return buildNote(parts, ALWAYS_ON_NOTE_MAX);
463
+ }
464
+ /**
465
+ * Full start note: always-on content plus skill and script indexes. "" when the surface is only stubs.
466
+ */
467
+ export function surfaceNote(root) {
468
+ if (!surfaceExists(root))
469
+ return "";
470
+ const skills = listSkills(root).map((name) => {
471
+ const desc = skillDesc(readFile(root, `skills/${name}/SKILL.md`));
472
+ return `- ${name}: ${desc} (read .agents/skills/${name}/SKILL.md)`;
473
+ });
474
+ const scripts = listScripts(root).map((name) => {
475
+ const desc = scriptDesc(readFile(root, `scripts/${name}`));
476
+ return `- ${name}: ${desc} (run: node ${join(root, ".ai-collab", "scripts", name)})`;
477
+ });
478
+ const parts = [
479
+ section("System", hasContent(readFile(root, "AGENTS.local.md")) ? readFile(root, "AGENTS.local.md") : ""),
480
+ memorySection(root),
481
+ section("Tool guidance", hasContent(readFile(root, "tool-guidance.md")) ? readFile(root, "tool-guidance.md") : ""),
482
+ skills.length ? `## Skills\n${skills.join("\n")}` : "",
483
+ scripts.length ? `## Scripts\n${scripts.join("\n")}` : "",
484
+ ];
485
+ return buildNote(parts, SURFACE_NOTE_MAX);
486
+ }