@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
@@ -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": "opencode",
4
4
  "stack": "nuxt",
5
5
  "semanticSource": "cursor/nuxt",
6
- "sourceRevision": "44e77b62f8babb38d97e92d4af7ca86f1fbc381df0568fbce7012b1bddc9630f",
6
+ "sourceRevision": "f31f863d855cbc0ffd32b8a4e54e168dc5d116aff4345d9b76c1f93ec6d64da4",
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": "opencode",
4
4
  "stack": "php-hexagonal",
5
5
  "semanticSource": "cursor/php-hexagonal",
6
- "sourceRevision": "d60c7303b439bfb58126e17bcf4e6291ac956468033e1e1d1dfa2cb64bad6172",
6
+ "sourceRevision": "db56d6730784e0318a47b8290539ebd17a9bd58e8a0883802127dda1cd405c85",
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 .opencode/commands; $ARGUMENTS kept"
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 .opencode/commands; $ARGUMENTS kept"
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 `.opencode/commands/` on `ai-rules init opencode --
52
52
  - Hooks: `../hooks/chain-team-phases.sh` only (semi-auto runner; no `hooks.json`)
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.
@@ -59,12 +59,26 @@ function readSessionLease(id) {
59
59
  return null;
60
60
  }
61
61
  }
62
+ // The lease carries the window the projector attributes rows with — never one
63
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
64
+ // pair; a different slug starts a new window, and a lease older than the TTL
65
+ // starts over instead of claiming an ancient first sighting.
66
+ function firstSeenAtOf(file, value, now) {
67
+ try {
68
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
69
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
70
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
71
+ } catch {}
72
+ return now;
73
+ }
62
74
  function writeSessionLease(id, value) {
63
75
  try {
64
76
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
65
77
  const file = sessionLeasePath(id);
66
78
  const temporary = `${file}.${process.pid}.tmp`;
67
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
79
+ const now = new Date().toISOString();
80
+ const firstSeenAt = firstSeenAtOf(file, value, now);
81
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
68
82
  fs.renameSync(temporary, file);
69
83
  for (const name of fs.readdirSync(LEASE_ROOT)) {
70
84
  if (!name.endsWith('.json')) continue;
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "php-laravel",
5
5
  "semanticSource": "cursor/php-laravel",
6
- "sourceRevision": "ff14228831038984e00c960ccbba2d355b27b2f059397b250b00b7a06c89512c",
6
+ "sourceRevision": "adfe101be4db9c98bf768d8345c2a9a5edb0a3dc8fb687d868b961fb832f5d87",
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 .opencode/commands; $ARGUMENTS kept"
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 .opencode/commands; $ARGUMENTS kept"
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 `.opencode/commands/` on `ai-rules init opencode --
52
52
  - Hooks: `../hooks/chain-team-phases.sh` only (semi-auto runner; no `hooks.json`)
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.
@@ -59,12 +59,26 @@ function readSessionLease(id) {
59
59
  return null;
60
60
  }
61
61
  }
62
+ // The lease carries the window the projector attributes rows with — never one
63
+ // instant. `firstSeenAt` survives every later write of the same (session, slug)
64
+ // pair; a different slug starts a new window, and a lease older than the TTL
65
+ // starts over instead of claiming an ancient first sighting.
66
+ function firstSeenAtOf(file, value, now) {
67
+ try {
68
+ if (Date.now() - fs.statSync(file).mtimeMs > LEASE_TTL_MS) return now;
69
+ const previous = JSON.parse(fs.readFileSync(file, 'utf8'));
70
+ if (previous && previous.slug === value && typeof previous.firstSeenAt === 'string') return previous.firstSeenAt;
71
+ } catch {}
72
+ return now;
73
+ }
62
74
  function writeSessionLease(id, value) {
63
75
  try {
64
76
  fs.mkdirSync(LEASE_ROOT, { recursive: true });
65
77
  const file = sessionLeasePath(id);
66
78
  const temporary = `${file}.${process.pid}.tmp`;
67
- fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, updatedAt: new Date().toISOString() })}\n`);
79
+ const now = new Date().toISOString();
80
+ const firstSeenAt = firstSeenAtOf(file, value, now);
81
+ fs.writeFileSync(temporary, `${JSON.stringify({ slug: value, sessionId: id, firstSeenAt, updatedAt: now })}\n`);
68
82
  fs.renameSync(temporary, file);
69
83
  for (const name of fs.readdirSync(LEASE_ROOT)) {
70
84
  if (!name.endsWith('.json')) continue;
@@ -20,7 +20,7 @@ call; persisted history is untouched.
20
20
  | Saved file | `.ai.local/team/output-guard/<sessionID>/outputs/<callID>-<tool>.txt`, 2 MiB cap |
21
21
  | Stats | `.ai.local/team/output-guard/stats.jsonl` (one row per replacement) |
22
22
  | Ledgers | `results.jsonl`, `usage.jsonl`, `context.jsonl` — see [Ledgers](#ledgers) |
23
- | Kill switch | `AI_RULES_OUTPUT_GUARD=0` |
23
+ | Kill switch | `AI_RULES_OUTPUT_GUARD=0` (the guard); `AI_RULES_ACTIONS=0` (the action and turn rows only) |
24
24
  | Debug | `AI_RULES_OUTPUT_GUARD_DEBUG=1` → `output-guard/debug.log` |
25
25
  | Host | OpenCode V2 with `ctx.session.hook`; a host without it no-ops |
26
26
 
@@ -84,6 +84,45 @@ existed, has no such key — absence means non-error. The report reads the rows
84
84
  back as `readCountPerPath` (per-path `read`-tool calls) and `mcpErrors`
85
85
  (errored results on `<server>_<tool>` names).
86
86
 
87
+ ## Action and turn capture
88
+
89
+ `AI_RULES_ACTIONS=0` drops the two rows below and nothing else: the rewrite, the
90
+ stats row and the context snapshot keep working, so the guard is still a guard
91
+ with capture off.
92
+
93
+ A `results.jsonl` row also carries the action fields: `parentSessionID`, `agent`,
94
+ `model`, `variant`, `intent`, `targetKey`, `durationMs`, `gapMs`, `exit`,
95
+ `errorClass`, `lines`, `truncated`, `repeatOf` and `repeatIndex`.
96
+
97
+ - `targetKey` is `sha256(tool + "\u0000" + target)` over the normalised
98
+ **repo-relative** target, so two absolute prefixes of one file collapse to one
99
+ key. The target text itself never leaves the ledger's own `command`/`path`
100
+ columns, which the projector does not read.
101
+ - `intent` is one of `explore | mutate | execute | delegate | ask | meta | web`;
102
+ the projector recomputes the column from the tool name, so the ledger copy is
103
+ never the source of truth.
104
+ - `errorClass` is one of `validation | notfound | permission | timeout |
105
+ upstream`, derived from the failure text and never the text itself.
106
+ - `durationMs` and `exit` come from the `tool.execute.before` / `.after` hooks.
107
+ This repository had never registered them, so their dispatch is **unverified**:
108
+ when they do not fire the two fields are `null` and the projector writes null
109
+ rather than a fabricated value. `exit` reads `metadata.exit` defensively.
110
+ - `gapMs` is the distance to the previous observed action of the session; the
111
+ first action of a session has no gap.
112
+ - `repeatOf` is the call id of the first action on the same `targetKey` in one
113
+ session, and `repeatIndex` counts from 2 on the repeats. The per-session map is
114
+ bounded (`MAX_TIMING_ENTRIES`), so a long session cannot grow the heap.
115
+
116
+ A `usage.jsonl` row also carries `reasoningParts`, `reasoningChars`,
117
+ `reasoningMs`, `textChars`, `toolCalls` and `compactions`. Counts and lengths
118
+ only: no reasoning, text or compaction content is stored. A message whose parts
119
+ the host does not expose reports `null` — never `0`, which would read as a
120
+ measured empty turn.
121
+
122
+ Every append keeps the shipped guard shape: a throwing append never fails a tool
123
+ call, and the capture block has its own `try`, so a capture failure cannot skip
124
+ the child discovery that follows the rewrite.
125
+
87
126
  ## Why a hook, not a rule
88
127
 
89
128
  A prose line asks the agent to pipe output; context-mode measured that path at
@@ -95,6 +134,8 @@ trade-off: the model loses the middle of the output and must search the file.
95
134
 
96
135
  - `index.ts` — host adapter: `Plugin.define`, team-root walk, writer, stats.
97
136
  - `rewrite.ts` — pure `rewriteMessages`; no host imports, fixture-tested.
137
+ - `actions.ts` — pure capture helpers (`intentOf`, `normalizeTarget`,
138
+ `targetKeyOf`, `errorClassOf`, `turnCounters`); no host imports, fixture-tested.
98
139
  - `package.json` — local plugin package (`exports` → `index.ts`).
99
140
 
100
141
  ## Not a security boundary
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Pure capture helpers for the action and turn telemetry (`results.jsonl`,
3
+ * `usage.jsonl`). No host imports: the adapter in `index.ts` supplies the
4
+ * observed values, and the fixture test imports this module directly.
5
+ *
6
+ * The privacy invariant lives here: a target becomes a sha256 key and never a
7
+ * stored string, a failure becomes one of five classes and never the host's
8
+ * message, and a value the plugin cannot observe stays `null`.
9
+ */
10
+
11
+ import { createHash } from "node:crypto"
12
+ import path from "node:path"
13
+
14
+ /** The seven intent values of `design.md` D-2; nothing else is a value. */
15
+ export type ActionIntent = "explore" | "mutate" | "execute" | "delegate" | "ask" | "meta" | "web"
16
+
17
+ const INTENT_BY_TOOL: ReadonlyMap<string, ActionIntent> = new Map<string, ActionIntent>([
18
+ ["read", "explore"],
19
+ ["grep", "explore"],
20
+ ["glob", "explore"],
21
+ ["list", "explore"],
22
+ ["edit", "mutate"],
23
+ ["write", "mutate"],
24
+ ["patch", "mutate"],
25
+ ["shell", "execute"],
26
+ ["bash", "execute"],
27
+ ["execute", "execute"],
28
+ ["subagent", "delegate"],
29
+ ["task", "delegate"],
30
+ ["question", "ask"],
31
+ ["permission", "ask"],
32
+ ["skill", "meta"],
33
+ ["todowrite", "meta"],
34
+ ["todoread", "meta"],
35
+ ["plan", "meta"],
36
+ ["webfetch", "web"],
37
+ ["websearch", "web"],
38
+ ])
39
+
40
+ /**
41
+ * The intent of one tool call. The projector recomputes this column from the
42
+ * tool name so the ledger copy can never become the source of truth; the P0
43
+ * fixture pins both tables against each other.
44
+ */
45
+ export const intentOf = (tool: string, command = ""): ActionIntent => {
46
+ const name = tool.toLowerCase()
47
+ const known = INTENT_BY_TOOL.get(name)
48
+ if (known !== undefined) return known
49
+ if (/\b(curl|wget|http)\b/i.test(command)) return "web"
50
+ if (/\b(git|test|lint|type-check|tsc|vitest|jest|playwright|eslint|build|compile|bundle)\b/i.test(command)) {
51
+ return "execute"
52
+ }
53
+ if (/\b(grep|rg|find|search)\b/i.test(command)) return "explore"
54
+ return "meta"
55
+ }
56
+
57
+ /** The five failure classes; `null` means "no failure observed". */
58
+ export type ActionErrorClass = "validation" | "notfound" | "permission" | "timeout" | "upstream"
59
+
60
+ const ERROR_CLASSES: ReadonlyArray<{ readonly errorClass: ActionErrorClass; readonly pattern: RegExp }> = [
61
+ { errorClass: "notfound", pattern: /(?:enoent|no such file|not found|does not exist)/i },
62
+ { errorClass: "permission", pattern: /(?:eacces|eperm|permission|denied|forbidden|401|403)/i },
63
+ { errorClass: "timeout", pattern: /(?:timed out|timeout|etimedout|deadline exceeded)/i },
64
+ { errorClass: "validation", pattern: /(?:invalid|validation|must be|cannot parse|unexpected token)/i },
65
+ { errorClass: "upstream", pattern: /(?:econnrefused|econnreset|enotfound|fetch failed|socket hang up|50\d)/i },
66
+ ]
67
+
68
+ /**
69
+ * The class of a failed tool result. The text is read once, never stored: a
70
+ * failure that matches no class keeps the residual `upstream`, and a call that
71
+ * did not fail is `null`.
72
+ */
73
+ export const errorClassOf = (resultType: unknown, value: unknown): ActionErrorClass | null => {
74
+ if (resultType !== "error") return null
75
+ const text =
76
+ typeof value === "string"
77
+ ? value
78
+ : (() => {
79
+ try {
80
+ return JSON.stringify(value) ?? ""
81
+ } catch {
82
+ return ""
83
+ }
84
+ })()
85
+ for (const entry of ERROR_CLASSES) {
86
+ if (entry.pattern.test(text)) return entry.errorClass
87
+ }
88
+ return "upstream"
89
+ }
90
+
91
+ const TARGET_KEYS = ["command", "filePath", "path", "pattern", "url", "query", "agent", "skill"] as const
92
+ const MAX_TARGET_CHARS = 512
93
+
94
+ /**
95
+ * The target value of a tool input, normalised so two absolute prefixes of one
96
+ * file collapse to one key. The value itself is hashed and never stored.
97
+ */
98
+ export const normalizeTarget = (input: unknown, projectRoot: string): string => {
99
+ if (!input || typeof input !== "object") return ""
100
+ const record = input as Record<string, unknown>
101
+ for (const key of TARGET_KEYS) {
102
+ const value = record[key]
103
+ if (typeof value !== "string" || value === "") continue
104
+ return normaliseValue(value, projectRoot)
105
+ }
106
+ return ""
107
+ }
108
+
109
+ const normaliseValue = (value: string, projectRoot: string): string => {
110
+ const trimmed = value.replace(/\s+/g, " ").trim().slice(0, MAX_TARGET_CHARS)
111
+ if (!trimmed.startsWith("/")) return trimmed.startsWith("./") ? trimmed.slice(2) : trimmed
112
+ const root = path.resolve(projectRoot).replace(/\/+$/, "")
113
+ if (root === "" || root === "/") return trimmed
114
+ const relative = path.relative(root, trimmed).split(path.sep).join("/")
115
+ return relative.startsWith("..") ? trimmed : relative
116
+ }
117
+
118
+ /** `sha256(tool + "\0" + target)`; `null` when the call carries no target. */
119
+ export const targetKeyOf = (tool: string, target: string): string | null => {
120
+ if (target === "") return null
121
+ return createHash("sha256").update(`${tool.toLowerCase()}\u0000${target}`, "utf8").digest("hex")
122
+ }
123
+
124
+ /** The counters of one assistant message; a value the host omits stays `null`. */
125
+ export type TurnCounters = {
126
+ reasoningParts: number | null
127
+ reasoningChars: number | null
128
+ reasoningMs: number | null
129
+ textChars: number | null
130
+ toolCalls: number | null
131
+ compactions: number | null
132
+ }
133
+
134
+ const EMPTY_COUNTERS: TurnCounters = {
135
+ reasoningParts: null,
136
+ reasoningChars: null,
137
+ reasoningMs: null,
138
+ textChars: null,
139
+ toolCalls: null,
140
+ compactions: null,
141
+ }
142
+
143
+ type Part = {
144
+ type?: unknown
145
+ text?: unknown
146
+ time?: { start?: unknown; end?: unknown }
147
+ }
148
+
149
+ // VERIFY: the parts array of a `session.context` message (host v2). The shapes
150
+ // read here are the SDK's `Part` union; a message that carries no parts yields
151
+ // nulls instead of zeroes, so an unobserved turn is never reported as empty.
152
+ const partsOf = (message: unknown): Part[] | null => {
153
+ if (!message || typeof message !== "object") return null
154
+ const record = message as { parts?: unknown; content?: unknown }
155
+ const parts = Array.isArray(record.parts) ? record.parts : Array.isArray(record.content) ? record.content : null
156
+ return parts === null ? null : (parts as Part[])
157
+ }
158
+
159
+ const durationOf = (part: Part): number | null => {
160
+ const start = part.time?.start
161
+ const end = part.time?.end
162
+ return typeof start === "number" && typeof end === "number" && end >= start ? end - start : null
163
+ }
164
+
165
+ /** The reasoning, text, tool-call and compaction counters of one message. */
166
+ export const turnCounters = (message: unknown): TurnCounters => {
167
+ const parts = partsOf(message)
168
+ if (parts === null) return { ...EMPTY_COUNTERS }
169
+ const counters: TurnCounters = {
170
+ reasoningParts: 0,
171
+ reasoningChars: 0,
172
+ reasoningMs: 0,
173
+ textChars: 0,
174
+ toolCalls: 0,
175
+ compactions: 0,
176
+ }
177
+ let measuredReasoningMs = false
178
+ for (const part of parts) {
179
+ if (part?.type === "reasoning") {
180
+ counters.reasoningParts += 1
181
+ if (typeof part.text === "string") counters.reasoningChars += part.text.length
182
+ const duration = durationOf(part)
183
+ if (duration !== null) {
184
+ counters.reasoningMs = (counters.reasoningMs ?? 0) + duration
185
+ measuredReasoningMs = true
186
+ }
187
+ } else if (part?.type === "text") {
188
+ if (typeof part.text === "string") counters.textChars += part.text.length
189
+ } else if (part?.type === "tool") {
190
+ counters.toolCalls += 1
191
+ } else if (part?.type === "compaction") {
192
+ counters.compactions += 1
193
+ }
194
+ }
195
+ // A reasoning part without a completion stamp leaves the duration unmeasured.
196
+ if (!measuredReasoningMs) counters.reasoningMs = null
197
+ return counters
198
+ }
199
+
200
+ /** The line count of a result text, or `null` when it is empty. */
201
+ export const lineCount = (text: string): number | null => (text === "" ? null : text.split("\n").length)