@bonesofspring/ai-rules 0.2.73 → 0.2.74

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 (216) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/bin/lib/engine-scripts.js +8 -0
  4. package/docs/TEAM-DB.md +86 -5
  5. package/docs/openapi/team-db.v1.json +1164 -224
  6. package/package.json +1 -1
  7. package/presets/_shared/ai-local/scripts/action-signals.mjs +225 -0
  8. package/presets/_shared/ai-local/scripts/actions-report.mjs +210 -0
  9. package/presets/_shared/ai-local/scripts/processes.mjs +5 -4
  10. package/presets/_shared/ai-local/scripts/rr-scheduler-start.mjs +161 -0
  11. package/presets/_shared/ai-local/scripts/team-db-api.mjs +347 -9
  12. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +309 -4
  13. package/presets/_shared/ai-local/scripts/team-db-project.mjs +239 -25
  14. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +86 -1
  15. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +15 -1
  16. package/presets/claude/android-kotlin/commands/README.md +4 -0
  17. package/presets/claude/android-kotlin/commands/rr-scheduler-start.md +32 -0
  18. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +15 -1
  19. package/presets/claude/go/commands/README.md +4 -0
  20. package/presets/claude/go/commands/rr-scheduler-start.md +32 -0
  21. package/presets/claude/go/hooks/chain-team-phases.sh +15 -1
  22. package/presets/claude/ios-swift/commands/README.md +4 -0
  23. package/presets/claude/ios-swift/commands/rr-scheduler-start.md +32 -0
  24. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +15 -1
  25. package/presets/claude/java/commands/README.md +4 -0
  26. package/presets/claude/java/commands/rr-scheduler-start.md +32 -0
  27. package/presets/claude/java/hooks/chain-team-phases.sh +15 -1
  28. package/presets/claude/mcp-ts/commands/README.md +4 -0
  29. package/presets/claude/mcp-ts/commands/rr-scheduler-start.md +32 -0
  30. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +15 -1
  31. package/presets/claude/mol/commands/README.md +4 -0
  32. package/presets/claude/mol/commands/rr-scheduler-start.md +32 -0
  33. package/presets/claude/mol/hooks/chain-team-phases.sh +15 -1
  34. package/presets/claude/next/commands/README.md +4 -0
  35. package/presets/claude/next/commands/rr-scheduler-start.md +32 -0
  36. package/presets/claude/next/hooks/chain-team-phases.sh +15 -1
  37. package/presets/claude/nuxt/commands/README.md +4 -0
  38. package/presets/claude/nuxt/commands/rr-scheduler-start.md +32 -0
  39. package/presets/claude/nuxt/hooks/chain-team-phases.sh +15 -1
  40. package/presets/claude/php-hexagonal/commands/README.md +4 -0
  41. package/presets/claude/php-hexagonal/commands/rr-scheduler-start.md +32 -0
  42. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +15 -1
  43. package/presets/claude/php-laravel/commands/README.md +4 -0
  44. package/presets/claude/php-laravel/commands/rr-scheduler-start.md +32 -0
  45. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +15 -1
  46. package/presets/claude/svelte/commands/README.md +4 -0
  47. package/presets/claude/svelte/commands/rr-scheduler-start.md +32 -0
  48. package/presets/claude/svelte/hooks/chain-team-phases.sh +15 -1
  49. package/presets/cursor/android-kotlin/commands/README.md +4 -0
  50. package/presets/cursor/android-kotlin/commands/rr-scheduler-start.md +32 -0
  51. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +15 -1
  52. package/presets/cursor/go/commands/README.md +4 -0
  53. package/presets/cursor/go/commands/rr-scheduler-start.md +32 -0
  54. package/presets/cursor/go/hooks/chain-team-phases.sh +15 -1
  55. package/presets/cursor/ios-swift/commands/README.md +4 -0
  56. package/presets/cursor/ios-swift/commands/rr-scheduler-start.md +32 -0
  57. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +15 -1
  58. package/presets/cursor/java/commands/README.md +4 -0
  59. package/presets/cursor/java/commands/rr-scheduler-start.md +32 -0
  60. package/presets/cursor/java/hooks/chain-team-phases.sh +15 -1
  61. package/presets/cursor/mcp-ts/commands/README.md +4 -0
  62. package/presets/cursor/mcp-ts/commands/rr-scheduler-start.md +32 -0
  63. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +15 -1
  64. package/presets/cursor/mol/commands/README.md +4 -0
  65. package/presets/cursor/mol/commands/rr-scheduler-start.md +32 -0
  66. package/presets/cursor/mol/hooks/chain-team-phases.sh +15 -1
  67. package/presets/cursor/next/commands/README.md +4 -0
  68. package/presets/cursor/next/commands/rr-scheduler-start.md +32 -0
  69. package/presets/cursor/next/hooks/chain-team-phases.sh +15 -1
  70. package/presets/cursor/nuxt/commands/README.md +4 -0
  71. package/presets/cursor/nuxt/commands/rr-scheduler-start.md +32 -0
  72. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +15 -1
  73. package/presets/cursor/php-hexagonal/commands/README.md +4 -0
  74. package/presets/cursor/php-hexagonal/commands/rr-scheduler-start.md +32 -0
  75. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +15 -1
  76. package/presets/cursor/php-laravel/commands/README.md +4 -0
  77. package/presets/cursor/php-laravel/commands/rr-scheduler-start.md +32 -0
  78. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +15 -1
  79. package/presets/cursor/svelte/commands/README.md +4 -0
  80. package/presets/cursor/svelte/commands/rr-scheduler-start.md +32 -0
  81. package/presets/cursor/svelte/hooks/chain-team-phases.sh +15 -1
  82. package/presets/mavis/android-kotlin/adapter-map.json +9 -1
  83. package/presets/mavis/android-kotlin/commands/README.md +4 -0
  84. package/presets/mavis/android-kotlin/commands/rr-scheduler-start.md +27 -0
  85. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +15 -1
  86. package/presets/mavis/go/adapter-map.json +9 -1
  87. package/presets/mavis/go/commands/README.md +4 -0
  88. package/presets/mavis/go/commands/rr-scheduler-start.md +27 -0
  89. package/presets/mavis/go/hooks/chain-team-phases.sh +15 -1
  90. package/presets/mavis/ios-swift/adapter-map.json +9 -1
  91. package/presets/mavis/ios-swift/commands/README.md +4 -0
  92. package/presets/mavis/ios-swift/commands/rr-scheduler-start.md +27 -0
  93. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +15 -1
  94. package/presets/mavis/java/adapter-map.json +9 -1
  95. package/presets/mavis/java/commands/README.md +4 -0
  96. package/presets/mavis/java/commands/rr-scheduler-start.md +27 -0
  97. package/presets/mavis/java/hooks/chain-team-phases.sh +15 -1
  98. package/presets/mavis/mcp-ts/adapter-map.json +9 -1
  99. package/presets/mavis/mcp-ts/commands/README.md +4 -0
  100. package/presets/mavis/mcp-ts/commands/rr-scheduler-start.md +27 -0
  101. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +15 -1
  102. package/presets/mavis/mol/adapter-map.json +9 -1
  103. package/presets/mavis/mol/commands/README.md +4 -0
  104. package/presets/mavis/mol/commands/rr-scheduler-start.md +27 -0
  105. package/presets/mavis/mol/hooks/chain-team-phases.sh +15 -1
  106. package/presets/mavis/next/adapter-map.json +9 -1
  107. package/presets/mavis/next/commands/README.md +4 -0
  108. package/presets/mavis/next/commands/rr-scheduler-start.md +27 -0
  109. package/presets/mavis/next/hooks/chain-team-phases.sh +15 -1
  110. package/presets/mavis/nuxt/adapter-map.json +9 -1
  111. package/presets/mavis/nuxt/commands/README.md +4 -0
  112. package/presets/mavis/nuxt/commands/rr-scheduler-start.md +27 -0
  113. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +15 -1
  114. package/presets/mavis/php-hexagonal/adapter-map.json +9 -1
  115. package/presets/mavis/php-hexagonal/commands/README.md +4 -0
  116. package/presets/mavis/php-hexagonal/commands/rr-scheduler-start.md +27 -0
  117. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +15 -1
  118. package/presets/mavis/php-laravel/adapter-map.json +9 -1
  119. package/presets/mavis/php-laravel/commands/README.md +4 -0
  120. package/presets/mavis/php-laravel/commands/rr-scheduler-start.md +27 -0
  121. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +15 -1
  122. package/presets/mavis/svelte/adapter-map.json +9 -1
  123. package/presets/mavis/svelte/commands/README.md +4 -0
  124. package/presets/mavis/svelte/commands/rr-scheduler-start.md +27 -0
  125. package/presets/mavis/svelte/hooks/chain-team-phases.sh +15 -1
  126. package/presets/opencode/android-kotlin/adapter-map.json +9 -1
  127. package/presets/opencode/android-kotlin/commands/README.md +4 -0
  128. package/presets/opencode/android-kotlin/commands/rr-scheduler-start.md +35 -0
  129. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +15 -1
  130. package/presets/opencode/go/adapter-map.json +9 -1
  131. package/presets/opencode/go/commands/README.md +4 -0
  132. package/presets/opencode/go/commands/rr-scheduler-start.md +35 -0
  133. package/presets/opencode/go/hooks/chain-team-phases.sh +15 -1
  134. package/presets/opencode/ios-swift/adapter-map.json +9 -1
  135. package/presets/opencode/ios-swift/commands/README.md +4 -0
  136. package/presets/opencode/ios-swift/commands/rr-scheduler-start.md +35 -0
  137. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +15 -1
  138. package/presets/opencode/java/adapter-map.json +9 -1
  139. package/presets/opencode/java/commands/README.md +4 -0
  140. package/presets/opencode/java/commands/rr-scheduler-start.md +35 -0
  141. package/presets/opencode/java/hooks/chain-team-phases.sh +15 -1
  142. package/presets/opencode/mcp-ts/adapter-map.json +9 -1
  143. package/presets/opencode/mcp-ts/commands/README.md +4 -0
  144. package/presets/opencode/mcp-ts/commands/rr-scheduler-start.md +35 -0
  145. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +15 -1
  146. package/presets/opencode/mol/adapter-map.json +9 -1
  147. package/presets/opencode/mol/commands/README.md +4 -0
  148. package/presets/opencode/mol/commands/rr-scheduler-start.md +35 -0
  149. package/presets/opencode/mol/hooks/chain-team-phases.sh +15 -1
  150. package/presets/opencode/next/adapter-map.json +9 -1
  151. package/presets/opencode/next/commands/README.md +4 -0
  152. package/presets/opencode/next/commands/rr-scheduler-start.md +35 -0
  153. package/presets/opencode/next/hooks/chain-team-phases.sh +15 -1
  154. package/presets/opencode/nuxt/adapter-map.json +9 -1
  155. package/presets/opencode/nuxt/commands/README.md +4 -0
  156. package/presets/opencode/nuxt/commands/rr-scheduler-start.md +35 -0
  157. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +15 -1
  158. package/presets/opencode/php-hexagonal/adapter-map.json +9 -1
  159. package/presets/opencode/php-hexagonal/commands/README.md +4 -0
  160. package/presets/opencode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
  161. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +15 -1
  162. package/presets/opencode/php-laravel/adapter-map.json +9 -1
  163. package/presets/opencode/php-laravel/commands/README.md +4 -0
  164. package/presets/opencode/php-laravel/commands/rr-scheduler-start.md +35 -0
  165. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +15 -1
  166. package/presets/opencode/plugins/output-guard/README.md +42 -1
  167. package/presets/opencode/plugins/output-guard/actions.ts +201 -0
  168. package/presets/opencode/plugins/output-guard/index.ts +147 -6
  169. package/presets/opencode/svelte/adapter-map.json +9 -1
  170. package/presets/opencode/svelte/commands/README.md +4 -0
  171. package/presets/opencode/svelte/commands/rr-scheduler-start.md +35 -0
  172. package/presets/opencode/svelte/hooks/chain-team-phases.sh +15 -1
  173. package/presets/zcode/android-kotlin/adapter-map.json +9 -1
  174. package/presets/zcode/android-kotlin/commands/README.md +4 -0
  175. package/presets/zcode/android-kotlin/commands/rr-scheduler-start.md +35 -0
  176. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +15 -1
  177. package/presets/zcode/go/adapter-map.json +9 -1
  178. package/presets/zcode/go/commands/README.md +4 -0
  179. package/presets/zcode/go/commands/rr-scheduler-start.md +35 -0
  180. package/presets/zcode/go/hooks/chain-team-phases.sh +15 -1
  181. package/presets/zcode/ios-swift/adapter-map.json +9 -1
  182. package/presets/zcode/ios-swift/commands/README.md +4 -0
  183. package/presets/zcode/ios-swift/commands/rr-scheduler-start.md +35 -0
  184. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +15 -1
  185. package/presets/zcode/java/adapter-map.json +9 -1
  186. package/presets/zcode/java/commands/README.md +4 -0
  187. package/presets/zcode/java/commands/rr-scheduler-start.md +35 -0
  188. package/presets/zcode/java/hooks/chain-team-phases.sh +15 -1
  189. package/presets/zcode/mcp-ts/adapter-map.json +9 -1
  190. package/presets/zcode/mcp-ts/commands/README.md +4 -0
  191. package/presets/zcode/mcp-ts/commands/rr-scheduler-start.md +35 -0
  192. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +15 -1
  193. package/presets/zcode/mol/adapter-map.json +9 -1
  194. package/presets/zcode/mol/commands/README.md +4 -0
  195. package/presets/zcode/mol/commands/rr-scheduler-start.md +35 -0
  196. package/presets/zcode/mol/hooks/chain-team-phases.sh +15 -1
  197. package/presets/zcode/next/adapter-map.json +9 -1
  198. package/presets/zcode/next/commands/README.md +4 -0
  199. package/presets/zcode/next/commands/rr-scheduler-start.md +35 -0
  200. package/presets/zcode/next/hooks/chain-team-phases.sh +15 -1
  201. package/presets/zcode/nuxt/adapter-map.json +9 -1
  202. package/presets/zcode/nuxt/commands/README.md +4 -0
  203. package/presets/zcode/nuxt/commands/rr-scheduler-start.md +35 -0
  204. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +15 -1
  205. package/presets/zcode/php-hexagonal/adapter-map.json +9 -1
  206. package/presets/zcode/php-hexagonal/commands/README.md +4 -0
  207. package/presets/zcode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
  208. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +15 -1
  209. package/presets/zcode/php-laravel/adapter-map.json +9 -1
  210. package/presets/zcode/php-laravel/commands/README.md +4 -0
  211. package/presets/zcode/php-laravel/commands/rr-scheduler-start.md +35 -0
  212. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +15 -1
  213. package/presets/zcode/svelte/adapter-map.json +9 -1
  214. package/presets/zcode/svelte/commands/README.md +4 -0
  215. package/presets/zcode/svelte/commands/rr-scheduler-start.md +35 -0
  216. package/presets/zcode/svelte/hooks/chain-team-phases.sh +15 -1
@@ -25,6 +25,14 @@ import { createHash } from "node:crypto"
25
25
  import fs from "node:fs"
26
26
  import path from "node:path"
27
27
  import { Plugin } from "@opencode/plugin"
28
+ import {
29
+ errorClassOf,
30
+ intentOf,
31
+ lineCount,
32
+ normalizeTarget,
33
+ targetKeyOf,
34
+ turnCounters,
35
+ } from "./actions.ts"
28
36
  import { parseRotateBytes, rotateLedger, ROTATE_BYTES_ENV } from "./ledger.ts"
29
37
  import { rewriteMessages } from "./rewrite.ts"
30
38
 
@@ -37,6 +45,8 @@ const HEAD_LINES = 40
37
45
  const TAIL_LINES = 15
38
46
  const MAX_TRACKED_SESSIONS = 12
39
47
  const DEFAULT_DISCOVERY_MS = 250
48
+ /** The bound on every timing map; a late `after` must not grow a session's heap. */
49
+ const MAX_TIMING_ENTRIES = 256
40
50
  const ALLOWLIST = new Set(["shell", "bash", "read", "grep", "glob", "webfetch"])
41
51
 
42
52
  const findTeamRoot = (start: string): string | null => {
@@ -224,8 +234,8 @@ const commandOf = (input: unknown): string => {
224
234
  * the bounded replacement from a previous request.
225
235
  */
226
236
  const collectToolActivity = (messages: unknown) => {
227
- const calls = new Map<string, { tool: string; command: string }>()
228
- const results: Array<{ id: string; tool: string; rawBytes: number; error: boolean }> = []
237
+ const calls = new Map<string, { tool: string; command: string; input: unknown }>()
238
+ const results: Array<{ id: string; tool: string; rawBytes: number; error: boolean; lines: number | null; errorValue: unknown }> = []
229
239
  if (!Array.isArray(messages)) return { calls, results }
230
240
  for (const message of messages as Array<{ content?: unknown }>) {
231
241
  const content = message?.content
@@ -235,6 +245,7 @@ const collectToolActivity = (messages: unknown) => {
235
245
  calls.set(item.id, {
236
246
  tool: typeof item.name === "string" ? item.name : "",
237
247
  command: commandOf(item.input),
248
+ input: item.input,
238
249
  })
239
250
  }
240
251
  if (
@@ -262,6 +273,10 @@ const collectToolActivity = (messages: unknown) => {
262
273
  tool: call?.tool ?? (typeof item.name === "string" ? item.name : ""),
263
274
  rawBytes: Buffer.byteLength(text, "utf8"),
264
275
  error: isError,
276
+ // A JSON-stringified error is one line of host message, not a
277
+ // measurement of the tool's own output.
278
+ lines: typeof item.result.value === "string" ? lineCount(text) : null,
279
+ errorValue: item.result.value,
265
280
  })
266
281
  }
267
282
  }
@@ -307,6 +322,40 @@ export default Plugin.define({
307
322
  const toolsetsSeen = loadToolsets(outputDir)
308
323
  const childrenByParent = new Map<string, Set<string>>()
309
324
 
325
+ // `AI_RULES_ACTIONS=0` drops the action and turn rows and nothing else:
326
+ // the rewrite, the stats and the context snapshot keep working, so the
327
+ // guard is still a guard with capture off.
328
+ const actionsEnabled = process.env.AI_RULES_ACTIONS !== "0"
329
+ // Everything below is an observation of something the host actually
330
+ // reported. A missing entry means "not observed", never a zero.
331
+ const sessionAgent = new Map<string, { agent: string | null; model: string | null; variant: string | null }>()
332
+ const sessionParent = new Map<string, string | null>()
333
+ const actionStartedAt = new Map<string, number>()
334
+ const actionTiming = new Map<string, { durationMs: number | null; exit: number | null }>()
335
+ const lastActionAt = new Map<string, number>()
336
+ const repeatsSeen = new Map<string, { callID: string; index: number }>()
337
+
338
+ const bounded = <T>(map: Map<string, T>, key: string, value: T) => {
339
+ map.set(key, value)
340
+ while (map.size > MAX_TIMING_ENTRIES) {
341
+ const oldest = map.keys().next().value
342
+ if (oldest === undefined) break
343
+ map.delete(oldest)
344
+ }
345
+ }
346
+
347
+ const actionKeyOf = (input: unknown): string | null => {
348
+ const record = recordOf(input)
349
+ const sessionID = typeof record.sessionID === "string" ? record.sessionID : ""
350
+ const callID = typeof record.callID === "string" ? record.callID : ""
351
+ return sessionID === "" || callID === "" ? null : `${sessionID}|${callID}`
352
+ }
353
+
354
+ const exitCodeOf = (value: unknown): number | null => {
355
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return null
356
+ return value
357
+ }
358
+
310
359
  const rememberChild = (parentID: string, childID: string) => {
311
360
  const known = childrenByParent.get(parentID)
312
361
  if (known) known.add(childID)
@@ -396,6 +445,16 @@ export default Plugin.define({
396
445
  finish?: unknown
397
446
  }>) {
398
447
  const id = typeof message?.id === "string" ? message.id : ""
448
+ const model = recordOf(message?.model)
449
+ const agent = typeof message?.agent === "string" ? message.agent : null
450
+ const modelId = typeof model.id === "string" ? model.id : null
451
+ if (agent !== null || modelId !== null) {
452
+ sessionAgent.set(sessionID, {
453
+ agent,
454
+ model: modelId,
455
+ variant: typeof model.variant === "string" ? model.variant : null,
456
+ })
457
+ }
399
458
  const tokens = message?.tokens
400
459
  if (id === "" || !tokens || typeof tokens.input !== "number") continue
401
460
  const key = `${sessionID}|${id}`
@@ -415,8 +474,13 @@ export default Plugin.define({
415
474
  cost: typeof message.cost === "number" ? message.cost : 0,
416
475
  finish: typeof message.finish === "string" ? message.finish : "",
417
476
  }
477
+ if (actionsEnabled) {
478
+ // Counts and lengths only: no reasoning, text or compaction
479
+ // content ever reaches the ledger.
480
+ Object.assign(row, turnCounters(message))
481
+ }
418
482
  if (parentSessionID !== undefined) row.parentSessionID = parentSessionID
419
- appendJsonl(outputDir, "usage.jsonl", row)
483
+ if (actionsEnabled) appendJsonl(outputDir, "usage.jsonl", row)
420
484
  }
421
485
  } catch {
422
486
  /* fail open: usage is an observation, not a guard input */
@@ -427,6 +491,7 @@ export default Plugin.define({
427
491
  const queue: Array<{ id: string; parentSessionID?: string }> = [
428
492
  { id: sessionID, parentSessionID: await parentOf(sessionID) },
429
493
  ]
494
+ sessionParent.set(sessionID, queue[0].parentSessionID ?? null)
430
495
  const visited = new Set([sessionID])
431
496
  for (let index = 0; index < queue.length && index < MAX_TRACKED_SESSIONS; index += 1) {
432
497
  const current = queue[index]
@@ -528,8 +593,10 @@ export default Plugin.define({
528
593
  if (resultsSeen.has(key)) continue
529
594
  resultsSeen.add(key)
530
595
  const changed = changedById.get(item.id)
531
- appendJsonl(outputDir, "results.jsonl", {
532
- at: new Date().toISOString(),
596
+ const call = calls.get(item.id)
597
+ const at = Date.now()
598
+ const row: Record<string, unknown> = {
599
+ at: new Date(at).toISOString(),
533
600
  sessionID,
534
601
  callID: item.id,
535
602
  tool: item.tool,
@@ -540,7 +607,51 @@ export default Plugin.define({
540
607
  path: changed?.path ?? "",
541
608
  // Absence means non-error; only the host's error variant carries the key.
542
609
  ...(item.error ? { error: true } : {}),
543
- })
610
+ }
611
+ if (actionsEnabled) {
612
+ // Guarded on its own: a capture failure must not skip discovery.
613
+ try {
614
+ const targetKey = targetKeyOf(item.tool, normalizeTarget(call?.input, projectRoot))
615
+ const previousAt = lastActionAt.get(sessionID)
616
+ const timing = actionTiming.get(key)
617
+ actionTiming.delete(key)
618
+ actionStartedAt.delete(key)
619
+ const parentSessionID = sessionParent.get(sessionID)
620
+ row.intent = intentOf(item.tool, call?.command ?? "")
621
+ row.lines = item.lines
622
+ row.truncated = changed !== undefined
623
+ row.errorClass = errorClassOf(item.error ? "error" : "text", item.errorValue)
624
+ row.durationMs = timing?.durationMs ?? null
625
+ row.exit = timing?.exit ?? null
626
+ // The gap is the distance to the previous observed action of
627
+ // this session; the first one has nothing to measure from.
628
+ row.gapMs = previousAt === undefined ? null : at - previousAt
629
+ if (targetKey !== null) {
630
+ row.targetKey = targetKey
631
+ const repeatKey = `${sessionID}|${targetKey}`
632
+ const previous = repeatsSeen.get(repeatKey)
633
+ if (previous === undefined) {
634
+ bounded(repeatsSeen, repeatKey, { callID: item.id, index: 1 })
635
+ } else {
636
+ row.repeatOf = previous.callID
637
+ row.repeatIndex = previous.index + 1
638
+ bounded(repeatsSeen, repeatKey, { callID: previous.callID, index: previous.index + 1 })
639
+ }
640
+ }
641
+ const meta = sessionAgent.get(sessionID)
642
+ if (meta !== undefined) {
643
+ row.agent = meta.agent
644
+ row.model = meta.model
645
+ row.variant = meta.variant
646
+ }
647
+ if (parentSessionID !== undefined && parentSessionID !== null) row.parentSessionID = parentSessionID
648
+ bounded(lastActionAt, sessionID, at)
649
+ } catch {
650
+ /* an unobserved action is a missing field, never a failed call */
651
+ }
652
+ }
653
+ // The kill switch drops the row itself, not just its fields.
654
+ if (actionsEnabled) appendJsonl(outputDir, "results.jsonl", row)
544
655
  }
545
656
  // Detached after the rewrite: the tool result must never depend on
546
657
  // discovery, and the deadline keeps a hung host from holding a task.
@@ -561,6 +672,36 @@ export default Plugin.define({
561
672
  }
562
673
  }
563
674
  })
675
+ // The installed plugin API declares `tool.execute.before` / `.after`
676
+ // (`@opencode-ai/plugin@1.18.31` `dist/index.d.ts:235,249`) and no other
677
+ // file in this repository has ever registered them, so their dispatch is
678
+ // unverified. They fill `durationMs` and `exit` when they fire and cost
679
+ // one bounded Map write when they do not; registration is separate and
680
+ // guarded so a host that rejects the names keeps the hook above.
681
+ if (actionsEnabled) {
682
+ try {
683
+ await ctx.session.hook("tool.execute.before", async (input: unknown) => {
684
+ const key = actionKeyOf(input)
685
+ if (key !== null) bounded(actionStartedAt, key, Date.now())
686
+ })
687
+ await ctx.session.hook("tool.execute.after", async (input: unknown, output: unknown) => {
688
+ const key = actionKeyOf(input)
689
+ if (key === null) return
690
+ const startedAt = actionStartedAt.get(key)
691
+ actionStartedAt.delete(key)
692
+ // VERIFY: the exit code of a shell call inside `metadata` (host v2).
693
+ // Both names are read defensively; neither is asserted to exist.
694
+ const metadata = recordOf(recordOf(output).metadata)
695
+ const exit = exitCodeOf(metadata.exit) ?? exitCodeOf(recordOf(input).exit)
696
+ bounded(actionTiming, key, {
697
+ durationMs: startedAt === undefined ? null : Date.now() - startedAt,
698
+ exit,
699
+ })
700
+ })
701
+ } catch {
702
+ /* a host without the timing hooks records null duration and exit */
703
+ }
704
+ }
564
705
  } catch (error) {
565
706
  if (process.env.AI_RULES_OUTPUT_GUARD_DEBUG === "1") {
566
707
  appendJsonl(
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "svelte",
5
5
  "semanticSource": "cursor/svelte",
6
- "sourceRevision": "821b15c39a4affebe260f6b87f38f73e8c30f8d4c5f6acf44112aee16d24a626",
6
+ "sourceRevision": "3f43fb4367fcf2ee8f0b4315822406a92437e8df96e68adb0b7f99c7bea81945",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -269,6 +269,14 @@
269
269
  "loadMode": "native-skill",
270
270
  "reason": "Native slash commands under .opencode/commands; $ARGUMENTS kept"
271
271
  },
272
+ {
273
+ "source": "commands/rr-scheduler-start.md",
274
+ "target": "commands/rr-scheduler-start.md",
275
+ "category": "commands",
276
+ "disposition": "transform",
277
+ "loadMode": "native-skill",
278
+ "reason": "Native slash commands under .opencode/commands; $ARGUMENTS kept"
279
+ },
272
280
  {
273
281
  "source": "commands/spec-start.md",
274
282
  "target": "commands/spec-start.md",
@@ -49,3 +49,7 @@ Slash commands are copied to `.opencode/commands/` on `ai-rules init opencode --
49
49
  - Hooks: `../hooks/chain-team-phases.sh` only (semi-auto runner; no `hooks.json`)
50
50
 
51
51
  Create and edit commands via `/commands` in Cursor or directly in this preset folder.
52
+
53
+ ## Scheduler
54
+
55
+ - **`/rr-scheduler-start`** — start the team-db scheduler, or restart it when one already holds the lease. `init` seeds `.ai.local/scripts/rr-scheduler-start.mjs`.
@@ -0,0 +1,35 @@
1
+ ---
2
+ description: "Start the team-db scheduler, or restart it when one is already running."
3
+ ---
4
+
5
+ ## Invocation arguments
6
+
7
+ $ARGUMENTS
8
+
9
+ # Start or restart the scheduler
10
+
11
+ Bring up `team-db.mjs schedule` for this repository. When a scheduler already holds the lease, stop that process and start a new one.
12
+
13
+ ## What to do
14
+
15
+ 1. From the repository root, run:
16
+
17
+ ```bash
18
+ node .ai.local/scripts/rr-scheduler-start.mjs
19
+ ```
20
+
21
+ 2. Quote the stdout verbatim. A start prints `scheduler: started pid <pid>`. A restart prints `scheduler: restarted pid <pid> (stopped <previous>)`, plus the `processes:` lines from the manager.
22
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not start `team-db.mjs schedule` by hand and do not signal a pid the script did not name.
23
+
24
+ ## What the script does
25
+
26
+ - Stops a scheduler this repository recorded, via `processes.mjs stop --name scheduler`.
27
+ - Signals a scheduler that was started outside the manager only when `scheduler.lock` names a live pid whose command line is `team-db.mjs schedule`. `SIGTERM`, then `SIGKILL` if it is still alive after 8 seconds. An in-flight child can outlive that kill.
28
+ - Removes `scheduler.lock` when its pid is already dead, so a crash does not block the next start for 90 seconds.
29
+ - Starts the timer through `processes.mjs start --name scheduler` with `exec node .ai.local/scripts/team-db.mjs schedule`, then waits until the new lease is fresh.
30
+
31
+ ## Do not
32
+
33
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
34
+ - Run `pkill`, `killall`, or `kill` against a pid the script did not print.
35
+ - Start a second `team-db.mjs schedule` after a non-zero exit.
@@ -57,12 +57,26 @@ function readSessionLease(id) {
57
57
  return null;
58
58
  }
59
59
  }
60
+ // The lease carries the window the projector attributes rows with — never one
61
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
62
+ // pair; a different slug starts a new window, and a lease older than the TTL
63
+ // starts over instead of claiming an ancient first sighting.
64
+ function firstSeenAtOf(file, value, now) {
65
+ try {
66
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
67
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
68
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
69
+ } catch {}
70
+ return now;
71
+ }
60
72
  function writeSessionLease(id, value) {
61
73
  try {
62
74
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
63
75
  const file = sessionLeasePath(id);
64
76
  const temporary = `${file}.${process.pid}.tmp`;
65
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
77
+ const now = new Date().toISOString();
78
+ const firstSeenAt = firstSeenAtOf(file, value, now);
79
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
66
80
  fs.renameSync(temporary, file);
67
81
  for (const name of fs.readdirSync(LEASE_ROOT)) {
68
82
  if (!name.endsWith('.json')) continue;
@@ -3,7 +3,7 @@
3
3
  "platform": "zcode",
4
4
  "stack": "android-kotlin",
5
5
  "semanticSource": "cursor/android-kotlin",
6
- "sourceRevision": "a175721e644dabd89f1e210a77ba0afb74fe4bc7cfe33fb8641f1685dcf4ef37",
6
+ "sourceRevision": "a108400dc9d8daa9742c78e8eff2ca2d416219308786eee3e60370428fd592fd",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -269,6 +269,14 @@
269
269
  "loadMode": "native-skill",
270
270
  "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
271
271
  },
272
+ {
273
+ "source": "commands/rr-scheduler-start.md",
274
+ "target": "commands/rr-scheduler-start.md",
275
+ "category": "commands",
276
+ "disposition": "transform",
277
+ "loadMode": "native-skill",
278
+ "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
279
+ },
272
280
  {
273
281
  "source": "commands/spec-start.md",
274
282
  "target": "commands/spec-start.md",
@@ -49,3 +49,7 @@ Slash commands are copied to `.zcode/commands/` on `ai-rules init zcode --preset
49
49
  - Hooks: `../hooks/chain-team-phases.sh` only (manual runner; no config `hooks` key)
50
50
 
51
51
  Create and edit commands via `/commands` in Cursor or directly in this preset folder.
52
+
53
+ ## Scheduler
54
+
55
+ - **`/rr-scheduler-start`** — start the team-db scheduler, or restart it when one already holds the lease. `init` seeds `.ai.local/scripts/rr-scheduler-start.mjs`.
@@ -0,0 +1,35 @@
1
+ ---
2
+ description: "Start the team-db scheduler, or restart it when one is already running."
3
+ ---
4
+
5
+ ## Invocation arguments
6
+
7
+ $ARGUMENTS
8
+
9
+ # Start or restart the scheduler
10
+
11
+ Bring up `team-db.mjs schedule` for this repository. When a scheduler already holds the lease, stop that process and start a new one.
12
+
13
+ ## What to do
14
+
15
+ 1. From the repository root, run:
16
+
17
+ ```bash
18
+ node .ai.local/scripts/rr-scheduler-start.mjs
19
+ ```
20
+
21
+ 2. Quote the stdout verbatim. A start prints `scheduler: started pid <pid>`. A restart prints `scheduler: restarted pid <pid> (stopped <previous>)`, plus the `processes:` lines from the manager.
22
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not start `team-db.mjs schedule` by hand and do not signal a pid the script did not name.
23
+
24
+ ## What the script does
25
+
26
+ - Stops a scheduler this repository recorded, via `processes.mjs stop --name scheduler`.
27
+ - Signals a scheduler that was started outside the manager only when `scheduler.lock` names a live pid whose command line is `team-db.mjs schedule`. `SIGTERM`, then `SIGKILL` if it is still alive after 8 seconds. An in-flight child can outlive that kill.
28
+ - Removes `scheduler.lock` when its pid is already dead, so a crash does not block the next start for 90 seconds.
29
+ - Starts the timer through `processes.mjs start --name scheduler` with `exec node .ai.local/scripts/team-db.mjs schedule`, then waits until the new lease is fresh.
30
+
31
+ ## Do not
32
+
33
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
34
+ - Run `pkill`, `killall`, or `kill` against a pid the script did not print.
35
+ - Start a second `team-db.mjs schedule` after a non-zero exit.
@@ -57,12 +57,26 @@ function readSessionLease(id) {
57
57
  return null;
58
58
  }
59
59
  }
60
+ // The lease carries the window the projector attributes rows with — never one
61
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
62
+ // pair; a different slug starts a new window, and a lease older than the TTL
63
+ // starts over instead of claiming an ancient first sighting.
64
+ function firstSeenAtOf(file, value, now) {
65
+ try {
66
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
67
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
68
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
69
+ } catch {}
70
+ return now;
71
+ }
60
72
  function writeSessionLease(id, value) {
61
73
  try {
62
74
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
63
75
  const file = sessionLeasePath(id);
64
76
  const temporary = `${file}.${process.pid}.tmp`;
65
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
77
+ const now = new Date().toISOString();
78
+ const firstSeenAt = firstSeenAtOf(file, value, now);
79
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
66
80
  fs.renameSync(temporary, file);
67
81
  for (const name of fs.readdirSync(LEASE_ROOT)) {
68
82
  if (!name.endsWith('.json')) continue;
@@ -3,7 +3,7 @@
3
3
  "platform": "zcode",
4
4
  "stack": "go",
5
5
  "semanticSource": "cursor/go",
6
- "sourceRevision": "31497dc7c8d26f37a9f872726301855b7b0ff24c5831dddff148b7983c61f501",
6
+ "sourceRevision": "c0666476d3cb94e4396108e68cd4b49732641097617db49771d28337b8dde0e6",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -251,6 +251,14 @@
251
251
  "loadMode": "native-skill",
252
252
  "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
253
253
  },
254
+ {
255
+ "source": "commands/rr-scheduler-start.md",
256
+ "target": "commands/rr-scheduler-start.md",
257
+ "category": "commands",
258
+ "disposition": "transform",
259
+ "loadMode": "native-skill",
260
+ "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
261
+ },
254
262
  {
255
263
  "source": "commands/spec-start.md",
256
264
  "target": "commands/spec-start.md",
@@ -52,3 +52,7 @@ Slash commands are copied to `.zcode/commands/` on `ai-rules init zcode --preset
52
52
  - Hooks: `../hooks/chain-team-phases.sh` only (manual runner; no config `hooks` key)
53
53
 
54
54
  Create and edit commands via `/commands` in Cursor or directly in this preset folder.
55
+
56
+ ## Scheduler
57
+
58
+ - **`/rr-scheduler-start`** — start the team-db scheduler, or restart it when one already holds the lease. `init` seeds `.ai.local/scripts/rr-scheduler-start.mjs`.
@@ -0,0 +1,35 @@
1
+ ---
2
+ description: "Start the team-db scheduler, or restart it when one is already running."
3
+ ---
4
+
5
+ ## Invocation arguments
6
+
7
+ $ARGUMENTS
8
+
9
+ # Start or restart the scheduler
10
+
11
+ Bring up `team-db.mjs schedule` for this repository. When a scheduler already holds the lease, stop that process and start a new one.
12
+
13
+ ## What to do
14
+
15
+ 1. From the repository root, run:
16
+
17
+ ```bash
18
+ node .ai.local/scripts/rr-scheduler-start.mjs
19
+ ```
20
+
21
+ 2. Quote the stdout verbatim. A start prints `scheduler: started pid <pid>`. A restart prints `scheduler: restarted pid <pid> (stopped <previous>)`, plus the `processes:` lines from the manager.
22
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not start `team-db.mjs schedule` by hand and do not signal a pid the script did not name.
23
+
24
+ ## What the script does
25
+
26
+ - Stops a scheduler this repository recorded, via `processes.mjs stop --name scheduler`.
27
+ - Signals a scheduler that was started outside the manager only when `scheduler.lock` names a live pid whose command line is `team-db.mjs schedule`. `SIGTERM`, then `SIGKILL` if it is still alive after 8 seconds. An in-flight child can outlive that kill.
28
+ - Removes `scheduler.lock` when its pid is already dead, so a crash does not block the next start for 90 seconds.
29
+ - Starts the timer through `processes.mjs start --name scheduler` with `exec node .ai.local/scripts/team-db.mjs schedule`, then waits until the new lease is fresh.
30
+
31
+ ## Do not
32
+
33
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
34
+ - Run `pkill`, `killall`, or `kill` against a pid the script did not print.
35
+ - Start a second `team-db.mjs schedule` after a non-zero exit.
@@ -58,12 +58,26 @@ function readSessionLease(id) {
58
58
  return null;
59
59
  }
60
60
  }
61
+ // The lease carries the window the projector attributes rows with — never one
62
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
63
+ // pair; a different slug starts a new window, and a lease older than the TTL
64
+ // starts over instead of claiming an ancient first sighting.
65
+ function firstSeenAtOf(file, value, now) {
66
+ try {
67
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
68
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
69
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
70
+ } catch {}
71
+ return now;
72
+ }
61
73
  function writeSessionLease(id, value) {
62
74
  try {
63
75
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
64
76
  const file = sessionLeasePath(id);
65
77
  const temporary = `${file}.${process.pid}.tmp`;
66
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
78
+ const now = new Date().toISOString();
79
+ const firstSeenAt = firstSeenAtOf(file, value, now);
80
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
67
81
  fs.renameSync(temporary, file);
68
82
  for (const name of fs.readdirSync(LEASE_ROOT)) {
69
83
  if (!name.endsWith('.json')) continue;
@@ -3,7 +3,7 @@
3
3
  "platform": "zcode",
4
4
  "stack": "ios-swift",
5
5
  "semanticSource": "cursor/ios-swift",
6
- "sourceRevision": "e2521ffaae5b3c15e314770048998fac95225949bab2c9e5e9e4fd293c1303d5",
6
+ "sourceRevision": "1de3d55238f8ede21ba9f5cc5046ea5e18451aef646bea87a0305e71ae944281",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -269,6 +269,14 @@
269
269
  "loadMode": "native-skill",
270
270
  "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
271
271
  },
272
+ {
273
+ "source": "commands/rr-scheduler-start.md",
274
+ "target": "commands/rr-scheduler-start.md",
275
+ "category": "commands",
276
+ "disposition": "transform",
277
+ "loadMode": "native-skill",
278
+ "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
279
+ },
272
280
  {
273
281
  "source": "commands/spec-start.md",
274
282
  "target": "commands/spec-start.md",
@@ -49,3 +49,7 @@ Slash commands are copied to `.zcode/commands/` on `ai-rules init zcode --preset
49
49
  - Hooks: `../hooks/chain-team-phases.sh` only (manual runner; no config `hooks` key)
50
50
 
51
51
  Create and edit commands via `/commands` in Cursor or directly in this preset folder.
52
+
53
+ ## Scheduler
54
+
55
+ - **`/rr-scheduler-start`** — start the team-db scheduler, or restart it when one already holds the lease. `init` seeds `.ai.local/scripts/rr-scheduler-start.mjs`.
@@ -0,0 +1,35 @@
1
+ ---
2
+ description: "Start the team-db scheduler, or restart it when one is already running."
3
+ ---
4
+
5
+ ## Invocation arguments
6
+
7
+ $ARGUMENTS
8
+
9
+ # Start or restart the scheduler
10
+
11
+ Bring up `team-db.mjs schedule` for this repository. When a scheduler already holds the lease, stop that process and start a new one.
12
+
13
+ ## What to do
14
+
15
+ 1. From the repository root, run:
16
+
17
+ ```bash
18
+ node .ai.local/scripts/rr-scheduler-start.mjs
19
+ ```
20
+
21
+ 2. Quote the stdout verbatim. A start prints `scheduler: started pid <pid>`. A restart prints `scheduler: restarted pid <pid> (stopped <previous>)`, plus the `processes:` lines from the manager.
22
+ 3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not start `team-db.mjs schedule` by hand and do not signal a pid the script did not name.
23
+
24
+ ## What the script does
25
+
26
+ - Stops a scheduler this repository recorded, via `processes.mjs stop --name scheduler`.
27
+ - Signals a scheduler that was started outside the manager only when `scheduler.lock` names a live pid whose command line is `team-db.mjs schedule`. `SIGTERM`, then `SIGKILL` if it is still alive after 8 seconds. An in-flight child can outlive that kill.
28
+ - Removes `scheduler.lock` when its pid is already dead, so a crash does not block the next start for 90 seconds.
29
+ - Starts the timer through `processes.mjs start --name scheduler` with `exec node .ai.local/scripts/team-db.mjs schedule`, then waits until the new lease is fresh.
30
+
31
+ ## Do not
32
+
33
+ - Write `status.json`, `metrics.json`, or any task or lifecycle file.
34
+ - Run `pkill`, `killall`, or `kill` against a pid the script did not print.
35
+ - Start a second `team-db.mjs schedule` after a non-zero exit.
@@ -57,12 +57,26 @@ function readSessionLease(id) {
57
57
  return null;
58
58
  }
59
59
  }
60
+ // The lease carries the window the projector attributes rows with — never one
61
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
62
+ // pair; a different slug starts a new window, and a lease older than the TTL
63
+ // starts over instead of claiming an ancient first sighting.
64
+ function firstSeenAtOf(file, value, now) {
65
+ try {
66
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
67
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
68
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
69
+ } catch {}
70
+ return now;
71
+ }
60
72
  function writeSessionLease(id, value) {
61
73
  try {
62
74
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
63
75
  const file = sessionLeasePath(id);
64
76
  const temporary = `${file}.${process.pid}.tmp`;
65
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
77
+ const now = new Date().toISOString();
78
+ const firstSeenAt = firstSeenAtOf(file, value, now);
79
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
66
80
  fs.renameSync(temporary, file);
67
81
  for (const name of fs.readdirSync(LEASE_ROOT)) {
68
82
  if (!name.endsWith('.json')) continue;
@@ -3,7 +3,7 @@
3
3
  "platform": "zcode",
4
4
  "stack": "java",
5
5
  "semanticSource": "cursor/java",
6
- "sourceRevision": "a455ed6cd1b5d5d0cd3a3506a7a33ce250b1410228ec1d251978bbb2fed4c750",
6
+ "sourceRevision": "d14ea6d152a75b97b3030dbc86e08eb6a997060f7b487aca482ff9de65b629cc",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -251,6 +251,14 @@
251
251
  "loadMode": "native-skill",
252
252
  "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
253
253
  },
254
+ {
255
+ "source": "commands/rr-scheduler-start.md",
256
+ "target": "commands/rr-scheduler-start.md",
257
+ "category": "commands",
258
+ "disposition": "transform",
259
+ "loadMode": "native-skill",
260
+ "reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
261
+ },
254
262
  {
255
263
  "source": "commands/spec-start.md",
256
264
  "target": "commands/spec-start.md",