ultra-builder-pro-cli 0.25.1 → 0.26.1
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/.ultra-template/changes/abandoned/.gitkeep +0 -0
- package/.ultra-template/contexts/TEMPLATE.md +94 -0
- package/.ultra-template/decisions/.gitkeep +1 -0
- package/.ultra-template/evidence/.gitkeep +1 -0
- package/.ultra-template/north-star.md +46 -0
- package/.ultra-template/research/.gitkeep +1 -0
- package/.ultra-template/specs/discovery.md +2 -2
- package/.ultra-template/tasks.json +3 -0
- package/.ultra-template/test-report.json +27 -0
- package/CHANGELOG.md +107 -1
- package/README.md +217 -579
- package/adapters/_shared/delegate-profiles/kimi-read-only.md +15 -0
- package/adapters/_shared/delegate-profiles/kimi-write.md +17 -0
- package/adapters/_shared/file-ops.cjs +76 -2
- package/adapters/_shared/host-profile.cjs +97 -0
- package/adapters/_shared/plugin-core.cjs +204 -0
- package/adapters/_shared/runtime-assets.cjs +31 -96
- package/adapters/claude.js +92 -291
- package/adapters/codex.js +309 -842
- package/adapters/grok.js +143 -1469
- package/adapters/kimi.js +124 -1053
- package/adapters/opencode.js +230 -742
- package/bin/delegate-worker.cjs +328 -0
- package/bin/delegate.cjs +463 -0
- package/bin/install.js +38 -11
- package/docs/ARCHITECTURE.md +125 -216
- package/docs/ARTIFACT-AUTHORITY.md +90 -268
- package/docs/DECISIONS.md +77 -87
- package/docs/PHILOSOPHY.md +208 -0
- package/docs/PLUGIN-ISOLATION-CONTRACT.md +65 -39
- package/docs/RUNTIME-COMPAT-MATRIX.md +140 -155
- package/docs/SKILL-AUTHORING.md +94 -73
- package/docs/WORKFLOW-LIFECYCLE.md +97 -189
- package/hooks/README.md +19 -37
- package/hooks/_common.py +113 -0
- package/hooks/adapters/codex.py +9 -16
- package/hooks/adapters/grok.py +5 -5
- package/hooks/adapters/kimi.py +8 -14
- package/hooks/block_dangerous_commands.py +201 -0
- package/hooks/compact_context.py +65 -0
- package/hooks/mid_workflow_recall.py +25 -0
- package/hooks/post_edit_guard.py +105 -0
- package/hooks/session_context.py +30 -0
- package/package.json +17 -52
- package/skills/ultra-change/SKILL.md +115 -50
- package/skills/ultra-change/references/change-contract.md +68 -3
- package/skills/ultra-delegate/SKILL.md +89 -0
- package/skills/ultra-delegate/references/delegation-contract.md +59 -0
- package/skills/ultra-delegate/scripts/delegate_wait.py +86 -0
- package/skills/ultra-deliver/SKILL.md +98 -42
- package/skills/ultra-deliver/references/baseline-reconciliation.md +39 -20
- package/skills/ultra-dev/SKILL.md +115 -62
- package/skills/ultra-dev/references/debugging.md +22 -0
- package/skills/ultra-domain-modeling/SKILL.md +79 -0
- package/skills/ultra-grilling/SKILL.md +118 -0
- package/skills/ultra-grilling/references/reframing.md +72 -0
- package/skills/ultra-init/SKILL.md +102 -37
- package/skills/ultra-init/references/brownfield-adoption.md +33 -83
- package/skills/ultra-init/scripts/init_project.cjs +84 -0
- package/skills/ultra-plan/SKILL.md +101 -68
- package/skills/ultra-research/SKILL.md +68 -48
- package/skills/ultra-research/references/00-problem-validation.md +5 -5
- package/skills/ultra-research/references/01-opportunity-discovery.md +3 -3
- package/skills/ultra-research/references/02-market-assessment.md +5 -4
- package/skills/ultra-research/references/03-competitive-landscape.md +3 -3
- package/skills/ultra-research/references/04-product-strategy.md +3 -3
- package/skills/ultra-research/references/05-assumptions-validation.md +5 -5
- package/skills/ultra-research/references/10-user-personas.md +3 -2
- package/skills/ultra-research/references/11-user-scenarios.md +3 -3
- package/skills/ultra-research/references/20-user-stories.md +4 -3
- package/skills/ultra-research/references/21-features-scope.md +3 -2
- package/skills/ultra-research/references/22-success-metrics.md +3 -3
- package/skills/ultra-research/references/30-architecture-context.md +3 -3
- package/skills/ultra-research/references/31-solution-strategy.md +3 -3
- package/skills/ultra-research/references/32-building-blocks.md +3 -3
- package/skills/ultra-research/references/40-deployment.md +3 -3
- package/skills/ultra-research/references/41-quality-risks.md +3 -3
- package/skills/ultra-research/references/99-synthesis.md +7 -7
- package/skills/ultra-review/SKILL.md +84 -32
- package/skills/ultra-review/references/code.md +17 -0
- package/skills/ultra-review/references/comments.md +12 -0
- package/skills/ultra-review/references/design.md +12 -0
- package/skills/ultra-review/references/errors.md +13 -0
- package/skills/ultra-review/references/spec.md +13 -0
- package/skills/ultra-review/references/tests.md +12 -0
- package/skills/ultra-review/references/worker-packet.md +40 -0
- package/skills/ultra-review/scripts/review_wait.py +26 -15
- package/skills/ultra-status/SKILL.md +61 -36
- package/skills/ultra-tdd/SKILL.md +81 -0
- package/skills/ultra-tdd/references/templates/README.md +20 -0
- package/skills/ultra-tdd/references/templates/feature-flag-default-audit.sh +79 -0
- package/skills/ultra-tdd/references/templates/persistence-real.ts +78 -0
- package/skills/ultra-tdd/references/templates/testcontainer-postgres.py +78 -0
- package/skills/ultra-tdd/references/templates/testcontainer-postgres.ts +73 -0
- package/skills/ultra-tdd/references/templates/vertical-slice.ts +66 -0
- package/skills/ultra-tdd/references/test-execution.md +18 -0
- package/skills/ultra-test/SKILL.md +75 -30
- package/skills/ultra-test/references/export-syntax.md +18 -0
- package/skills/ultra-test/scripts/worktree_digest.cjs +54 -0
- package/skills/ultra-think/SKILL.md +49 -27
- package/skills/ultra-think/references/autonomy-boundary.md +48 -0
- package/skills/ultra-think/references/interaction-boundary.md +18 -33
- package/.ultra-template/docs/research/README.md +0 -55
- package/.ultra-template/reports/templates/delivery-report.json +0 -17
- package/.ultra-template/reports/templates/test-report.json +0 -18
- package/.ultra-template/tasks/tasks.json +0 -15
- package/.ultra-template/templates/task-context.md +0 -19
- package/adapters/_shared/codex-assets.cjs +0 -725
- package/adapters/_shared/codex-ultra-tools-entry.cjs +0 -11
- package/adapters/_shared/interaction-contract.cjs +0 -129
- package/adapters/_shared/path-rewrite.cjs +0 -79
- package/adapters/_shared/runtime-native.cjs +0 -132
- package/adapters/_shared/settings-merge.cjs +0 -76
- package/agents/code-reviewer.md +0 -42
- package/agents/debugger.md +0 -40
- package/agents/review-code.md +0 -49
- package/agents/review-comments.md +0 -38
- package/agents/review-coordinator.md +0 -56
- package/agents/review-design.md +0 -40
- package/agents/review-errors.md +0 -43
- package/agents/review-spec.md +0 -39
- package/agents/review-tests.md +0 -40
- package/agents/tdd-runner.md +0 -38
- package/bin/orchestrator.js +0 -383
- package/commands/ultra-change.md +0 -10
- package/commands/ultra-deliver.md +0 -10
- package/commands/ultra-dev.md +0 -10
- package/commands/ultra-doctor.md +0 -10
- package/commands/ultra-init.md +0 -10
- package/commands/ultra-plan.md +0 -10
- package/commands/ultra-research.md +0 -10
- package/commands/ultra-review.md +0 -10
- package/commands/ultra-status.md +0 -10
- package/commands/ultra-test.md +0 -10
- package/commands/ultra-think.md +0 -10
- package/docs/AGENT-CONTEXT.md +0 -191
- package/docs/COMMIT-HASH-BACKFILL.md +0 -51
- package/docs/LEGACY-CLI-CROSSWALK.md +0 -175
- package/docs/ROADMAP.md +0 -101
- package/docs/STATE-DB-ACCESS-POLICY.md +0 -161
- package/hooks/active_task_context.py +0 -152
- package/hooks/context_envelope.py +0 -100
- package/hooks/health_check.py +0 -196
- package/hooks/pre_stop_check.py +0 -66
- package/hooks/runtime_paths.py +0 -396
- package/hooks/subagent_tracker.py +0 -88
- package/hooks/workflow_checkpoint.py +0 -76
- package/hooks/workflow_context.py +0 -48
- package/hooks/workflow_resume.py +0 -84
- package/mcp-server/hook-context.cjs +0 -38
- package/mcp-server/hook-event.cjs +0 -34
- package/mcp-server/lib/archive-journal.cjs +0 -1119
- package/mcp-server/lib/archive-mutation-worker.py +0 -365
- package/mcp-server/lib/artifact-registry.cjs +0 -1232
- package/mcp-server/lib/baseline-workflow.cjs +0 -1193
- package/mcp-server/lib/canonical-json.cjs +0 -19
- package/mcp-server/lib/change-authority.cjs +0 -26
- package/mcp-server/lib/change-packet.cjs +0 -790
- package/mcp-server/lib/change-workflow.cjs +0 -65
- package/mcp-server/lib/context-envelope.cjs +0 -581
- package/mcp-server/lib/context-paths.cjs +0 -142
- package/mcp-server/lib/decision-records.cjs +0 -423
- package/mcp-server/lib/delivery-transaction.cjs +0 -471
- package/mcp-server/lib/doctor-backup-worker.cjs +0 -328
- package/mcp-server/lib/doctor.cjs +0 -627
- package/mcp-server/lib/git-bootstrap.cjs +0 -651
- package/mcp-server/lib/init-project.cjs +0 -1021
- package/mcp-server/lib/kernel-change-workflow.cjs +0 -2029
- package/mcp-server/lib/legacy-change-workflow.cjs +0 -3032
- package/mcp-server/lib/managed-file-write.cjs +0 -172
- package/mcp-server/lib/plan-checkpoint.cjs +0 -177
- package/mcp-server/lib/plan-publication-worker.cjs +0 -830
- package/mcp-server/lib/plan-store.cjs +0 -794
- package/mcp-server/lib/prd-parser.cjs +0 -83
- package/mcp-server/lib/pricing.cjs +0 -44
- package/mcp-server/lib/project-context.cjs +0 -178
- package/mcp-server/lib/projector.cjs +0 -386
- package/mcp-server/lib/provider-refs.cjs +0 -42
- package/mcp-server/lib/runtime-paths.cjs +0 -1714
- package/mcp-server/lib/runtime-state.cjs +0 -222
- package/mcp-server/lib/safe-project-file.cjs +0 -385
- package/mcp-server/lib/stage-checkpoints.cjs +0 -463
- package/mcp-server/lib/state-authority.cjs +0 -95
- package/mcp-server/lib/state-db.cjs +0 -1580
- package/mcp-server/lib/state-ops.cjs +0 -1428
- package/mcp-server/lib/task-contract.cjs +0 -404
- package/mcp-server/lib/task-expander.cjs +0 -105
- package/mcp-server/lib/task-ledger.cjs +0 -1964
- package/mcp-server/lib/telemetry.cjs +0 -85
- package/mcp-server/lib/topo.cjs +0 -131
- package/mcp-server/lib/ultra-facade.cjs +0 -2684
- package/mcp-server/lib/worker-packet.cjs +0 -358
- package/mcp-server/server.cjs +0 -437
- package/orchestrator/auto-merge.cjs +0 -128
- package/orchestrator/daemon.cjs +0 -264
- package/orchestrator/dispatch-rules.cjs +0 -78
- package/orchestrator/parallel-orchestrator.cjs +0 -903
- package/orchestrator/planner/plan-builder.cjs +0 -125
- package/orchestrator/recovery.cjs +0 -188
- package/orchestrator/session-close-journal-worker.cjs +0 -5
- package/orchestrator/session-close-journal.cjs +0 -1014
- package/orchestrator/session-runner.cjs +0 -1153
- package/orchestrator/worktree-manager.cjs +0 -282
- package/settings.json +0 -7
- package/skills/cc-collab/SKILL.md +0 -42
- package/skills/code-review-expert/SKILL.md +0 -43
- package/skills/code-review-expert/references/correctness-reliability.md +0 -30
- package/skills/code-review-expert/references/design-boundaries.md +0 -26
- package/skills/code-review-expert/references/removal-plan.md +0 -24
- package/skills/codex-collab/SKILL.md +0 -49
- package/skills/codex-collab/evals/evals.json +0 -35
- package/skills/integration-rules/SKILL.md +0 -32
- package/skills/security-rules/SKILL.md +0 -38
- package/skills/testing-rules/SKILL.md +0 -32
- package/skills/ultra-doctor/SKILL.md +0 -41
- package/skills/ultra-plan/references/semantic-preflight.md +0 -20
- package/skills/ultra-verify/SKILL.md +0 -46
- package/skills/ultra-verify/evals/evals.json +0 -46
- package/skills/ultra-verify/references/cross-verify-modes.md +0 -28
- package/skills/ultra-verify/references/evidence-status.md +0 -21
- package/skills/ultra-verify/scripts/verify_wait.py +0 -94
- package/spec/cli-protocol.md +0 -102
- package/spec/mcp-tools.yaml +0 -312
- package/spec/schemas/baseline-reconciliation.v1.schema.json +0 -73
- package/spec/schemas/change-delta.v1.schema.json +0 -153
- package/spec/schemas/command-manifest.schema.json +0 -29
- package/spec/schemas/context-file.v4.5.schema.json +0 -54
- package/spec/schemas/delivery-report.v1.schema.json +0 -66
- package/spec/schemas/documentation-reconciliation.v1.schema.json +0 -106
- package/spec/schemas/mcp-tools.schema.json +0 -136
- package/spec/schemas/skill-manifest.schema.json +0 -24
- package/spec/schemas/state-db.sql +0 -641
- package/spec/schemas/task-ledger.v2.schema.json +0 -296
- package/spec/schemas/tasks.v4.5.schema.json +0 -96
- package/spec/schemas/test-report.v1.schema.json +0 -225
- package/ultra-tools/cli.cjs +0 -129
- package/ultra-tools/commands/db.cjs +0 -226
- package/ultra-tools/commands/legacy-memory.cjs +0 -159
- package/ultra-tools/commands/migrate.cjs +0 -1386
- package/ultra-tools/commands/session.cjs +0 -213
- package/ultra-tools/commands/status.cjs +0 -559
- package/ultra-tools/commands/system.cjs +0 -498
- package/ultra-tools/commands/task.cjs +0 -105
|
@@ -1,627 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crypto = require('node:crypto');
|
|
4
|
-
const childProcess = require('node:child_process');
|
|
5
|
-
const fs = require('node:fs');
|
|
6
|
-
const path = require('node:path');
|
|
7
|
-
|
|
8
|
-
const { REQUIRED_TABLES, tableNames } = require('./state-db.cjs');
|
|
9
|
-
const ops = require('./state-ops.cjs');
|
|
10
|
-
const runtime = require('./runtime-state.cjs');
|
|
11
|
-
const projector = require('./projector.cjs');
|
|
12
|
-
const recovery = require('../../orchestrator/recovery.cjs');
|
|
13
|
-
const baselines = require('./baseline-workflow.cjs');
|
|
14
|
-
const changes = require('./change-workflow.cjs');
|
|
15
|
-
const archiveJournal = require('./archive-journal.cjs');
|
|
16
|
-
const stageCheckpoints = require('./stage-checkpoints.cjs');
|
|
17
|
-
const runtimePaths = require('./runtime-paths.cjs');
|
|
18
|
-
const artifactRegistry = require('./artifact-registry.cjs');
|
|
19
|
-
const planStore = require('./plan-store.cjs');
|
|
20
|
-
const taskLedger = require('./task-ledger.cjs');
|
|
21
|
-
const closeJournal = require('../../orchestrator/session-close-journal.cjs');
|
|
22
|
-
|
|
23
|
-
const SPEC_CONSUMER = 'spec-staleness';
|
|
24
|
-
const BACKUP_WORKER_FILENAME = 'doctor-backup-worker.cjs';
|
|
25
|
-
const BACKUP_WORKER_TIMEOUT_MS = 120 * 1000;
|
|
26
|
-
const BACKUP_WORKER_METHOD = 'sqlite-serialize-pinned-fd-v1';
|
|
27
|
-
|
|
28
|
-
class DoctorError extends Error {
|
|
29
|
-
constructor(code, message, { cause, details } = {}) {
|
|
30
|
-
super(message);
|
|
31
|
-
this.name = 'DoctorError';
|
|
32
|
-
this.code = code;
|
|
33
|
-
if (cause) this.cause = cause;
|
|
34
|
-
if (details !== undefined) this.details = details;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function timestamp() {
|
|
39
|
-
return new Date().toISOString().replace(/[:.]/g, '-');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function inspectSessionCloses(db, {
|
|
43
|
-
rootDir = process.cwd(),
|
|
44
|
-
sessionsAvailable = true,
|
|
45
|
-
} = {}) {
|
|
46
|
-
let intents;
|
|
47
|
-
try {
|
|
48
|
-
intents = closeJournal.list(rootDir);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return {
|
|
51
|
-
status: 'fail',
|
|
52
|
-
pending: 1,
|
|
53
|
-
items: [{
|
|
54
|
-
code: error.code || 'SESSION_CLOSE_JOURNAL_INVALID',
|
|
55
|
-
reason: 'journal_invalid',
|
|
56
|
-
message: error.message,
|
|
57
|
-
}],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const items = intents.map((intent) => {
|
|
61
|
-
const session = sessionsAvailable ? ops.readSession(db, intent.sid) : null;
|
|
62
|
-
let reason = 'recovery_required';
|
|
63
|
-
if (!sessionsAvailable) reason = 'session_state_unavailable';
|
|
64
|
-
else if (!session) reason = 'session_missing';
|
|
65
|
-
else if (session.status === intent.requested_status) reason = 'terminal_reconciliation_required';
|
|
66
|
-
else if (['completed', 'crashed'].includes(session.status)) {
|
|
67
|
-
reason = `terminal_status_conflict:${session.status}`;
|
|
68
|
-
} else if (recovery._internal.isPidAlive(session.pid)) {
|
|
69
|
-
reason = 'worker_still_alive';
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
code: 'SESSION_CLOSE_PENDING',
|
|
73
|
-
sid: intent.sid,
|
|
74
|
-
task_id: intent.task_id,
|
|
75
|
-
requested_status: intent.requested_status,
|
|
76
|
-
phase: intent.phase,
|
|
77
|
-
reason,
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
status: items.length === 0 ? 'pass' : 'fail',
|
|
82
|
-
pending: items.length,
|
|
83
|
-
items,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function inspectTeamTaskLedger(db, rootDir) {
|
|
88
|
-
try {
|
|
89
|
-
const health = taskLedger.inspectTaskLedger(db, { rootDir });
|
|
90
|
-
const taskCount = db.prepare('SELECT COUNT(*) AS count FROM tasks').get().count;
|
|
91
|
-
let status = 'warning';
|
|
92
|
-
if (health.status === 'current') status = 'pass';
|
|
93
|
-
return {
|
|
94
|
-
...health,
|
|
95
|
-
condition: health.status,
|
|
96
|
-
status,
|
|
97
|
-
task_count: taskCount,
|
|
98
|
-
};
|
|
99
|
-
} catch (error) {
|
|
100
|
-
return {
|
|
101
|
-
status: 'fail',
|
|
102
|
-
condition: 'invalid',
|
|
103
|
-
code: error.code || 'TASK_LEDGER_INVALID',
|
|
104
|
-
message: error.message,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function inspectStageCheckpoints(db) {
|
|
110
|
-
const rows = db.prepare(
|
|
111
|
-
`SELECT id, stage, scope_type, scope_id, revision, status, payload_json,
|
|
112
|
-
evidence_json, diagnostics_json, context_envelope_id, digest,
|
|
113
|
-
supersedes_id
|
|
114
|
-
FROM stage_checkpoints ORDER BY stage, scope_type, scope_id, revision`,
|
|
115
|
-
).all();
|
|
116
|
-
const counts = { draft: 0, accepted: 0, superseded: 0 };
|
|
117
|
-
const issues = [];
|
|
118
|
-
for (const row of rows) {
|
|
119
|
-
counts[row.status] = Number(counts[row.status] || 0) + 1;
|
|
120
|
-
let payload;
|
|
121
|
-
let evidence;
|
|
122
|
-
let diagnostics;
|
|
123
|
-
try {
|
|
124
|
-
payload = JSON.parse(row.payload_json);
|
|
125
|
-
evidence = JSON.parse(row.evidence_json);
|
|
126
|
-
diagnostics = JSON.parse(row.diagnostics_json);
|
|
127
|
-
} catch {
|
|
128
|
-
issues.push({ code: 'CHECKPOINT_JSON_INVALID', checkpoint_id: row.id });
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const expected = stageCheckpoints.checkpointDigest({
|
|
132
|
-
stage: row.stage,
|
|
133
|
-
scope_type: row.scope_type,
|
|
134
|
-
scope_id: row.scope_id,
|
|
135
|
-
revision: row.revision,
|
|
136
|
-
payload,
|
|
137
|
-
evidence,
|
|
138
|
-
diagnostics,
|
|
139
|
-
context_envelope_id: row.context_envelope_id,
|
|
140
|
-
supersedes_id: row.supersedes_id,
|
|
141
|
-
});
|
|
142
|
-
if (expected !== row.digest) {
|
|
143
|
-
issues.push({ code: 'CHECKPOINT_DIGEST_MISMATCH', checkpoint_id: row.id });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
status: issues.length === 0 ? 'pass' : 'fail',
|
|
148
|
-
total: rows.length,
|
|
149
|
-
...counts,
|
|
150
|
-
issues,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function inspectDecisionRecords(db) {
|
|
155
|
-
const rows = db.prepare(
|
|
156
|
-
`SELECT id, status, digest, artifact_path
|
|
157
|
-
FROM decision_records ORDER BY created_at, id`,
|
|
158
|
-
).all();
|
|
159
|
-
return {
|
|
160
|
-
status: 'pass',
|
|
161
|
-
total: rows.length,
|
|
162
|
-
accepted: rows.filter((row) => row.status === 'accepted').length,
|
|
163
|
-
superseded: rows.filter((row) => row.status === 'superseded').length,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function inspectLegacyHistory(db) {
|
|
168
|
-
const count = (table) => db.prepare(`SELECT COUNT(*) AS count FROM ${table}`).get().count;
|
|
169
|
-
return {
|
|
170
|
-
status: 'informational',
|
|
171
|
-
workflow_runs: count('workflow_runs'),
|
|
172
|
-
workflow_steps: count('workflow_steps'),
|
|
173
|
-
decision_threads: count('decision_threads'),
|
|
174
|
-
decision_items: count('decision_items'),
|
|
175
|
-
authority: false,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function inspectSystem(db, { rootDir = process.cwd() } = {}) {
|
|
180
|
-
const tables = new Set(tableNames(db));
|
|
181
|
-
const missing = REQUIRED_TABLES.filter((name) => !tables.has(name));
|
|
182
|
-
const integrity = db.pragma('quick_check', { simple: true });
|
|
183
|
-
const incidents = missing.length === 0 ? runtime.listIncidents(db, { status: 'open' }) : [];
|
|
184
|
-
const pending = missing.length === 0 ? runtime.listProjectionJobs(db, { status: 'pending' }) : [];
|
|
185
|
-
const running = missing.length === 0 ? runtime.listProjectionJobs(db, { status: 'running' }) : [];
|
|
186
|
-
const failed = missing.length === 0 ? runtime.listProjectionJobs(db, { status: 'failed' }) : [];
|
|
187
|
-
const orphanSessions = missing.length === 0
|
|
188
|
-
? db.prepare("SELECT COUNT(*) AS count FROM sessions WHERE status = 'orphan'").get().count
|
|
189
|
-
: 0;
|
|
190
|
-
const sessionCloses = inspectSessionCloses(db, {
|
|
191
|
-
rootDir,
|
|
192
|
-
sessionsAvailable: missing.length === 0,
|
|
193
|
-
});
|
|
194
|
-
const eventCursor = missing.length === 0
|
|
195
|
-
? Number(db.prepare('SELECT COALESCE(MAX(id), 0) AS id FROM events').get().id)
|
|
196
|
-
: 0;
|
|
197
|
-
const projectedCursor = missing.length === 0
|
|
198
|
-
? Number(db.prepare(
|
|
199
|
-
"SELECT COALESCE(MAX(event_cursor), 0) AS id FROM projection_jobs WHERE status = 'completed'",
|
|
200
|
-
).get().id)
|
|
201
|
-
: 0;
|
|
202
|
-
const activeMissing = missing.length === 0
|
|
203
|
-
? db.prepare(
|
|
204
|
-
`SELECT artifact_root FROM changes
|
|
205
|
-
WHERE status IN ('active', 'blocked', 'ready') AND artifact_root IS NOT NULL`,
|
|
206
|
-
).all().filter((row) => row.artifact_root && !fs.existsSync(path.resolve(rootDir, row.artifact_root))).length
|
|
207
|
-
: 0;
|
|
208
|
-
const archiveIntents = missing.length === 0 ? archiveJournal.listArchiveIntents(rootDir) : [];
|
|
209
|
-
const corruptArchiveIntents = archiveIntents.filter((item) => item.error).length;
|
|
210
|
-
const baseline = missing.length === 0
|
|
211
|
-
? baselines.inspectBaseline(db, { rootDir })
|
|
212
|
-
: { status: 'fail', blockers: ['BASELINE_STATE_UNAVAILABLE'], warnings: [], baseline: null };
|
|
213
|
-
const checkpointHealth = missing.length === 0
|
|
214
|
-
? inspectStageCheckpoints(db)
|
|
215
|
-
: { status: 'fail', total: 0, issues: [{ code: 'STATE_DB_UNAVAILABLE' }] };
|
|
216
|
-
const decisionHealth = missing.length === 0
|
|
217
|
-
? inspectDecisionRecords(db)
|
|
218
|
-
: { status: 'fail', total: 0, accepted: 0, superseded: 0 };
|
|
219
|
-
const legacyHistory = missing.length === 0
|
|
220
|
-
? inspectLegacyHistory(db)
|
|
221
|
-
: {
|
|
222
|
-
status: 'informational',
|
|
223
|
-
workflow_runs: 0,
|
|
224
|
-
workflow_steps: 0,
|
|
225
|
-
decision_threads: 0,
|
|
226
|
-
decision_items: 0,
|
|
227
|
-
authority: false,
|
|
228
|
-
};
|
|
229
|
-
const artifactHealth = missing.length === 0
|
|
230
|
-
? artifactRegistry.inspectArtifactHealth(db, { rootDir })
|
|
231
|
-
: { status: 'fail', registered: 0, issues: [], counts: {} };
|
|
232
|
-
const planPublications = missing.length === 0
|
|
233
|
-
? planStore.inspectPlanPublications(db, { rootDir })
|
|
234
|
-
: { status: 'fail', pending: 0, transactions: [], issues: [] };
|
|
235
|
-
const taskLedgerHealth = missing.length === 0
|
|
236
|
-
? inspectTeamTaskLedger(db, rootDir)
|
|
237
|
-
: { status: 'fail', condition: 'state_unavailable', code: 'STATE_DB_UNAVAILABLE' };
|
|
238
|
-
const baselineCheckStatus = baseline.status === 'pass'
|
|
239
|
-
? 'pass'
|
|
240
|
-
: (baseline.baseline?.status === 'ready' ? 'fail' : 'warning');
|
|
241
|
-
const degraded = integrity !== 'ok' || missing.length > 0 || incidents.length > 0
|
|
242
|
-
|| pending.length > 0 || running.length > 0 || failed.length > 0 || orphanSessions > 0 || activeMissing > 0
|
|
243
|
-
|| sessionCloses.status === 'fail'
|
|
244
|
-
|| archiveIntents.length > 0
|
|
245
|
-
|| eventCursor > projectedCursor || checkpointHealth.status === 'fail'
|
|
246
|
-
|| decisionHealth.status === 'fail'
|
|
247
|
-
|| artifactHealth.status === 'fail'
|
|
248
|
-
|| planPublications.status === 'fail'
|
|
249
|
-
|| taskLedgerHealth.status === 'fail'
|
|
250
|
-
|| baselineCheckStatus === 'fail';
|
|
251
|
-
return {
|
|
252
|
-
status: degraded ? 'degraded' : 'healthy',
|
|
253
|
-
checks: {
|
|
254
|
-
state_db: { status: integrity === 'ok' && missing.length === 0 ? 'pass' : 'fail', integrity, missing_tables: missing },
|
|
255
|
-
incidents: { status: incidents.length === 0 ? 'pass' : 'fail', open: incidents.length, items: incidents },
|
|
256
|
-
projections: {
|
|
257
|
-
status: pending.length === 0 && running.length === 0 && failed.length === 0 && eventCursor <= projectedCursor ? 'pass' : 'fail',
|
|
258
|
-
pending: pending.length, running: running.length, failed: failed.length,
|
|
259
|
-
event_cursor: eventCursor, projected_cursor: projectedCursor,
|
|
260
|
-
},
|
|
261
|
-
sessions: {
|
|
262
|
-
status: orphanSessions === 0 && sessionCloses.status === 'pass' ? 'pass' : 'fail',
|
|
263
|
-
orphan: orphanSessions,
|
|
264
|
-
close_pending: sessionCloses.pending,
|
|
265
|
-
close_intents: sessionCloses.items,
|
|
266
|
-
},
|
|
267
|
-
change_artifacts: { status: activeMissing === 0 ? 'pass' : 'fail', missing: activeMissing },
|
|
268
|
-
artifacts: artifactHealth,
|
|
269
|
-
task_ledger: taskLedgerHealth,
|
|
270
|
-
plan_publications: planPublications,
|
|
271
|
-
archive_recovery: {
|
|
272
|
-
status: archiveIntents.length === 0 ? 'pass' : 'fail',
|
|
273
|
-
pending: archiveIntents.length, corrupt: corruptArchiveIntents,
|
|
274
|
-
},
|
|
275
|
-
baseline: {
|
|
276
|
-
status: baselineCheckStatus,
|
|
277
|
-
readiness: baseline.status,
|
|
278
|
-
mode: baseline.baseline?.mode || null,
|
|
279
|
-
baseline_status: baseline.baseline?.status || null,
|
|
280
|
-
id: baseline.baseline?.id || null,
|
|
281
|
-
repository_revision: baseline.baseline?.repository_revision || null,
|
|
282
|
-
repository_branch: baseline.baseline?.repository_branch || null,
|
|
283
|
-
worktree_state: baseline.baseline?.worktree_state || 'unavailable',
|
|
284
|
-
gaps: baseline.baseline ? baselines.summarizeGaps(baseline.baseline.gaps) : null,
|
|
285
|
-
blockers: baseline.blockers,
|
|
286
|
-
warnings: baseline.warnings,
|
|
287
|
-
},
|
|
288
|
-
checkpoints: checkpointHealth,
|
|
289
|
-
decisions: decisionHealth,
|
|
290
|
-
legacy_history: legacyHistory,
|
|
291
|
-
external_providers: {
|
|
292
|
-
status: 'pass', ownership: 'external',
|
|
293
|
-
note: 'Ultra stores provider metadata references only and never owns memory or code-graph content.',
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function statIdentity(stat) {
|
|
300
|
-
return { dev: String(stat.dev), ino: String(stat.ino) };
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function sameIdentity(left, right) {
|
|
304
|
-
return String(left?.dev) === String(right?.dev)
|
|
305
|
-
&& String(left?.ino) === String(right?.ino);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function backupWorkerPath() {
|
|
309
|
-
const runtimeRoot = process.env.UBP_RUNTIME_ROOT
|
|
310
|
-
? path.resolve(process.env.UBP_RUNTIME_ROOT)
|
|
311
|
-
: null;
|
|
312
|
-
const candidate = runtimeRoot
|
|
313
|
-
? path.join(runtimeRoot, 'runtime', BACKUP_WORKER_FILENAME)
|
|
314
|
-
: path.join(__dirname, BACKUP_WORKER_FILENAME);
|
|
315
|
-
const stat = fs.lstatSync(candidate, { throwIfNoEntry: false });
|
|
316
|
-
if (!stat || stat.isSymbolicLink() || !stat.isFile()) {
|
|
317
|
-
throw new DoctorError(
|
|
318
|
-
'BACKUP_FAILED',
|
|
319
|
-
`Doctor backup worker is missing or unsafe: ${candidate}`,
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
return candidate;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function canonicalStateDb(db) {
|
|
326
|
-
const main = db.pragma('database_list').find((row) => row.name === 'main');
|
|
327
|
-
const sourcePath = path.resolve(String(main?.file || ''));
|
|
328
|
-
const stat = fs.lstatSync(sourcePath, {
|
|
329
|
-
bigint: true,
|
|
330
|
-
throwIfNoEntry: false,
|
|
331
|
-
});
|
|
332
|
-
if (!main?.file || !stat || stat.isSymbolicLink() || !stat.isFile()) {
|
|
333
|
-
throw new DoctorError(
|
|
334
|
-
'BACKUP_FAILED',
|
|
335
|
-
`canonical state database is missing or unsafe: ${sourcePath}`,
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
return { sourcePath, sourceIdentity: statIdentity(stat) };
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function decodeBackupWorker(result, expected) {
|
|
342
|
-
if (result.error) {
|
|
343
|
-
throw new DoctorError(
|
|
344
|
-
'BACKUP_FAILED',
|
|
345
|
-
`cannot start Doctor backup worker: ${result.error.message}`,
|
|
346
|
-
{ cause: result.error },
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
let payload;
|
|
350
|
-
try {
|
|
351
|
-
payload = JSON.parse(String(result.stdout || '').trim());
|
|
352
|
-
} catch (cause) {
|
|
353
|
-
throw new DoctorError(
|
|
354
|
-
'BACKUP_FAILED',
|
|
355
|
-
`Doctor backup worker returned invalid output: ${String(result.stderr || '').trim()}`,
|
|
356
|
-
{ cause },
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
if (!payload?.ok) {
|
|
360
|
-
throw new DoctorError(
|
|
361
|
-
'BACKUP_FAILED',
|
|
362
|
-
payload?.error?.message || 'Doctor backup worker failed',
|
|
363
|
-
{ details: payload?.error },
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
const value = payload.result;
|
|
367
|
-
const valid = result.status === 0
|
|
368
|
-
&& value && typeof value === 'object' && !Array.isArray(value)
|
|
369
|
-
&& value.output_name === expected.outputName
|
|
370
|
-
&& value.integrity === 'ok'
|
|
371
|
-
&& value.method === BACKUP_WORKER_METHOD
|
|
372
|
-
&& Number.isSafeInteger(value.size) && value.size > 0
|
|
373
|
-
&& /^[0-9a-f]{64}$/.test(value.digest || '')
|
|
374
|
-
&& sameIdentity(value.directory_identity, expected.directoryIdentity)
|
|
375
|
-
&& sameIdentity(value.source_identity, expected.sourceIdentity)
|
|
376
|
-
&& value.backup_identity && typeof value.backup_identity === 'object';
|
|
377
|
-
if (!valid) {
|
|
378
|
-
throw new DoctorError(
|
|
379
|
-
'BACKUP_FAILED',
|
|
380
|
-
'Doctor backup worker returned an invalid success payload',
|
|
381
|
-
{ details: { status: result.status, payload } },
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
return value;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function verifyPublishedBackup(backupDir, backupPath, expected) {
|
|
388
|
-
const directory = fs.lstatSync(backupDir, {
|
|
389
|
-
bigint: true,
|
|
390
|
-
throwIfNoEntry: false,
|
|
391
|
-
});
|
|
392
|
-
if (!directory || directory.isSymbolicLink() || !directory.isDirectory()
|
|
393
|
-
|| !sameIdentity(statIdentity(directory), expected.directoryIdentity)) {
|
|
394
|
-
throw new DoctorError(
|
|
395
|
-
'BACKUP_FAILED',
|
|
396
|
-
'Doctor backup directory changed before backup publication could be verified',
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
if (!Number.isInteger(fs.constants.O_NOFOLLOW) || fs.constants.O_NOFOLLOW === 0) {
|
|
400
|
-
throw new DoctorError(
|
|
401
|
-
'BACKUP_FAILED',
|
|
402
|
-
'Doctor cannot verify backups without no-follow file support on this platform',
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
let backupFd;
|
|
406
|
-
try {
|
|
407
|
-
backupFd = fs.openSync(
|
|
408
|
-
backupPath,
|
|
409
|
-
fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW,
|
|
410
|
-
);
|
|
411
|
-
} catch (cause) {
|
|
412
|
-
throw new DoctorError(
|
|
413
|
-
'BACKUP_FAILED',
|
|
414
|
-
'Doctor backup publication is missing or unsafe',
|
|
415
|
-
{ cause },
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
let backup;
|
|
419
|
-
let digest;
|
|
420
|
-
try {
|
|
421
|
-
backup = fs.fstatSync(backupFd, { bigint: true });
|
|
422
|
-
if (!backup.isFile()
|
|
423
|
-
|| !sameIdentity(statIdentity(backup), expected.backupIdentity)) {
|
|
424
|
-
throw new DoctorError(
|
|
425
|
-
'BACKUP_FAILED',
|
|
426
|
-
'Doctor backup publication does not match the worker-pinned file',
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
digest = crypto.createHash('sha256').update(fs.readFileSync(backupFd)).digest('hex');
|
|
430
|
-
} finally {
|
|
431
|
-
fs.closeSync(backupFd);
|
|
432
|
-
}
|
|
433
|
-
if (digest !== expected.digest || Number(backup.size) !== expected.size) {
|
|
434
|
-
throw new DoctorError(
|
|
435
|
-
'BACKUP_FAILED',
|
|
436
|
-
'Doctor backup publication failed post-worker verification',
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
async function backupDatabase(db, rootDir, { beforeWorker = null } = {}) {
|
|
442
|
-
const backupDir = runtimePaths.pathsFor(rootDir).backupsDir;
|
|
443
|
-
const outputName = `state-${timestamp()}-${crypto.randomUUID()}.db`;
|
|
444
|
-
const backupPath = path.join(backupDir, outputName);
|
|
445
|
-
try {
|
|
446
|
-
runtimePaths.validateProjectLayout(rootDir, {
|
|
447
|
-
env: {},
|
|
448
|
-
validateRuntimeTree: true,
|
|
449
|
-
});
|
|
450
|
-
fs.mkdirSync(backupDir, { recursive: true, mode: 0o700 });
|
|
451
|
-
runtimePaths.assertManagedBackupDestination(rootDir, backupPath);
|
|
452
|
-
const backupDirectory = fs.lstatSync(backupDir, { bigint: true });
|
|
453
|
-
if (backupDirectory.isSymbolicLink() || !backupDirectory.isDirectory()) {
|
|
454
|
-
throw new DoctorError('BACKUP_FAILED', `backup root is unsafe: ${backupDir}`);
|
|
455
|
-
}
|
|
456
|
-
const directoryIdentity = statIdentity(backupDirectory);
|
|
457
|
-
const { sourcePath, sourceIdentity } = canonicalStateDb(db);
|
|
458
|
-
if (beforeWorker) {
|
|
459
|
-
beforeWorker({
|
|
460
|
-
backupDir,
|
|
461
|
-
backupPath,
|
|
462
|
-
directoryIdentity,
|
|
463
|
-
sourcePath,
|
|
464
|
-
sourceIdentity,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
const result = childProcess.spawnSync(
|
|
468
|
-
process.execPath,
|
|
469
|
-
[backupWorkerPath()],
|
|
470
|
-
{
|
|
471
|
-
cwd: backupDir,
|
|
472
|
-
input: JSON.stringify({
|
|
473
|
-
directory_identity: directoryIdentity,
|
|
474
|
-
source_path: sourcePath,
|
|
475
|
-
source_identity: sourceIdentity,
|
|
476
|
-
output_name: outputName,
|
|
477
|
-
}),
|
|
478
|
-
encoding: 'utf8',
|
|
479
|
-
maxBuffer: 1024 * 1024,
|
|
480
|
-
timeout: BACKUP_WORKER_TIMEOUT_MS,
|
|
481
|
-
windowsHide: true,
|
|
482
|
-
},
|
|
483
|
-
);
|
|
484
|
-
const published = decodeBackupWorker(result, {
|
|
485
|
-
outputName,
|
|
486
|
-
directoryIdentity,
|
|
487
|
-
sourceIdentity,
|
|
488
|
-
});
|
|
489
|
-
verifyPublishedBackup(backupDir, backupPath, {
|
|
490
|
-
directoryIdentity,
|
|
491
|
-
backupIdentity: published.backup_identity,
|
|
492
|
-
digest: published.digest,
|
|
493
|
-
size: published.size,
|
|
494
|
-
});
|
|
495
|
-
return backupPath;
|
|
496
|
-
} catch (error) {
|
|
497
|
-
if (error instanceof DoctorError) throw error;
|
|
498
|
-
throw new DoctorError(
|
|
499
|
-
'BACKUP_FAILED',
|
|
500
|
-
`state.db backup failed: ${error.message}`,
|
|
501
|
-
{ cause: error },
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
async function runDoctor(db, {
|
|
507
|
-
rootDir = process.cwd(), repair = false, project = projector.projectAll,
|
|
508
|
-
projectionStaleAfterMs = 5 * 60 * 1000,
|
|
509
|
-
_beforeBackupWorker = null,
|
|
510
|
-
} = {}) {
|
|
511
|
-
if (!repair) return { ...inspectSystem(db, { rootDir }), repair_performed: false };
|
|
512
|
-
const backupPath = await backupDatabase(db, rootDir, {
|
|
513
|
-
beforeWorker: _beforeBackupWorker,
|
|
514
|
-
});
|
|
515
|
-
const recovered = recovery.recoverOnBoot(db, { repoRoot: rootDir });
|
|
516
|
-
if (recovered.close_pending.length > 0) {
|
|
517
|
-
const deferred = {
|
|
518
|
-
status: 'deferred',
|
|
519
|
-
code: 'SESSION_CLOSE_PENDING',
|
|
520
|
-
pending: recovered.close_pending,
|
|
521
|
-
};
|
|
522
|
-
return {
|
|
523
|
-
...inspectSystem(db, { rootDir }),
|
|
524
|
-
repair_performed: true,
|
|
525
|
-
backup_path: backupPath,
|
|
526
|
-
repair: {
|
|
527
|
-
close_intents: recovered,
|
|
528
|
-
recovered,
|
|
529
|
-
plan_publications: deferred,
|
|
530
|
-
archives: deferred,
|
|
531
|
-
legacy_history: deferred,
|
|
532
|
-
},
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
const planPublications = planStore.recoverPlanPublications(db, { rootDir });
|
|
536
|
-
if (planPublications.pending > 0 || planPublications.issues.length > 0) {
|
|
537
|
-
const blocked = planPublications.issues.length > 0;
|
|
538
|
-
const planGate = {
|
|
539
|
-
...planPublications,
|
|
540
|
-
status: blocked ? 'blocked' : 'deferred',
|
|
541
|
-
code: 'PLAN_RECOVERY_REQUIRED',
|
|
542
|
-
};
|
|
543
|
-
const deferred = {
|
|
544
|
-
status: 'deferred',
|
|
545
|
-
code: 'PLAN_RECOVERY_REQUIRED',
|
|
546
|
-
blocked_by: 'plan_publications',
|
|
547
|
-
};
|
|
548
|
-
return {
|
|
549
|
-
...inspectSystem(db, { rootDir }),
|
|
550
|
-
status: 'degraded',
|
|
551
|
-
repair_performed: true,
|
|
552
|
-
backup_path: backupPath,
|
|
553
|
-
repair: {
|
|
554
|
-
close_intents: recovered,
|
|
555
|
-
recovered,
|
|
556
|
-
plan_publications: planGate,
|
|
557
|
-
archives: deferred,
|
|
558
|
-
legacy_history: deferred,
|
|
559
|
-
spec_events: deferred,
|
|
560
|
-
interrupted: deferred,
|
|
561
|
-
requeued: deferred,
|
|
562
|
-
ensured: deferred,
|
|
563
|
-
projections: deferred,
|
|
564
|
-
},
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
const archives = changes.recoverInterruptedArchives(db, { rootDir });
|
|
568
|
-
const unresolvedArchives = archiveJournal.listArchiveIntents(rootDir);
|
|
569
|
-
if (archives.failed > 0 || unresolvedArchives.length > 0) {
|
|
570
|
-
const archiveGate = {
|
|
571
|
-
...archives,
|
|
572
|
-
pending: unresolvedArchives.length,
|
|
573
|
-
status: 'blocked',
|
|
574
|
-
code: 'ARCHIVE_RECOVERY_REQUIRED',
|
|
575
|
-
};
|
|
576
|
-
const deferred = {
|
|
577
|
-
status: 'deferred',
|
|
578
|
-
code: 'ARCHIVE_RECOVERY_REQUIRED',
|
|
579
|
-
blocked_by: 'archives',
|
|
580
|
-
};
|
|
581
|
-
return {
|
|
582
|
-
...inspectSystem(db, { rootDir }),
|
|
583
|
-
status: 'degraded',
|
|
584
|
-
repair_performed: true,
|
|
585
|
-
backup_path: backupPath,
|
|
586
|
-
repair: {
|
|
587
|
-
close_intents: recovered,
|
|
588
|
-
recovered,
|
|
589
|
-
plan_publications: planPublications,
|
|
590
|
-
archives: archiveGate,
|
|
591
|
-
legacy_history: deferred,
|
|
592
|
-
spec_events: deferred,
|
|
593
|
-
interrupted: deferred,
|
|
594
|
-
requeued: deferred,
|
|
595
|
-
ensured: deferred,
|
|
596
|
-
projections: deferred,
|
|
597
|
-
},
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
const cursor = runtime.readConsumerCursor(db, SPEC_CONSUMER);
|
|
601
|
-
const consumed = ops.consumeSpecChangedEvents(db, { since_id: cursor, limit: 500 });
|
|
602
|
-
runtime.writeConsumerCursor(db, SPEC_CONSUMER, consumed.next_since_id);
|
|
603
|
-
const interrupted = runtime.requeueInterruptedProjections(db, {
|
|
604
|
-
staleBefore: new Date(Date.now() - Math.max(0, projectionStaleAfterMs)).toISOString(),
|
|
605
|
-
});
|
|
606
|
-
const requeued = runtime.requeueFailedProjections(db);
|
|
607
|
-
const ensured = runtime.ensureProjectionJob(db, { tool_name: 'system.doctor' });
|
|
608
|
-
const projections = runtime.processProjectionJobs(db, { rootDir, project, limit: 500 });
|
|
609
|
-
return {
|
|
610
|
-
...inspectSystem(db, { rootDir }),
|
|
611
|
-
repair_performed: true,
|
|
612
|
-
backup_path: backupPath,
|
|
613
|
-
repair: {
|
|
614
|
-
close_intents: recovered,
|
|
615
|
-
plan_publications: planPublications,
|
|
616
|
-
archives, recovered, consumed,
|
|
617
|
-
interrupted, requeued, ensured, projections,
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
module.exports = {
|
|
623
|
-
DoctorError,
|
|
624
|
-
SPEC_CONSUMER,
|
|
625
|
-
inspectSystem,
|
|
626
|
-
runDoctor,
|
|
627
|
-
};
|