@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.
- package/CHANGELOG.md +24 -0
- package/README.md +27 -3
- package/bin/cli.js +551 -60
- package/bin/lib/engine-scripts.js +10 -0
- package/bin/lib/mcp/clients.js +168 -0
- package/bin/lib/mcp/credentials.js +298 -0
- package/bin/lib/mcp/doctor.js +394 -0
- package/bin/lib/mcp/prompt.js +115 -0
- package/bin/lib/mcp/registry.js +170 -0
- package/bin/lib/mcp/run.js +123 -0
- package/bin/lib/merged-config.js +45 -0
- package/bin/lib/seed-ai-local-team.js +5 -0
- package/bin/lib/tool-installs.js +27 -0
- package/docs/MCP-SETUP.md +62 -0
- package/docs/PRESET-CONTRIBUTION.md +3 -1
- package/docs/TEAM-DB.md +173 -0
- package/docs/openapi/team-db.v1.json +5085 -0
- package/mcp/gitlab.mjs +123 -0
- package/mcp/lib/envfile.mjs +126 -0
- package/mcp/lib/yandex.mjs +384 -0
- package/mcp/yandex-mcp-proxy.mjs +155 -0
- package/mcp/yandex-token-refresh.mjs +65 -0
- package/package.json +14 -1
- package/presets/_shared/ai-local/scripts/manifest.mjs +99 -0
- package/presets/_shared/ai-local/scripts/team-db-api.mjs +1275 -0
- package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +1067 -0
- package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +1301 -0
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +1506 -0
- package/presets/_shared/ai-local/scripts/team-db-schema.mjs +831 -0
- package/presets/_shared/ai-local/scripts/team-db.mjs +251 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +109 -0
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/android-kotlin/team/README.md +10 -0
- package/presets/claude/go/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/go/team/README.md +10 -0
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/ios-swift/team/README.md +10 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/java/team/README.md +10 -0
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/mcp-ts/team/README.md +10 -0
- package/presets/claude/next/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/next/team/README.md +10 -0
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/nuxt/team/README.md +10 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/php-hexagonal/team/README.md +10 -0
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/php-laravel/team/README.md +10 -0
- package/presets/claude/svelte/hooks/chain-team-phases.sh +109 -0
- package/presets/claude/svelte/team/README.md +10 -0
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/android-kotlin/team/README.md +10 -0
- package/presets/cursor/go/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/go/team/README.md +10 -0
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/ios-swift/team/README.md +10 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/java/team/README.md +10 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/mcp-ts/team/README.md +10 -0
- package/presets/cursor/next/MCP.md +7 -0
- package/presets/cursor/next/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/next/team/README.md +10 -0
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/nuxt/team/README.md +10 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/php-hexagonal/team/README.md +10 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/php-laravel/team/README.md +10 -0
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +109 -0
- package/presets/cursor/svelte/team/README.md +10 -0
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/android-kotlin/team/README.md +10 -0
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/go/team/README.md +10 -0
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/ios-swift/team/README.md +10 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/java/team/README.md +10 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/mcp-ts/team/README.md +10 -0
- package/presets/mavis/next/MCP.md +7 -0
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/next/team/README.md +10 -0
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/nuxt/team/README.md +10 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/php-hexagonal/team/README.md +10 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/php-laravel/team/README.md +10 -0
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +109 -0
- package/presets/mavis/svelte/team/README.md +10 -0
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/android-kotlin/team/README.md +10 -0
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/go/team/README.md +10 -0
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/ios-swift/team/README.md +10 -0
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/java/team/README.md +10 -0
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/mcp-ts/team/README.md +10 -0
- package/presets/opencode/next/MCP.md +7 -0
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/next/team/README.md +10 -0
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/nuxt/team/README.md +10 -0
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/php-hexagonal/team/README.md +10 -0
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/php-laravel/team/README.md +10 -0
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +109 -0
- package/presets/opencode/svelte/team/README.md +10 -0
|
@@ -2618,6 +2618,115 @@ if (!input || input.status !== 'completed') {
|
|
|
2618
2618
|
process.exit(0);
|
|
2619
2619
|
}
|
|
2620
2620
|
|
|
2621
|
+
// --- TEAM_DB_PROJECTION -------------------------------------------------------
|
|
2622
|
+
// The status, metrics, compaction and focus writes are already durable when this
|
|
2623
|
+
// postflight starts. The projection is a bounded child process: it must never
|
|
2624
|
+
// fail this stop, never change hook stdout/stderr beyond the capability line,
|
|
2625
|
+
// and never write a task file. A disabled switch, a missing script, or a
|
|
2626
|
+
// runtime without `node:sqlite` is a skip; a child failure is one log line.
|
|
2627
|
+
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
2628
|
+
// all 40 rendered bodies and needs no per-stack fragment.
|
|
2629
|
+
// <<<team-db-projection>>>
|
|
2630
|
+
function teamDbTruthy(value) {
|
|
2631
|
+
if (typeof value !== 'string') return false;
|
|
2632
|
+
const normalized = value.trim().toLowerCase();
|
|
2633
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes';
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
function teamDbLogPath(env) {
|
|
2637
|
+
const override = typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2638
|
+
if (override) return path.resolve(override);
|
|
2639
|
+
return path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
function teamDbLogPhase(env) {
|
|
2643
|
+
const value = typeof env.AI_RULES_TEAM_DB_SEAM === 'string' ? env.AI_RULES_TEAM_DB_SEAM.trim() : '';
|
|
2644
|
+
return value === 'hook' || value === 'receipt' || value === 'cli' || value === 'serve' ? value : 'hook';
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
// One line per failure, newest 200 lines and at most 64 KiB. Never a prompt
|
|
2648
|
+
// body: only the code and the message this block owns.
|
|
2649
|
+
function teamDbLogFailure(env, code, message) {
|
|
2650
|
+
try {
|
|
2651
|
+
const target = teamDbLogPath(env);
|
|
2652
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2653
|
+
const line = new Date().toISOString() + ' ' + code + ' ' + teamDbLogPhase(env) + ' ' + message;
|
|
2654
|
+
fs.appendFileSync(target, line + '\n');
|
|
2655
|
+
let content = fs.readFileSync(target, 'utf8');
|
|
2656
|
+
let lines = content.split('\n').filter(function (entry) { return entry.length > 0; });
|
|
2657
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2658
|
+
while (Buffer.byteLength(lines.join('\n') + '\n', 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2659
|
+
content = lines.join('\n') + (lines.length > 0 ? '\n' : '');
|
|
2660
|
+
fs.writeFileSync(target, content);
|
|
2661
|
+
} catch (error) {
|
|
2662
|
+
/* a log failure is not a stop failure */
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
function teamDbSqliteAvailable(env) {
|
|
2667
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_FORCE_FALLBACK)) return false;
|
|
2668
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(String(process.versions.node || ''));
|
|
2669
|
+
if (!match) return false;
|
|
2670
|
+
const major = Number(match[1]);
|
|
2671
|
+
const minor = Number(match[2]);
|
|
2672
|
+
if (major < 22) return false;
|
|
2673
|
+
if (major === 22 && minor < 13) return false;
|
|
2674
|
+
try {
|
|
2675
|
+
const sqlite = require('node:sqlite');
|
|
2676
|
+
return typeof sqlite.DatabaseSync === 'function';
|
|
2677
|
+
} catch (error) {
|
|
2678
|
+
return false;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
function teamDbProject() {
|
|
2683
|
+
try {
|
|
2684
|
+
const env = process.env;
|
|
2685
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
2686
|
+
// Same pattern as POSTFLIGHT_SLUG_RE above: the slug is re-derived from
|
|
2687
|
+
// `active-task.json` on this path too, so it cannot escape the tree.
|
|
2688
|
+
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2689
|
+
let slug = '';
|
|
2690
|
+
try {
|
|
2691
|
+
const active = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'));
|
|
2692
|
+
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
2693
|
+
} catch (error) {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2696
|
+
if (!slug || slug.length > 48 || !slugPattern.test(slug)) return;
|
|
2697
|
+
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
2698
|
+
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
2699
|
+
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
2700
|
+
if (!fs.existsSync(script)) return;
|
|
2701
|
+
if (!teamDbSqliteAvailable(env)) {
|
|
2702
|
+
process.stderr.write('team-db: projection skipped (node:sqlite unavailable); file-only mode\n');
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
const result = spawnSync(
|
|
2706
|
+
process.execPath,
|
|
2707
|
+
['.ai.local/scripts/team-db.mjs', 'sync', '--slug', slug, '--quiet', '--no-rebuild', '--deadline-ms', '4500'],
|
|
2708
|
+
{ cwd: process.cwd(), env: env, encoding: 'utf8', timeout: 5000, killSignal: 'SIGKILL', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
2709
|
+
);
|
|
2710
|
+
if (result.error && result.error.code === 'ETIMEDOUT') {
|
|
2711
|
+
teamDbLogFailure(env, 'E_PROJECTION_TIMEOUT', 'projection exceeded 5000 ms and was killed');
|
|
2712
|
+
return;
|
|
2713
|
+
}
|
|
2714
|
+
if (result.error) {
|
|
2715
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection could not start: ' + String(result.error.code || 'unknown'));
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
2719
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection exited ' + result.status);
|
|
2720
|
+
}
|
|
2721
|
+
} catch (error) {
|
|
2722
|
+
/* the seam never fails the stop */
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
teamDbProject();
|
|
2727
|
+
// <<<team-db-projection-end>>>
|
|
2728
|
+
// --- end TEAM_DB_PROJECTION ---------------------------------------------------
|
|
2729
|
+
|
|
2621
2730
|
// Ratchet: off for `light` pipelines and `spike` intents. A policy skip is
|
|
2622
2731
|
// silent on purpose — a warning on every light receipt would make the
|
|
2623
2732
|
// containment warnings below unreadable.
|
|
@@ -90,6 +90,16 @@ printf '%s\n' '{"status":"completed","action":"end_human_gate","activateNext":tr
|
|
|
90
90
|
|
|
91
91
|
Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.sh`.
|
|
92
92
|
|
|
93
|
+
## Database projection
|
|
94
|
+
|
|
95
|
+
`team-db.mjs` projects this tree into `.ai.local/team/team.db` (SQLite, WAL). The files remain authoritative: the database is rebuildable and git-ignored (`team.db`, `team.db-wal`, `team.db-shm`, `team-db-errors.log`).
|
|
96
|
+
|
|
97
|
+
- Write points: the chain hook after its file writes, and `manifest.mjs` after a receipt. Both run one bounded 5 s child; a failure logs one line and never fails the file write.
|
|
98
|
+
- No agent writes lifecycle fields through the database. `status.json` / `metrics.json` stay hook-owned.
|
|
99
|
+
- `AI_RULES_TEAM_DB_DISABLE=1` stops every write point and `serve`; a runtime without `node:sqlite` stays file-only with exit 0.
|
|
100
|
+
- Inspect: `node .ai.local/scripts/team-db.mjs sync`, then `check`; `serve` opens the read-only dashboard at `http://127.0.0.1:4178`.
|
|
101
|
+
- Never commit the database. Delete `team.db*` and run `sync` to rebuild.
|
|
102
|
+
|
|
93
103
|
## Contracts
|
|
94
104
|
|
|
95
105
|
- **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
|
|
@@ -2613,6 +2613,115 @@ if (!input || input.status !== 'completed') {
|
|
|
2613
2613
|
process.exit(0);
|
|
2614
2614
|
}
|
|
2615
2615
|
|
|
2616
|
+
// --- TEAM_DB_PROJECTION -------------------------------------------------------
|
|
2617
|
+
// The status, metrics, compaction and focus writes are already durable when this
|
|
2618
|
+
// postflight starts. The projection is a bounded child process: it must never
|
|
2619
|
+
// fail this stop, never change hook stdout/stderr beyond the capability line,
|
|
2620
|
+
// and never write a task file. A disabled switch, a missing script, or a
|
|
2621
|
+
// runtime without `node:sqlite` is a skip; a child failure is one log line.
|
|
2622
|
+
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
2623
|
+
// all 40 rendered bodies and needs no per-stack fragment.
|
|
2624
|
+
// <<<team-db-projection>>>
|
|
2625
|
+
function teamDbTruthy(value) {
|
|
2626
|
+
if (typeof value !== 'string') return false;
|
|
2627
|
+
const normalized = value.trim().toLowerCase();
|
|
2628
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes';
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
function teamDbLogPath(env) {
|
|
2632
|
+
const override = typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2633
|
+
if (override) return path.resolve(override);
|
|
2634
|
+
return path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
function teamDbLogPhase(env) {
|
|
2638
|
+
const value = typeof env.AI_RULES_TEAM_DB_SEAM === 'string' ? env.AI_RULES_TEAM_DB_SEAM.trim() : '';
|
|
2639
|
+
return value === 'hook' || value === 'receipt' || value === 'cli' || value === 'serve' ? value : 'hook';
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// One line per failure, newest 200 lines and at most 64 KiB. Never a prompt
|
|
2643
|
+
// body: only the code and the message this block owns.
|
|
2644
|
+
function teamDbLogFailure(env, code, message) {
|
|
2645
|
+
try {
|
|
2646
|
+
const target = teamDbLogPath(env);
|
|
2647
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2648
|
+
const line = new Date().toISOString() + ' ' + code + ' ' + teamDbLogPhase(env) + ' ' + message;
|
|
2649
|
+
fs.appendFileSync(target, line + '\n');
|
|
2650
|
+
let content = fs.readFileSync(target, 'utf8');
|
|
2651
|
+
let lines = content.split('\n').filter(function (entry) { return entry.length > 0; });
|
|
2652
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2653
|
+
while (Buffer.byteLength(lines.join('\n') + '\n', 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2654
|
+
content = lines.join('\n') + (lines.length > 0 ? '\n' : '');
|
|
2655
|
+
fs.writeFileSync(target, content);
|
|
2656
|
+
} catch (error) {
|
|
2657
|
+
/* a log failure is not a stop failure */
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
function teamDbSqliteAvailable(env) {
|
|
2662
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_FORCE_FALLBACK)) return false;
|
|
2663
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(String(process.versions.node || ''));
|
|
2664
|
+
if (!match) return false;
|
|
2665
|
+
const major = Number(match[1]);
|
|
2666
|
+
const minor = Number(match[2]);
|
|
2667
|
+
if (major < 22) return false;
|
|
2668
|
+
if (major === 22 && minor < 13) return false;
|
|
2669
|
+
try {
|
|
2670
|
+
const sqlite = require('node:sqlite');
|
|
2671
|
+
return typeof sqlite.DatabaseSync === 'function';
|
|
2672
|
+
} catch (error) {
|
|
2673
|
+
return false;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
function teamDbProject() {
|
|
2678
|
+
try {
|
|
2679
|
+
const env = process.env;
|
|
2680
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
2681
|
+
// Same pattern as POSTFLIGHT_SLUG_RE above: the slug is re-derived from
|
|
2682
|
+
// `active-task.json` on this path too, so it cannot escape the tree.
|
|
2683
|
+
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2684
|
+
let slug = '';
|
|
2685
|
+
try {
|
|
2686
|
+
const active = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'));
|
|
2687
|
+
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
2688
|
+
} catch (error) {
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
if (!slug || slug.length > 48 || !slugPattern.test(slug)) return;
|
|
2692
|
+
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
2693
|
+
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
2694
|
+
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
2695
|
+
if (!fs.existsSync(script)) return;
|
|
2696
|
+
if (!teamDbSqliteAvailable(env)) {
|
|
2697
|
+
process.stderr.write('team-db: projection skipped (node:sqlite unavailable); file-only mode\n');
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
const result = spawnSync(
|
|
2701
|
+
process.execPath,
|
|
2702
|
+
['.ai.local/scripts/team-db.mjs', 'sync', '--slug', slug, '--quiet', '--no-rebuild', '--deadline-ms', '4500'],
|
|
2703
|
+
{ cwd: process.cwd(), env: env, encoding: 'utf8', timeout: 5000, killSignal: 'SIGKILL', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
2704
|
+
);
|
|
2705
|
+
if (result.error && result.error.code === 'ETIMEDOUT') {
|
|
2706
|
+
teamDbLogFailure(env, 'E_PROJECTION_TIMEOUT', 'projection exceeded 5000 ms and was killed');
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2709
|
+
if (result.error) {
|
|
2710
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection could not start: ' + String(result.error.code || 'unknown'));
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
2714
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection exited ' + result.status);
|
|
2715
|
+
}
|
|
2716
|
+
} catch (error) {
|
|
2717
|
+
/* the seam never fails the stop */
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
teamDbProject();
|
|
2722
|
+
// <<<team-db-projection-end>>>
|
|
2723
|
+
// --- end TEAM_DB_PROJECTION ---------------------------------------------------
|
|
2724
|
+
|
|
2616
2725
|
// Ratchet: off for `light` pipelines and `spike` intents. A policy skip is
|
|
2617
2726
|
// silent on purpose — a warning on every light receipt would make the
|
|
2618
2727
|
// containment warnings below unreadable.
|
|
@@ -90,6 +90,16 @@ printf '%s\n' '{"status":"completed","action":"end_human_gate","activateNext":tr
|
|
|
90
90
|
|
|
91
91
|
Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.sh`.
|
|
92
92
|
|
|
93
|
+
## Database projection
|
|
94
|
+
|
|
95
|
+
`team-db.mjs` projects this tree into `.ai.local/team/team.db` (SQLite, WAL). The files remain authoritative: the database is rebuildable and git-ignored (`team.db`, `team.db-wal`, `team.db-shm`, `team-db-errors.log`).
|
|
96
|
+
|
|
97
|
+
- Write points: the chain hook after its file writes, and `manifest.mjs` after a receipt. Both run one bounded 5 s child; a failure logs one line and never fails the file write.
|
|
98
|
+
- No agent writes lifecycle fields through the database. `status.json` / `metrics.json` stay hook-owned.
|
|
99
|
+
- `AI_RULES_TEAM_DB_DISABLE=1` stops every write point and `serve`; a runtime without `node:sqlite` stays file-only with exit 0.
|
|
100
|
+
- Inspect: `node .ai.local/scripts/team-db.mjs sync`, then `check`; `serve` opens the read-only dashboard at `http://127.0.0.1:4178`.
|
|
101
|
+
- Never commit the database. Delete `team.db*` and run `sync` to rebuild.
|
|
102
|
+
|
|
93
103
|
## Contracts
|
|
94
104
|
|
|
95
105
|
- **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
|
|
@@ -2560,6 +2560,115 @@ if (!input || input.status !== 'completed') {
|
|
|
2560
2560
|
process.exit(0);
|
|
2561
2561
|
}
|
|
2562
2562
|
|
|
2563
|
+
// --- TEAM_DB_PROJECTION -------------------------------------------------------
|
|
2564
|
+
// The status, metrics, compaction and focus writes are already durable when this
|
|
2565
|
+
// postflight starts. The projection is a bounded child process: it must never
|
|
2566
|
+
// fail this stop, never change hook stdout/stderr beyond the capability line,
|
|
2567
|
+
// and never write a task file. A disabled switch, a missing script, or a
|
|
2568
|
+
// runtime without `node:sqlite` is a skip; a child failure is one log line.
|
|
2569
|
+
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
2570
|
+
// all 40 rendered bodies and needs no per-stack fragment.
|
|
2571
|
+
// <<<team-db-projection>>>
|
|
2572
|
+
function teamDbTruthy(value) {
|
|
2573
|
+
if (typeof value !== 'string') return false;
|
|
2574
|
+
const normalized = value.trim().toLowerCase();
|
|
2575
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes';
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
function teamDbLogPath(env) {
|
|
2579
|
+
const override = typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2580
|
+
if (override) return path.resolve(override);
|
|
2581
|
+
return path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
function teamDbLogPhase(env) {
|
|
2585
|
+
const value = typeof env.AI_RULES_TEAM_DB_SEAM === 'string' ? env.AI_RULES_TEAM_DB_SEAM.trim() : '';
|
|
2586
|
+
return value === 'hook' || value === 'receipt' || value === 'cli' || value === 'serve' ? value : 'hook';
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
// One line per failure, newest 200 lines and at most 64 KiB. Never a prompt
|
|
2590
|
+
// body: only the code and the message this block owns.
|
|
2591
|
+
function teamDbLogFailure(env, code, message) {
|
|
2592
|
+
try {
|
|
2593
|
+
const target = teamDbLogPath(env);
|
|
2594
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2595
|
+
const line = new Date().toISOString() + ' ' + code + ' ' + teamDbLogPhase(env) + ' ' + message;
|
|
2596
|
+
fs.appendFileSync(target, line + '\n');
|
|
2597
|
+
let content = fs.readFileSync(target, 'utf8');
|
|
2598
|
+
let lines = content.split('\n').filter(function (entry) { return entry.length > 0; });
|
|
2599
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2600
|
+
while (Buffer.byteLength(lines.join('\n') + '\n', 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2601
|
+
content = lines.join('\n') + (lines.length > 0 ? '\n' : '');
|
|
2602
|
+
fs.writeFileSync(target, content);
|
|
2603
|
+
} catch (error) {
|
|
2604
|
+
/* a log failure is not a stop failure */
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
function teamDbSqliteAvailable(env) {
|
|
2609
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_FORCE_FALLBACK)) return false;
|
|
2610
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(String(process.versions.node || ''));
|
|
2611
|
+
if (!match) return false;
|
|
2612
|
+
const major = Number(match[1]);
|
|
2613
|
+
const minor = Number(match[2]);
|
|
2614
|
+
if (major < 22) return false;
|
|
2615
|
+
if (major === 22 && minor < 13) return false;
|
|
2616
|
+
try {
|
|
2617
|
+
const sqlite = require('node:sqlite');
|
|
2618
|
+
return typeof sqlite.DatabaseSync === 'function';
|
|
2619
|
+
} catch (error) {
|
|
2620
|
+
return false;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
function teamDbProject() {
|
|
2625
|
+
try {
|
|
2626
|
+
const env = process.env;
|
|
2627
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
2628
|
+
// Same pattern as POSTFLIGHT_SLUG_RE above: the slug is re-derived from
|
|
2629
|
+
// `active-task.json` on this path too, so it cannot escape the tree.
|
|
2630
|
+
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2631
|
+
let slug = '';
|
|
2632
|
+
try {
|
|
2633
|
+
const active = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'));
|
|
2634
|
+
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
2635
|
+
} catch (error) {
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
if (!slug || slug.length > 48 || !slugPattern.test(slug)) return;
|
|
2639
|
+
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
2640
|
+
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
2641
|
+
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
2642
|
+
if (!fs.existsSync(script)) return;
|
|
2643
|
+
if (!teamDbSqliteAvailable(env)) {
|
|
2644
|
+
process.stderr.write('team-db: projection skipped (node:sqlite unavailable); file-only mode\n');
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2647
|
+
const result = spawnSync(
|
|
2648
|
+
process.execPath,
|
|
2649
|
+
['.ai.local/scripts/team-db.mjs', 'sync', '--slug', slug, '--quiet', '--no-rebuild', '--deadline-ms', '4500'],
|
|
2650
|
+
{ cwd: process.cwd(), env: env, encoding: 'utf8', timeout: 5000, killSignal: 'SIGKILL', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
2651
|
+
);
|
|
2652
|
+
if (result.error && result.error.code === 'ETIMEDOUT') {
|
|
2653
|
+
teamDbLogFailure(env, 'E_PROJECTION_TIMEOUT', 'projection exceeded 5000 ms and was killed');
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
if (result.error) {
|
|
2657
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection could not start: ' + String(result.error.code || 'unknown'));
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
2661
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection exited ' + result.status);
|
|
2662
|
+
}
|
|
2663
|
+
} catch (error) {
|
|
2664
|
+
/* the seam never fails the stop */
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
teamDbProject();
|
|
2669
|
+
// <<<team-db-projection-end>>>
|
|
2670
|
+
// --- end TEAM_DB_PROJECTION ---------------------------------------------------
|
|
2671
|
+
|
|
2563
2672
|
// Ratchet: off for `light` pipelines and `spike` intents. A policy skip is
|
|
2564
2673
|
// silent on purpose — a warning on every light receipt would make the
|
|
2565
2674
|
// containment warnings below unreadable.
|
|
@@ -90,6 +90,16 @@ printf '%s\n' '{"status":"completed","action":"end_human_gate","activateNext":tr
|
|
|
90
90
|
|
|
91
91
|
Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.sh`.
|
|
92
92
|
|
|
93
|
+
## Database projection
|
|
94
|
+
|
|
95
|
+
`team-db.mjs` projects this tree into `.ai.local/team/team.db` (SQLite, WAL). The files remain authoritative: the database is rebuildable and git-ignored (`team.db`, `team.db-wal`, `team.db-shm`, `team-db-errors.log`).
|
|
96
|
+
|
|
97
|
+
- Write points: the chain hook after its file writes, and `manifest.mjs` after a receipt. Both run one bounded 5 s child; a failure logs one line and never fails the file write.
|
|
98
|
+
- No agent writes lifecycle fields through the database. `status.json` / `metrics.json` stay hook-owned.
|
|
99
|
+
- `AI_RULES_TEAM_DB_DISABLE=1` stops every write point and `serve`; a runtime without `node:sqlite` stays file-only with exit 0.
|
|
100
|
+
- Inspect: `node .ai.local/scripts/team-db.mjs sync`, then `check`; `serve` opens the read-only dashboard at `http://127.0.0.1:4178`.
|
|
101
|
+
- Never commit the database. Delete `team.db*` and run `sync` to rebuild.
|
|
102
|
+
|
|
93
103
|
## Contracts
|
|
94
104
|
|
|
95
105
|
- **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
|
|
@@ -2616,6 +2616,115 @@ if (!input || input.status !== 'completed') {
|
|
|
2616
2616
|
process.exit(0);
|
|
2617
2617
|
}
|
|
2618
2618
|
|
|
2619
|
+
// --- TEAM_DB_PROJECTION -------------------------------------------------------
|
|
2620
|
+
// The status, metrics, compaction and focus writes are already durable when this
|
|
2621
|
+
// postflight starts. The projection is a bounded child process: it must never
|
|
2622
|
+
// fail this stop, never change hook stdout/stderr beyond the capability line,
|
|
2623
|
+
// and never write a task file. A disabled switch, a missing script, or a
|
|
2624
|
+
// runtime without `node:sqlite` is a skip; a child failure is one log line.
|
|
2625
|
+
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
2626
|
+
// all 40 rendered bodies and needs no per-stack fragment.
|
|
2627
|
+
// <<<team-db-projection>>>
|
|
2628
|
+
function teamDbTruthy(value) {
|
|
2629
|
+
if (typeof value !== 'string') return false;
|
|
2630
|
+
const normalized = value.trim().toLowerCase();
|
|
2631
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes';
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
function teamDbLogPath(env) {
|
|
2635
|
+
const override = typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2636
|
+
if (override) return path.resolve(override);
|
|
2637
|
+
return path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
function teamDbLogPhase(env) {
|
|
2641
|
+
const value = typeof env.AI_RULES_TEAM_DB_SEAM === 'string' ? env.AI_RULES_TEAM_DB_SEAM.trim() : '';
|
|
2642
|
+
return value === 'hook' || value === 'receipt' || value === 'cli' || value === 'serve' ? value : 'hook';
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
// One line per failure, newest 200 lines and at most 64 KiB. Never a prompt
|
|
2646
|
+
// body: only the code and the message this block owns.
|
|
2647
|
+
function teamDbLogFailure(env, code, message) {
|
|
2648
|
+
try {
|
|
2649
|
+
const target = teamDbLogPath(env);
|
|
2650
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2651
|
+
const line = new Date().toISOString() + ' ' + code + ' ' + teamDbLogPhase(env) + ' ' + message;
|
|
2652
|
+
fs.appendFileSync(target, line + '\n');
|
|
2653
|
+
let content = fs.readFileSync(target, 'utf8');
|
|
2654
|
+
let lines = content.split('\n').filter(function (entry) { return entry.length > 0; });
|
|
2655
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2656
|
+
while (Buffer.byteLength(lines.join('\n') + '\n', 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2657
|
+
content = lines.join('\n') + (lines.length > 0 ? '\n' : '');
|
|
2658
|
+
fs.writeFileSync(target, content);
|
|
2659
|
+
} catch (error) {
|
|
2660
|
+
/* a log failure is not a stop failure */
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
function teamDbSqliteAvailable(env) {
|
|
2665
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_FORCE_FALLBACK)) return false;
|
|
2666
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(String(process.versions.node || ''));
|
|
2667
|
+
if (!match) return false;
|
|
2668
|
+
const major = Number(match[1]);
|
|
2669
|
+
const minor = Number(match[2]);
|
|
2670
|
+
if (major < 22) return false;
|
|
2671
|
+
if (major === 22 && minor < 13) return false;
|
|
2672
|
+
try {
|
|
2673
|
+
const sqlite = require('node:sqlite');
|
|
2674
|
+
return typeof sqlite.DatabaseSync === 'function';
|
|
2675
|
+
} catch (error) {
|
|
2676
|
+
return false;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
function teamDbProject() {
|
|
2681
|
+
try {
|
|
2682
|
+
const env = process.env;
|
|
2683
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
2684
|
+
// Same pattern as POSTFLIGHT_SLUG_RE above: the slug is re-derived from
|
|
2685
|
+
// `active-task.json` on this path too, so it cannot escape the tree.
|
|
2686
|
+
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2687
|
+
let slug = '';
|
|
2688
|
+
try {
|
|
2689
|
+
const active = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'));
|
|
2690
|
+
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
2691
|
+
} catch (error) {
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
if (!slug || slug.length > 48 || !slugPattern.test(slug)) return;
|
|
2695
|
+
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
2696
|
+
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
2697
|
+
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
2698
|
+
if (!fs.existsSync(script)) return;
|
|
2699
|
+
if (!teamDbSqliteAvailable(env)) {
|
|
2700
|
+
process.stderr.write('team-db: projection skipped (node:sqlite unavailable); file-only mode\n');
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
const result = spawnSync(
|
|
2704
|
+
process.execPath,
|
|
2705
|
+
['.ai.local/scripts/team-db.mjs', 'sync', '--slug', slug, '--quiet', '--no-rebuild', '--deadline-ms', '4500'],
|
|
2706
|
+
{ cwd: process.cwd(), env: env, encoding: 'utf8', timeout: 5000, killSignal: 'SIGKILL', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
2707
|
+
);
|
|
2708
|
+
if (result.error && result.error.code === 'ETIMEDOUT') {
|
|
2709
|
+
teamDbLogFailure(env, 'E_PROJECTION_TIMEOUT', 'projection exceeded 5000 ms and was killed');
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
if (result.error) {
|
|
2713
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection could not start: ' + String(result.error.code || 'unknown'));
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
2717
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection exited ' + result.status);
|
|
2718
|
+
}
|
|
2719
|
+
} catch (error) {
|
|
2720
|
+
/* the seam never fails the stop */
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
teamDbProject();
|
|
2725
|
+
// <<<team-db-projection-end>>>
|
|
2726
|
+
// --- end TEAM_DB_PROJECTION ---------------------------------------------------
|
|
2727
|
+
|
|
2619
2728
|
// Ratchet: off for `light` pipelines and `spike` intents. A policy skip is
|
|
2620
2729
|
// silent on purpose — a warning on every light receipt would make the
|
|
2621
2730
|
// containment warnings below unreadable.
|
|
@@ -102,6 +102,16 @@ printf '%s\n' '{"status":"completed","action":"end_human_gate","activateNext":tr
|
|
|
102
102
|
|
|
103
103
|
Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.sh`.
|
|
104
104
|
|
|
105
|
+
## Database projection
|
|
106
|
+
|
|
107
|
+
`team-db.mjs` projects this tree into `.ai.local/team/team.db` (SQLite, WAL). The files remain authoritative: the database is rebuildable and git-ignored (`team.db`, `team.db-wal`, `team.db-shm`, `team-db-errors.log`).
|
|
108
|
+
|
|
109
|
+
- Write points: the chain hook after its file writes, and `manifest.mjs` after a receipt. Both run one bounded 5 s child; a failure logs one line and never fails the file write.
|
|
110
|
+
- No agent writes lifecycle fields through the database. `status.json` / `metrics.json` stay hook-owned.
|
|
111
|
+
- `AI_RULES_TEAM_DB_DISABLE=1` stops every write point and `serve`; a runtime without `node:sqlite` stays file-only with exit 0.
|
|
112
|
+
- Inspect: `node .ai.local/scripts/team-db.mjs sync`, then `check`; `serve` opens the read-only dashboard at `http://127.0.0.1:4178`.
|
|
113
|
+
- Never commit the database. Delete `team.db*` and run `sync` to rebuild.
|
|
114
|
+
|
|
105
115
|
## Contracts
|
|
106
116
|
|
|
107
117
|
- **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
|
|
@@ -2616,6 +2616,115 @@ if (!input || input.status !== 'completed') {
|
|
|
2616
2616
|
process.exit(0);
|
|
2617
2617
|
}
|
|
2618
2618
|
|
|
2619
|
+
// --- TEAM_DB_PROJECTION -------------------------------------------------------
|
|
2620
|
+
// The status, metrics, compaction and focus writes are already durable when this
|
|
2621
|
+
// postflight starts. The projection is a bounded child process: it must never
|
|
2622
|
+
// fail this stop, never change hook stdout/stderr beyond the capability line,
|
|
2623
|
+
// and never write a task file. A disabled switch, a missing script, or a
|
|
2624
|
+
// runtime without `node:sqlite` is a skip; a child failure is one log line.
|
|
2625
|
+
// This is a plain region marker, not a `hook-slot`: the block is identical in
|
|
2626
|
+
// all 40 rendered bodies and needs no per-stack fragment.
|
|
2627
|
+
// <<<team-db-projection>>>
|
|
2628
|
+
function teamDbTruthy(value) {
|
|
2629
|
+
if (typeof value !== 'string') return false;
|
|
2630
|
+
const normalized = value.trim().toLowerCase();
|
|
2631
|
+
return normalized === '1' || normalized === 'true' || normalized === 'yes';
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
function teamDbLogPath(env) {
|
|
2635
|
+
const override = typeof env.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
|
|
2636
|
+
if (override) return path.resolve(override);
|
|
2637
|
+
return path.join(process.cwd(), '.ai.local', 'team', 'team-db-errors.log');
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
function teamDbLogPhase(env) {
|
|
2641
|
+
const value = typeof env.AI_RULES_TEAM_DB_SEAM === 'string' ? env.AI_RULES_TEAM_DB_SEAM.trim() : '';
|
|
2642
|
+
return value === 'hook' || value === 'receipt' || value === 'cli' || value === 'serve' ? value : 'hook';
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
// One line per failure, newest 200 lines and at most 64 KiB. Never a prompt
|
|
2646
|
+
// body: only the code and the message this block owns.
|
|
2647
|
+
function teamDbLogFailure(env, code, message) {
|
|
2648
|
+
try {
|
|
2649
|
+
const target = teamDbLogPath(env);
|
|
2650
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
2651
|
+
const line = new Date().toISOString() + ' ' + code + ' ' + teamDbLogPhase(env) + ' ' + message;
|
|
2652
|
+
fs.appendFileSync(target, line + '\n');
|
|
2653
|
+
let content = fs.readFileSync(target, 'utf8');
|
|
2654
|
+
let lines = content.split('\n').filter(function (entry) { return entry.length > 0; });
|
|
2655
|
+
if (lines.length > 200) lines = lines.slice(lines.length - 200);
|
|
2656
|
+
while (Buffer.byteLength(lines.join('\n') + '\n', 'utf8') > 65536 && lines.length > 1) lines.shift();
|
|
2657
|
+
content = lines.join('\n') + (lines.length > 0 ? '\n' : '');
|
|
2658
|
+
fs.writeFileSync(target, content);
|
|
2659
|
+
} catch (error) {
|
|
2660
|
+
/* a log failure is not a stop failure */
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
function teamDbSqliteAvailable(env) {
|
|
2665
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_FORCE_FALLBACK)) return false;
|
|
2666
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(String(process.versions.node || ''));
|
|
2667
|
+
if (!match) return false;
|
|
2668
|
+
const major = Number(match[1]);
|
|
2669
|
+
const minor = Number(match[2]);
|
|
2670
|
+
if (major < 22) return false;
|
|
2671
|
+
if (major === 22 && minor < 13) return false;
|
|
2672
|
+
try {
|
|
2673
|
+
const sqlite = require('node:sqlite');
|
|
2674
|
+
return typeof sqlite.DatabaseSync === 'function';
|
|
2675
|
+
} catch (error) {
|
|
2676
|
+
return false;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
function teamDbProject() {
|
|
2681
|
+
try {
|
|
2682
|
+
const env = process.env;
|
|
2683
|
+
if (teamDbTruthy(env.AI_RULES_TEAM_DB_DISABLE)) return;
|
|
2684
|
+
// Same pattern as POSTFLIGHT_SLUG_RE above: the slug is re-derived from
|
|
2685
|
+
// `active-task.json` on this path too, so it cannot escape the tree.
|
|
2686
|
+
const slugPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
2687
|
+
let slug = '';
|
|
2688
|
+
try {
|
|
2689
|
+
const active = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.ai.local', 'team', 'active-task.json'), 'utf8'));
|
|
2690
|
+
slug = typeof active.slug === 'string' ? active.slug : '';
|
|
2691
|
+
} catch (error) {
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
if (!slug || slug.length > 48 || !slugPattern.test(slug)) return;
|
|
2695
|
+
const taskDir = path.join(process.cwd(), '.ai.local', 'team', 'tasks', slug);
|
|
2696
|
+
if (!fs.existsSync(path.join(taskDir, 'status.json'))) return;
|
|
2697
|
+
const script = path.join(process.cwd(), '.ai.local', 'scripts', 'team-db.mjs');
|
|
2698
|
+
if (!fs.existsSync(script)) return;
|
|
2699
|
+
if (!teamDbSqliteAvailable(env)) {
|
|
2700
|
+
process.stderr.write('team-db: projection skipped (node:sqlite unavailable); file-only mode\n');
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
const result = spawnSync(
|
|
2704
|
+
process.execPath,
|
|
2705
|
+
['.ai.local/scripts/team-db.mjs', 'sync', '--slug', slug, '--quiet', '--no-rebuild', '--deadline-ms', '4500'],
|
|
2706
|
+
{ cwd: process.cwd(), env: env, encoding: 'utf8', timeout: 5000, killSignal: 'SIGKILL', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
2707
|
+
);
|
|
2708
|
+
if (result.error && result.error.code === 'ETIMEDOUT') {
|
|
2709
|
+
teamDbLogFailure(env, 'E_PROJECTION_TIMEOUT', 'projection exceeded 5000 ms and was killed');
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
if (result.error) {
|
|
2713
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection could not start: ' + String(result.error.code || 'unknown'));
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
if (typeof result.status === 'number' && result.status !== 0) {
|
|
2717
|
+
teamDbLogFailure(env, 'E_PROJECTION_FAILED', 'projection exited ' + result.status);
|
|
2718
|
+
}
|
|
2719
|
+
} catch (error) {
|
|
2720
|
+
/* the seam never fails the stop */
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
teamDbProject();
|
|
2725
|
+
// <<<team-db-projection-end>>>
|
|
2726
|
+
// --- end TEAM_DB_PROJECTION ---------------------------------------------------
|
|
2727
|
+
|
|
2619
2728
|
// Ratchet: off for `light` pipelines and `spike` intents. A policy skip is
|
|
2620
2729
|
// silent on purpose — a warning on every light receipt would make the
|
|
2621
2730
|
// containment warnings below unreadable.
|