cc-codeconductor 1.7.2 → 1.8.0
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/README.md +6 -6
- package/dist/core/goal/goal-state.d.ts +18 -0
- package/dist/core/hooks/hook-runner.d.ts +75 -0
- package/dist/core/orchestrator/runtime-orchestrator.d.ts +11 -3
- package/dist/core/telemetry/hook-telemetry.d.ts +55 -0
- package/dist/core/telemetry/schema.d.ts +94 -0
- package/dist/core/telemetry/store.d.ts +43 -0
- package/dist/index.js +6129 -872
- package/dist/library.js +605 -25
- package/dist/validation/schemas.d.ts +143 -8
- package/docs/generated/cli.md +11 -1
- package/package.json +3 -1
- package/presets/agy/scripts/invoke-hook.cjs +15 -2
- package/presets/claude/settings.json +33 -0
- package/presets/shared/invoke-hook.cjs +15 -2
- package/pricing/pricing.v1.json +130 -0
- package/schemas/harness-telemetry.v1.json +239 -0
package/dist/library.js
CHANGED
|
@@ -283,7 +283,7 @@ function validateProductEvent(data) {
|
|
|
283
283
|
function validateSkillsRegistry(data) {
|
|
284
284
|
return SkillsRegistrySchema.parse(data);
|
|
285
285
|
}
|
|
286
|
-
var CouncilAgentSpecSchema, CouncilSpecSchema, ProjectProfileSchema, CompileCheckConfigSchema, LoopConfigSchema, CodeConductorConfigSchema, RunnerTargetSchema, InstallStrategySchema, ContainedRelativePathSchema, ManifestEntrySchema, InstallManifestSchema, ToolProviderNamesSchema, PermissionProviderNamesSchema, ModelConfigSchema, SkillFrontmatterSchema, CommandFrontmatterSchema, TargetCapabilitiesSchema, ContractTargetSchema, ContractFormatSchema, AgentContractSchema, CouncilFindingSchema, CouncilVerdictInputSchema, ConsensusConfigSchema, CouncilVerdictSchema, ClaudeAgentFileSchema, OpenCodeAgentFileSchema, SentryStackFrameSchema, SentryWebhookSchema, MemoryPointerSchema, MemoryIndexSchema, GoalTaskSchema, GoalGraphSchema, ConfidenceLevelSchema, ProductNodeTypeSchema, GraphRelationSchema, KnowledgeEntitySchema, DecisionSchema, EvidenceSchema, TddValidationRecordSchema, CanonicalTaskCardStatusSchema, CanonicalTaskCardSchema, ProductGraphNodeSchema, ProductGraphEdgeSchema, ProductGraphSchema, ProductMetaSchema, ProductEventTypeSchema, ProductEventSchema, OperationalStateSchema, StrategicMemorySchema, ImpactReportSchema, BusinessReviewOutputSchema, VerificationReportSchema, BacklogStatusSchema, BacklogTypeSchema, BacklogPrioritySchema, BacklogGlobalSchema, BacklogItemSchema, BacklogDocumentSchema, OpenspecTaskCardPhaseSchema, OpenspecTaskCardStatusSchema, OpenspecTaskCardSchema, OpenspecStateSchema, SpecAnalyzeFindingSchema, SpecAnalyzeReportSchema, WorkflowCommandSchema, CcepOutputFormatSchema, CommandEnvelopeSchema, WorkflowPhaseSchema, WorkflowRiskRuleSchema, WorkflowProfileSchema, ExecutionContextSchema, PlannerOutputSchema, AgentArtifactSchema, AgentOutputSchema, ImplementerTestsSchema, ImplementerOutputSchema, ReviewAxisSchema, ReviewFindingSchema, ReviewerOutputSchema, TechnicalPlanOutputSchema, FixIntakeOutputSchema, ScorecardVerdictSchema, ScorecardCriterionIdSchema, ScorecardCriterionSchema, ScorecardRecordSchema, TaskOutcomeSourceSchema, TaskOutcomeStatusSchema, DeliveryRouteSchema, TokenUsageSchema, DeliveryTelemetrySchema, DeliveryLedgerTaskSchema, DeliveryLedgerSchema, HandoffEnvelopeSchema, RepoRelativePathSchema, DeliveryLedgerRequestSchema, TaskOutcomeSchema, HarnessComponentIdSchema, HarnessComponentLayerSchema, HarnessToggleKindSchema, HarnessCatalogEntrySchema, HarnessCatalogSchema, HarnessOverlaySchema, HarnessExperimentSchema, HarnessSuiteTaskSchema, HarnessSuiteSchema, EvaluationIndexSchema, ExecutionProfileNameSchema, ExecutionProfileSchema, SkillsRegistrySchema;
|
|
286
|
+
var CouncilAgentSpecSchema, CouncilSpecSchema, ProjectProfileSchema, CompileCheckConfigSchema, LoopConfigSchema, CodeConductorConfigSchema, RunnerTargetSchema, InstallStrategySchema, ContainedRelativePathSchema, ManifestEntrySchema, InstallManifestSchema, ToolProviderNamesSchema, PermissionProviderNamesSchema, ModelConfigSchema, SkillFrontmatterSchema, CommandFrontmatterSchema, TargetCapabilitiesSchema, ContractTargetSchema, ContractFormatSchema, AgentContractSchema, CouncilFindingSchema, CouncilVerdictInputSchema, ConsensusConfigSchema, CouncilVerdictSchema, ClaudeAgentFileSchema, OpenCodeAgentFileSchema, SentryStackFrameSchema, SentryWebhookSchema, MemoryPointerSchema, MemoryIndexSchema, CodeIndexSymbolSchema, CodeIndexSchema, GoalTaskSchema, GoalGraphSchema, ConfidenceLevelSchema, ProductNodeTypeSchema, GraphRelationSchema, KnowledgeEntitySchema, DecisionSchema, EvidenceSchema, TddValidationRecordSchema, CanonicalTaskCardStatusSchema, CanonicalTaskCardSchema, ProductGraphNodeSchema, ProductGraphEdgeSchema, ProductGraphSchema, ProductMetaSchema, ProductEventTypeSchema, ProductEventSchema, OperationalStateSchema, StrategicMemorySchema, ImpactReportSchema, BusinessReviewOutputSchema, VerificationReportSchema, BacklogStatusSchema, BacklogTypeSchema, BacklogPrioritySchema, BacklogGlobalSchema, BacklogItemSchema, BacklogDocumentSchema, OpenspecTaskCardPhaseSchema, OpenspecTaskCardStatusSchema, OpenspecTaskCardSchema, OpenspecStateSchema, SpecAnalyzeFindingSchema, SpecAnalyzeReportSchema, WorkflowCommandSchema, CcepOutputFormatSchema, CommandEnvelopeSchema, WorkflowPhaseSchema, WorkflowRiskRuleSchema, WorkflowProfileSchema, ExecutionContextSchema, PlannerOutputSchema, AgentArtifactSchema, AgentOutputSchema, ImplementerTestsSchema, ImplementerOutputSchema, ReviewAxisSchema, ReviewFindingSchema, ReviewerOutputSchema, EdgeCaseSchema, TechnicalPlanOutputSchema, FixIntakeOutputSchema, ScorecardVerdictSchema, ScorecardCriterionIdSchema, ScorecardCriterionSchema, ScorecardRecordSchema, TaskOutcomeSourceSchema, TaskOutcomeStatusSchema, DeliveryRouteSchema, TokenUsageSchema, DeliveryTelemetrySchema, DeliveryLedgerTaskSchema, DeliveryLedgerSchema, HandoffEnvelopeSchema, RepoRelativePathSchema, DeliveryLedgerRequestSchema, TaskOutcomeSchema, HarnessComponentIdSchema, HarnessComponentLayerSchema, HarnessToggleKindSchema, HarnessCatalogEntrySchema, HarnessCatalogSchema, HarnessOverlaySchema, HarnessExperimentSchema, HarnessSuiteTaskSchema, HarnessSuiteSchema, EvaluationIndexSchema, ExecutionProfileNameSchema, ExecutionProfileSchema, SkillsRegistrySchema;
|
|
287
287
|
var init_schemas = __esm(() => {
|
|
288
288
|
init_runner_target();
|
|
289
289
|
init_scoped_context_schemas();
|
|
@@ -524,6 +524,17 @@ var init_schemas = __esm(() => {
|
|
|
524
524
|
version: z2.literal(1),
|
|
525
525
|
pointers: z2.array(MemoryPointerSchema)
|
|
526
526
|
});
|
|
527
|
+
CodeIndexSymbolSchema = z2.object({
|
|
528
|
+
name: z2.string().min(1),
|
|
529
|
+
kind: z2.enum(["function", "class", "interface", "type", "const"]),
|
|
530
|
+
startLine: z2.number().int().positive(),
|
|
531
|
+
endLine: z2.number().int().positive()
|
|
532
|
+
});
|
|
533
|
+
CodeIndexSchema = z2.object({
|
|
534
|
+
version: z2.literal(1),
|
|
535
|
+
generatedAt: z2.string(),
|
|
536
|
+
files: z2.record(z2.string(), z2.array(CodeIndexSymbolSchema))
|
|
537
|
+
});
|
|
527
538
|
GoalTaskSchema = z2.object({
|
|
528
539
|
id: z2.string(),
|
|
529
540
|
title: z2.string(),
|
|
@@ -534,7 +545,9 @@ var init_schemas = __esm(() => {
|
|
|
534
545
|
depends_on: z2.array(z2.string()).optional().default([]),
|
|
535
546
|
acceptance_criteria: z2.array(z2.string()),
|
|
536
547
|
blocked_reason: z2.string().optional(),
|
|
537
|
-
context_scope: z2.enum(["isolated", "continuation", "full"]).optional().default("isolated")
|
|
548
|
+
context_scope: z2.enum(["isolated", "continuation", "full"]).optional().default("isolated"),
|
|
549
|
+
consecutive_failures: z2.number().int().nonnegative().optional(),
|
|
550
|
+
frozen: z2.boolean().optional()
|
|
538
551
|
});
|
|
539
552
|
GoalGraphSchema = z2.object({
|
|
540
553
|
objective: z2.string(),
|
|
@@ -1022,11 +1035,18 @@ var init_schemas = __esm(() => {
|
|
|
1022
1035
|
artifacts: z2.array(AgentArtifactSchema).default([]),
|
|
1023
1036
|
next_actions: z2.array(z2.string()).default([])
|
|
1024
1037
|
});
|
|
1038
|
+
EdgeCaseSchema = z2.object({
|
|
1039
|
+
scenario: z2.string().min(1),
|
|
1040
|
+
input: z2.string().min(1),
|
|
1041
|
+
expected: z2.string().min(1)
|
|
1042
|
+
});
|
|
1025
1043
|
TechnicalPlanOutputSchema = z2.object({
|
|
1026
1044
|
approach: z2.string(),
|
|
1027
1045
|
filesAffected: z2.array(z2.string()).default([]),
|
|
1028
1046
|
risks: z2.array(z2.string()).default([]),
|
|
1029
|
-
openQuestions: z2.array(z2.string()).optional()
|
|
1047
|
+
openQuestions: z2.array(z2.string()).optional(),
|
|
1048
|
+
edgeCases: z2.array(EdgeCaseSchema).min(1),
|
|
1049
|
+
symbolsAffected: z2.record(z2.string(), z2.array(z2.string())).default({})
|
|
1030
1050
|
});
|
|
1031
1051
|
FixIntakeOutputSchema = z2.object({
|
|
1032
1052
|
actualBehavior: z2.string(),
|
|
@@ -1175,7 +1195,22 @@ var init_schemas = __esm(() => {
|
|
|
1175
1195
|
suiteTaskId: z2.string().optional(),
|
|
1176
1196
|
harnessFingerprint: z2.string().optional(),
|
|
1177
1197
|
disabledComponents: z2.array(z2.string()).optional(),
|
|
1178
|
-
delivery: DeliveryTelemetrySchema.optional()
|
|
1198
|
+
delivery: DeliveryTelemetrySchema.optional(),
|
|
1199
|
+
cacheRead: z2.number().nullable().optional(),
|
|
1200
|
+
cacheWrite: z2.number().nullable().optional(),
|
|
1201
|
+
calls: z2.number().nullable().optional(),
|
|
1202
|
+
iterations: z2.number().nullable().optional(),
|
|
1203
|
+
retries: z2.number().nullable().optional(),
|
|
1204
|
+
usageSource: z2.enum([
|
|
1205
|
+
"cc-json",
|
|
1206
|
+
"cc-otel",
|
|
1207
|
+
"cc-transcript",
|
|
1208
|
+
"openrouter-usage",
|
|
1209
|
+
"codex-json",
|
|
1210
|
+
"harness",
|
|
1211
|
+
"none"
|
|
1212
|
+
]).nullable().optional(),
|
|
1213
|
+
pricingVersion: z2.string().nullable().optional()
|
|
1179
1214
|
});
|
|
1180
1215
|
HarnessComponentIdSchema = z2.enum([
|
|
1181
1216
|
"wayfinding",
|
|
@@ -1238,7 +1273,7 @@ var init_schemas = __esm(() => {
|
|
|
1238
1273
|
HarnessSuiteTaskSchema = z2.object({
|
|
1239
1274
|
id: z2.string(),
|
|
1240
1275
|
title: z2.string(),
|
|
1241
|
-
type: z2.enum(["feature", "fix", "refactor"]),
|
|
1276
|
+
type: z2.enum(["feature", "fix", "refactor", "review"]),
|
|
1242
1277
|
risk: z2.enum(["low", "medium", "high"]).default("low"),
|
|
1243
1278
|
prompt: z2.string(),
|
|
1244
1279
|
scope: z2.string(),
|
|
@@ -1473,9 +1508,12 @@ var init_lock = __esm(() => {
|
|
|
1473
1508
|
// src/core/goal/goal-state.ts
|
|
1474
1509
|
var exports_goal_state = {};
|
|
1475
1510
|
__export(exports_goal_state, {
|
|
1511
|
+
BREAKER_TRIP_THRESHOLD: () => BREAKER_TRIP_THRESHOLD,
|
|
1476
1512
|
loadGoal: () => loadGoal,
|
|
1477
1513
|
markTaskBlocked: () => markTaskBlocked,
|
|
1478
1514
|
propagateBlockedTasks: () => propagateBlockedTasks,
|
|
1515
|
+
recordTaskStrike: () => recordTaskStrike,
|
|
1516
|
+
unfreezeTask: () => unfreezeTask,
|
|
1479
1517
|
writeGoal: () => writeGoal
|
|
1480
1518
|
});
|
|
1481
1519
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
@@ -1599,7 +1637,61 @@ async function markTaskBlockedUnlocked(projectRoot, taskId, reason) {
|
|
|
1599
1637
|
propagateBlockedTasks(graph);
|
|
1600
1638
|
return writeGoal(projectRoot, graph);
|
|
1601
1639
|
}
|
|
1602
|
-
|
|
1640
|
+
async function recordTaskStrike(projectRoot, taskId, reason) {
|
|
1641
|
+
return withQueueLock(projectRoot, () => recordTaskStrikeUnlocked(projectRoot, taskId, reason));
|
|
1642
|
+
}
|
|
1643
|
+
async function recordTaskStrikeUnlocked(projectRoot, taskId, reason) {
|
|
1644
|
+
const loadResult = await loadGoal(projectRoot);
|
|
1645
|
+
if (!loadResult.success)
|
|
1646
|
+
return loadResult;
|
|
1647
|
+
const graph = loadResult.data;
|
|
1648
|
+
const task = graph.tasks.find((t) => t.id === taskId);
|
|
1649
|
+
if (!task) {
|
|
1650
|
+
return err(new Error(`Task "${taskId}" not found in goal graph`));
|
|
1651
|
+
}
|
|
1652
|
+
if (task.status === "done") {
|
|
1653
|
+
return err(new Error(`Task "${taskId}" is done and cannot accrue failures`));
|
|
1654
|
+
}
|
|
1655
|
+
const failures = (task.consecutive_failures ?? 0) + 1;
|
|
1656
|
+
task.consecutive_failures = failures;
|
|
1657
|
+
const tripped = failures >= BREAKER_TRIP_THRESHOLD || task.frozen === true;
|
|
1658
|
+
if (tripped) {
|
|
1659
|
+
task.consecutive_failures = Math.min(failures, BREAKER_TRIP_THRESHOLD);
|
|
1660
|
+
if (task.frozen !== true) {
|
|
1661
|
+
task.status = "blocked";
|
|
1662
|
+
task.frozen = true;
|
|
1663
|
+
task.blocked_reason = `Circuit breaker tripped after ${BREAKER_TRIP_THRESHOLD} consecutive failures ` + `(last: ${reason}). Escalate to debug agent or /cc-help.`;
|
|
1664
|
+
propagateBlockedTasks(graph);
|
|
1665
|
+
}
|
|
1666
|
+
const write2 = await writeGoal(projectRoot, graph);
|
|
1667
|
+
if (!write2.success)
|
|
1668
|
+
return write2;
|
|
1669
|
+
return ok({ taskId, failures: task.consecutive_failures, tripped: true });
|
|
1670
|
+
}
|
|
1671
|
+
const write = await writeGoal(projectRoot, graph);
|
|
1672
|
+
if (!write.success)
|
|
1673
|
+
return write;
|
|
1674
|
+
return ok({ taskId, failures, tripped: false });
|
|
1675
|
+
}
|
|
1676
|
+
async function unfreezeTask(projectRoot, taskId) {
|
|
1677
|
+
return withQueueLock(projectRoot, () => unfreezeTaskUnlocked(projectRoot, taskId));
|
|
1678
|
+
}
|
|
1679
|
+
async function unfreezeTaskUnlocked(projectRoot, taskId) {
|
|
1680
|
+
const loadResult = await loadGoal(projectRoot);
|
|
1681
|
+
if (!loadResult.success)
|
|
1682
|
+
return loadResult;
|
|
1683
|
+
const graph = loadResult.data;
|
|
1684
|
+
const task = graph.tasks.find((t) => t.id === taskId);
|
|
1685
|
+
if (!task) {
|
|
1686
|
+
return err(new Error(`Task "${taskId}" not found in goal graph`));
|
|
1687
|
+
}
|
|
1688
|
+
task.status = "pending";
|
|
1689
|
+
task.consecutive_failures = 0;
|
|
1690
|
+
task.frozen = false;
|
|
1691
|
+
task.blocked_reason = undefined;
|
|
1692
|
+
return writeGoal(projectRoot, graph);
|
|
1693
|
+
}
|
|
1694
|
+
var GOAL_FILE = ".codeconductor/current-goal.yml", BREAKER_TRIP_THRESHOLD = 3;
|
|
1603
1695
|
var init_goal_state = __esm(() => {
|
|
1604
1696
|
init_schemas();
|
|
1605
1697
|
init_lock();
|
|
@@ -1781,8 +1873,8 @@ async function clearActiveTask(projectRoot, taskId) {
|
|
|
1781
1873
|
// src/core/verification/verification-runner.ts
|
|
1782
1874
|
init_schemas();
|
|
1783
1875
|
import { existsSync } from "node:fs";
|
|
1784
|
-
import { readFile as
|
|
1785
|
-
import { dirname, join as
|
|
1876
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
1877
|
+
import { dirname as dirname2, join as join4, resolve as resolve11 } from "node:path";
|
|
1786
1878
|
|
|
1787
1879
|
// src/core/config/config-loader.ts
|
|
1788
1880
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
@@ -2089,7 +2181,7 @@ async function runCompileCheck(options) {
|
|
|
2089
2181
|
// src/core/verification/verification-runner.ts
|
|
2090
2182
|
init_paths();
|
|
2091
2183
|
init_episodic_store();
|
|
2092
|
-
import { mkdir as
|
|
2184
|
+
import { mkdir as mkdir8, readdir as readdir3, writeFile as writeFile6 } from "node:fs/promises";
|
|
2093
2185
|
|
|
2094
2186
|
// src/core/verification/rdd-receipt.ts
|
|
2095
2187
|
import { createHash as createHash2, randomBytes } from "node:crypto";
|
|
@@ -2237,6 +2329,253 @@ async function verifyReceipt(projectRoot, receipt) {
|
|
|
2237
2329
|
};
|
|
2238
2330
|
}
|
|
2239
2331
|
|
|
2332
|
+
// src/core/telemetry/hook-telemetry.ts
|
|
2333
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
2334
|
+
import { readFile as readFile9 } from "node:fs/promises";
|
|
2335
|
+
import { resolve as resolve10 } from "node:path";
|
|
2336
|
+
|
|
2337
|
+
// src/core/presets/package-paths.ts
|
|
2338
|
+
import { dirname, resolve as resolve7, sep as sep2 } from "node:path";
|
|
2339
|
+
import { fileURLToPath } from "node:url";
|
|
2340
|
+
var moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
2341
|
+
var PACKAGE_ROOT = moduleDir.endsWith(`${sep2}dist`) ? resolve7(moduleDir, "..") : resolve7(moduleDir, "..", "..", "..");
|
|
2342
|
+
var SRC_PRESETS_DIR = resolve7(PACKAGE_ROOT, "src", "presets");
|
|
2343
|
+
var ROOT_PRESETS_DIR = resolve7(PACKAGE_ROOT, "presets");
|
|
2344
|
+
var POLICY_PATH = resolve7(PACKAGE_ROOT, "policy.yml");
|
|
2345
|
+
var SKILLS_REGISTRY_PATH = resolve7(PACKAGE_ROOT, "skills-registry.json");
|
|
2346
|
+
|
|
2347
|
+
// src/core/telemetry/schema.ts
|
|
2348
|
+
import { resolve as resolve8 } from "node:path";
|
|
2349
|
+
var HARNESS_TELEMETRY_SCHEMA = "harness-telemetry/v1";
|
|
2350
|
+
var HARNESS_TELEMETRY_SCHEMA_PATH = resolve8(PACKAGE_ROOT, "schemas", "harness-telemetry.v1.json");
|
|
2351
|
+
var EVENT_NAMES = new Set([
|
|
2352
|
+
"run.start",
|
|
2353
|
+
"run.end",
|
|
2354
|
+
"task.start",
|
|
2355
|
+
"task.end",
|
|
2356
|
+
"agent.end",
|
|
2357
|
+
"model.call",
|
|
2358
|
+
"verification",
|
|
2359
|
+
"retry",
|
|
2360
|
+
"iteration"
|
|
2361
|
+
]);
|
|
2362
|
+
var HARNESS_NAMES = new Set(["codeconductor", "microsdd"]);
|
|
2363
|
+
function isHarnessTelemetryEvent(value) {
|
|
2364
|
+
if (value === null || typeof value !== "object")
|
|
2365
|
+
return false;
|
|
2366
|
+
const v = value;
|
|
2367
|
+
if (v.schema !== HARNESS_TELEMETRY_SCHEMA)
|
|
2368
|
+
return false;
|
|
2369
|
+
if (typeof v.ts !== "string" || v.ts.length === 0)
|
|
2370
|
+
return false;
|
|
2371
|
+
if (typeof v.runId !== "string" || v.runId.length === 0)
|
|
2372
|
+
return false;
|
|
2373
|
+
if (typeof v.event !== "string" || !EVENT_NAMES.has(v.event))
|
|
2374
|
+
return false;
|
|
2375
|
+
if (v.harness === null || typeof v.harness !== "object")
|
|
2376
|
+
return false;
|
|
2377
|
+
const harness = v.harness;
|
|
2378
|
+
if (typeof harness.name !== "string" || !HARNESS_NAMES.has(harness.name))
|
|
2379
|
+
return false;
|
|
2380
|
+
return true;
|
|
2381
|
+
}
|
|
2382
|
+
function assertHarnessTelemetryEvent(value) {
|
|
2383
|
+
if (!isHarnessTelemetryEvent(value)) {
|
|
2384
|
+
throw new Error("Invalid harness-telemetry/v1 event");
|
|
2385
|
+
}
|
|
2386
|
+
return value;
|
|
2387
|
+
}
|
|
2388
|
+
function createBaseEvent(input) {
|
|
2389
|
+
return {
|
|
2390
|
+
schema: HARNESS_TELEMETRY_SCHEMA,
|
|
2391
|
+
ts: input.ts ?? new Date().toISOString(),
|
|
2392
|
+
harness: {
|
|
2393
|
+
name: input.harnessName ?? "codeconductor",
|
|
2394
|
+
version: input.harnessVersion ?? null,
|
|
2395
|
+
commit: input.harnessCommit ?? null,
|
|
2396
|
+
promptCompilerVersion: null,
|
|
2397
|
+
promptFingerprint: null
|
|
2398
|
+
},
|
|
2399
|
+
runId: input.runId,
|
|
2400
|
+
taskId: null,
|
|
2401
|
+
agent: null,
|
|
2402
|
+
event: input.event,
|
|
2403
|
+
host: null,
|
|
2404
|
+
model: null,
|
|
2405
|
+
usage: null,
|
|
2406
|
+
cost: null,
|
|
2407
|
+
loop: null,
|
|
2408
|
+
verification: null,
|
|
2409
|
+
durationMs: null,
|
|
2410
|
+
outcome: null,
|
|
2411
|
+
source: null,
|
|
2412
|
+
privacy: input.privacy ?? "standard"
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
// src/core/telemetry/store.ts
|
|
2417
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
2418
|
+
import { appendFile as appendFile2, mkdir as mkdir7, readFile as readFile8, readdir as readdir2, unlink as unlink3, writeFile as writeFile5 } from "node:fs/promises";
|
|
2419
|
+
import { join as join3, resolve as resolve9 } from "node:path";
|
|
2420
|
+
import { parse as parseYaml } from "yaml";
|
|
2421
|
+
var TELEMETRY_DIR = ".codeconductor/telemetry";
|
|
2422
|
+
var REPORTS_DIR = ".codeconductor/reports";
|
|
2423
|
+
var PROJECT_CONFIG = ".codeconductor/config.yml";
|
|
2424
|
+
var DEFAULT_REPORT = {
|
|
2425
|
+
level: "off",
|
|
2426
|
+
history: true,
|
|
2427
|
+
privacy: "standard"
|
|
2428
|
+
};
|
|
2429
|
+
async function resolveReportSettings(projectRoot, overrides = {}) {
|
|
2430
|
+
let project = {};
|
|
2431
|
+
try {
|
|
2432
|
+
const raw = await readFile8(resolve9(projectRoot, PROJECT_CONFIG), "utf-8");
|
|
2433
|
+
const data = parseYaml(raw);
|
|
2434
|
+
if (data?.report && typeof data.report === "object") {
|
|
2435
|
+
const r = data.report;
|
|
2436
|
+
project = {
|
|
2437
|
+
level: r.level === "off" || r.level === "minimal" || r.level === "detailed" ? r.level : undefined,
|
|
2438
|
+
history: typeof r.history === "boolean" ? r.history : undefined,
|
|
2439
|
+
privacy: r.privacy === "standard" || r.privacy === "strict" ? r.privacy : undefined
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
} catch {}
|
|
2443
|
+
const envHistory = process.env.CC_REPORT_HISTORY;
|
|
2444
|
+
const envPrivacy = process.env.CC_REPORT_PRIVACY;
|
|
2445
|
+
const envLevel = process.env.CC_REPORT;
|
|
2446
|
+
const level = overrides.level ?? (envLevel === "off" || envLevel === "minimal" || envLevel === "detailed" ? envLevel : undefined) ?? project.level ?? DEFAULT_REPORT.level;
|
|
2447
|
+
const historyCandidates = [
|
|
2448
|
+
overrides.history,
|
|
2449
|
+
envHistory === "false" ? false : envHistory === "true" ? true : undefined,
|
|
2450
|
+
project.history,
|
|
2451
|
+
DEFAULT_REPORT.history
|
|
2452
|
+
].filter((v) => typeof v === "boolean");
|
|
2453
|
+
const history = historyCandidates.includes(false) ? false : historyCandidates[0] ?? DEFAULT_REPORT.history;
|
|
2454
|
+
const privacy = overrides.privacy ?? (envPrivacy === "standard" || envPrivacy === "strict" ? envPrivacy : undefined) ?? project.privacy ?? DEFAULT_REPORT.privacy;
|
|
2455
|
+
return { level, history, privacy };
|
|
2456
|
+
}
|
|
2457
|
+
function applyPrivacy(event, privacy) {
|
|
2458
|
+
const next = { ...event, privacy };
|
|
2459
|
+
if (privacy !== "strict") {
|
|
2460
|
+
if (next.loop?.retryReason && next.loop.retryReason.length > 120) {
|
|
2461
|
+
next.loop = { ...next.loop, retryReason: next.loop.retryReason.slice(0, 120) };
|
|
2462
|
+
}
|
|
2463
|
+
return next;
|
|
2464
|
+
}
|
|
2465
|
+
next.model = next.model ? { id: null, provider: next.model.provider, effort: next.model.effort } : null;
|
|
2466
|
+
next.agent = next.agent ? { role: next.agent.role, agentId: null } : null;
|
|
2467
|
+
if (next.loop?.retryReason) {
|
|
2468
|
+
const hash = createHash3("sha256").update(next.loop.retryReason).digest("hex").slice(0, 16);
|
|
2469
|
+
next.loop = { ...next.loop, retryReason: `sha256:${hash}` };
|
|
2470
|
+
}
|
|
2471
|
+
return next;
|
|
2472
|
+
}
|
|
2473
|
+
async function ensureTelemetryDirs(projectRoot) {
|
|
2474
|
+
const telemetryDir = resolve9(projectRoot, TELEMETRY_DIR);
|
|
2475
|
+
const reportsDir = resolve9(projectRoot, REPORTS_DIR);
|
|
2476
|
+
await mkdir7(telemetryDir, { recursive: true });
|
|
2477
|
+
await mkdir7(reportsDir, { recursive: true });
|
|
2478
|
+
return { telemetryDir, reportsDir };
|
|
2479
|
+
}
|
|
2480
|
+
function telemetryRunPath(projectRoot, runId) {
|
|
2481
|
+
const safe = runId.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
2482
|
+
return resolve9(projectRoot, TELEMETRY_DIR, `${safe}.jsonl`);
|
|
2483
|
+
}
|
|
2484
|
+
async function appendTelemetryEvent(projectRoot, event, options = {}) {
|
|
2485
|
+
try {
|
|
2486
|
+
const settings = await resolveReportSettings(projectRoot, {
|
|
2487
|
+
history: options.history,
|
|
2488
|
+
privacy: options.privacy
|
|
2489
|
+
});
|
|
2490
|
+
if (!settings.history) {
|
|
2491
|
+
return ok({ written: false, path: null });
|
|
2492
|
+
}
|
|
2493
|
+
const validated = assertHarnessTelemetryEvent(event);
|
|
2494
|
+
const scrubbed = applyPrivacy(validated, options.privacy ?? settings.privacy);
|
|
2495
|
+
const { telemetryDir } = await ensureTelemetryDirs(projectRoot);
|
|
2496
|
+
const path = telemetryRunPath(projectRoot, scrubbed.runId);
|
|
2497
|
+
await mkdir7(telemetryDir, { recursive: true });
|
|
2498
|
+
await appendFile2(path, JSON.stringify(scrubbed) + `
|
|
2499
|
+
`, "utf-8");
|
|
2500
|
+
return ok({ written: true, path });
|
|
2501
|
+
} catch (e) {
|
|
2502
|
+
return err(e instanceof Error ? e : new Error(String(e)));
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
// src/core/telemetry/hook-telemetry.ts
|
|
2507
|
+
function formatRetryReason(reason, privacy) {
|
|
2508
|
+
if (privacy === "strict") {
|
|
2509
|
+
return `sha256:${createHash4("sha256").update(reason).digest("hex").slice(0, 16)}`;
|
|
2510
|
+
}
|
|
2511
|
+
return reason.length > 120 ? reason.slice(0, 120) : reason;
|
|
2512
|
+
}
|
|
2513
|
+
async function harnessMeta() {
|
|
2514
|
+
try {
|
|
2515
|
+
const pkg = JSON.parse(await readFile9(resolve10(PACKAGE_ROOT, "package.json"), "utf-8"));
|
|
2516
|
+
return { version: typeof pkg.version === "string" ? pkg.version : null, commit: null };
|
|
2517
|
+
} catch {
|
|
2518
|
+
return { version: null, commit: null };
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
async function emit(projectRoot, event) {
|
|
2522
|
+
await appendTelemetryEvent(projectRoot, event);
|
|
2523
|
+
}
|
|
2524
|
+
async function emitLoopIteration(projectRoot, input) {
|
|
2525
|
+
const settings = await resolveReportSettings(projectRoot);
|
|
2526
|
+
const meta = await harnessMeta();
|
|
2527
|
+
const event = createBaseEvent({
|
|
2528
|
+
runId: input.runId,
|
|
2529
|
+
event: "iteration",
|
|
2530
|
+
harnessVersion: meta.version,
|
|
2531
|
+
privacy: settings.privacy
|
|
2532
|
+
});
|
|
2533
|
+
event.taskId = input.taskId ?? null;
|
|
2534
|
+
event.loop = {
|
|
2535
|
+
iteration: input.iteration,
|
|
2536
|
+
retryReason: null,
|
|
2537
|
+
maxIterations: input.maxIterations
|
|
2538
|
+
};
|
|
2539
|
+
event.source = { usage: "harness", reliability: "high" };
|
|
2540
|
+
await emit(projectRoot, event);
|
|
2541
|
+
}
|
|
2542
|
+
async function emitLoopRetry(projectRoot, input) {
|
|
2543
|
+
const settings = await resolveReportSettings(projectRoot);
|
|
2544
|
+
const meta = await harnessMeta();
|
|
2545
|
+
const event = createBaseEvent({
|
|
2546
|
+
runId: input.runId,
|
|
2547
|
+
event: "retry",
|
|
2548
|
+
harnessVersion: meta.version,
|
|
2549
|
+
privacy: settings.privacy
|
|
2550
|
+
});
|
|
2551
|
+
event.taskId = input.taskId ?? null;
|
|
2552
|
+
event.loop = {
|
|
2553
|
+
iteration: input.iteration,
|
|
2554
|
+
retryReason: formatRetryReason(input.feedback, settings.privacy),
|
|
2555
|
+
maxIterations: input.maxIterations
|
|
2556
|
+
};
|
|
2557
|
+
event.source = { usage: "harness", reliability: "high" };
|
|
2558
|
+
await emit(projectRoot, event);
|
|
2559
|
+
}
|
|
2560
|
+
async function emitVerificationGate(projectRoot, input) {
|
|
2561
|
+
const settings = await resolveReportSettings(projectRoot);
|
|
2562
|
+
const meta = await harnessMeta();
|
|
2563
|
+
const event = createBaseEvent({
|
|
2564
|
+
runId: input.runId,
|
|
2565
|
+
event: "verification",
|
|
2566
|
+
harnessVersion: meta.version,
|
|
2567
|
+
privacy: settings.privacy
|
|
2568
|
+
});
|
|
2569
|
+
event.taskId = input.taskId;
|
|
2570
|
+
event.verification = {
|
|
2571
|
+
gate: input.gate,
|
|
2572
|
+
passed: input.passed,
|
|
2573
|
+
durationMs: input.durationMs ?? null
|
|
2574
|
+
};
|
|
2575
|
+
event.source = { usage: "harness", reliability: "high" };
|
|
2576
|
+
await emit(projectRoot, event);
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2240
2579
|
// src/core/verification/verification-runner.ts
|
|
2241
2580
|
function isPassingEvidence(ev) {
|
|
2242
2581
|
switch (ev.type) {
|
|
@@ -2263,8 +2602,8 @@ async function isCurrentPassingEvidence(projectRoot, ev) {
|
|
|
2263
2602
|
return (await verifyReceipt(projectRoot, receipt)).valid;
|
|
2264
2603
|
}
|
|
2265
2604
|
function evidenceFilePath(evDir, id) {
|
|
2266
|
-
const path =
|
|
2267
|
-
if (
|
|
2605
|
+
const path = resolve11(evDir, `${id.replace(/[^A-Za-z0-9_-]/g, "_")}.json`);
|
|
2606
|
+
if (dirname2(path) !== resolve11(evDir)) {
|
|
2268
2607
|
return err(new Error(`Refusing to write evidence for "${id}" outside ${evDir}`));
|
|
2269
2608
|
}
|
|
2270
2609
|
return ok(path);
|
|
@@ -2275,8 +2614,8 @@ async function persistEvidence(projectRoot, evidence) {
|
|
|
2275
2614
|
if (!evidencePath.success)
|
|
2276
2615
|
return evidencePath;
|
|
2277
2616
|
try {
|
|
2278
|
-
await
|
|
2279
|
-
await
|
|
2617
|
+
await mkdir8(evDir, { recursive: true });
|
|
2618
|
+
await writeFile6(evidencePath.data, JSON.stringify(evidence, null, 2), "utf-8");
|
|
2280
2619
|
} catch (e) {
|
|
2281
2620
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
2282
2621
|
}
|
|
@@ -2290,7 +2629,7 @@ async function collectTaskEvidence(projectRoot, taskId) {
|
|
|
2290
2629
|
return ok({ records, invalid });
|
|
2291
2630
|
let files;
|
|
2292
2631
|
try {
|
|
2293
|
-
files = await
|
|
2632
|
+
files = await readdir3(evDir);
|
|
2294
2633
|
} catch (e) {
|
|
2295
2634
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
2296
2635
|
}
|
|
@@ -2298,7 +2637,7 @@ async function collectTaskEvidence(projectRoot, taskId) {
|
|
|
2298
2637
|
if (!file.endsWith(".json"))
|
|
2299
2638
|
continue;
|
|
2300
2639
|
try {
|
|
2301
|
-
const raw = await
|
|
2640
|
+
const raw = await readFile10(join4(evDir, file), "utf-8");
|
|
2302
2641
|
const ev = EvidenceSchema.parse(JSON.parse(raw));
|
|
2303
2642
|
if (ev.relatedTask === taskId)
|
|
2304
2643
|
records.push(ev);
|
|
@@ -2442,6 +2781,16 @@ async function runVerification(projectRoot, taskId, goal, options) {
|
|
|
2442
2781
|
});
|
|
2443
2782
|
if (!event.success)
|
|
2444
2783
|
return event;
|
|
2784
|
+
const runId = `r-verify-${taskId}`;
|
|
2785
|
+
for (const check of checks) {
|
|
2786
|
+
await emitVerificationGate(projectRoot, {
|
|
2787
|
+
runId,
|
|
2788
|
+
taskId,
|
|
2789
|
+
gate: check.name,
|
|
2790
|
+
passed: check.passed,
|
|
2791
|
+
durationMs: null
|
|
2792
|
+
});
|
|
2793
|
+
}
|
|
2445
2794
|
return ok({ passed, checks, evidenceIds });
|
|
2446
2795
|
}
|
|
2447
2796
|
async function gateTaskCompletion(projectRoot, taskId, evidenceRequired, evidenceIds) {
|
|
@@ -2552,7 +2901,7 @@ async function readRunnerTddEvidence(projectRoot, taskId, evidenceId) {
|
|
|
2552
2901
|
return path;
|
|
2553
2902
|
let raw;
|
|
2554
2903
|
try {
|
|
2555
|
-
raw = await
|
|
2904
|
+
raw = await readFile10(path.data, "utf-8");
|
|
2556
2905
|
} catch (e) {
|
|
2557
2906
|
return err(e instanceof Error ? e : new Error(String(e)));
|
|
2558
2907
|
}
|
|
@@ -2600,14 +2949,14 @@ async function listRunnerTddRecords(projectRoot, taskId) {
|
|
|
2600
2949
|
return collected.data.records.filter((ev) => ev.type === "tdd" && ev.source === TDD_EVIDENCE_SOURCE && ev.data?.capturedBy === TDD_CAPTURED_BY);
|
|
2601
2950
|
}
|
|
2602
2951
|
function tddValidationFilePath(projectRoot, taskId) {
|
|
2603
|
-
return evidenceFilePath(
|
|
2952
|
+
return evidenceFilePath(join4(resolve11(projectRoot), ".codeconductor", "tdd-validations"), taskId);
|
|
2604
2953
|
}
|
|
2605
2954
|
async function loadTddValidation(projectRoot, taskId) {
|
|
2606
2955
|
const path = tddValidationFilePath(projectRoot, taskId);
|
|
2607
2956
|
if (!path.success)
|
|
2608
2957
|
return;
|
|
2609
2958
|
try {
|
|
2610
|
-
const record = TddValidationRecordSchema.parse(JSON.parse(await
|
|
2959
|
+
const record = TddValidationRecordSchema.parse(JSON.parse(await readFile10(path.data, "utf-8")));
|
|
2611
2960
|
return record.taskId === taskId ? record : undefined;
|
|
2612
2961
|
} catch {
|
|
2613
2962
|
return;
|
|
@@ -2634,8 +2983,165 @@ async function hasTddRunnerEvidence(projectRoot, taskId, expectedPhase) {
|
|
|
2634
2983
|
}
|
|
2635
2984
|
return false;
|
|
2636
2985
|
}
|
|
2986
|
+
// src/core/hooks/hook-runner.ts
|
|
2987
|
+
var DEFAULT_PROTECTED_PATTERNS = [
|
|
2988
|
+
"tests/",
|
|
2989
|
+
"test/",
|
|
2990
|
+
"specs/",
|
|
2991
|
+
"contracts/",
|
|
2992
|
+
".test.",
|
|
2993
|
+
".spec.",
|
|
2994
|
+
"_test.",
|
|
2995
|
+
"_spec."
|
|
2996
|
+
];
|
|
2997
|
+
function normalizeHookPath(filePath, path) {
|
|
2998
|
+
const windowsPath = filePath.includes("\\") || /^[a-z]:\//i.test(filePath);
|
|
2999
|
+
const normalized = path.replace(/\\/g, "/");
|
|
3000
|
+
return windowsPath ? normalized.toLowerCase() : normalized;
|
|
3001
|
+
}
|
|
3002
|
+
function scopeMatchesFile(filePath, scopeFiles) {
|
|
3003
|
+
if (scopeFiles.length === 0)
|
|
3004
|
+
return false;
|
|
3005
|
+
const normalizedPath = normalizeHookPath(filePath, filePath);
|
|
3006
|
+
return scopeFiles.some((entry) => {
|
|
3007
|
+
const pattern = normalizeHookPath(filePath, entry).replace(/\*\*/g, "");
|
|
3008
|
+
return pattern !== "" && normalizedPath.includes(pattern);
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
function evaluateScopeAccess(filePath, scopeFiles) {
|
|
3012
|
+
if (scopeFiles.length === 0)
|
|
3013
|
+
return { allowed: true };
|
|
3014
|
+
if (!scopeMatchesFile(filePath, scopeFiles)) {
|
|
3015
|
+
return { allowed: false, reason: `ScopeViolation: File '${filePath}' is outside the task scope.` };
|
|
3016
|
+
}
|
|
3017
|
+
return { allowed: true };
|
|
3018
|
+
}
|
|
3019
|
+
var DISPATCH_MODES = [
|
|
3020
|
+
"full",
|
|
3021
|
+
"surgical-fix",
|
|
3022
|
+
"refactor-only",
|
|
3023
|
+
"test-add",
|
|
3024
|
+
"scaffold",
|
|
3025
|
+
"rename-move",
|
|
3026
|
+
"dep-bump"
|
|
3027
|
+
];
|
|
3028
|
+
function isDispatchMode(raw) {
|
|
3029
|
+
return typeof raw === "string" && DISPATCH_MODES.includes(raw);
|
|
3030
|
+
}
|
|
3031
|
+
var DEP_MANIFESTS = new Set([
|
|
3032
|
+
"package.json",
|
|
3033
|
+
"package-lock.json",
|
|
3034
|
+
"bun.lock",
|
|
3035
|
+
"yarn.lock",
|
|
3036
|
+
"pnpm-lock.yaml",
|
|
3037
|
+
"cargo.toml",
|
|
3038
|
+
"cargo.lock",
|
|
3039
|
+
"go.mod",
|
|
3040
|
+
"go.sum",
|
|
3041
|
+
"requirements.txt",
|
|
3042
|
+
"pyproject.toml",
|
|
3043
|
+
"poetry.lock",
|
|
3044
|
+
"gemfile",
|
|
3045
|
+
"gemfile.lock",
|
|
3046
|
+
"pom.xml",
|
|
3047
|
+
"build.gradle",
|
|
3048
|
+
"build.gradle.kts",
|
|
3049
|
+
"composer.json",
|
|
3050
|
+
"composer.lock"
|
|
3051
|
+
]);
|
|
3052
|
+
function isTestFile(filePath) {
|
|
3053
|
+
const normalized = normalizeHookPath(filePath, filePath);
|
|
3054
|
+
return DEFAULT_PROTECTED_PATTERNS.some((p) => normalized.includes(normalizeHookPath(filePath, p)));
|
|
3055
|
+
}
|
|
3056
|
+
function evaluateDispatchMode(mode, input) {
|
|
3057
|
+
const { filePath, command } = input;
|
|
3058
|
+
if (mode === "rename-move") {
|
|
3059
|
+
if (filePath) {
|
|
3060
|
+
return { allowed: false, reason: `DispatchMode(rename-move): file writes denied, rename via git mv instead of touching '${filePath}'.` };
|
|
3061
|
+
}
|
|
3062
|
+
if (command) {
|
|
3063
|
+
const normalized = stripGitBinary(normalizeCommand(command));
|
|
3064
|
+
if (/^git\s+mv\b/i.test(normalized))
|
|
3065
|
+
return { allowed: true };
|
|
3066
|
+
return { allowed: false, reason: "DispatchMode(rename-move): only `git mv` commands allowed." };
|
|
3067
|
+
}
|
|
3068
|
+
return { allowed: true };
|
|
3069
|
+
}
|
|
3070
|
+
if (!filePath)
|
|
3071
|
+
return { allowed: true };
|
|
3072
|
+
switch (mode) {
|
|
3073
|
+
case "full":
|
|
3074
|
+
if (isTestFile(filePath)) {
|
|
3075
|
+
return { allowed: false, reason: `DispatchMode(full): test files are read-only, use test-add for '${filePath}'.` };
|
|
3076
|
+
}
|
|
3077
|
+
return { allowed: true };
|
|
3078
|
+
case "surgical-fix": {
|
|
3079
|
+
if (!input.scopeFiles || input.scopeFiles.length === 0) {
|
|
3080
|
+
return { allowed: false, reason: "DispatchMode(surgical-fix): requires --scope with the task boundary." };
|
|
3081
|
+
}
|
|
3082
|
+
const scope = evaluateScopeAccess(filePath, input.scopeFiles);
|
|
3083
|
+
if (!scope.allowed)
|
|
3084
|
+
return scope;
|
|
3085
|
+
if (input.exists !== true) {
|
|
3086
|
+
return {
|
|
3087
|
+
allowed: false,
|
|
3088
|
+
reason: input.exists === false ? `DispatchMode(surgical-fix): no new files, use scaffold for '${filePath}'.` : `DispatchMode(surgical-fix): cannot verify '${filePath}' exists.`
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3091
|
+
if (isTestFile(filePath)) {
|
|
3092
|
+
return { allowed: false, reason: `DispatchMode(surgical-fix): tests are frozen, '${filePath}' is out of mode.` };
|
|
3093
|
+
}
|
|
3094
|
+
return { allowed: true };
|
|
3095
|
+
}
|
|
3096
|
+
case "refactor-only":
|
|
3097
|
+
if (input.exists !== true) {
|
|
3098
|
+
return {
|
|
3099
|
+
allowed: false,
|
|
3100
|
+
reason: input.exists === false ? `DispatchMode(refactor-only): no new files, use scaffold for '${filePath}'.` : `DispatchMode(refactor-only): cannot verify '${filePath}' exists.`
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
return { allowed: true };
|
|
3104
|
+
case "test-add":
|
|
3105
|
+
if (!isTestFile(filePath)) {
|
|
3106
|
+
return { allowed: false, reason: `DispatchMode(test-add): only test files are writable, got '${filePath}'.` };
|
|
3107
|
+
}
|
|
3108
|
+
return { allowed: true };
|
|
3109
|
+
case "scaffold":
|
|
3110
|
+
if (input.exists !== false) {
|
|
3111
|
+
return {
|
|
3112
|
+
allowed: false,
|
|
3113
|
+
reason: input.exists === true ? `DispatchMode(scaffold): '${filePath}' already exists.` : `DispatchMode(scaffold): cannot verify '${filePath}' is new.`
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
return { allowed: true };
|
|
3117
|
+
case "dep-bump": {
|
|
3118
|
+
const base = filePath.replace(/\\/g, "/").split("/").pop().toLowerCase();
|
|
3119
|
+
if (!DEP_MANIFESTS.has(base)) {
|
|
3120
|
+
return { allowed: false, reason: `DispatchMode(dep-bump): only manifests/lockfiles are writable, got '${filePath}'.` };
|
|
3121
|
+
}
|
|
3122
|
+
return { allowed: true };
|
|
3123
|
+
}
|
|
3124
|
+
default: {
|
|
3125
|
+
const _exhaustive = mode;
|
|
3126
|
+
return { allowed: true };
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
var DELEGATION_TOOLS = new Set(["task", "subagent"]);
|
|
3131
|
+
function normalizeCommand(raw) {
|
|
3132
|
+
return raw.replace(/\s+/g, " ").trim();
|
|
3133
|
+
}
|
|
3134
|
+
function stripGitBinary(command) {
|
|
3135
|
+
const match = command.match(/^(?:&\s*)?("[^"]+"|'[^']+'|[^\s]+)([\s\S]*)$/);
|
|
3136
|
+
if (!match)
|
|
3137
|
+
return command;
|
|
3138
|
+
const binary = match[1].replace(/^["']|["']$/g, "").replace(/\\/g, "/").split("/").pop();
|
|
3139
|
+
return /^git(?:\.exe)?$/i.test(binary ?? "") ? `git${match[2]}` : command;
|
|
3140
|
+
}
|
|
2637
3141
|
|
|
2638
3142
|
// src/core/orchestrator/runtime-orchestrator.ts
|
|
3143
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
3144
|
+
import { join as join5 } from "node:path";
|
|
2639
3145
|
async function rollbackTaskStatus(projectRoot, graph, task, previousStatus, previousState, cause) {
|
|
2640
3146
|
return withQueueLock(projectRoot, async () => {
|
|
2641
3147
|
task.status = previousStatus;
|
|
@@ -2697,16 +3203,49 @@ function buildTaskEnvelope(card, projectRoot, projectName) {
|
|
|
2697
3203
|
}
|
|
2698
3204
|
};
|
|
2699
3205
|
}
|
|
2700
|
-
|
|
2701
|
-
|
|
3206
|
+
function taskTypeToDispatchMode(type) {
|
|
3207
|
+
switch (type) {
|
|
3208
|
+
case "fix":
|
|
3209
|
+
return "surgical-fix";
|
|
3210
|
+
case "refactor":
|
|
3211
|
+
return "refactor-only";
|
|
3212
|
+
case "test":
|
|
3213
|
+
return "test-add";
|
|
3214
|
+
case "feature":
|
|
3215
|
+
case "docs":
|
|
3216
|
+
return "full";
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
function resolveEffectiveMode(type, override) {
|
|
3220
|
+
if (override === undefined)
|
|
3221
|
+
return ok(taskTypeToDispatchMode(type));
|
|
3222
|
+
if (!isDispatchMode(override)) {
|
|
3223
|
+
return err(new Error(`Unknown dispatch mode: ${override}. Use: ${DISPATCH_MODES.join(", ")}`));
|
|
3224
|
+
}
|
|
3225
|
+
return ok(override);
|
|
3226
|
+
}
|
|
3227
|
+
function checkDispatchClearance(projectRoot, mode, targetFiles) {
|
|
3228
|
+
for (const file of targetFiles) {
|
|
3229
|
+
const verdict = evaluateDispatchMode(mode, {
|
|
3230
|
+
filePath: file,
|
|
3231
|
+
scopeFiles: targetFiles,
|
|
3232
|
+
exists: existsSync2(join5(projectRoot, file))
|
|
3233
|
+
});
|
|
3234
|
+
if (!verdict.allowed)
|
|
3235
|
+
return err(new Error(`Dispatch denied: ${verdict.reason}`));
|
|
3236
|
+
}
|
|
3237
|
+
return ok(undefined);
|
|
3238
|
+
}
|
|
3239
|
+
async function getNextTask(projectRoot, projectName, dispatchMode) {
|
|
3240
|
+
return withQueueLock(projectRoot, () => getNextTaskUnlocked(projectRoot, projectName, dispatchMode));
|
|
2702
3241
|
}
|
|
2703
|
-
async function startTask(projectRoot, taskId, agent) {
|
|
2704
|
-
return withQueueLock(projectRoot, () => startTaskUnlocked(projectRoot, taskId, agent));
|
|
3242
|
+
async function startTask(projectRoot, taskId, agent, dispatchMode) {
|
|
3243
|
+
return withQueueLock(projectRoot, () => startTaskUnlocked(projectRoot, taskId, agent, dispatchMode));
|
|
2705
3244
|
}
|
|
2706
3245
|
async function completeTask(projectRoot, taskId, evidenceIds) {
|
|
2707
3246
|
return withQueueLock(projectRoot, () => completeTaskUnlocked(projectRoot, taskId, evidenceIds));
|
|
2708
3247
|
}
|
|
2709
|
-
async function getNextTaskUnlocked(projectRoot, projectName) {
|
|
3248
|
+
async function getNextTaskUnlocked(projectRoot, projectName, dispatchOverride) {
|
|
2710
3249
|
const goalResult = await loadGoal(projectRoot);
|
|
2711
3250
|
if (!goalResult.success)
|
|
2712
3251
|
return goalResult;
|
|
@@ -2724,15 +3263,23 @@ async function getNextTaskUnlocked(projectRoot, projectName) {
|
|
|
2724
3263
|
}
|
|
2725
3264
|
const task = ready[0];
|
|
2726
3265
|
const enrichedTask = enriched.enrichedTasks.find((t) => t.id === task.id);
|
|
3266
|
+
const effective = resolveEffectiveMode(enrichedTask.type, dispatchOverride);
|
|
3267
|
+
if (!effective.success)
|
|
3268
|
+
return effective;
|
|
3269
|
+
const dispatchMode = effective.data;
|
|
3270
|
+
const clearance = checkDispatchClearance(projectRoot, dispatchMode, enrichedTask.targetFiles);
|
|
3271
|
+
if (!clearance.success)
|
|
3272
|
+
return clearance;
|
|
2727
3273
|
const card = goalTaskToCanonicalCard(enrichedTask, enriched.objective);
|
|
2728
3274
|
const envelope = buildTaskEnvelope(card, projectRoot, projectName);
|
|
2729
3275
|
return ok({
|
|
2730
3276
|
task: card,
|
|
2731
3277
|
envelope,
|
|
2732
|
-
readyCount: ready.length
|
|
3278
|
+
readyCount: ready.length,
|
|
3279
|
+
dispatchMode
|
|
2733
3280
|
});
|
|
2734
3281
|
}
|
|
2735
|
-
async function startTaskUnlocked(projectRoot, taskId, agent) {
|
|
3282
|
+
async function startTaskUnlocked(projectRoot, taskId, agent, dispatchOverride) {
|
|
2736
3283
|
const goalResult = await loadGoal(projectRoot);
|
|
2737
3284
|
if (!goalResult.success)
|
|
2738
3285
|
return goalResult;
|
|
@@ -2746,6 +3293,15 @@ async function startTaskUnlocked(projectRoot, taskId, agent) {
|
|
|
2746
3293
|
const unmet = (task.depends_on ?? []).filter((id) => !done.has(id));
|
|
2747
3294
|
if (unmet.length > 0)
|
|
2748
3295
|
return err(new Error(`Task ${taskId} has unmet dependencies: ${unmet.join(", ")}`));
|
|
3296
|
+
const graphResult = await loadGraph(projectRoot);
|
|
3297
|
+
const enriched = enrichGoalWithProduct(goalResult.data, graphResult.success ? graphResult.data : undefined);
|
|
3298
|
+
const enrichedTask = enriched.enrichedTasks.find((t) => t.id === taskId);
|
|
3299
|
+
const effective = resolveEffectiveMode(task.type, dispatchOverride);
|
|
3300
|
+
if (!effective.success)
|
|
3301
|
+
return effective;
|
|
3302
|
+
const clearance = checkDispatchClearance(projectRoot, effective.data, enrichedTask?.targetFiles ?? []);
|
|
3303
|
+
if (!clearance.success)
|
|
3304
|
+
return clearance;
|
|
2749
3305
|
const stateBefore = await loadOperationalState(projectRoot);
|
|
2750
3306
|
if (!stateBefore.success)
|
|
2751
3307
|
return stateBefore;
|
|
@@ -3154,10 +3710,18 @@ async function runLoop(generateFn, compileCheckFn, config = {}, taskTitle = "com
|
|
|
3154
3710
|
let feedbackText;
|
|
3155
3711
|
let compileCheck;
|
|
3156
3712
|
let compileCheckSkipReason;
|
|
3713
|
+
const projectRoot = config.cwd ?? process.cwd();
|
|
3714
|
+
const loopRunId = `r-loop-${Date.now().toString(36)}`;
|
|
3157
3715
|
logTransition(state.phase, "INIT", state.iteration);
|
|
3158
3716
|
const startResult = loopStateMachine(state, { type: "START" });
|
|
3159
3717
|
state = startResult.state;
|
|
3160
3718
|
logTransition(state.phase, "START", state.iteration);
|
|
3719
|
+
await emitLoopIteration(projectRoot, {
|
|
3720
|
+
runId: loopRunId,
|
|
3721
|
+
taskId: taskTitle,
|
|
3722
|
+
iteration: state.iteration,
|
|
3723
|
+
maxIterations
|
|
3724
|
+
});
|
|
3161
3725
|
while (true) {
|
|
3162
3726
|
const hit = await engine.evaluate();
|
|
3163
3727
|
if (hit) {
|
|
@@ -3206,9 +3770,22 @@ async function runLoop(generateFn, compileCheckFn, config = {}, taskTitle = "com
|
|
|
3206
3770
|
case "FEEDBACK": {
|
|
3207
3771
|
logTransition(state.phase, "FORMAT_FEEDBACK", state.iteration);
|
|
3208
3772
|
feedbackText = formatFeedback(state.errors);
|
|
3773
|
+
await emitLoopRetry(projectRoot, {
|
|
3774
|
+
runId: loopRunId,
|
|
3775
|
+
taskId: taskTitle,
|
|
3776
|
+
iteration: state.iteration,
|
|
3777
|
+
maxIterations,
|
|
3778
|
+
feedback: feedbackText
|
|
3779
|
+
});
|
|
3209
3780
|
const fbResult = loopStateMachine(state, { type: "FEEDBACK_FORMATTED" });
|
|
3210
3781
|
state = fbResult.state;
|
|
3211
3782
|
logTransition(state.phase, "FEEDBACK_FORMATTED", state.iteration);
|
|
3783
|
+
await emitLoopIteration(projectRoot, {
|
|
3784
|
+
runId: loopRunId,
|
|
3785
|
+
taskId: taskTitle,
|
|
3786
|
+
iteration: state.iteration,
|
|
3787
|
+
maxIterations
|
|
3788
|
+
});
|
|
3212
3789
|
break;
|
|
3213
3790
|
}
|
|
3214
3791
|
case "DONE": {
|
|
@@ -3408,6 +3985,8 @@ export {
|
|
|
3408
3985
|
CcepOutputFormatSchema,
|
|
3409
3986
|
ClaudeAgentFileSchema,
|
|
3410
3987
|
CodeConductorConfigSchema,
|
|
3988
|
+
CodeIndexSchema,
|
|
3989
|
+
CodeIndexSymbolSchema,
|
|
3411
3990
|
CommandEnvelopeSchema,
|
|
3412
3991
|
CommandFrontmatterSchema,
|
|
3413
3992
|
CompileCheckConfigSchema,
|
|
@@ -3429,6 +4008,7 @@ export {
|
|
|
3429
4008
|
DeliveryTelemetrySchema,
|
|
3430
4009
|
DependencyEvidenceSchema,
|
|
3431
4010
|
DetectionStatusSchema,
|
|
4011
|
+
EdgeCaseSchema,
|
|
3432
4012
|
EvaluationIndexSchema,
|
|
3433
4013
|
EvidenceSchema,
|
|
3434
4014
|
ExecutionContextSchema,
|