@bonesofspring/ai-rules 0.2.52 → 0.2.53

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 (134) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +27 -3
  3. package/bin/cli.js +551 -60
  4. package/bin/lib/engine-scripts.js +10 -0
  5. package/bin/lib/mcp/clients.js +168 -0
  6. package/bin/lib/mcp/credentials.js +298 -0
  7. package/bin/lib/mcp/doctor.js +394 -0
  8. package/bin/lib/mcp/prompt.js +115 -0
  9. package/bin/lib/mcp/registry.js +170 -0
  10. package/bin/lib/mcp/run.js +123 -0
  11. package/bin/lib/merged-config.js +45 -0
  12. package/bin/lib/seed-ai-local-team.js +5 -0
  13. package/bin/lib/tool-installs.js +27 -0
  14. package/docs/MCP-SETUP.md +62 -0
  15. package/docs/PRESET-CONTRIBUTION.md +3 -1
  16. package/docs/TEAM-DB.md +173 -0
  17. package/docs/openapi/team-db.v1.json +5085 -0
  18. package/mcp/gitlab.mjs +123 -0
  19. package/mcp/lib/envfile.mjs +126 -0
  20. package/mcp/lib/yandex.mjs +384 -0
  21. package/mcp/yandex-mcp-proxy.mjs +155 -0
  22. package/mcp/yandex-token-refresh.mjs +65 -0
  23. package/package.json +14 -1
  24. package/presets/_shared/ai-local/scripts/manifest.mjs +99 -0
  25. package/presets/_shared/ai-local/scripts/team-db-api.mjs +1275 -0
  26. package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +1067 -0
  27. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +1301 -0
  28. package/presets/_shared/ai-local/scripts/team-db-project.mjs +1506 -0
  29. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +831 -0
  30. package/presets/_shared/ai-local/scripts/team-db.mjs +251 -0
  31. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +109 -0
  32. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +109 -0
  33. package/presets/claude/android-kotlin/team/README.md +10 -0
  34. package/presets/claude/go/hooks/chain-team-phases.sh +109 -0
  35. package/presets/claude/go/team/README.md +10 -0
  36. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +109 -0
  37. package/presets/claude/ios-swift/team/README.md +10 -0
  38. package/presets/claude/java/hooks/chain-team-phases.sh +109 -0
  39. package/presets/claude/java/team/README.md +10 -0
  40. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +109 -0
  41. package/presets/claude/mcp-ts/team/README.md +10 -0
  42. package/presets/claude/next/hooks/chain-team-phases.sh +109 -0
  43. package/presets/claude/next/team/README.md +10 -0
  44. package/presets/claude/nuxt/hooks/chain-team-phases.sh +109 -0
  45. package/presets/claude/nuxt/team/README.md +10 -0
  46. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  47. package/presets/claude/php-hexagonal/team/README.md +10 -0
  48. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +109 -0
  49. package/presets/claude/php-laravel/team/README.md +10 -0
  50. package/presets/claude/svelte/hooks/chain-team-phases.sh +109 -0
  51. package/presets/claude/svelte/team/README.md +10 -0
  52. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +109 -0
  53. package/presets/cursor/android-kotlin/team/README.md +10 -0
  54. package/presets/cursor/go/hooks/chain-team-phases.sh +109 -0
  55. package/presets/cursor/go/team/README.md +10 -0
  56. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +109 -0
  57. package/presets/cursor/ios-swift/team/README.md +10 -0
  58. package/presets/cursor/java/hooks/chain-team-phases.sh +109 -0
  59. package/presets/cursor/java/team/README.md +10 -0
  60. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +109 -0
  61. package/presets/cursor/mcp-ts/team/README.md +10 -0
  62. package/presets/cursor/next/MCP.md +7 -0
  63. package/presets/cursor/next/hooks/chain-team-phases.sh +109 -0
  64. package/presets/cursor/next/team/README.md +10 -0
  65. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +109 -0
  66. package/presets/cursor/nuxt/team/README.md +10 -0
  67. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  68. package/presets/cursor/php-hexagonal/team/README.md +10 -0
  69. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +109 -0
  70. package/presets/cursor/php-laravel/team/README.md +10 -0
  71. package/presets/cursor/svelte/hooks/chain-team-phases.sh +109 -0
  72. package/presets/cursor/svelte/team/README.md +10 -0
  73. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  74. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +109 -0
  75. package/presets/mavis/android-kotlin/team/README.md +10 -0
  76. package/presets/mavis/go/adapter-map.json +1 -1
  77. package/presets/mavis/go/hooks/chain-team-phases.sh +109 -0
  78. package/presets/mavis/go/team/README.md +10 -0
  79. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  80. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +109 -0
  81. package/presets/mavis/ios-swift/team/README.md +10 -0
  82. package/presets/mavis/java/adapter-map.json +1 -1
  83. package/presets/mavis/java/hooks/chain-team-phases.sh +109 -0
  84. package/presets/mavis/java/team/README.md +10 -0
  85. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  86. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +109 -0
  87. package/presets/mavis/mcp-ts/team/README.md +10 -0
  88. package/presets/mavis/next/MCP.md +7 -0
  89. package/presets/mavis/next/adapter-map.json +1 -1
  90. package/presets/mavis/next/hooks/chain-team-phases.sh +109 -0
  91. package/presets/mavis/next/team/README.md +10 -0
  92. package/presets/mavis/nuxt/adapter-map.json +1 -1
  93. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +109 -0
  94. package/presets/mavis/nuxt/team/README.md +10 -0
  95. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  96. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  97. package/presets/mavis/php-hexagonal/team/README.md +10 -0
  98. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  99. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +109 -0
  100. package/presets/mavis/php-laravel/team/README.md +10 -0
  101. package/presets/mavis/svelte/adapter-map.json +1 -1
  102. package/presets/mavis/svelte/hooks/chain-team-phases.sh +109 -0
  103. package/presets/mavis/svelte/team/README.md +10 -0
  104. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  105. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +109 -0
  106. package/presets/opencode/android-kotlin/team/README.md +10 -0
  107. package/presets/opencode/go/adapter-map.json +1 -1
  108. package/presets/opencode/go/hooks/chain-team-phases.sh +109 -0
  109. package/presets/opencode/go/team/README.md +10 -0
  110. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  111. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +109 -0
  112. package/presets/opencode/ios-swift/team/README.md +10 -0
  113. package/presets/opencode/java/adapter-map.json +1 -1
  114. package/presets/opencode/java/hooks/chain-team-phases.sh +109 -0
  115. package/presets/opencode/java/team/README.md +10 -0
  116. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  117. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +109 -0
  118. package/presets/opencode/mcp-ts/team/README.md +10 -0
  119. package/presets/opencode/next/MCP.md +7 -0
  120. package/presets/opencode/next/adapter-map.json +1 -1
  121. package/presets/opencode/next/hooks/chain-team-phases.sh +109 -0
  122. package/presets/opencode/next/team/README.md +10 -0
  123. package/presets/opencode/nuxt/adapter-map.json +1 -1
  124. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +109 -0
  125. package/presets/opencode/nuxt/team/README.md +10 -0
  126. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  127. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  128. package/presets/opencode/php-hexagonal/team/README.md +10 -0
  129. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  130. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +109 -0
  131. package/presets/opencode/php-laravel/team/README.md +10 -0
  132. package/presets/opencode/svelte/adapter-map.json +1 -1
  133. package/presets/opencode/svelte/hooks/chain-team-phases.sh +109 -0
  134. package/presets/opencode/svelte/team/README.md +10 -0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Runtime support for `ai-rules mcp …`: project-root resolution, the Node floor,
3
+ * and the `mcp run` spawn. The moved `mcp/*.mjs` modules import this file so a
4
+ * published package never derives its project root from `import.meta.url`
5
+ * (which would resolve inside the npm cache / `node_modules`).
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ const NODE_FLOOR_MAJOR = 20;
11
+ const PROJECT_ROOT_NEXT = 'start the client from the repository root or set AI_RULES_PROJECT_ROOT';
12
+
13
+ /** A directory containing any of these is a consumer project root; `.git` is the walk boundary. */
14
+ const PROJECT_MARKERS = [
15
+ '.git',
16
+ '.ai.local',
17
+ '.cursor/.ai-rules-install.json',
18
+ '.claude/.ai-rules-install.json',
19
+ '.mavis/.ai-rules-install.json',
20
+ '.opencode/.ai-rules-install.json',
21
+ '.cursor/mcp.json',
22
+ '.mcp.json',
23
+ '.mavis/mcp.json',
24
+ 'opencode.json',
25
+ ];
26
+
27
+ /** A `ConfigError`-shaped failure the runtime and the doctor can print as one next step. */
28
+ class ProjectRootError extends Error {
29
+ constructor(message, next = PROJECT_ROOT_NEXT) {
30
+ super(message);
31
+ this.name = 'ConfigError';
32
+ this.next = next;
33
+ }
34
+ }
35
+
36
+ function nodeMajor(version) {
37
+ const major = Number.parseInt(String(version).split('.')[0], 10);
38
+ return Number.isNaN(major) ? 0 : major;
39
+ }
40
+
41
+ /** Pure floor check: `assertNodeFloor('18.20.0', 20) === false`. */
42
+ function assertNodeFloor(version, floor = NODE_FLOOR_MAJOR) {
43
+ return nodeMajor(version) >= floor;
44
+ }
45
+
46
+ function isDirectory(target) {
47
+ try {
48
+ return fs.statSync(target).isDirectory();
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ function isInsideNodeModules(dir) {
55
+ return dir.split(path.sep).includes('node_modules');
56
+ }
57
+
58
+ /**
59
+ * @returns {{ root: string, source: 'env' | 'marker' | 'cwd' }}
60
+ * `source` lets the doctor explain a fallback to the current directory.
61
+ */
62
+ function resolveProjectRootDetailed({ cwd = process.cwd(), env = process.env } = {}) {
63
+ const fromEnv = env.AI_RULES_PROJECT_ROOT;
64
+ if (typeof fromEnv === 'string' && fromEnv !== '' && isDirectory(fromEnv)) {
65
+ const resolved = path.resolve(fromEnv);
66
+ if (isInsideNodeModules(resolved)) {
67
+ throw new ProjectRootError(
68
+ `AI_RULES_PROJECT_ROOT points inside node_modules; ${PROJECT_ROOT_NEXT}`,
69
+ );
70
+ }
71
+ return { root: resolved, source: 'env' };
72
+ }
73
+
74
+ const resolvedCwd = path.resolve(cwd);
75
+ let current = resolvedCwd;
76
+ while (true) {
77
+ if (!isInsideNodeModules(current) && PROJECT_MARKERS.some((rel) => fs.existsSync(path.join(current, rel)))) {
78
+ return { root: current, source: 'marker' };
79
+ }
80
+ const parent = path.dirname(current);
81
+ if (parent === current) {
82
+ break;
83
+ }
84
+ current = parent;
85
+ }
86
+
87
+ if (isInsideNodeModules(resolvedCwd)) {
88
+ throw new ProjectRootError(
89
+ `project root not found: the working directory is inside node_modules; ${PROJECT_ROOT_NEXT}`,
90
+ );
91
+ }
92
+
93
+ return { root: resolvedCwd, source: 'cwd' };
94
+ }
95
+
96
+ function resolveProjectRoot(options) {
97
+ return resolveProjectRootDetailed(options).root;
98
+ }
99
+
100
+ function packageVersion(packageRoot) {
101
+ try {
102
+ return JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8')).version;
103
+ } catch {
104
+ return '0.0.0';
105
+ }
106
+ }
107
+
108
+ function runtimeEntryPath(packageRoot, entry) {
109
+ return path.join(packageRoot, entry);
110
+ }
111
+
112
+ module.exports = {
113
+ NODE_FLOOR_MAJOR,
114
+ PROJECT_MARKERS,
115
+ PROJECT_ROOT_NEXT,
116
+ ProjectRootError,
117
+ nodeMajor,
118
+ assertNodeFloor,
119
+ resolveProjectRootDetailed,
120
+ resolveProjectRoot,
121
+ packageVersion,
122
+ runtimeEntryPath,
123
+ };
@@ -208,6 +208,49 @@ function stripMergedConfigs(cwd, records) {
208
208
  }
209
209
  }
210
210
 
211
+ /**
212
+ * Merge one shipped server object. Preset scalar fields win; nested `env` / `headers`
213
+ * keep consumer keys unless the preset defines the same nested key.
214
+ */
215
+ function mergeServerEntry(existingEntry, presetEntry) {
216
+ if (!isPlainObject(existingEntry) || !isPlainObject(presetEntry)) {
217
+ return presetEntry;
218
+ }
219
+ const merged = { ...existingEntry, ...presetEntry };
220
+ for (const nested of ['env', 'headers']) {
221
+ const existingNested = existingEntry[nested];
222
+ const presetNested = presetEntry[nested];
223
+ if (isPlainObject(existingNested) && isPlainObject(presetNested)) {
224
+ merged[nested] = { ...existingNested, ...presetNested };
225
+ } else if (isPlainObject(existingNested) && presetNested === undefined) {
226
+ merged[nested] = existingNested;
227
+ }
228
+ }
229
+ return merged;
230
+ }
231
+
232
+ /**
233
+ * Extra local `mcpServers` keys are kept. Shipped keys update; nested `env` / `headers`
234
+ * on overlapping keys are preserved unless the preset defines them.
235
+ * Other unknown top-level keys on the existing file are preserved.
236
+ * @returns {{ merged: object, extrasKept: string[] }}
237
+ */
238
+ function mergeMcpConfig(presetObj, existingObj) {
239
+ const preset = isPlainObject(presetObj) ? presetObj : {};
240
+ const existing = isPlainObject(existingObj) ? existingObj : {};
241
+ const presetServers = isPlainObject(preset.mcpServers) ? preset.mcpServers : {};
242
+ const existingServers = isPlainObject(existing.mcpServers) ? existing.mcpServers : {};
243
+ const extrasKept = ownKeys(existingServers).filter((key) => !Object.hasOwn(presetServers, key));
244
+ const mergedServers = { ...existingServers };
245
+ for (const key of ownKeys(presetServers)) {
246
+ mergedServers[key] = mergeServerEntry(existingServers[key], presetServers[key]);
247
+ }
248
+ return {
249
+ merged: { ...existing, ...preset, mcpServers: mergedServers },
250
+ extrasKept,
251
+ };
252
+ }
253
+
211
254
  /**
212
255
  * Union `permissions.*` arrays and add preset hooks by event (deduped by `command`).
213
256
  * Every other consumer key wins. Bare `Bash(git commit)` and `Bash(git push)` are
@@ -316,4 +359,6 @@ module.exports = {
316
359
  mergedConfigRecords,
317
360
  stripMergedConfigs,
318
361
  mergeClaudeSettings,
362
+ mergeServerEntry,
363
+ mergeMcpConfig,
319
364
  };
@@ -23,6 +23,11 @@ const AI_LOCAL_GITIGNORE = [
23
23
  '.rollback/',
24
24
  '.template-base.json',
25
25
  '*.intent',
26
+ '# Rebuildable SQLite projection of .ai.local/team; never commit a database.',
27
+ 'team.db',
28
+ 'team.db-wal',
29
+ 'team.db-shm',
30
+ 'team-db-errors.log',
26
31
  '',
27
32
  ].join('\n');
28
33
  const POINTER_README = `# Agent team artifacts moved
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Install-presence markers shared by `clean` and the MCP registration command.
3
+ *
4
+ * A leftover directory does not mean a tool install is still present; these
5
+ * markers do (see `clean`'s AGENTS.md ownership rule).
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ /** Markers that mean a tool install is still present (directory leftovers do not count). */
11
+ const TOOL_INSTALL_MARKERS = {
12
+ '.cursor': ['.cursor/AGENTS.md', '.cursor/hooks.json', '.cursor/rules'],
13
+ '.claude': ['.claude/CLAUDE.md', '.claude/rules', '.claude/settings.json'],
14
+ '.mavis': ['.mavis/.ai-rules-install.json', '.mavis/AGENTS.md'],
15
+ '.opencode': ['.opencode/.ai-rules-install.json', '.opencode/AGENTS.md'],
16
+ };
17
+
18
+ function otherToolInstallPresent(cwd, exceptRoot) {
19
+ return Object.entries(TOOL_INSTALL_MARKERS).some(([root, markers]) => {
20
+ if (root === exceptRoot) {
21
+ return false;
22
+ }
23
+ return markers.some((rel) => fs.existsSync(path.join(cwd, rel)));
24
+ });
25
+ }
26
+
27
+ module.exports = { TOOL_INSTALL_MARKERS, otherToolInstallPresent };
@@ -0,0 +1,62 @@
1
+ # MCP setup: GitLab, Yandex Tracker, Yandex Wiki
2
+
3
+ Two sequences. Nothing here stores a token in a client config.
4
+ `mcp setup` writes the exact installed version pin into the client config; the runtime is pinned even though setup runs `@latest`.
5
+ It registers only the clients already installed in the repository.
6
+ GitLab credentials live in `.ai-rules/mcp/credentials.env`; Yandex keeps only non-secret settings in `.ai-rules/mcp/config.env`.
7
+ Both sequences are idempotent: rerun a step instead of editing a client config by hand.
8
+ Prerequisites: Node 20+, an MCP client, network to your GitLab instance and to Yandex.
9
+
10
+ ## 1. GitLab
11
+
12
+ 1. **Create a personal access token.**
13
+ Open Preferences → Access Tokens on your GitLab instance and add scope `read_api`; add `api` only if the agent must write.
14
+ [GitLab: personal access tokens](https://docs.gitlab.com/user/profile/personal_access_tokens/)
15
+ → expected: the token is shown once; keep it for the next step.
16
+
17
+ 2. **Save the credentials.** Paste the instance URL, then the token at the hidden prompt.
18
+ The token is validated against the API before the file is written.
19
+ `npx @bonesofspring/ai-rules@latest mcp setup gitlab`
20
+ → expected: `ok credentials … (0600, ignored)`, then `ok registration` per client.
21
+
22
+ 3. **Reconnect the client.**
23
+
24
+ - OpenCode: `opencode reload`
25
+ - Cursor: restart the server in Settings → MCP
26
+ - Claude Code: `/mcp`, then approve the server
27
+ - Mavis: reconnect the server
28
+
29
+ → expected: `gitlab` is connected and lists tools.
30
+
31
+ 4. **Verify the setup.** Any failure exits 1 and names the next command.
32
+ `npx @bonesofspring/ai-rules@latest mcp doctor gitlab`
33
+ → expected: four `ok` lines — runtime, registration, credentials, upstream — and exit 0.
34
+
35
+ 5. **Rotate the token.** Create a new token with the same scopes.
36
+ Rerun the setup; the file is rewritten only after the new token validates.
37
+ `npx @bonesofspring/ai-rules@latest mcp setup gitlab`
38
+ → expected: the new token is validated and saved; the server reconnects with it.
39
+
40
+ ## 2. Yandex (Tracker + Wiki)
41
+
42
+ 1. **Install the Yandex Cloud CLI.**
43
+ [Yandex Cloud CLI: installation](https://yandex.cloud/en/docs/cli/operations/install-cli)
44
+ → expected: `yc --version` prints a version.
45
+
46
+ 2. **Log in through your federation.** Use the federation id from your cloud admin; it is not a secret.
47
+ The wizard opens the browser and asks for a profile, cloud, and folder.
48
+ `yc init --federation-id <id>`
49
+ → expected: `yc iam create-token` prints an IAM token.
50
+
51
+ 3. **Save the settings.** Enter the organization id at the prompt; it is not a secret.
52
+ The setup registers the clients present and finishes with a doctor over both servers.
53
+ `npx @bonesofspring/ai-rules@latest mcp setup yandex`
54
+ → expected: `ok credentials` with the organization id saved, then `ok` lines for `yandex tracker` and `yandex wiki`.
55
+
56
+ 4. **Reconnect both servers** with the client action from GitLab step 3 (`opencode reload` in OpenCode).
57
+ → expected: `yandex tracker` and `yandex wiki` are connected and list tools.
58
+
59
+ 5. **Refresh the SSO session** when `mcp doctor yandex` exits 2; finish the browser login, then reconnect.
60
+ The IAM token stays in the `yc` profile; `.ai-rules/mcp/` holds no token.
61
+ `npx @bonesofspring/ai-rules@latest mcp refresh yandex`
62
+ → expected: `Yandex IAM token refreshed` and exit 0; no token is stored.
@@ -394,7 +394,7 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
394
394
 
395
395
  | Script / npm | Purpose |
396
396
  |--------------|---------|
397
- | `yarn fix:generated` | Regenerate every released generated platform and recapture all required CLI goldens. Run after changing Cursor SoT, before fail-only checks. Dogfood sync remains separate. |
397
+ | `yarn fix:generated` | Regenerate every released generated platform and recapture the CLI goldens it owns (`cursor/next`, `claude/next`, and every Mavis/OpenCode stack). Run after changing Cursor SoT, before fail-only checks. Capture a non-`next` Cursor/Claude golden explicitly with `node scripts/capture-cli-golden.mjs <cursor|claude> <stack>`; never hand-edit one. Dogfood sync remains separate. |
398
398
  | `scripts/sync-dogfood-cursor.sh` | Copy `presets/cursor/<preset>/` → root `.cursor/` (`AI_RULES_DOGFOOD_PRESET`, default `next`). Also copies `REPO_AGENTS.md` → repo-root `AGENTS.md`. Seeds `.ai.local/team` templates; preserves `.ai.local/team/tasks/`. |
399
399
  | `scripts/check-shared-core-drift.sh` / `yarn check:shared-core-drift` | Check embed-mode adapters vs core; lists lineage consumers. **Always hard:** every `_shared/core/**` file must be classified `embed | lineage | internal` in `_lib/embed-stems.json` (unclassified → exit 1). Drift is soft by default; set `AI_RULES_DRIFT_FAIL=1` (or use `check:preset-structure`) to exit non-zero. A stem listed in `requiredSentences` is checked in the core **and in every adapter of that stem, whatever the lineage class** — the body comparison cannot cover a platform whose adapter is not a byte-embed of the core (the Cursor family reorders, omits and adds sections), so the normative fragments of that stem are pinned separately. |
400
400
  | `scripts/check-preset-twin-map.sh` / `yarn check:preset-twin-map` | **FAIL** if Cursor `.mdc` missing from Claude mapping table, twin file missing, or orphan topic `.md` (excl. `**/README.md`). Stacks: `next`, `nuxt`, `svelte`, `ios-swift`, `android-kotlin`, `go`, `java`, `mcp-ts`, `php-hexagonal`, `php-laravel`. **Rules only** — commands and skills are guarded by `check-preset-twin-drift.mjs`. |
@@ -413,6 +413,8 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
413
413
  | `yarn check:product-specs:dogfood` | Same script against monorepo `dogfood/mcp-ts-sample`. Soft WARN inside `check:preset-structure` + CI step (`continue-on-error`); not a hard consumer CI gate. |
414
414
  | `scripts/check-rule-eval.mjs` / `yarn check:rule-eval` | **Hard gate** inside `check-preset-structure.sh`: validates Incorrect/Correct pairs + `impact:` on **next-only** golden stems (`eval/next/manifest.json`). Backend / ios / php-hexagonal / php-laravel stems are out of scope until a stack adds `eval/<stack>/`. |
415
415
  | `scripts/check-release-consistency.mjs` / `yarn check:release-consistency` | **FAIL** when `packages/ai-rules/package.json` version and the newest `## <version>` heading in `CHANGELOG.md` disagree — a tag must not ship the previous release's notes. Wired into `check-preset-structure.sh`; fixture `test-release-consistency.mjs`. |
416
+ | `scripts/check-team-db-contract.mjs` / `yarn check:team-db-contract` | **FAIL** when the checked-in OpenAPI 3.1 document (`docs/openapi/team-db.v1.json`) drifts from `team-db-openapi.mjs`, fails the vendored 3.1 meta-schema (sha256-pinned), loses an `operationId`, diverges from `ROUTE_TABLE` in either direction, carries an invalid example, or leaves a `$ref` unresolved. `--write` is the only writer; no network at gate time. Wired into `check-preset-structure.sh`. |
417
+ | `scripts/test-team-db-*.mjs` | The team-db suite family: schema (13), project (17), dual-write (13), API (12), security (10), dashboard (9), concurrency (6), and FAIL-direction fixtures (14). The fixtures prove each gate fails on its planted defect; `test-team-db-concurrency.mjs` covers first-creation races, a mixed writer/reader load, `SIGKILL` recovery, a held lock, and the 5 s hook budget. Wired into `check-preset-structure.sh`; `yarn test:team-db` runs the family. |
416
418
 
417
419
  Run from `packages/ai-rules/`:
418
420
 
@@ -0,0 +1,173 @@
1
+ # Team database projection
2
+
3
+ `@bonesofspring/ai-rules` ships a rebuildable SQLite projection of `.ai.local/team/`.
4
+ The task files remain the source of truth; the database exists so an operator or a tool can
5
+ query history without walking JSON on every request.
6
+
7
+ The projection is installed by `init` as six modules under `.ai.local/scripts/`:
8
+
9
+ | Module | Role |
10
+ |---|---|
11
+ | `team-db.mjs` | CLI: `init`, `sync`, `check`, `serve` |
12
+ | `team-db-schema.mjs` | capability probe, embedded migrations, pragmas, fingerprint, integrity |
13
+ | `team-db-project.mjs` | parsers, idempotent projector, retention, search |
14
+ | `team-db-api.mjs` | read-only `node:http` server, query layer, security boundary |
15
+ | `team-db-openapi.mjs` | the OpenAPI 3.1 document source |
16
+ | `team-db-dashboard.mjs` | the no-build dashboard (HTML, CSS, JS strings) |
17
+
18
+ ## Behavior contract
19
+
20
+ - **Files are authoritative.** `status.json`, `pipeline.json`, `metrics.json`,
21
+ `artifact-manifest.json`, prompts, memlogs, and review ledgers are read, never written.
22
+ No agent writes a lifecycle field through the projection.
23
+ - **The database is rebuildable.** Delete `team.db*` and run `sync`; the next run recreates
24
+ the schema and reconverges. A schema fingerprint mismatch rebuilds automatically.
25
+ - **Writes are isolated.** A projection failure never fails a file write or a receipt. The
26
+ hook and `manifest.mjs` run a bounded child (5 s, `SIGKILL`) and append one line to
27
+ `team-db-errors.log` on failure.
28
+ - **One read-only surface.** `POST /api/v1/sync` is the only mutation; every other route is
29
+ `GET`/`HEAD`. There is no write-back, no telemetry, and no outbound request.
30
+ - **Local only.** The server binds loopback by default, checks `Host` and `Origin`, sends no
31
+ CORS header, and serves raw documents from SQLite by exact `(slug, path)` lookup.
32
+
33
+ ## Location and ignore rules
34
+
35
+ The database lives at `.ai.local/team/team.db` with its `-wal` and `-shm` companions.
36
+ `init` writes (or completes) `.ai.local/.gitignore` so these paths are ignored:
37
+
38
+ ```text
39
+ team.db
40
+ team.db-wal
41
+ team.db-shm
42
+ team-db-errors.log
43
+ ```
44
+
45
+ The consumer root `.gitignore` is never created or edited. Never commit the database even
46
+ for a demo: it contains copies of prompts and task documents.
47
+
48
+ ## Node floor
49
+
50
+ The floor is Node 22.13.0. `node:sqlite` was unflagged in that release
51
+ ([Node.js 22.13.0 release notes](https://nodejs.org/en/blog/release/v22.13.0), commit
52
+ `55239a48b6`, PR [#55890](https://github.com/nodejs/node/pull/55890)); the module is still
53
+ marked experimental. `MIN_NODE = '22.13.0'` in `team-db-schema.mjs` is the code constant
54
+ behind this sentence; `engines` stays `>=18`.
55
+
56
+ Measured surface: Node 24.21.0 with SQLite 3.54.1 (`DatabaseSync`, prepared statements,
57
+ `PRAGMA`, WAL, FTS5); re-verified on Node 26.13.0 / SQLite 3.54.1 for this release. A runtime
58
+ below the floor, or a build without `node:sqlite`, is detected at runtime:
59
+
60
+ | Entry point | No `node:sqlite` | `AI_RULES_TEAM_DB_DISABLE=1` |
61
+ |---|---|---|
62
+ | hook postflight | one line, no child, exit 0 | silent, exit 0 |
63
+ | `manifest.mjs` upsert | one line, return 0 after the receipt | silent, return 0 |
64
+ | `team-db.mjs init` / `sync` | one line, exit 0, no file | one line, exit 0, no file |
65
+ | `team-db.mjs check` | one line, exit 1 | one line, exit 1 |
66
+ | `team-db.mjs serve` | one line, exit 0 | one line, exit 0 |
67
+
68
+ The file-only pipeline is unchanged: `status.json` / `metrics.json` writes, manifest upserts,
69
+ and the pipeline run with exit 0.
70
+
71
+ ## Commands
72
+
73
+ ```bash
74
+ node .ai.local/scripts/team-db.mjs init [--root <team-dir>] [--rebuild]
75
+ node .ai.local/scripts/team-db.mjs sync [--root <team-dir>] [--slug <slug>] [--quiet] [--json]
76
+ [--maintain] [--prune] [--vacuum]
77
+ [--rebuild | --no-rebuild] [--deadline-ms <n>]
78
+ node .ai.local/scripts/team-db.mjs check [--root <team-dir>]
79
+ node .ai.local/scripts/team-db.mjs serve [--root <team-dir>] [--host <addr>] [--port <n>]
80
+ [--allow-remote] [--open]
81
+ ```
82
+
83
+ Exit codes: `0` ok, `1` at least one task failed or a migration checksum drifted, `2`
84
+ database-level failure, `3` usage, `4` deadline or busy database on the hook-shaped `--slug`
85
+ path.
86
+
87
+ `sync` is idempotent: a second run reports `inserted=0 updated=0 unchanged=<n>`. One changed
88
+ byte changes exactly one document hash and one task content hash. A removed task directory is
89
+ tombstoned with `absent_at` (soft delete) and `--prune` removes tombstones.
90
+
91
+ ## Environment names
92
+
93
+ | Name | Effect |
94
+ |---|---|
95
+ | `AI_RULES_TEAM_DB_DISABLE` | truthy value disables every write point and `serve`; files are untouched |
96
+ | `AI_RULES_TEAM_DB_FORCE_FALLBACK` | truthy value forces the file-only path even on a supported runtime |
97
+ | `AI_RULES_TEAM_DB_ROOT` | team directory when `--root` is absent |
98
+ | `AI_RULES_TEAM_DB_PATH` | database file path (default `<teamRoot>/team.db`) |
99
+ | `AI_RULES_TEAM_DB_LOG` | error-log path (default `<cwd>/.ai.local/team/team-db-errors.log`) |
100
+ | `AI_RULES_TEAM_DB_SEAM` | phase label in the error log: `hook`, `receipt`, `cli`, `serve` |
101
+
102
+ No other environment value is read or persisted. The error log stores a timestamp, a code,
103
+ a phase, and a message; it never stores prompt content or an environment value, and it is
104
+ trimmed to the newest 200 lines / 64 KiB.
105
+
106
+ ## Schema
107
+
108
+ One embedded migration (`0001-init`, sha256-pinned) creates 15 row tables: `schema_migrations`,
109
+ `schema_meta`, `tasks`, `pipeline_steps`, `pipeline_step_agents`, `attempts`, `events`,
110
+ `gates`, `artifacts`, `artifact_paths`, `prompts`, `review_ledger`, `outcomes`, `documents`,
111
+ `sync_runs`; 19 indexes; and the `attempt_timeline` view. FTS5 (`search_fts`) is a runtime
112
+ capability created after migration, with an escaped `LIKE` fallback.
113
+
114
+ Each connection sets `journal_mode=WAL`, `busy_timeout=5000`, `foreign_keys=ON`, and
115
+ `synchronous=NORMAL`. One task is projected in one transaction; a `SIGKILL` mid-sync
116
+ rolls back the in-flight task and leaves `integrity_check` `ok`.
117
+
118
+ Raw document content is capped at 32 MiB; above that the row keeps path, sha256, and length
119
+ and sets `content_omitted=size` (binary content sets `binary`). Raw content older than 90
120
+ days on an absent task is nulled only by `sync --maintain`; `sync --vacuum` checkpoints WAL and
121
+ runs `VACUUM`. The `sync_runs` table keeps the newest 200 runs.
122
+
123
+ ## Dashboard and API
124
+
125
+ `team-db.mjs serve` prints one line with the bound URL (default
126
+ `http://127.0.0.1:4178`). The dashboard is a single no-build HTML document at `/`, its CSS and
127
+ JS are served from `/assets/`, and the OpenAPI 3.1 document is at `/openapi.json`. The frozen
128
+ document is checked in at `packages/ai-rules/docs/openapi/team-db.v1.json`; the gate is
129
+ `node scripts/check-team-db-contract.mjs`.
130
+
131
+ Security boundary: loopback bind by default (`--host` outside loopback needs
132
+ `--allow-remote`, and a wildcard address is refused), exact `Host`/`Origin` allow-list,
133
+ no `Access-Control-*` header, hardened response headers, request bodies bounded at 1 KiB,
134
+ document chunks at 1 MiB, exports at 5 MiB, parameterized SQL only, and no outbound call.
135
+
136
+ ## Privacy and retention
137
+
138
+ Prompts are copied verbatim into `prompts` and `documents`. The database is local, git-ignored,
139
+ and readable by the same OS user who can read the task folder; that is the trust boundary.
140
+ There is no upload, telemetry, or remote asset. `sync --maintain` nulls raw document content
141
+ for tasks absent longer than 90 days while keeping normalized rows and hashes.
142
+
143
+ ## Rollback
144
+
145
+ 1. Set `AI_RULES_TEAM_DB_DISABLE=1`. Every write point and `serve` becomes a no-op with exit 0.
146
+ 2. Delete the projection: `rm -f .ai.local/team/team.db .ai.local/team/team.db-wal
147
+ .ai.local/team/team.db-shm .ai.local/team/team-db-errors.log`. No task file is touched.
148
+ 3. Revert the code: remove the hook region and the `projectAfterReceipt` call, delete the six
149
+ modules from `ENGINE_SCRIPTS`, then run `yarn fix:generated` and recapture the goldens.
150
+ 4. The ADR stays as history: mark it superseded instead of deleting it.
151
+
152
+ ## Gates
153
+
154
+ From `packages/ai-rules`:
155
+
156
+ ```bash
157
+ node scripts/check-team-db-contract.mjs
158
+ node scripts/test-team-db-schema.mjs
159
+ node scripts/test-team-db-project.mjs
160
+ node scripts/test-team-db-dualwrite.mjs
161
+ node scripts/test-team-db-api.mjs
162
+ node scripts/test-team-db-security.mjs
163
+ node scripts/test-team-db-dashboard.mjs
164
+ node scripts/test-team-db-concurrency.mjs
165
+ node scripts/test-team-db-fixtures.mjs
166
+ ```
167
+
168
+ `test-team-db-fixtures.mjs` is the FAIL-direction suite: every gate above is exercised on a
169
+ planted defect, not only on the happy path.
170
+
171
+ Links: [`../README.md`](../README.md), [`PRESET-CONTRIBUTION.md`](PRESET-CONTRIBUTION.md),
172
+ the OpenSpec change `openspec/changes/2026-11-06-agent-team-sqlite-dashboard/`, and ADR
173
+ `.ai.local/adr/0004-team-db-projection.md` in this repository.