@bonesofspring/ai-rules 0.2.84 → 0.2.86

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 (28) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/docs/PRESET-CONTRIBUTION.md +19 -10
  3. package/docs/TEAM-DB.md +76 -3
  4. package/docs/openapi/team-db.v1.json +7069 -5895
  5. package/package.json +5 -2
  6. package/presets/_shared/ai-local/scripts/team-db-api.mjs +253 -15
  7. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +310 -4
  8. package/presets/_shared/ai-local/scripts/team-db-project.mjs +733 -8
  9. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +44 -0
  10. package/presets/_shared/ai-local/scripts/team-db.mjs +43 -3
  11. package/presets/claude/next/agents/build-verifier.md +2 -1
  12. package/presets/claude/next/agents/feature-developer.md +1 -1
  13. package/presets/cursor/next/agents/build-verifier.md +2 -1
  14. package/presets/cursor/next/agents/feature-developer.md +1 -1
  15. package/presets/mavis/next/adapter-map.json +1 -1
  16. package/presets/mavis/next/agents/build-verifier.md +2 -1
  17. package/presets/mavis/next/agents/feature-developer.md +1 -1
  18. package/presets/opencode/next/adapter-map.json +1 -1
  19. package/presets/opencode/next/agents/build-verifier.md +2 -1
  20. package/presets/opencode/next/agents/feature-developer.md +1 -1
  21. package/presets/opencode/plugins/task-status/README.md +1 -1
  22. package/presets/opencode/plugins/task-status/deepseek.ts +13 -3
  23. package/presets/opencode/plugins/task-status/task-view.ts +4 -1
  24. package/presets/opencode/plugins/task-status/tui.tsx +4 -6
  25. package/presets/opencode/plugins/task-status/types.ts +5 -1
  26. package/presets/zcode/next/adapter-map.json +1 -1
  27. package/presets/zcode/next/agents/build-verifier.md +2 -1
  28. package/presets/zcode/next/agents/feature-developer.md +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.84",
3
+ "version": "0.2.86",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -40,10 +40,12 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "check:fast": "bash scripts/check-preset-fast.sh",
43
+ "check:classified": "node scripts/run-classified-gates.mjs",
43
44
  "check:changed": "node scripts/check-preset-delta.mjs --base HEAD",
44
45
  "check:task": "node scripts/check-preset-delta.mjs --since-task",
45
46
  "test:hooks": "node scripts/test-chain-team-phases-coverage.mjs && node scripts/test-chain-team-phases-resume-blocked.mjs && node scripts/test-agent-task-metrics-hooks.mjs && node scripts/test-chain-team-phases-dev-cleanup.mjs",
46
47
  "check:preset-structure": "bash scripts/check-preset-structure.sh",
48
+ "test:tooling": "node scripts/run-locked.mjs --label test:tooling -- bash scripts/run-tooling-tests.sh",
47
49
  "release:gate": "bash scripts/release-gate.sh",
48
50
  "check:platform-scripts": "node scripts/check-platform-scripts.mjs",
49
51
  "test:platform": "node scripts/run-platform-tests.mjs",
@@ -149,7 +151,8 @@
149
151
  "check:zcode-local-overlay": "node scripts/check-zcode-local-overlay.mjs",
150
152
  "test:opencode-context-budget": "node scripts/test-opencode-context-budget.mjs",
151
153
  "test:probe-mavis-capabilities": "node scripts/test-probe-mavis-capabilities.mjs",
152
- "preset:loop": "yarn fix:generated && yarn check:changed && yarn check:fast",
154
+ "check:task-receipt": "node scripts/check-task-receipt.mjs",
155
+ "preset:loop": "yarn fix:generated && yarn check:classified",
153
156
  "fix:generated": "node scripts/fix-generated.mjs",
154
157
  "generate:claude": "node scripts/generate-claude.mjs",
155
158
  "generate:mavis": "node scripts/generate-mavis.mjs",
@@ -108,6 +108,9 @@ export const TRACKER_QUEUE_BODY_MAX = 1024;
108
108
  export const REPOSITORY_BODY_MAX = 16384;
109
109
  export const REPOSITORY_WRITE_CHILD_TIMEOUT_MS = 10000;
110
110
  export const REPOSITORY_DELETE_CHILD_TIMEOUT_MS = 30000;
111
+ export const PROJECT_BODY_MAX = 16384;
112
+ export const PROJECT_WRITE_CHILD_TIMEOUT_MS = 10000;
113
+ export const PROJECT_DELETE_CHILD_TIMEOUT_MS = 30000;
111
114
  export const TRACKER_WRITE_CHILD_TIMEOUT_MS = 10000;
112
115
  export const TRACKER_DELETE_CHILD_TIMEOUT_MS = 30000;
113
116
  export const TRACKER_DEFAULT_LIMIT = 50;
@@ -156,6 +159,7 @@ const CODE_STATUS_ROWS = [
156
159
  ['E_ACTIVE_TASK', 409],
157
160
  ['E_CONFLICT', 409],
158
161
  ['E_REPOSITORY_IN_USE', 409],
162
+ ['E_PROJECT_IN_USE', 409],
159
163
  ['E_SCHEDULER_OFFLINE', 409],
160
164
  ['E_RANGE', 416],
161
165
  ['E_DISABLED', 503],
@@ -206,14 +210,31 @@ const TASK_REPOSITORY_FILTER = `
206
210
  )
207
211
  )`;
208
212
 
213
+ /**
214
+ * The project filter of the task list (D1 = derive): a task belongs to a
215
+ * project iff it is linked to at least one member repository. A second
216
+ * separate fragment beside the repository one — the twelve statements that
217
+ * share bare `TASK_FILTER` and their nine binds stay untouched, and only
218
+ * `listTasks` / `countTasks` carry this. An empty slot is "no filter"; a
219
+ * well-shaped unknown id filters to an empty page, never an error.
220
+ */
221
+ const TASK_PROJECT_FILTER = `
222
+ AND (
223
+ ?11 = '' OR EXISTS (
224
+ SELECT 1 FROM project_repositories pr
225
+ JOIN task_repositories tr ON tr.repository_id = pr.repository_id
226
+ WHERE pr.project_id = ?11 AND tr.task_slug = t.slug
227
+ )
228
+ )`;
229
+
209
230
  const TASK_ORDER = `
210
231
  ORDER BY
211
- CASE ?11 WHEN 'slug' THEN t.slug END ASC NULLS LAST,
212
- CASE ?11 WHEN '-slug' THEN t.slug END DESC NULLS LAST,
213
- CASE ?11 WHEN 'updatedAt' THEN t.updated_at END ASC NULLS LAST,
214
- CASE ?11 WHEN '-updatedAt' THEN t.updated_at END DESC NULLS LAST,
215
- CASE ?11 WHEN 'startAt' THEN t.start_at END ASC NULLS LAST,
216
- CASE ?11 WHEN '-startAt' THEN t.start_at END DESC NULLS LAST,
232
+ CASE ?12 WHEN 'slug' THEN t.slug END ASC NULLS LAST,
233
+ CASE ?12 WHEN '-slug' THEN t.slug END DESC NULLS LAST,
234
+ CASE ?12 WHEN 'updatedAt' THEN t.updated_at END ASC NULLS LAST,
235
+ CASE ?12 WHEN '-updatedAt' THEN t.updated_at END DESC NULLS LAST,
236
+ CASE ?12 WHEN 'startAt' THEN t.start_at END ASC NULLS LAST,
237
+ CASE ?12 WHEN '-startAt' THEN t.start_at END DESC NULLS LAST,
217
238
  t.slug ASC`;
218
239
 
219
240
  const ATTEMPT_ORDER = `
@@ -272,9 +293,9 @@ const SQL = {
272
293
  (SELECT CASE WHEN json_valid(d.content) THEN json_extract(d.content, '$.task.platform') END
273
294
  FROM documents d WHERE d.task_slug = t.slug AND d.path = 'metrics.json') AS platform
274
295
  FROM tasks t
275
- WHERE ${TASK_FILTER}${TASK_REPOSITORY_FILTER}${TASK_ORDER}
276
- LIMIT ?12 OFFSET ?13`,
277
- countTasks: `SELECT count(*) AS total FROM tasks t WHERE ${TASK_FILTER}${TASK_REPOSITORY_FILTER}`,
296
+ WHERE ${TASK_FILTER}${TASK_REPOSITORY_FILTER}${TASK_PROJECT_FILTER}${TASK_ORDER}
297
+ LIMIT ?13 OFFSET ?14`,
298
+ countTasks: `SELECT count(*) AS total FROM tasks t WHERE ${TASK_FILTER}${TASK_REPOSITORY_FILTER}${TASK_PROJECT_FILTER}`,
278
299
  getTask: `SELECT
279
300
  t.slug, t.title, t.intent, t.profile, t.spec_mode, t.state, t.phase,
280
301
  t.pipeline_index, t.current_agent, t.awaiting_human_gate, t.updated_at,
@@ -357,6 +378,15 @@ const SQL = {
357
378
  getRepository: `SELECT r.*,
358
379
  (SELECT count(*) FROM task_repositories tr WHERE tr.repository_id = r.id) AS linked_task_count
359
380
  FROM repositories r WHERE r.id = ?1 AND r.absent_at IS NULL`,
381
+ listProjects: `SELECT p.* FROM projects p WHERE p.absent_at IS NULL
382
+ ORDER BY p.status, p.name COLLATE NOCASE, p.id
383
+ LIMIT ?1 OFFSET ?2`,
384
+ countProjects: 'SELECT count(*) AS total FROM projects p WHERE p.absent_at IS NULL',
385
+ getProject: 'SELECT p.* FROM projects p WHERE p.id = ?1 AND p.absent_at IS NULL',
386
+ listProjectRepositories: `SELECT r.id, r.name, r.status
387
+ FROM project_repositories pr JOIN repositories r ON r.id = pr.repository_id
388
+ WHERE pr.project_id = ?1 AND r.absent_at IS NULL
389
+ ORDER BY r.name COLLATE NOCASE, r.id`,
360
390
  eventCounts: `SELECT type, count(*) AS count FROM events WHERE task_slug = ?1 GROUP BY type ORDER BY type`,
361
391
  attemptsByAgent: `SELECT agent, count(*) AS attempts, COALESCE(SUM(duration_ms), 0) AS duration
362
392
  FROM attempts WHERE task_slug = ?1 GROUP BY agent ORDER BY duration DESC, agent ASC`,
@@ -724,12 +754,14 @@ const taskFilters = (db, query, includeAbsentDefault = false) => {
724
754
  if (from && to && from > to) fail('E_VALIDATION', 422, 'from must not be later than to', { parameter: 'from' });
725
755
  const q = parseQuery(query.get('q'), 'q');
726
756
  const repository = parsePattern(query.get('repository'), 'repository', slugPattern, 48);
757
+ const project = parsePattern(query.get('project'), 'project', slugPattern, 48);
727
758
  // An active search with no matches is an empty result set, not "no filter".
728
759
  const searchActive = q === '' ? 0 : 1;
729
760
  const slugs = searchActive === 1 ? searchSlugs(db, q) : [];
730
761
  return {
731
762
  includeAbsent,
732
763
  repository,
764
+ project,
733
765
  params: [includeAbsent ? 1 : 0, JSON.stringify(states), agent, intent, profile, from, to, searchActive, JSON.stringify(slugs)],
734
766
  };
735
767
  };
@@ -791,11 +823,12 @@ const listTasks = (db, query) => {
791
823
  const limit = parseInteger(query.get('limit'), 'limit', { min: 1, max: MAX_LIMIT, fallback: DEFAULT_LIMIT });
792
824
  const offset = parseInteger(query.get('offset'), 'offset', { min: 0, max: MAX_OFFSET, fallback: 0 });
793
825
  const sort = parseEnum(query.get('sort'), 'sort', SORT_VALUE_SET, '-updatedAt');
794
- const { params, repository } = taskFilters(db, query);
795
- // Contiguous slots: `?1..?9` filters, `?10` repository, `?11` sort,
796
- // `?12`/`?13` the page. A gap makes `node:sqlite` refuse the statement.
797
- const rows = db.prepare(SQL.listTasks).all(...params, repository, sort, limit, offset);
798
- const total = Number(db.prepare(SQL.countTasks).get(...params, repository).total);
826
+ const { params, repository, project } = taskFilters(db, query);
827
+ // Contiguous slots: `?1..?9` filters, `?10` repository, `?11` project,
828
+ // `?12` sort, `?13`/`?14` the page. A gap makes `node:sqlite` refuse the
829
+ // statement.
830
+ const rows = db.prepare(SQL.listTasks).all(...params, repository, project, sort, limit, offset);
831
+ const total = Number(db.prepare(SQL.countTasks).get(...params, repository, project).total);
799
832
  return page(rows.map(taskRow), total, limit, offset);
800
833
  };
801
834
 
@@ -2341,7 +2374,180 @@ const deleteRepository = async (context) => {
2341
2374
  }
2342
2375
  fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? `removing ${id} was refused`));
2343
2376
  }
2344
- return { json: { ok: true, id: String(result.id ?? id), linksRemoved: Number(result.linksRemoved ?? 0) } };
2377
+ return {
2378
+ json: {
2379
+ ok: true,
2380
+ id: String(result.id ?? id),
2381
+ linksRemoved: Number(result.linksRemoved ?? 0),
2382
+ // The project-registry cleanup the same write performed (the
2383
+ // resurrection guard): how many memberships named this repository.
2384
+ membersRemoved: Number(result.membersRemoved ?? 0),
2385
+ },
2386
+ };
2387
+ };
2388
+
2389
+ /* --------------------------------- projects -------------------------------- */
2390
+
2391
+ const parseProjectId = (value) => {
2392
+ if (typeof value !== 'string' || value.length > 48 || !slugPattern.test(value)) {
2393
+ fail('E_VALIDATION', 422, 'the project id has an invalid shape', { parameter: 'id' });
2394
+ }
2395
+ return value;
2396
+ };
2397
+
2398
+ const projectRow = (row) => ({
2399
+ id: row.id,
2400
+ name: row.name,
2401
+ description: row.description ?? null,
2402
+ status: row.status,
2403
+ revision: row.revision,
2404
+ createdAt: row.created_at,
2405
+ updatedAt: row.updated_at,
2406
+ });
2407
+
2408
+ /**
2409
+ * The read/write asymmetry of the repositories block, mirrored: a read answers
2410
+ * `ProjectSummary` — the record plus its member refs — because the list row,
2411
+ * the delete dialog's N and the repository-detail reverse block all read the
2412
+ * member array; a write answers plain `Project`, because membership is not a
2413
+ * property of the stored record.
2414
+ */
2415
+ const projectSummaryRow = (db, row) => ({
2416
+ ...projectRow(row),
2417
+ repositories: db.prepare(SQL.listProjectRepositories).all(row.id).map((ref) => ({
2418
+ id: ref.id,
2419
+ name: ref.name,
2420
+ status: ref.status,
2421
+ })),
2422
+ });
2423
+
2424
+ const listProjects = (db, query) => {
2425
+ const limit = parseInteger(query.get('limit'), 'limit', { min: 1, max: MAX_LIMIT, fallback: DEFAULT_LIMIT });
2426
+ const offset = parseInteger(query.get('offset'), 'offset', { min: 0, max: MAX_OFFSET, fallback: 0 });
2427
+ const rows = db.prepare(SQL.listProjects).all(limit, offset);
2428
+ const total = Number(db.prepare(SQL.countProjects).get().total);
2429
+ return page(rows.map((row) => projectSummaryRow(db, row)), total, limit, offset);
2430
+ };
2431
+
2432
+ const requireProjectRow = (db, id) => {
2433
+ const row = db.prepare(SQL.getProject).get(id);
2434
+ if (!row) fail('E_NOT_FOUND', 404, `no project "${id}" in the projection`);
2435
+ return row;
2436
+ };
2437
+
2438
+ const getProjectDetail = (db, id) => projectSummaryRow(db, requireProjectRow(db, id));
2439
+
2440
+ const projectBody = (context) => {
2441
+ const text = context.body.toString('utf8').trim();
2442
+ if (text === '') fail('E_VALIDATION', 422, 'a project body is required', { parameter: 'body' });
2443
+ let parsed;
2444
+ try {
2445
+ parsed = JSON.parse(text);
2446
+ } catch {
2447
+ fail('E_VALIDATION', 422, 'the project body is not valid JSON', { parameter: 'body' });
2448
+ }
2449
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
2450
+ fail('E_VALIDATION', 422, 'the project body must be an object', { parameter: 'body' });
2451
+ }
2452
+ return parsed;
2453
+ };
2454
+
2455
+ /**
2456
+ * `POST` creates the body's `id`; `PUT` refuses a body id that differs from
2457
+ * the path id. Both write one record through the lock-guarded child; the
2458
+ * answer is the child's own record, verbatim.
2459
+ */
2460
+ const createOrUpdateProject = async (context, mode) => {
2461
+ const parsed = projectBody(context);
2462
+ const pathId = mode === 'update' ? parseProjectId(context.params.id) : null;
2463
+ if (mode === 'update' && parsed.id !== undefined && parsed.id !== pathId) {
2464
+ fail('E_CONFLICT', 409, 'the body id differs from the path id; the id is immutable');
2465
+ }
2466
+ if (mode === 'create') {
2467
+ const existing = parsed.id === undefined ? null : context.db().prepare(SQL.getProject).get(parsed.id);
2468
+ if (existing) fail('E_CONFLICT', 409, `a project with the id "${parsed.id}" already exists`);
2469
+ }
2470
+ const body = JSON.stringify(mode === 'update' ? { ...parsed, id: pathId } : parsed);
2471
+ const result = await runTeamDbChild(['projects', 'put', '--file', '-'], {
2472
+ settings: context.settings,
2473
+ timeoutMs: PROJECT_WRITE_CHILD_TIMEOUT_MS,
2474
+ input: body,
2475
+ label: 'project write',
2476
+ });
2477
+ if (result.ok !== true) {
2478
+ const code = typeof result.code === 'string' ? result.code : 'E_INTERNAL';
2479
+ const details = typeof result.parameter === 'string' ? { parameter: result.parameter } : undefined;
2480
+ fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? 'the project write was refused'), details);
2481
+ }
2482
+ return { json: result.project, status: mode === 'create' ? 201 : 200 };
2483
+ };
2484
+
2485
+ /**
2486
+ * The D3 delete guard: `N > 0` without `force` answers 409
2487
+ * `E_PROJECT_IN_USE` with `details.memberRepositories = N`; `force` removes
2488
+ * the record and only its memberships in the same write — the repositories
2489
+ * and their tasks stay.
2490
+ */
2491
+ const deleteProject = async (context) => {
2492
+ const id = parseProjectId(context.params.id);
2493
+ requireProjectRow(context.db(), id);
2494
+ const force = parseBoolean(context.query.get('force'), 'force', false);
2495
+ const revision = context.query.get('revision') === null
2496
+ ? undefined
2497
+ : parseInteger(context.query.get('revision'), 'revision', { min: 1, max: 2_147_483_647, fallback: undefined });
2498
+ const args = ['projects', 'delete', id];
2499
+ if (force) args.push('--force');
2500
+ if (revision !== undefined) args.push('--revision', String(revision));
2501
+ const result = await runTeamDbChild(args, {
2502
+ settings: context.settings,
2503
+ timeoutMs: PROJECT_DELETE_CHILD_TIMEOUT_MS,
2504
+ label: 'project delete',
2505
+ });
2506
+ if (result.ok !== true) {
2507
+ const code = typeof result.code === 'string' ? result.code : 'E_INTERNAL';
2508
+ if (code === 'E_PROJECT_IN_USE') {
2509
+ fail('E_PROJECT_IN_USE', 409, String(result.message ?? `removing ${id} was refused`), {
2510
+ memberRepositories: Number(result.memberRepositories ?? 0),
2511
+ });
2512
+ }
2513
+ fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? `removing ${id} was refused`));
2514
+ }
2515
+ return { json: { ok: true, id: String(result.id ?? id), membersRemoved: Number(result.membersRemoved ?? 0) } };
2516
+ };
2517
+
2518
+ /**
2519
+ * One membership write, add or remove, as a bounded child. The route
2520
+ * pre-checks both endpoints and the pair against the projection so the
2521
+ * documented codes are exact (404 unknown endpoint or non-member pair, 409
2522
+ * duplicate pair); the child's own refusals stay the backstop for races.
2523
+ * Both return the updated `ProjectSummary` the child read from the projection,
2524
+ * so the UI updates the section in place without a refetch.
2525
+ */
2526
+ const membershipProject = async (context, mode) => {
2527
+ const projectId = parseProjectId(context.params.id);
2528
+ const repositoryId = parseRepositoryId(context.params.repositoryId);
2529
+ const db = context.db();
2530
+ requireProjectRow(db, projectId);
2531
+ requireRepositoryRow(db, repositoryId);
2532
+ const pair = db
2533
+ .prepare('SELECT 1 AS member FROM project_repositories WHERE project_id = ?1 AND repository_id = ?2')
2534
+ .get(projectId, repositoryId);
2535
+ if (mode === 'link' && pair) {
2536
+ fail('E_CONFLICT', 409, `"${repositoryId}" is already a member of "${projectId}"`);
2537
+ }
2538
+ if (mode === 'unlink' && !pair) {
2539
+ fail('E_NOT_FOUND', 404, `"${repositoryId}" is not a member of "${projectId}"`);
2540
+ }
2541
+ const result = await runTeamDbChild(['projects', mode, projectId, repositoryId], {
2542
+ settings: context.settings,
2543
+ timeoutMs: PROJECT_WRITE_CHILD_TIMEOUT_MS,
2544
+ label: `project membership ${mode}`,
2545
+ });
2546
+ if (result.ok !== true) {
2547
+ const code = typeof result.code === 'string' ? result.code : 'E_INTERNAL';
2548
+ fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? 'the membership write was refused'));
2549
+ }
2550
+ return { json: result.project };
2345
2551
  };
2346
2552
 
2347
2553
  /**
@@ -3334,6 +3540,33 @@ export const ROUTES = [
3334
3540
  route('DELETE', '/api/v1/repositories/{id}', 'deleteRepository', (context) => deleteRepository(context), {
3335
3541
  bodyLimit: MAX_REQUEST_BODY_BYTES,
3336
3542
  }),
3543
+ // The project entries: three paths, seven operations. Both path parameters
3544
+ // are contract slug ids, so no `pathPatterns` entry is needed.
3545
+ route('GET', '/api/v1/projects', 'listProjects', (context) => ({
3546
+ json: listProjects(context.db(), context.query),
3547
+ })),
3548
+ route('POST', '/api/v1/projects', 'createProject', (context) => createOrUpdateProject(context, 'create'), {
3549
+ bodyLimit: PROJECT_BODY_MAX,
3550
+ requireJson: true,
3551
+ }),
3552
+ route('GET', '/api/v1/projects/{id}', 'getProject', (context) => ({
3553
+ json: getProjectDetail(context.db(), parseProjectId(context.params.id)),
3554
+ })),
3555
+ route('PUT', '/api/v1/projects/{id}', 'updateProject', (context) => createOrUpdateProject(context, 'update'), {
3556
+ bodyLimit: PROJECT_BODY_MAX,
3557
+ requireJson: true,
3558
+ }),
3559
+ route('DELETE', '/api/v1/projects/{id}', 'deleteProject', (context) => deleteProject(context), {
3560
+ bodyLimit: MAX_REQUEST_BODY_BYTES,
3561
+ }),
3562
+ route('POST', '/api/v1/projects/{id}/repositories/{repositoryId}', 'addProjectRepository', (context) =>
3563
+ membershipProject(context, 'link'), {
3564
+ bodyLimit: MAX_REQUEST_BODY_BYTES,
3565
+ }),
3566
+ route('DELETE', '/api/v1/projects/{id}/repositories/{repositoryId}', 'removeProjectRepository', (context) =>
3567
+ membershipProject(context, 'unlink'), {
3568
+ bodyLimit: MAX_REQUEST_BODY_BYTES,
3569
+ }),
3337
3570
  // The tracker entries: `/api/v1/tracker/queue` sits before
3338
3571
  // `/api/v1/tracker/{id}` so the `{id}` pattern can never shadow the literal
3339
3572
  // `queue` segment — the same discipline that keeps `/api/v1/jobs/{id}` from
@@ -3476,6 +3709,11 @@ const sendError = (req, res, error) => {
3476
3709
 
3477
3710
  const mapTeamDbCode = (code, asStatus = false) => {
3478
3711
  if (code === 'E_DB_BUSY' || code === 'E_DEADLINE') return asStatus ? 503 : 'E_BUSY';
3712
+ // The projects lock has its own CLI code; the contract maps a busy registry
3713
+ // to one transport refusal, so a held `.project-registry.lock` is a 503
3714
+ // `E_BUSY`, never an internal error. (`E_REPOSITORIES_BUSY` predates this
3715
+ // branch and is deliberately left untouched.)
3716
+ if (code === 'E_PROJECTS_BUSY') return asStatus ? 503 : 'E_BUSY';
3479
3717
  if (code === 'E_SQLITE_UNAVAILABLE') return asStatus ? 503 : 'E_DB_MISSING';
3480
3718
  if (code === 'E_USAGE') return asStatus ? 500 : 'E_INTERNAL';
3481
3719
  if (CODE_STATUS.has(code)) return asStatus ? CODE_STATUS.get(code) : code;