@cortex-agent/server 2026.7.30 → 2026.8.3

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 (348) hide show
  1. package/README.md +1 -1
  2. package/defaults/CORTEX.md +1 -0
  3. package/defaults/config/CORTEX.md +2 -1
  4. package/defaults/config/hooks/13-status-md-guard.json +11 -0
  5. package/defaults/config/hooks/CORTEX.md +1 -0
  6. package/defaults/config/mcp-config-empty.json +3 -0
  7. package/defaults/config/thread-templates/agents/benchmark-coder.json +22 -0
  8. package/defaults/config/thread-templates/agents/benchmark-reviewer.json +22 -0
  9. package/defaults/config/thread-templates/agents/coder-reviewer.json +4 -9
  10. package/defaults/config/thread-templates/agents/coder.json +4 -14
  11. package/defaults/config/thread-templates/templates/benchmark-coder-review.json +37 -0
  12. package/defaults/config/thread-templates/templates/coder-review.json +3 -27
  13. package/defaults/context/projects/CORTEX.md +1 -1
  14. package/defaults/data/schedules.json +12 -0
  15. package/defaults/hooks/CORTEX.md +1 -0
  16. package/defaults/hooks/new-session-hook.mjs +2 -2
  17. package/defaults/hooks/status-md-guard.mjs +193 -0
  18. package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
  19. package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +28 -2
  20. package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +1 -1
  21. package/defaults/plugins/cortex-common/skills/compound/SKILL.md +1 -1
  22. package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +4 -2
  23. package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +1 -1
  24. package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +1 -1
  25. package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +1 -1
  26. package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +1 -0
  27. package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +2 -2
  28. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +11 -8
  29. package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +1 -1
  30. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +13 -16
  31. package/defaults/prompts/directives/coder-reviewer.md +24 -20
  32. package/defaults/prompts/directives/coder.md +4 -5
  33. package/defaults/prompts/directives/director.md +4 -10
  34. package/defaults/prompts/directives/manager.md +9 -10
  35. package/defaults/prompts/systemPrompts/worker.md +2 -2
  36. package/defaults/rules/cortex-md.md +31 -0
  37. package/defaults/rules/experiment-format.md +8 -1
  38. package/defaults/rules/issues-md.md +10 -9
  39. package/defaults/rules/meta-conventions.md +5 -4
  40. package/defaults/rules/mission-md.md +2 -1
  41. package/defaults/rules/status-md.md +39 -21
  42. package/dist/agent-adapter/bg-wait.d.ts +10 -12
  43. package/dist/agent-adapter/bg-wait.js +209 -129
  44. package/dist/agent-adapter/claude/adapter-tui.d.ts +3 -1
  45. package/dist/agent-adapter/claude/adapter-tui.js +8 -5
  46. package/dist/agent-adapter/claude/adapter.d.ts +43 -14
  47. package/dist/agent-adapter/claude/adapter.js +276 -161
  48. package/dist/agent-adapter/claude/defaults.d.ts +2 -0
  49. package/dist/agent-adapter/claude/defaults.js +5 -5
  50. package/dist/agent-adapter/claude/event-parser.d.ts +3 -8
  51. package/dist/agent-adapter/claude/event-parser.js +28 -31
  52. package/dist/agent-adapter/claude/hooks-builder.js +4 -3
  53. package/dist/agent-adapter/claude/jsonl-tail.js +54 -35
  54. package/dist/agent-adapter/claude/spawn-args.d.ts +15 -12
  55. package/dist/agent-adapter/claude/spawn-args.js +44 -38
  56. package/dist/agent-adapter/claude/tmux-control.d.ts +4 -17
  57. package/dist/agent-adapter/claude/tmux-control.js +39 -32
  58. package/dist/agent-adapter/event-tee.d.ts +19 -0
  59. package/dist/agent-adapter/event-tee.js +145 -0
  60. package/dist/agent-adapter/index.d.ts +1 -0
  61. package/dist/agent-adapter/index.js +7 -3
  62. package/dist/agent-adapter/normalize/event-types.d.ts +17 -9
  63. package/dist/agent-adapter/normalize/event-types.js +4 -4
  64. package/dist/agent-adapter/pi/adapter.d.ts +16 -4
  65. package/dist/agent-adapter/pi/adapter.js +69 -36
  66. package/dist/agent-adapter/pi/discovery.d.ts +19 -3
  67. package/dist/agent-adapter/pi/discovery.js +81 -43
  68. package/dist/agent-adapter/pi/event-parser.js +4 -2
  69. package/dist/agent-adapter/pi/spawn-args.d.ts +2 -4
  70. package/dist/agent-adapter/pi/spawn-args.js +6 -5
  71. package/dist/agent-adapter/types.d.ts +43 -2
  72. package/dist/agent-adapter/types.js +8 -4
  73. package/dist/core/atomic-write.d.ts +6 -1
  74. package/dist/core/atomic-write.js +183 -7
  75. package/dist/core/cli-utils.d.ts +15 -2
  76. package/dist/core/cli-utils.js +46 -41
  77. package/dist/core/config-generator.d.ts +4 -0
  78. package/dist/core/config-generator.js +34 -21
  79. package/dist/core/json-repository.d.ts +4 -0
  80. package/dist/core/json-repository.js +6 -3
  81. package/dist/core/locales/en.d.ts +94 -0
  82. package/dist/core/locales/slices/commands.d.ts +76 -0
  83. package/dist/core/locales/slices/commands.js +155 -1
  84. package/dist/core/locales/slices/status.d.ts +18 -0
  85. package/dist/core/locales/slices/status.js +43 -2
  86. package/dist/core/log.d.ts +5 -0
  87. package/dist/core/log.js +25 -23
  88. package/dist/core/pi-session-filename.d.ts +2 -0
  89. package/dist/core/pi-session-filename.js +18 -0
  90. package/dist/core/resume-reminder.d.ts +5 -0
  91. package/dist/core/resume-reminder.js +18 -0
  92. package/dist/core/runtime-env.d.ts +1 -0
  93. package/dist/core/runtime-env.js +15 -0
  94. package/dist/core/settings-migration.d.ts +5 -0
  95. package/dist/core/settings-migration.js +128 -0
  96. package/dist/core/settings-spec.d.ts +174 -0
  97. package/dist/core/settings-spec.js +150 -0
  98. package/dist/core/settings.d.ts +10 -0
  99. package/dist/core/settings.js +235 -0
  100. package/dist/core/task-parser.d.ts +11 -1
  101. package/dist/core/task-parser.js +34 -3
  102. package/dist/core/types/agent-types.d.ts +19 -0
  103. package/dist/core/types/agent-types.js +1 -1
  104. package/dist/core/types/thread-types.d.ts +48 -3
  105. package/dist/core/types/thread-types.js +2 -2
  106. package/dist/domain/agent-run/access-probe-cli.d.ts +7 -0
  107. package/dist/domain/agent-run/access-probe-cli.js +139 -0
  108. package/dist/domain/agent-run/access-probe-policy.d.ts +61 -0
  109. package/dist/domain/agent-run/access-probe-policy.js +614 -0
  110. package/dist/domain/agent-run/access-probe.d.ts +21 -0
  111. package/dist/domain/agent-run/access-probe.js +194 -0
  112. package/dist/domain/agent-run/agent-run-cli.d.ts +19 -0
  113. package/dist/domain/agent-run/agent-run-cli.js +171 -0
  114. package/dist/domain/agent-run/atif.d.ts +54 -0
  115. package/dist/domain/agent-run/atif.js +211 -0
  116. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +32 -0
  117. package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +616 -0
  118. package/dist/domain/agent-run/benchmark-thread-identity.d.ts +34 -0
  119. package/dist/domain/agent-run/benchmark-thread-identity.js +106 -0
  120. package/dist/domain/agent-run/identity.d.ts +62 -0
  121. package/dist/domain/agent-run/identity.js +118 -0
  122. package/dist/domain/agent-run/journal.d.ts +51 -0
  123. package/dist/domain/agent-run/journal.js +259 -0
  124. package/dist/domain/agent-run/manifest-contract.d.ts +44 -0
  125. package/dist/domain/agent-run/manifest-contract.js +134 -0
  126. package/dist/domain/agent-run/manifest.d.ts +51 -0
  127. package/dist/domain/agent-run/manifest.js +801 -0
  128. package/dist/domain/agent-run/pinned-node-process.d.ts +35 -0
  129. package/dist/domain/agent-run/pinned-node-process.js +206 -0
  130. package/dist/domain/agent-run/role-surface.d.ts +4 -0
  131. package/dist/domain/agent-run/role-surface.js +99 -0
  132. package/dist/domain/agent-run/run-config.d.ts +22 -0
  133. package/dist/domain/agent-run/run-config.js +135 -0
  134. package/dist/domain/agent-run/runner.d.ts +7 -0
  135. package/dist/domain/agent-run/runner.js +518 -0
  136. package/dist/domain/agent-run/supervisor.d.ts +78 -0
  137. package/dist/domain/agent-run/supervisor.js +425 -0
  138. package/dist/domain/agent-run/trajectory-merge-cli.d.ts +11 -0
  139. package/dist/domain/agent-run/trajectory-merge-cli.js +111 -0
  140. package/dist/domain/agent-run/trajectory-merge.d.ts +39 -0
  141. package/dist/domain/agent-run/trajectory-merge.js +505 -0
  142. package/dist/domain/agents/config.d.ts +10 -0
  143. package/dist/domain/agents/config.js +149 -44
  144. package/dist/domain/agents/facade.d.ts +42 -7
  145. package/dist/domain/agents/facade.js +174 -170
  146. package/dist/domain/agents/provider-run-lifecycle.d.ts +18 -0
  147. package/dist/domain/agents/provider-run-lifecycle.js +60 -0
  148. package/dist/domain/auth/auth-events.d.ts +18 -0
  149. package/dist/domain/auth/auth-events.js +38 -0
  150. package/dist/domain/auth/auth-format.d.ts +2 -0
  151. package/dist/domain/auth/auth-format.js +58 -0
  152. package/dist/domain/auth/auth-status.d.ts +61 -0
  153. package/dist/domain/auth/auth-status.js +304 -0
  154. package/dist/domain/auth/auth-watch.d.ts +16 -0
  155. package/dist/domain/auth/auth-watch.js +125 -0
  156. package/dist/domain/auth/cc-login.d.ts +7 -0
  157. package/dist/domain/auth/cc-login.js +16 -0
  158. package/dist/domain/auth/cc-subscription.d.ts +38 -0
  159. package/dist/domain/auth/cc-subscription.js +204 -0
  160. package/dist/domain/auth/index.d.ts +12 -0
  161. package/dist/domain/auth/index.js +16 -0
  162. package/dist/domain/auth/login-flow.d.ts +120 -0
  163. package/dist/domain/auth/login-flow.js +253 -0
  164. package/dist/domain/auth/login-service.d.ts +32 -0
  165. package/dist/domain/auth/login-service.js +97 -0
  166. package/dist/domain/auth/logout.d.ts +32 -0
  167. package/dist/domain/auth/logout.js +123 -0
  168. package/dist/domain/auth/pi-login.d.ts +36 -0
  169. package/dist/domain/auth/pi-login.js +72 -0
  170. package/dist/domain/auth/pi-oauth.d.ts +36 -0
  171. package/dist/domain/auth/pi-oauth.js +84 -0
  172. package/dist/domain/auth/pi-runtime.d.ts +72 -0
  173. package/dist/domain/auth/pi-runtime.js +86 -0
  174. package/dist/domain/mcp/benchmark-thread-server.d.ts +1 -0
  175. package/dist/domain/mcp/benchmark-thread-server.js +26 -0
  176. package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +23 -0
  177. package/dist/domain/mcp/tools/benchmark-thread-run.js +146 -0
  178. package/dist/domain/memory/user-context.js +6 -8
  179. package/dist/domain/monitor/disk-monitor.js +47 -16
  180. package/dist/domain/projects/project-store.js +23 -6
  181. package/dist/domain/remote/client-manager.js +12 -6
  182. package/dist/domain/scheduling/jobs/auth-expiry-scan.d.ts +14 -0
  183. package/dist/domain/scheduling/jobs/auth-expiry-scan.js +86 -0
  184. package/dist/domain/scheduling/jobs/task-dispatch.js +36 -40
  185. package/dist/domain/scheduling/runner.d.ts +2 -0
  186. package/dist/domain/scheduling/runner.js +7 -4
  187. package/dist/domain/sessions/session-backup.d.ts +14 -20
  188. package/dist/domain/sessions/session-backup.js +57 -68
  189. package/dist/domain/system/doctor.d.ts +4 -0
  190. package/dist/domain/system/doctor.js +113 -28
  191. package/dist/domain/system/server-update-check.js +7 -5
  192. package/dist/domain/system/system-notice.d.ts +3 -1
  193. package/dist/domain/system/system-notice.js +6 -11
  194. package/dist/domain/tasks/archiver.d.ts +1 -0
  195. package/dist/domain/tasks/archiver.js +13 -7
  196. package/dist/domain/tasks/claim-recovery.d.ts +3 -3
  197. package/dist/domain/tasks/claim-recovery.js +12 -8
  198. package/dist/domain/tasks/dispatch-utils.d.ts +15 -14
  199. package/dist/domain/tasks/dispatch-utils.js +22 -18
  200. package/dist/domain/tasks/dispatcher.d.ts +1 -0
  201. package/dist/domain/tasks/dispatcher.js +9 -5
  202. package/dist/domain/tasks/mutator.d.ts +21 -11
  203. package/dist/domain/tasks/mutator.js +30 -24
  204. package/dist/domain/tasks/pending-tracker.d.ts +5 -2
  205. package/dist/domain/tasks/pending-tracker.js +11 -5
  206. package/dist/domain/tasks/system/cortex-run.d.ts +2 -1
  207. package/dist/domain/tasks/system/cortex-run.js +24 -4
  208. package/dist/domain/tasks/system/task-cli.d.ts +1 -0
  209. package/dist/domain/tasks/system/task-cli.js +72 -22
  210. package/dist/domain/tasks/system/task-completion.d.ts +19 -2
  211. package/dist/domain/tasks/system/task-completion.js +31 -17
  212. package/dist/domain/tasks/system/task-file-input.d.ts +10 -0
  213. package/dist/domain/tasks/system/task-file-input.js +57 -0
  214. package/dist/domain/tasks/system/task-id-utils.d.ts +9 -9
  215. package/dist/domain/tasks/system/task-id-utils.js +13 -4
  216. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -2
  217. package/dist/domain/tasks/system/task-lifecycle-edit.js +200 -6
  218. package/dist/domain/tasks/system/task-lock.js +19 -5
  219. package/dist/domain/tasks/system/task-mutations.d.ts +22 -12
  220. package/dist/domain/tasks/system/task-mutations.js +28 -4
  221. package/dist/domain/tasks/system/task-process.js +10 -8
  222. package/dist/domain/tasks/system/task-state.d.ts +65 -11
  223. package/dist/domain/tasks/system/task-state.js +86 -13
  224. package/dist/domain/threads/local-runtime-deps.d.ts +32 -0
  225. package/dist/domain/threads/local-runtime-deps.js +91 -0
  226. package/dist/domain/threads/local-runtime-scope.d.ts +6 -0
  227. package/dist/domain/threads/local-runtime-scope.js +12 -0
  228. package/dist/domain/threads/pending-user-inputs.d.ts +3 -0
  229. package/dist/domain/threads/pending-user-inputs.js +37 -0
  230. package/dist/domain/threads/prompt-builder.d.ts +12 -1
  231. package/dist/domain/threads/prompt-builder.js +73 -26
  232. package/dist/domain/threads/runner.d.ts +15 -3
  233. package/dist/domain/threads/runner.js +261 -105
  234. package/dist/domain/threads/state-machine.d.ts +1 -1
  235. package/dist/domain/threads/state-machine.js +17 -8
  236. package/dist/domain/ui-service/app-router.d.ts +86 -6
  237. package/dist/domain/ui-service/app-router.js +171 -133
  238. package/dist/domain/ui-service/input-schemas.d.ts +132 -10
  239. package/dist/domain/ui-service/input-schemas.js +59 -5
  240. package/dist/domain/ui-service/mutate/approvals.d.ts +2 -1
  241. package/dist/domain/ui-service/mutate/approvals.js +2 -1
  242. package/dist/domain/ui-service/mutate/auth.d.ts +6 -0
  243. package/dist/domain/ui-service/mutate/auth.js +83 -0
  244. package/dist/domain/ui-service/mutate/config.js +11 -10
  245. package/dist/domain/ui-service/query/approvals.js +3 -0
  246. package/dist/domain/ui-service/query/auth.d.ts +6 -0
  247. package/dist/domain/ui-service/query/auth.js +12 -0
  248. package/dist/domain/ui-service/query/config.d.ts +5 -5
  249. package/dist/domain/ui-service/query/config.js +27 -17
  250. package/dist/domain/ui-service/query/tasks.d.ts +1 -1
  251. package/dist/domain/ui-service/query/tasks.js +69 -30
  252. package/dist/domain/ui-service/query/threads.js +3 -3
  253. package/dist/domain/ui-service/types.d.ts +67 -8
  254. package/dist/domain/ui-service/types.js +2 -2
  255. package/dist/domain/ui-service/ui-service.js +16 -2
  256. package/dist/entry/admin-channel-hot-reload.d.ts +4 -0
  257. package/dist/entry/admin-channel-hot-reload.js +22 -0
  258. package/dist/entry/app.js +38 -38
  259. package/dist/entry/auth-cli.d.ts +10 -0
  260. package/dist/entry/auth-cli.js +52 -0
  261. package/dist/entry/cli-help.d.ts +5 -0
  262. package/dist/entry/cli-help.js +130 -0
  263. package/dist/entry/cli.d.ts +5 -5
  264. package/dist/entry/cli.js +174 -248
  265. package/dist/entry/daemon.d.ts +11 -0
  266. package/dist/entry/daemon.js +204 -103
  267. package/dist/entry/draft-attachments.d.ts +8 -0
  268. package/dist/entry/draft-attachments.js +83 -0
  269. package/dist/entry/feishu-login.d.ts +2 -6
  270. package/dist/entry/feishu-login.js +16 -21
  271. package/dist/entry/init.js +6 -4
  272. package/dist/entry/start-ui-http.d.ts +2 -8
  273. package/dist/entry/start-ui-http.js +7 -34
  274. package/dist/events/event-logger.js +11 -13
  275. package/dist/events/event-types.d.ts +19 -1
  276. package/dist/events/event-types.js +3 -3
  277. package/dist/events/index.d.ts +1 -1
  278. package/dist/events/index.js +3 -3
  279. package/dist/hooks/new-session-hook.mjs +2 -2
  280. package/dist/hooks/status-md-guard.mjs +193 -0
  281. package/dist/orchestration/agent-file-send.js +44 -14
  282. package/dist/orchestration/agent-runner.d.ts +7 -3
  283. package/dist/orchestration/agent-runner.js +65 -41
  284. package/dist/orchestration/conversation-runner.d.ts +5 -1
  285. package/dist/orchestration/conversation-runner.js +16 -7
  286. package/dist/orchestration/lifecycle.d.ts +23 -1
  287. package/dist/orchestration/lifecycle.js +103 -40
  288. package/dist/orchestration/mid-turn-inject.d.ts +2 -0
  289. package/dist/orchestration/mid-turn-inject.js +29 -13
  290. package/dist/orchestration/resume-dispatcher.d.ts +3 -5
  291. package/dist/orchestration/resume-dispatcher.js +9 -17
  292. package/dist/orchestration/routing/commands/index.d.ts +4 -1
  293. package/dist/orchestration/routing/commands/index.js +83 -61
  294. package/dist/orchestration/routing/commands/login-notice.d.ts +21 -0
  295. package/dist/orchestration/routing/commands/login-notice.js +97 -0
  296. package/dist/orchestration/routing/commands/login.d.ts +12 -0
  297. package/dist/orchestration/routing/commands/login.js +555 -0
  298. package/dist/orchestration/routing/commands/status.js +45 -59
  299. package/dist/orchestration/routing/edit-handler.d.ts +5 -0
  300. package/dist/orchestration/routing/edit-handler.js +127 -73
  301. package/dist/orchestration/routing/webhook.js +5 -4
  302. package/dist/orchestration/session-rewind.d.ts +5 -1
  303. package/dist/orchestration/session-rewind.js +106 -62
  304. package/dist/orchestration/session-send.d.ts +2 -0
  305. package/dist/orchestration/session-send.js +5 -6
  306. package/dist/orchestration/status-helpers.d.ts +1 -2
  307. package/dist/orchestration/status-helpers.js +7 -10
  308. package/dist/orchestration/thread-callback.d.ts +19 -11
  309. package/dist/orchestration/thread-callback.js +132 -61
  310. package/dist/orchestration/thread-executor.js +37 -27
  311. package/dist/orchestration/turn-mutation-lock.d.ts +3 -0
  312. package/dist/orchestration/turn-mutation-lock.js +36 -0
  313. package/dist/orchestration/turn-notify.d.ts +2 -5
  314. package/dist/orchestration/turn-notify.js +9 -21
  315. package/dist/platform/adapter.d.ts +1 -0
  316. package/dist/platform/adapter.js +2 -2
  317. package/dist/platform/adapters/composite-adapter.d.ts +2 -0
  318. package/dist/platform/adapters/composite-adapter.js +13 -3
  319. package/dist/platform/adapters/feishu.d.ts +2 -4
  320. package/dist/platform/adapters/feishu.js +38 -59
  321. package/dist/platform/adapters/index.d.ts +1 -1
  322. package/dist/platform/adapters/index.js +13 -12
  323. package/dist/platform/adapters/slack.d.ts +1 -1
  324. package/dist/platform/adapters/slack.js +12 -35
  325. package/dist/platform/index.d.ts +2 -1
  326. package/dist/platform/index.js +3 -3
  327. package/dist/platform/testing.d.ts +1 -0
  328. package/dist/platform/testing.js +13 -4
  329. package/dist/platform/tool-trace.js +6 -11
  330. package/dist/platform/ui-http/ui-http-server.d.ts +1 -1
  331. package/dist/platform/ui-http/ui-http-server.js +6 -18
  332. package/dist/store/execution-repo.d.ts +17 -1
  333. package/dist/store/execution-repo.js +55 -4
  334. package/dist/store/prompt-migration-replacements.d.ts +4 -0
  335. package/dist/store/prompt-migration-replacements.js +149 -0
  336. package/dist/store/thread-repo.d.ts +15 -4
  337. package/dist/store/thread-repo.js +61 -24
  338. package/dist/store/version-migrations.js +36 -1
  339. package/native/cortex-supervisor/dist/build-manifest.json +22 -0
  340. package/native/cortex-supervisor/dist/cortex-supervisor +0 -0
  341. package/package.json +5 -2
  342. package/web/dist/assets/index-DrNx9R6c.js +139 -0
  343. package/web/dist/assets/index-zpf3OSKC.css +1 -0
  344. package/web/dist/index.html +2 -2
  345. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +0 -1
  346. package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +0 -78
  347. package/web/dist/assets/index-B19jLgji.js +0 -138
  348. package/web/dist/assets/index-BuFyPyRW.css +0 -1
@@ -1,4 +1,4 @@
1
- // input: JsonRepoOptions<T> (filePath, defaultValue, optional migrate)
1
+ // input: JsonRepoOptions<T> (filePath, defaultValue, migrate?, compact?)
2
2
  // output: JsonRepository<T> — read / write / mutate / invalidate
3
3
  // pos: unified file-backed JSON store with in-memory cache and AsyncMutex serialization
4
4
  // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
@@ -59,7 +59,7 @@ export class JsonRepository {
59
59
  // Persist migrated data back to disk so the new shape survives
60
60
  // across restarts even when no mutate() follows.
61
61
  if (JSON.stringify(parsed) !== JSON.stringify(migrated)) {
62
- await atomicWrite(this.opts.filePath, JSON.stringify(migrated, null, 2));
62
+ await atomicWrite(this.opts.filePath, this.serialize(migrated));
63
63
  }
64
64
  this.cache = migrated;
65
65
  }
@@ -97,9 +97,12 @@ export class JsonRepository {
97
97
  */
98
98
  async write(next) {
99
99
  await this.ensureSwept();
100
- await atomicWrite(this.opts.filePath, JSON.stringify(next, null, 2));
100
+ await atomicWrite(this.opts.filePath, this.serialize(next));
101
101
  this.cache = next;
102
102
  }
103
+ serialize(value) {
104
+ return this.opts.compact ? JSON.stringify(value) : JSON.stringify(value, null, 2);
105
+ }
103
106
  /**
104
107
  * Wait until any in-flight `mutate()` has fully completed (tmp written + rename landed).
105
108
  * Acquire-release the mutex without doing any work; FIFO ordering guarantees that once this
@@ -338,6 +338,81 @@ export declare const en: {
338
338
  'cmd.tail.preview': "*Tailing daemon.log* (last ${n} lines, refresh every 3s)\n```\n${content}\n```\nUse `!tail stop` to stop.";
339
339
  'cmd.tail.cannotRead': "Cannot read daemon.log: ${error}";
340
340
  'cmd.tail.alreadyTailing': "Already tailing. Use `!tail stop` to stop first.";
341
+ 'cmd.auth.heading': "*Authentication status*";
342
+ 'cmd.auth.generatedAt': "Generated: ${time}";
343
+ 'cmd.auth.runtimeLine': "PI runtime: ${status}${version}";
344
+ 'cmd.auth.runtimeAvailable': "available";
345
+ 'cmd.auth.runtimeUnavailable': "unavailable";
346
+ 'cmd.auth.runtimeVersion': " · version ${version}";
347
+ 'cmd.auth.backend.claude': "Claude";
348
+ 'cmd.auth.backend.pi': "PI";
349
+ 'cmd.auth.inUse': " · in use";
350
+ 'cmd.auth.type.oauth': "OAuth";
351
+ 'cmd.auth.type.api_key': "API key";
352
+ 'cmd.auth.type.none': "No active credential";
353
+ 'cmd.auth.state.logged-in': "Logged in";
354
+ 'cmd.auth.state.expiring': "Expiring";
355
+ 'cmd.auth.state.expired': "Expired";
356
+ 'cmd.auth.state.logged-out': "Logged out";
357
+ 'cmd.auth.state.unknown': "Unknown";
358
+ 'cmd.auth.accountLine': "• ${backend} · ${label} · ${authType} · ${state}${inUse}";
359
+ 'cmd.auth.credentials': " Credentials:";
360
+ 'cmd.auth.credentialLine': " - ${authType} · ${state} · ${source}${expires}${refreshExpires}";
361
+ 'cmd.auth.expires': " · expires ${time}";
362
+ 'cmd.auth.refreshExpires': " · refresh expires ${time}";
363
+ 'cmd.auth.hiddenLoggedOut': "${n} logged-out provider hidden.";
364
+ 'cmd.auth.usage': "Usage: `!login [status|cc|pi [provider]]`";
365
+ 'cmd.auth.loginReady': "${authType} login is ready for `${provider}`.";
366
+ 'cmd.auth.loginAgain': "Log in again";
367
+ 'cmd.auth.loginContinue': "Enter API key";
368
+ 'cmd.auth.loginEnterCode': "Enter authorization code";
369
+ 'cmd.auth.loginChoose': "Choose";
370
+ 'cmd.auth.loginChooseProvider': "Choose a PI provider.";
371
+ 'cmd.auth.loginChooseAuthType': "Choose an authentication type for `${provider}`.";
372
+ 'cmd.auth.loginUnknownProvider': "Provider `${provider}` is not available for login.";
373
+ 'cmd.auth.loginNoProviders': "No PI provider supports login.";
374
+ 'cmd.auth.loginModalTitle': "Backend login";
375
+ 'cmd.auth.loginProviderLabel': "PI provider";
376
+ 'cmd.auth.loginProviderPlaceholder': "Choose a provider";
377
+ 'cmd.auth.loginAuthTypeLabel': "Authentication type";
378
+ 'cmd.auth.loginAuthTypePlaceholder': "Choose an authentication type";
379
+ 'cmd.auth.loginTextLabel': "Response";
380
+ 'cmd.auth.loginTextPlaceholder': "Enter the response";
381
+ 'cmd.auth.loginSecretLabel': "API key";
382
+ 'cmd.auth.loginSecretPlaceholder': "Paste the API key";
383
+ 'cmd.auth.loginCodeLabel': "Authorization code";
384
+ 'cmd.auth.loginCodePlaceholder': "Paste the authorization code or redirect URL";
385
+ 'cmd.auth.loginSelectPlaceholder': "Choose an option";
386
+ 'cmd.auth.loginSubmit': "Log in";
387
+ 'cmd.auth.loginCancel': "Cancel";
388
+ 'cmd.auth.loginRequired': "A response is required.";
389
+ 'cmd.auth.loginInProgress': "Login is still in progress.";
390
+ 'cmd.auth.loginAlreadyActive': "A login flow is already active on another surface.";
391
+ 'cmd.auth.loginExpired': "Login flow expired.";
392
+ 'cmd.auth.loginOpenAuthorization': "Open the authorization page:";
393
+ 'cmd.auth.loginDeviceCode': "Device code";
394
+ 'cmd.auth.loginVerificationPage': "Verification page";
395
+ 'cmd.auth.loginDeviceExpires': "This code expires in ${seconds} seconds.";
396
+ 'cmd.auth.loginProgress': "Login progress: ${message}";
397
+ 'cmd.auth.loginSucceeded': "Login succeeded: `${provider}` · ${authType} · expires ${expires}";
398
+ 'cmd.auth.loginNoExpiry': "no expiry";
399
+ 'cmd.auth.loginFailed': "Login failed: ${error}";
400
+ 'cmd.auth.loginUnknownFailure': "Unknown failure";
401
+ 'cmd.auth.loginCancelled': "Login cancelled.";
402
+ 'cmd.auth.cli.description': "Inspect backend authentication status";
403
+ 'cmd.auth.cli.statusDescription': "Show the backend authentication snapshot";
404
+ 'cmd.auth.cli.jsonDescription': "Print the raw AuthStatusSnapshot as JSON";
405
+ 'cmd.auth.cli.helpDescription': "Show this help";
406
+ 'cmd.auth.cli.helpUsage': "Usage:";
407
+ 'cmd.auth.cli.helpCommands': "Commands:";
408
+ 'cmd.auth.cli.helpOptions': "Options:";
409
+ 'cmd.auth.cli.helpExamples': "Examples:";
410
+ 'cmd.auth.cli.validValues': "Valid values:";
411
+ 'cmd.auth.cli.hint': "Hint:";
412
+ 'cmd.auth.cli.exampleSummary': "Show a localized status summary";
413
+ 'cmd.auth.cli.exampleJson': "Print the machine-readable snapshot";
414
+ 'cmd.auth.cli.unknownSubcommand': "Unknown auth command: '${command}'.";
415
+ 'cmd.auth.cli.unknownFlag': "Unknown auth status option: '${flag}'.";
341
416
  'cmd.status.unavailable': "Execution status reporting is not available in this process.";
342
417
  'cmd.status.refreshButton': "Refresh";
343
418
  'cmd.help.catSession': "Session";
@@ -357,6 +432,7 @@ export declare const en: {
357
432
  'cmd.help.config.skills': "`!skills` — list available skills";
358
433
  'cmd.help.monitoring.cost': "`!cost [project]` — show cost summary (global or per-project)";
359
434
  'cmd.help.monitoring.status': "`!status` — show running execution summary";
435
+ 'cmd.help.monitoring.login': "`!login [status|cc|pi [provider]]` — inspect status or start backend login";
360
436
  'cmd.help.monitoring.budget': "`!budget $X/d $Y/m` — set daily/monthly budget";
361
437
  'cmd.help.monitoring.schedule': "`!schedule` — list, add, pause, resume, or remove scheduled tasks";
362
438
  'cmd.help.tasks.tasks': "`!tasks <project>` — list all tasks with details for a project";
@@ -451,6 +527,24 @@ export declare const en: {
451
527
  'notify.agentFallback': "Model fallback: ${from} → ${to}.";
452
528
  'notify.backendSessionReset': "Previous backend session was unavailable; started a fresh session.";
453
529
  'notify.rateLimitAutoResume': "Rate limited — this chat will resume automatically when the limit resets.";
530
+ 'notify.authRequired.title': "Authentication required";
531
+ 'notify.authRequired.body': "Authentication required for backend `${backend}` / provider `${provider}` (${kind}). ${guidance}";
532
+ 'notify.authRequired.kind.loginRequired': "login required";
533
+ 'notify.authRequired.kind.oauthExpired': "OAuth login expired";
534
+ 'notify.authRequired.kind.invalidApiKey': "invalid API key";
535
+ 'notify.authRequired.kind.unauthorized': "unauthorized request";
536
+ 'notify.authRequired.kind.invalidGrant': "invalid OAuth grant";
537
+ 'notify.authRequired.guide.action': "Use the one-click login action below to sign in again.";
538
+ 'notify.authRequired.guide.claude': "SSH to the Cortex host and run `claude /login` to sign in again.";
539
+ 'notify.authRequired.guide.pi': "SSH to the Cortex host, run `pi`, then enter `/login` and select provider `${provider}`.";
540
+ 'notify.authExpiry.title': "Authentication status warning";
541
+ 'notify.authExpiry.body': "Backend `${backend}` / provider `${provider}` is ${state}.${expiry} ${guidance}";
542
+ 'notify.authExpiry.state.expiring': "expiring";
543
+ 'notify.authExpiry.state.expired': "expired";
544
+ 'notify.authExpiry.state.loggedOut': "logged out";
545
+ 'notify.authExpiry.expiresAt': "Expires at `${expiresAt}`.";
546
+ 'notify.authExpiry.refreshExpiresAt': "Refresh credential expires at `${expiresAt}`.";
547
+ 'notify.authExpiry.guide.action': "Use the one-click login action below to sign in again.";
454
548
  'status.noRunningExecutions': "No running executions.";
455
549
  'status.runningExecutions': "Running executions: ${count}";
456
550
  'btn.cancel': "Cancel";
@@ -128,6 +128,81 @@ export declare const commandsEn: {
128
128
  readonly 'cmd.tail.preview': "*Tailing daemon.log* (last ${n} lines, refresh every 3s)\n```\n${content}\n```\nUse `!tail stop` to stop.";
129
129
  readonly 'cmd.tail.cannotRead': "Cannot read daemon.log: ${error}";
130
130
  readonly 'cmd.tail.alreadyTailing': "Already tailing. Use `!tail stop` to stop first.";
131
+ readonly 'cmd.auth.heading': "*Authentication status*";
132
+ readonly 'cmd.auth.generatedAt': "Generated: ${time}";
133
+ readonly 'cmd.auth.runtimeLine': "PI runtime: ${status}${version}";
134
+ readonly 'cmd.auth.runtimeAvailable': "available";
135
+ readonly 'cmd.auth.runtimeUnavailable': "unavailable";
136
+ readonly 'cmd.auth.runtimeVersion': " · version ${version}";
137
+ readonly 'cmd.auth.backend.claude': "Claude";
138
+ readonly 'cmd.auth.backend.pi': "PI";
139
+ readonly 'cmd.auth.inUse': " · in use";
140
+ readonly 'cmd.auth.type.oauth': "OAuth";
141
+ readonly 'cmd.auth.type.api_key': "API key";
142
+ readonly 'cmd.auth.type.none': "No active credential";
143
+ readonly 'cmd.auth.state.logged-in': "Logged in";
144
+ readonly 'cmd.auth.state.expiring': "Expiring";
145
+ readonly 'cmd.auth.state.expired': "Expired";
146
+ readonly 'cmd.auth.state.logged-out': "Logged out";
147
+ readonly 'cmd.auth.state.unknown': "Unknown";
148
+ readonly 'cmd.auth.accountLine': "• ${backend} · ${label} · ${authType} · ${state}${inUse}";
149
+ readonly 'cmd.auth.credentials': " Credentials:";
150
+ readonly 'cmd.auth.credentialLine': " - ${authType} · ${state} · ${source}${expires}${refreshExpires}";
151
+ readonly 'cmd.auth.expires': " · expires ${time}";
152
+ readonly 'cmd.auth.refreshExpires': " · refresh expires ${time}";
153
+ readonly 'cmd.auth.hiddenLoggedOut': "${n} logged-out provider hidden.";
154
+ readonly 'cmd.auth.usage': "Usage: `!login [status|cc|pi [provider]]`";
155
+ readonly 'cmd.auth.loginReady': "${authType} login is ready for `${provider}`.";
156
+ readonly 'cmd.auth.loginAgain': "Log in again";
157
+ readonly 'cmd.auth.loginContinue': "Enter API key";
158
+ readonly 'cmd.auth.loginEnterCode': "Enter authorization code";
159
+ readonly 'cmd.auth.loginChoose': "Choose";
160
+ readonly 'cmd.auth.loginChooseProvider': "Choose a PI provider.";
161
+ readonly 'cmd.auth.loginChooseAuthType': "Choose an authentication type for `${provider}`.";
162
+ readonly 'cmd.auth.loginUnknownProvider': "Provider `${provider}` is not available for login.";
163
+ readonly 'cmd.auth.loginNoProviders': "No PI provider supports login.";
164
+ readonly 'cmd.auth.loginModalTitle': "Backend login";
165
+ readonly 'cmd.auth.loginProviderLabel': "PI provider";
166
+ readonly 'cmd.auth.loginProviderPlaceholder': "Choose a provider";
167
+ readonly 'cmd.auth.loginAuthTypeLabel': "Authentication type";
168
+ readonly 'cmd.auth.loginAuthTypePlaceholder': "Choose an authentication type";
169
+ readonly 'cmd.auth.loginTextLabel': "Response";
170
+ readonly 'cmd.auth.loginTextPlaceholder': "Enter the response";
171
+ readonly 'cmd.auth.loginSecretLabel': "API key";
172
+ readonly 'cmd.auth.loginSecretPlaceholder': "Paste the API key";
173
+ readonly 'cmd.auth.loginCodeLabel': "Authorization code";
174
+ readonly 'cmd.auth.loginCodePlaceholder': "Paste the authorization code or redirect URL";
175
+ readonly 'cmd.auth.loginSelectPlaceholder': "Choose an option";
176
+ readonly 'cmd.auth.loginSubmit': "Log in";
177
+ readonly 'cmd.auth.loginCancel': "Cancel";
178
+ readonly 'cmd.auth.loginRequired': "A response is required.";
179
+ readonly 'cmd.auth.loginInProgress': "Login is still in progress.";
180
+ readonly 'cmd.auth.loginAlreadyActive': "A login flow is already active on another surface.";
181
+ readonly 'cmd.auth.loginExpired': "Login flow expired.";
182
+ readonly 'cmd.auth.loginOpenAuthorization': "Open the authorization page:";
183
+ readonly 'cmd.auth.loginDeviceCode': "Device code";
184
+ readonly 'cmd.auth.loginVerificationPage': "Verification page";
185
+ readonly 'cmd.auth.loginDeviceExpires': "This code expires in ${seconds} seconds.";
186
+ readonly 'cmd.auth.loginProgress': "Login progress: ${message}";
187
+ readonly 'cmd.auth.loginSucceeded': "Login succeeded: `${provider}` · ${authType} · expires ${expires}";
188
+ readonly 'cmd.auth.loginNoExpiry': "no expiry";
189
+ readonly 'cmd.auth.loginFailed': "Login failed: ${error}";
190
+ readonly 'cmd.auth.loginUnknownFailure': "Unknown failure";
191
+ readonly 'cmd.auth.loginCancelled': "Login cancelled.";
192
+ readonly 'cmd.auth.cli.description': "Inspect backend authentication status";
193
+ readonly 'cmd.auth.cli.statusDescription': "Show the backend authentication snapshot";
194
+ readonly 'cmd.auth.cli.jsonDescription': "Print the raw AuthStatusSnapshot as JSON";
195
+ readonly 'cmd.auth.cli.helpDescription': "Show this help";
196
+ readonly 'cmd.auth.cli.helpUsage': "Usage:";
197
+ readonly 'cmd.auth.cli.helpCommands': "Commands:";
198
+ readonly 'cmd.auth.cli.helpOptions': "Options:";
199
+ readonly 'cmd.auth.cli.helpExamples': "Examples:";
200
+ readonly 'cmd.auth.cli.validValues': "Valid values:";
201
+ readonly 'cmd.auth.cli.hint': "Hint:";
202
+ readonly 'cmd.auth.cli.exampleSummary': "Show a localized status summary";
203
+ readonly 'cmd.auth.cli.exampleJson': "Print the machine-readable snapshot";
204
+ readonly 'cmd.auth.cli.unknownSubcommand': "Unknown auth command: '${command}'.";
205
+ readonly 'cmd.auth.cli.unknownFlag': "Unknown auth status option: '${flag}'.";
131
206
  readonly 'cmd.status.unavailable': "Execution status reporting is not available in this process.";
132
207
  readonly 'cmd.status.refreshButton': "Refresh";
133
208
  readonly 'cmd.help.catSession': "Session";
@@ -147,6 +222,7 @@ export declare const commandsEn: {
147
222
  readonly 'cmd.help.config.skills': "`!skills` — list available skills";
148
223
  readonly 'cmd.help.monitoring.cost': "`!cost [project]` — show cost summary (global or per-project)";
149
224
  readonly 'cmd.help.monitoring.status': "`!status` — show running execution summary";
225
+ readonly 'cmd.help.monitoring.login': "`!login [status|cc|pi [provider]]` — inspect status or start backend login";
150
226
  readonly 'cmd.help.monitoring.budget': "`!budget $X/d $Y/m` — set daily/monthly budget";
151
227
  readonly 'cmd.help.monitoring.schedule': "`!schedule` — list, add, pause, resume, or remove scheduled tasks";
152
228
  readonly 'cmd.help.tasks.tasks': "`!tasks <project>` — list all tasks with details for a project";
@@ -1,5 +1,5 @@
1
1
  // input: nothing (leaf data slice)
2
- // output: English/Chinese command messages including !compact
2
+ // output: English/Chinese command, auth-status, and login copy
3
3
  // pos: Localized message table for orchestration commands
4
4
  // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
5
5
  export const commandsEn = {
@@ -142,6 +142,82 @@ export const commandsEn = {
142
142
  'cmd.tail.preview': '*Tailing daemon.log* (last ${n} lines, refresh every 3s)\n```\n${content}\n```\nUse `!tail stop` to stop.',
143
143
  'cmd.tail.cannotRead': 'Cannot read daemon.log: ${error}',
144
144
  'cmd.tail.alreadyTailing': 'Already tailing. Use `!tail stop` to stop first.',
145
+ // --- authentication status ---
146
+ 'cmd.auth.heading': '*Authentication status*',
147
+ 'cmd.auth.generatedAt': 'Generated: ${time}',
148
+ 'cmd.auth.runtimeLine': 'PI runtime: ${status}${version}',
149
+ 'cmd.auth.runtimeAvailable': 'available',
150
+ 'cmd.auth.runtimeUnavailable': 'unavailable',
151
+ 'cmd.auth.runtimeVersion': ' · version ${version}',
152
+ 'cmd.auth.backend.claude': 'Claude',
153
+ 'cmd.auth.backend.pi': 'PI',
154
+ 'cmd.auth.inUse': ' · in use',
155
+ 'cmd.auth.type.oauth': 'OAuth',
156
+ 'cmd.auth.type.api_key': 'API key',
157
+ 'cmd.auth.type.none': 'No active credential',
158
+ 'cmd.auth.state.logged-in': 'Logged in',
159
+ 'cmd.auth.state.expiring': 'Expiring',
160
+ 'cmd.auth.state.expired': 'Expired',
161
+ 'cmd.auth.state.logged-out': 'Logged out',
162
+ 'cmd.auth.state.unknown': 'Unknown',
163
+ 'cmd.auth.accountLine': '• ${backend} · ${label} · ${authType} · ${state}${inUse}',
164
+ 'cmd.auth.credentials': ' Credentials:',
165
+ 'cmd.auth.credentialLine': ' - ${authType} · ${state} · ${source}${expires}${refreshExpires}',
166
+ 'cmd.auth.expires': ' · expires ${time}',
167
+ 'cmd.auth.refreshExpires': ' · refresh expires ${time}',
168
+ 'cmd.auth.hiddenLoggedOut': '${n} logged-out provider hidden.',
169
+ 'cmd.auth.usage': 'Usage: `!login [status|cc|pi [provider]]`',
170
+ 'cmd.auth.loginReady': '${authType} login is ready for `${provider}`.',
171
+ 'cmd.auth.loginAgain': 'Log in again',
172
+ 'cmd.auth.loginContinue': 'Enter API key',
173
+ 'cmd.auth.loginEnterCode': 'Enter authorization code',
174
+ 'cmd.auth.loginChoose': 'Choose',
175
+ 'cmd.auth.loginChooseProvider': 'Choose a PI provider.',
176
+ 'cmd.auth.loginChooseAuthType': 'Choose an authentication type for `${provider}`.',
177
+ 'cmd.auth.loginUnknownProvider': 'Provider `${provider}` is not available for login.',
178
+ 'cmd.auth.loginNoProviders': 'No PI provider supports login.',
179
+ 'cmd.auth.loginModalTitle': 'Backend login',
180
+ 'cmd.auth.loginProviderLabel': 'PI provider',
181
+ 'cmd.auth.loginProviderPlaceholder': 'Choose a provider',
182
+ 'cmd.auth.loginAuthTypeLabel': 'Authentication type',
183
+ 'cmd.auth.loginAuthTypePlaceholder': 'Choose an authentication type',
184
+ 'cmd.auth.loginTextLabel': 'Response',
185
+ 'cmd.auth.loginTextPlaceholder': 'Enter the response',
186
+ 'cmd.auth.loginSecretLabel': 'API key',
187
+ 'cmd.auth.loginSecretPlaceholder': 'Paste the API key',
188
+ 'cmd.auth.loginCodeLabel': 'Authorization code',
189
+ 'cmd.auth.loginCodePlaceholder': 'Paste the authorization code or redirect URL',
190
+ 'cmd.auth.loginSelectPlaceholder': 'Choose an option',
191
+ 'cmd.auth.loginSubmit': 'Log in',
192
+ 'cmd.auth.loginCancel': 'Cancel',
193
+ 'cmd.auth.loginRequired': 'A response is required.',
194
+ 'cmd.auth.loginInProgress': 'Login is still in progress.',
195
+ 'cmd.auth.loginAlreadyActive': 'A login flow is already active on another surface.',
196
+ 'cmd.auth.loginExpired': 'Login flow expired.',
197
+ 'cmd.auth.loginOpenAuthorization': 'Open the authorization page:',
198
+ 'cmd.auth.loginDeviceCode': 'Device code',
199
+ 'cmd.auth.loginVerificationPage': 'Verification page',
200
+ 'cmd.auth.loginDeviceExpires': 'This code expires in ${seconds} seconds.',
201
+ 'cmd.auth.loginProgress': 'Login progress: ${message}',
202
+ 'cmd.auth.loginSucceeded': 'Login succeeded: `${provider}` · ${authType} · expires ${expires}',
203
+ 'cmd.auth.loginNoExpiry': 'no expiry',
204
+ 'cmd.auth.loginFailed': 'Login failed: ${error}',
205
+ 'cmd.auth.loginUnknownFailure': 'Unknown failure',
206
+ 'cmd.auth.loginCancelled': 'Login cancelled.',
207
+ 'cmd.auth.cli.description': 'Inspect backend authentication status',
208
+ 'cmd.auth.cli.statusDescription': 'Show the backend authentication snapshot',
209
+ 'cmd.auth.cli.jsonDescription': 'Print the raw AuthStatusSnapshot as JSON',
210
+ 'cmd.auth.cli.helpDescription': 'Show this help',
211
+ 'cmd.auth.cli.helpUsage': 'Usage:',
212
+ 'cmd.auth.cli.helpCommands': 'Commands:',
213
+ 'cmd.auth.cli.helpOptions': 'Options:',
214
+ 'cmd.auth.cli.helpExamples': 'Examples:',
215
+ 'cmd.auth.cli.validValues': 'Valid values:',
216
+ 'cmd.auth.cli.hint': 'Hint:',
217
+ 'cmd.auth.cli.exampleSummary': 'Show a localized status summary',
218
+ 'cmd.auth.cli.exampleJson': 'Print the machine-readable snapshot',
219
+ 'cmd.auth.cli.unknownSubcommand': "Unknown auth command: '${command}'.",
220
+ 'cmd.auth.cli.unknownFlag': "Unknown auth status option: '${flag}'.",
145
221
  // --- status / help ---
146
222
  'cmd.status.unavailable': 'Execution status reporting is not available in this process.',
147
223
  'cmd.status.refreshButton': 'Refresh',
@@ -162,6 +238,7 @@ export const commandsEn = {
162
238
  'cmd.help.config.skills': '`!skills` — list available skills',
163
239
  'cmd.help.monitoring.cost': '`!cost [project]` — show cost summary (global or per-project)',
164
240
  'cmd.help.monitoring.status': '`!status` — show running execution summary',
241
+ 'cmd.help.monitoring.login': '`!login [status|cc|pi [provider]]` — inspect status or start backend login',
165
242
  'cmd.help.monitoring.budget': '`!budget $X/d $Y/m` — set daily/monthly budget',
166
243
  'cmd.help.monitoring.schedule': '`!schedule` — list, add, pause, resume, or remove scheduled tasks',
167
244
  'cmd.help.tasks.tasks': '`!tasks <project>` — list all tasks with details for a project',
@@ -383,6 +460,82 @@ export const commandsZh = {
383
460
  'cmd.tail.preview': '*正在 tail daemon.log*(最后 ${n} 行,每 3 秒刷新)\n```\n${content}\n```\n使用 `!tail stop` 停止。',
384
461
  'cmd.tail.cannotRead': '无法读取 daemon.log:${error}',
385
462
  'cmd.tail.alreadyTailing': '已在 tail。请先使用 `!tail stop` 停止。',
463
+ // --- authentication status ---
464
+ 'cmd.auth.heading': '*认证状态*',
465
+ 'cmd.auth.generatedAt': '生成时间:${time}',
466
+ 'cmd.auth.runtimeLine': 'PI 运行时:${status}${version}',
467
+ 'cmd.auth.runtimeAvailable': '可用',
468
+ 'cmd.auth.runtimeUnavailable': '不可用',
469
+ 'cmd.auth.runtimeVersion': ' · 版本 ${version}',
470
+ 'cmd.auth.backend.claude': 'Claude',
471
+ 'cmd.auth.backend.pi': 'PI',
472
+ 'cmd.auth.inUse': ' · 使用中',
473
+ 'cmd.auth.type.oauth': 'OAuth',
474
+ 'cmd.auth.type.api_key': 'API key',
475
+ 'cmd.auth.type.none': '无生效凭据',
476
+ 'cmd.auth.state.logged-in': '已登录',
477
+ 'cmd.auth.state.expiring': '即将过期',
478
+ 'cmd.auth.state.expired': '已过期',
479
+ 'cmd.auth.state.logged-out': '未登录',
480
+ 'cmd.auth.state.unknown': '未知',
481
+ 'cmd.auth.accountLine': '• ${backend} · ${label} · ${authType} · ${state}${inUse}',
482
+ 'cmd.auth.credentials': ' 凭据:',
483
+ 'cmd.auth.credentialLine': ' - ${authType} · ${state} · ${source}${expires}${refreshExpires}',
484
+ 'cmd.auth.expires': ' · 过期时间 ${time}',
485
+ 'cmd.auth.refreshExpires': ' · 刷新凭据过期时间 ${time}',
486
+ 'cmd.auth.hiddenLoggedOut': '已隐藏 ${n} 个未登录 provider。',
487
+ 'cmd.auth.usage': '用法:`!login [status|cc|pi [provider]]`',
488
+ 'cmd.auth.loginReady': '`${provider}` 的 ${authType} 登录已就绪。',
489
+ 'cmd.auth.loginAgain': '重新登录',
490
+ 'cmd.auth.loginContinue': '输入 API key',
491
+ 'cmd.auth.loginEnterCode': '输入授权码',
492
+ 'cmd.auth.loginChoose': '选择',
493
+ 'cmd.auth.loginChooseProvider': '选择 PI provider。',
494
+ 'cmd.auth.loginChooseAuthType': '为 `${provider}` 选择认证类型。',
495
+ 'cmd.auth.loginUnknownProvider': 'Provider `${provider}` 不可用于登录。',
496
+ 'cmd.auth.loginNoProviders': '没有支持登录的 PI provider。',
497
+ 'cmd.auth.loginModalTitle': 'Backend 登录',
498
+ 'cmd.auth.loginProviderLabel': 'PI provider',
499
+ 'cmd.auth.loginProviderPlaceholder': '选择 provider',
500
+ 'cmd.auth.loginAuthTypeLabel': '认证类型',
501
+ 'cmd.auth.loginAuthTypePlaceholder': '选择认证类型',
502
+ 'cmd.auth.loginTextLabel': '响应',
503
+ 'cmd.auth.loginTextPlaceholder': '输入响应',
504
+ 'cmd.auth.loginSecretLabel': 'API key',
505
+ 'cmd.auth.loginSecretPlaceholder': '粘贴 API key',
506
+ 'cmd.auth.loginCodeLabel': '授权码',
507
+ 'cmd.auth.loginCodePlaceholder': '粘贴授权码或重定向 URL',
508
+ 'cmd.auth.loginSelectPlaceholder': '选择一个选项',
509
+ 'cmd.auth.loginSubmit': '登录',
510
+ 'cmd.auth.loginCancel': '取消',
511
+ 'cmd.auth.loginRequired': '必须填写响应。',
512
+ 'cmd.auth.loginInProgress': '登录仍在进行中。',
513
+ 'cmd.auth.loginAlreadyActive': '另一个界面已有进行中的登录流程。',
514
+ 'cmd.auth.loginExpired': '登录流程已过期。',
515
+ 'cmd.auth.loginOpenAuthorization': '打开授权页面:',
516
+ 'cmd.auth.loginDeviceCode': '设备码',
517
+ 'cmd.auth.loginVerificationPage': '验证页面',
518
+ 'cmd.auth.loginDeviceExpires': '此设备码将在 ${seconds} 秒后过期。',
519
+ 'cmd.auth.loginProgress': '登录进度:${message}',
520
+ 'cmd.auth.loginSucceeded': '登录成功:`${provider}` · ${authType} · 过期时间 ${expires}',
521
+ 'cmd.auth.loginNoExpiry': '不过期',
522
+ 'cmd.auth.loginFailed': '登录失败:${error}',
523
+ 'cmd.auth.loginUnknownFailure': '未知错误',
524
+ 'cmd.auth.loginCancelled': '登录已取消。',
525
+ 'cmd.auth.cli.description': '检查 backend 认证状态',
526
+ 'cmd.auth.cli.statusDescription': '显示 backend 认证状态快照',
527
+ 'cmd.auth.cli.jsonDescription': '以 JSON 输出原始 AuthStatusSnapshot',
528
+ 'cmd.auth.cli.helpDescription': '显示帮助',
529
+ 'cmd.auth.cli.helpUsage': '用法:',
530
+ 'cmd.auth.cli.helpCommands': '命令:',
531
+ 'cmd.auth.cli.helpOptions': '选项:',
532
+ 'cmd.auth.cli.helpExamples': '示例:',
533
+ 'cmd.auth.cli.validValues': '合法值:',
534
+ 'cmd.auth.cli.hint': '提示:',
535
+ 'cmd.auth.cli.exampleSummary': '显示本地化状态摘要',
536
+ 'cmd.auth.cli.exampleJson': '输出机器可读快照',
537
+ 'cmd.auth.cli.unknownSubcommand': "未知 auth 命令:'${command}'。",
538
+ 'cmd.auth.cli.unknownFlag': "未知 auth status 选项:'${flag}'。",
386
539
  // --- status / help ---
387
540
  'cmd.status.unavailable': '本进程不支持执行状态报告。',
388
541
  'cmd.status.refreshButton': '刷新',
@@ -403,6 +556,7 @@ export const commandsZh = {
403
556
  'cmd.help.config.skills': '`!skills` — 列出可用技能',
404
557
  'cmd.help.monitoring.cost': '`!cost [project]` — 显示成本汇总(全局或按项目)',
405
558
  'cmd.help.monitoring.status': '`!status` — 显示运行中的执行汇总',
559
+ 'cmd.help.monitoring.login': '`!login [status|cc|pi [provider]]` — 查看状态或启动 backend 登录',
406
560
  'cmd.help.monitoring.budget': '`!budget $X/d $Y/m` — 设置每日/每月预算',
407
561
  'cmd.help.monitoring.schedule': '`!schedule` — 列出、添加、暂停、恢复或移除定时任务',
408
562
  'cmd.help.tasks.tasks': '`!tasks <project>` — 列出项目的所有任务及详情',
@@ -20,6 +20,24 @@ export declare const statusEn: {
20
20
  readonly 'notify.agentFallback': "Model fallback: ${from} → ${to}.";
21
21
  readonly 'notify.backendSessionReset': "Previous backend session was unavailable; started a fresh session.";
22
22
  readonly 'notify.rateLimitAutoResume': "Rate limited — this chat will resume automatically when the limit resets.";
23
+ readonly 'notify.authRequired.title': "Authentication required";
24
+ readonly 'notify.authRequired.body': "Authentication required for backend `${backend}` / provider `${provider}` (${kind}). ${guidance}";
25
+ readonly 'notify.authRequired.kind.loginRequired': "login required";
26
+ readonly 'notify.authRequired.kind.oauthExpired': "OAuth login expired";
27
+ readonly 'notify.authRequired.kind.invalidApiKey': "invalid API key";
28
+ readonly 'notify.authRequired.kind.unauthorized': "unauthorized request";
29
+ readonly 'notify.authRequired.kind.invalidGrant': "invalid OAuth grant";
30
+ readonly 'notify.authRequired.guide.action': "Use the one-click login action below to sign in again.";
31
+ readonly 'notify.authRequired.guide.claude': "SSH to the Cortex host and run `claude /login` to sign in again.";
32
+ readonly 'notify.authRequired.guide.pi': "SSH to the Cortex host, run `pi`, then enter `/login` and select provider `${provider}`.";
33
+ readonly 'notify.authExpiry.title': "Authentication status warning";
34
+ readonly 'notify.authExpiry.body': "Backend `${backend}` / provider `${provider}` is ${state}.${expiry} ${guidance}";
35
+ readonly 'notify.authExpiry.state.expiring': "expiring";
36
+ readonly 'notify.authExpiry.state.expired': "expired";
37
+ readonly 'notify.authExpiry.state.loggedOut': "logged out";
38
+ readonly 'notify.authExpiry.expiresAt': "Expires at `${expiresAt}`.";
39
+ readonly 'notify.authExpiry.refreshExpiresAt': "Refresh credential expires at `${expiresAt}`.";
40
+ readonly 'notify.authExpiry.guide.action': "Use the one-click login action below to sign in again.";
23
41
  readonly 'status.noRunningExecutions': "No running executions.";
24
42
  readonly 'status.runningExecutions': "Running executions: ${count}";
25
43
  readonly 'btn.cancel': "Cancel";
@@ -1,7 +1,8 @@
1
1
  // input: nothing (leaf data slice)
2
- // output: statusEn / statusZh — message slice (filled by i18n extraction)
2
+ // output: statusEn/statusZh lifecycle and auth warning messages
3
3
  // pos: one locale slice; aggregated by core/locales/en.ts & zh.ts barrels
4
- // >>> Keep en and zh keys in lockstep (zh typed against keyof typeof statusEn) <<<
4
+ // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
+ // Keep en and zh keys in lockstep (zh is typed against keyof typeof statusEn).
5
6
  export const statusEn = {
6
7
  // --- Status / lifecycle phrases ---
7
8
  'status.processing': 'Processing',
@@ -27,6 +28,26 @@ export const statusEn = {
27
28
  'notify.agentFallback': 'Model fallback: ${from} → ${to}.',
28
29
  'notify.backendSessionReset': 'Previous backend session was unavailable; started a fresh session.',
29
30
  'notify.rateLimitAutoResume': 'Rate limited — this chat will resume automatically when the limit resets.',
31
+ // --- Authentication-required notification ---
32
+ 'notify.authRequired.title': 'Authentication required',
33
+ 'notify.authRequired.body': 'Authentication required for backend `${backend}` / provider `${provider}` (${kind}). ${guidance}',
34
+ 'notify.authRequired.kind.loginRequired': 'login required',
35
+ 'notify.authRequired.kind.oauthExpired': 'OAuth login expired',
36
+ 'notify.authRequired.kind.invalidApiKey': 'invalid API key',
37
+ 'notify.authRequired.kind.unauthorized': 'unauthorized request',
38
+ 'notify.authRequired.kind.invalidGrant': 'invalid OAuth grant',
39
+ 'notify.authRequired.guide.action': 'Use the one-click login action below to sign in again.',
40
+ 'notify.authRequired.guide.claude': 'SSH to the Cortex host and run `claude /login` to sign in again.',
41
+ 'notify.authRequired.guide.pi': 'SSH to the Cortex host, run `pi`, then enter `/login` and select provider `${provider}`.',
42
+ // --- Scheduled authentication status warning ---
43
+ 'notify.authExpiry.title': 'Authentication status warning',
44
+ 'notify.authExpiry.body': 'Backend `${backend}` / provider `${provider}` is ${state}.${expiry} ${guidance}',
45
+ 'notify.authExpiry.state.expiring': 'expiring',
46
+ 'notify.authExpiry.state.expired': 'expired',
47
+ 'notify.authExpiry.state.loggedOut': 'logged out',
48
+ 'notify.authExpiry.expiresAt': 'Expires at `${expiresAt}`.',
49
+ 'notify.authExpiry.refreshExpiresAt': 'Refresh credential expires at `${expiresAt}`.',
50
+ 'notify.authExpiry.guide.action': 'Use the one-click login action below to sign in again.',
30
51
  // --- Execution report ---
31
52
  'status.noRunningExecutions': 'No running executions.',
32
53
  'status.runningExecutions': 'Running executions: ${count}',
@@ -61,6 +82,26 @@ export const statusZh = {
61
82
  'notify.agentFallback': '模型回退:${from} → ${to}。',
62
83
  'notify.backendSessionReset': '之前的后端会话不可用,已启动新会话。',
63
84
  'notify.rateLimitAutoResume': '触发限流,解除后此对话将自动续跑。',
85
+ // --- Authentication-required notification ---
86
+ 'notify.authRequired.title': '需要重新认证',
87
+ 'notify.authRequired.body': '后端 `${backend}` / Provider `${provider}` 的认证已失效(${kind})。${guidance}',
88
+ 'notify.authRequired.kind.loginRequired': '需要登录',
89
+ 'notify.authRequired.kind.oauthExpired': 'OAuth 登录已过期',
90
+ 'notify.authRequired.kind.invalidApiKey': 'API Key 无效',
91
+ 'notify.authRequired.kind.unauthorized': '请求未获授权',
92
+ 'notify.authRequired.kind.invalidGrant': 'OAuth 授权已失效',
93
+ 'notify.authRequired.guide.action': '请使用下方的一键登录操作重新认证。',
94
+ 'notify.authRequired.guide.claude': '请 SSH 到 Cortex 主机并运行 `claude /login` 重新登录。',
95
+ 'notify.authRequired.guide.pi': '请 SSH 到 Cortex 主机,运行 `pi`,然后输入 `/login` 并选择 Provider `${provider}`。',
96
+ // --- Scheduled authentication status warning ---
97
+ 'notify.authExpiry.title': '认证状态预警',
98
+ 'notify.authExpiry.body': '后端 `${backend}` / Provider `${provider}` 的认证状态为${state}。${expiry} ${guidance}',
99
+ 'notify.authExpiry.state.expiring': '即将过期',
100
+ 'notify.authExpiry.state.expired': '已过期',
101
+ 'notify.authExpiry.state.loggedOut': '未登录',
102
+ 'notify.authExpiry.expiresAt': '过期时间:`${expiresAt}`。',
103
+ 'notify.authExpiry.refreshExpiresAt': '刷新凭据过期时间:`${expiresAt}`。',
104
+ 'notify.authExpiry.guide.action': '请使用下方的一键登录操作重新认证。',
64
105
  // --- Execution report ---
65
106
  'status.noRunningExecutions': '没有正在运行的执行。',
66
107
  'status.runningExecutions': '正在运行的执行:${count}',
@@ -1,3 +1,8 @@
1
+ export interface ProcessLogPolicy {
2
+ consoleToStderr: boolean;
3
+ files: boolean;
4
+ }
5
+ export declare function setProcessLogPolicy(policy: ProcessLogPolicy): () => void;
1
6
  export interface Logger {
2
7
  info(...args: unknown[]): void;
3
8
  warn(...args: unknown[]): void;
package/dist/core/log.js CHANGED
@@ -1,7 +1,7 @@
1
- // input: shared process-wide DEBUG gate
2
- // output: createLogger() factory
3
- // pos: centralized logging — console + daily-rotating file sink, DEBUG-gated debug level
4
- // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
1
+ // input: process DEBUG state and log policy
2
+ // output: logger factory and process-scoped sink policy
3
+ // pos: Central console and rotating-file logger
4
+ // >>> If I am updated, update my header and folder CORTEX.md <<<
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { LOGS_DIR } from './paths.js';
@@ -17,6 +17,12 @@ process.stdout.on('error', () => { });
17
17
  const RETENTION_DAYS = 14;
18
18
  const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MB — rotate when exceeded
19
19
  const MAX_ROTATED_FILES = 2; // keep up to .1.log, .2.log
20
+ let processLogPolicy = { consoleToStderr: false, files: true };
21
+ export function setProcessLogPolicy(policy) {
22
+ const previous = processLogPolicy;
23
+ processLogPolicy = policy;
24
+ return () => { processLogPolicy = previous; };
25
+ }
20
26
  // ── File sink (daily rotation) ──────────────────────────
21
27
  let currentDate = '';
22
28
  let stream = null;
@@ -109,30 +115,26 @@ function formatArg(a) {
109
115
  return String(a);
110
116
  }
111
117
  // ── Core write ──────────────────────────────────────────
118
+ function writeConsole(level, prefix, args) {
119
+ if (processLogPolicy.consoleToStderr)
120
+ return console.error(prefix, ...args);
121
+ if (level === 'ERROR')
122
+ return console.error(prefix, ...args);
123
+ if (level === 'WARN')
124
+ return console.warn(prefix, ...args);
125
+ if (level === 'DEBUG')
126
+ return console.debug(prefix, ...args);
127
+ console.log(prefix, ...args);
128
+ }
112
129
  function write(level, mod, args) {
113
130
  const ts = new Date().toLocaleTimeString('en-GB', { hour12: false });
114
131
  const prefix = `[${mod} ${ts}]`;
115
- // Console output — wrapped so a broken pipe (EPIPE) on stderr/stdout doesn't
116
- // crash the process. See also the stderr/stdout error listeners at the top of
117
- // this file.
118
132
  try {
119
- switch (level) {
120
- case 'ERROR':
121
- console.error(prefix, ...args);
122
- break;
123
- case 'WARN':
124
- console.warn(prefix, ...args);
125
- break;
126
- case 'DEBUG':
127
- console.debug(prefix, ...args);
128
- break;
129
- default: console.log(prefix, ...args);
130
- }
131
- }
132
- catch {
133
- // stderr/stdout may be a broken pipe — ignore; file sink below still works
133
+ writeConsole(level, prefix, args);
134
134
  }
135
- // File output
135
+ catch { /* stderr/stdout may be a broken pipe */ }
136
+ if (!processLogPolicy.files)
137
+ return;
136
138
  const line = `${prefix} ${level} ${args.map(formatArg).join(' ')}\n`;
137
139
  try {
138
140
  getStream().write(line);
@@ -0,0 +1,2 @@
1
+ /** Prefer PI's canonical id filename, then the newest timestamp-prefixed form. */
2
+ export declare function selectPISessionFilename(filenames: string[], sessionId: string): string | null;
@@ -0,0 +1,18 @@
1
+ // input: PI filenames and backend session id
2
+ // output: deterministic transcript filename or null
3
+ // pos: Shared PI transcript filename selector
4
+ // >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
5
+ /** Prefer PI's canonical id filename, then the newest timestamp-prefixed form. */
6
+ export function selectPISessionFilename(filenames, sessionId) {
7
+ const canonical = `${sessionId}.jsonl`;
8
+ if (filenames.includes(canonical))
9
+ return canonical;
10
+ let newest = null;
11
+ for (const filename of filenames) {
12
+ if (!filename.endsWith(`_${sessionId}.jsonl`))
13
+ continue;
14
+ if (newest === null || filename > newest)
15
+ newest = filename;
16
+ }
17
+ return newest;
18
+ }
@@ -0,0 +1,5 @@
1
+ /** The continuation prompt injected into a resumed session/thread after a provider interruption
2
+ * (rate limit or outage). Self-contained — the prior turn's content is already in the resumed
3
+ * session/thread history. Shared by the direct-session resume (resume-dispatcher) and the
4
+ * interrupted-thread-step rerun (prompt-builder). */
5
+ export declare function buildResumeReminder(): string;