gsd-pi 2.37.1-dev.7775114 → 2.37.1-dev.d3ace49
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 +1 -1
- package/dist/onboarding.js +1 -0
- package/dist/resources/extensions/gsd/auto-dispatch.js +67 -1
- package/dist/resources/extensions/gsd/auto-post-unit.js +14 -0
- package/dist/resources/extensions/gsd/auto-prompts.js +91 -2
- package/dist/resources/extensions/gsd/auto-recovery.js +37 -1
- package/dist/resources/extensions/gsd/doctor-providers.js +35 -1
- package/dist/resources/extensions/gsd/files.js +41 -0
- package/dist/resources/extensions/gsd/observability-validator.js +24 -0
- package/dist/resources/extensions/gsd/preferences-types.js +2 -1
- package/dist/resources/extensions/gsd/preferences-validation.js +42 -0
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +2 -1
- package/dist/resources/extensions/gsd/prompts/reactive-execute.md +41 -0
- package/dist/resources/extensions/gsd/reactive-graph.js +227 -0
- package/dist/resources/extensions/gsd/templates/task-plan.md +11 -3
- package/package.json +2 -1
- package/packages/pi-ai/dist/env-api-keys.js +13 -0
- package/packages/pi-ai/dist/env-api-keys.js.map +1 -1
- package/packages/pi-ai/dist/models.generated.d.ts +172 -0
- package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/packages/pi-ai/dist/models.generated.js +172 -0
- package/packages/pi-ai/dist/models.generated.js.map +1 -1
- package/packages/pi-ai/dist/providers/anthropic-shared.d.ts +64 -0
- package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/anthropic-shared.js +668 -0
- package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -0
- package/packages/pi-ai/dist/providers/anthropic-vertex.d.ts +5 -0
- package/packages/pi-ai/dist/providers/anthropic-vertex.d.ts.map +1 -0
- package/packages/pi-ai/dist/providers/anthropic-vertex.js +85 -0
- package/packages/pi-ai/dist/providers/anthropic-vertex.js.map +1 -0
- package/packages/pi-ai/dist/providers/anthropic.d.ts +4 -30
- package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/anthropic.js +47 -764
- package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
- package/packages/pi-ai/dist/providers/register-builtins.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/register-builtins.js +6 -0
- package/packages/pi-ai/dist/providers/register-builtins.js.map +1 -1
- package/packages/pi-ai/dist/types.d.ts +2 -2
- package/packages/pi-ai/dist/types.d.ts.map +1 -1
- package/packages/pi-ai/dist/types.js.map +1 -1
- package/packages/pi-ai/package.json +1 -0
- package/packages/pi-ai/src/env-api-keys.ts +14 -0
- package/packages/pi-ai/src/models.generated.ts +172 -0
- package/packages/pi-ai/src/providers/anthropic-shared.ts +761 -0
- package/packages/pi-ai/src/providers/anthropic-vertex.ts +130 -0
- package/packages/pi-ai/src/providers/anthropic.ts +76 -868
- package/packages/pi-ai/src/providers/register-builtins.ts +7 -0
- package/packages/pi-ai/src/types.ts +2 -0
- package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.js +1 -0
- package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
- package/packages/pi-coding-agent/src/core/model-resolver.ts +1 -0
- package/src/resources/extensions/gsd/auto-dispatch.ts +93 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +14 -0
- package/src/resources/extensions/gsd/auto-prompts.ts +125 -3
- package/src/resources/extensions/gsd/auto-recovery.ts +42 -0
- package/src/resources/extensions/gsd/doctor-providers.ts +38 -1
- package/src/resources/extensions/gsd/files.ts +45 -0
- package/src/resources/extensions/gsd/observability-validator.ts +27 -0
- package/src/resources/extensions/gsd/preferences-types.ts +5 -1
- package/src/resources/extensions/gsd/preferences-validation.ts +41 -0
- package/src/resources/extensions/gsd/prompts/plan-slice.md +2 -1
- package/src/resources/extensions/gsd/prompts/reactive-execute.md +41 -0
- package/src/resources/extensions/gsd/reactive-graph.ts +289 -0
- package/src/resources/extensions/gsd/templates/task-plan.md +11 -3
- package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +108 -3
- package/src/resources/extensions/gsd/tests/plan-quality-validator.test.ts +111 -0
- package/src/resources/extensions/gsd/tests/reactive-executor.test.ts +511 -0
- package/src/resources/extensions/gsd/tests/reactive-graph.test.ts +299 -0
- package/src/resources/extensions/gsd/types.ts +43 -0
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
Summary, SummaryFrontmatter, SummaryRequires, FileModified,
|
|
16
16
|
Continue, ContinueFrontmatter, ContinueStatus,
|
|
17
17
|
RequirementCounts,
|
|
18
|
+
TaskIO,
|
|
18
19
|
SecretsManifest, SecretsManifestEntry, SecretsManifestEntryStatus,
|
|
19
20
|
ManifestStatus,
|
|
20
21
|
} from './types.js';
|
|
@@ -724,6 +725,50 @@ export function countMustHavesMentionedInSummary(
|
|
|
724
725
|
return count;
|
|
725
726
|
}
|
|
726
727
|
|
|
728
|
+
// ─── Task Plan IO Extractor ────────────────────────────────────────────────
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Extract input and output file paths from a task plan's `## Inputs` and
|
|
732
|
+
* `## Expected Output` sections. Looks for backtick-wrapped file paths on
|
|
733
|
+
* each line (e.g. `` `src/foo.ts` ``).
|
|
734
|
+
*
|
|
735
|
+
* Returns empty arrays for missing/empty sections — callers should treat
|
|
736
|
+
* tasks with no IO as ambiguous (sequential fallback trigger).
|
|
737
|
+
*/
|
|
738
|
+
export function parseTaskPlanIO(content: string): { inputFiles: string[]; outputFiles: string[] } {
|
|
739
|
+
const backtickPathRegex = /`([^`]+)`/g;
|
|
740
|
+
|
|
741
|
+
function extractPaths(sectionText: string | null): string[] {
|
|
742
|
+
if (!sectionText) return [];
|
|
743
|
+
const paths: string[] = [];
|
|
744
|
+
for (const line of sectionText.split("\n")) {
|
|
745
|
+
const trimmed = line.trim();
|
|
746
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
747
|
+
let match: RegExpExecArray | null;
|
|
748
|
+
backtickPathRegex.lastIndex = 0;
|
|
749
|
+
while ((match = backtickPathRegex.exec(trimmed)) !== null) {
|
|
750
|
+
const candidate = match[1];
|
|
751
|
+
// Filter out things that look like code tokens rather than file paths
|
|
752
|
+
// (e.g. `true`, `false`, `npm run test`). A file path has at least one
|
|
753
|
+
// dot or slash.
|
|
754
|
+
if (candidate.includes("/") || candidate.includes(".")) {
|
|
755
|
+
paths.push(candidate);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return paths;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const [, body] = splitFrontmatter(content);
|
|
763
|
+
const inputSection = extractSection(body, "Inputs");
|
|
764
|
+
const outputSection = extractSection(body, "Expected Output");
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
inputFiles: extractPaths(inputSection),
|
|
768
|
+
outputFiles: extractPaths(outputSection),
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
727
772
|
// ─── UAT Type Extractor ────────────────────────────────────────────────────
|
|
728
773
|
|
|
729
774
|
/**
|
|
@@ -235,6 +235,33 @@ export function validateTaskPlanContent(file: string, content: string): Validati
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
// Rule: Inputs and Expected Output should contain backtick-wrapped file paths
|
|
239
|
+
const inputsSection = getSection(content, "Inputs", 2);
|
|
240
|
+
const outputSection = getSection(content, "Expected Output", 2);
|
|
241
|
+
const backtickPathPattern = /`[^`]*[./][^`]*`/;
|
|
242
|
+
|
|
243
|
+
if (outputSection === null || !backtickPathPattern.test(outputSection)) {
|
|
244
|
+
issues.push({
|
|
245
|
+
severity: "warning",
|
|
246
|
+
scope: "task-plan",
|
|
247
|
+
file,
|
|
248
|
+
ruleId: "missing_output_file_paths",
|
|
249
|
+
message: "Task plan `## Expected Output` is missing or has no backtick-wrapped file paths.",
|
|
250
|
+
suggestion: "List concrete output file paths in backticks (e.g. `src/types.ts`). These are machine-parsed to derive task dependencies.",
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (inputsSection !== null && inputsSection.trim().length > 0 && !backtickPathPattern.test(inputsSection)) {
|
|
255
|
+
issues.push({
|
|
256
|
+
severity: "info",
|
|
257
|
+
scope: "task-plan",
|
|
258
|
+
file,
|
|
259
|
+
ruleId: "missing_input_file_paths",
|
|
260
|
+
message: "Task plan `## Inputs` has content but no backtick-wrapped file paths.",
|
|
261
|
+
suggestion: "List input file paths in backticks (e.g. `src/config.json`). These are machine-parsed to derive task dependencies.",
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
238
265
|
// ── Observability rules (gated by runtime relevance) ──
|
|
239
266
|
|
|
240
267
|
const relevant = textSuggestsObservabilityRelevant(content);
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
ParallelConfig,
|
|
19
19
|
CompressionStrategy,
|
|
20
20
|
ContextSelectionMode,
|
|
21
|
+
ReactiveExecutionConfig,
|
|
21
22
|
} from "./types.js";
|
|
22
23
|
import type { DynamicRoutingConfig } from "./model-router.js";
|
|
23
24
|
|
|
@@ -86,12 +87,13 @@ export const KNOWN_PREFERENCE_KEYS = new Set<string>([
|
|
|
86
87
|
"compression_strategy",
|
|
87
88
|
"context_selection",
|
|
88
89
|
"widget_mode",
|
|
90
|
+
"reactive_execution",
|
|
89
91
|
]);
|
|
90
92
|
|
|
91
93
|
/** Canonical list of all dispatch unit types. */
|
|
92
94
|
export const KNOWN_UNIT_TYPES = [
|
|
93
95
|
"research-milestone", "plan-milestone", "research-slice", "plan-slice",
|
|
94
|
-
"execute-task", "complete-slice", "replan-slice", "reassess-roadmap",
|
|
96
|
+
"execute-task", "reactive-execute", "complete-slice", "replan-slice", "reassess-roadmap",
|
|
95
97
|
"run-uat", "complete-milestone",
|
|
96
98
|
] as const;
|
|
97
99
|
export type UnitType = (typeof KNOWN_UNIT_TYPES)[number];
|
|
@@ -215,6 +217,8 @@ export interface GSDPreferences {
|
|
|
215
217
|
context_selection?: ContextSelectionMode;
|
|
216
218
|
/** Default widget display mode for auto-mode dashboard. "full" | "small" | "min" | "off". Default: "full". */
|
|
217
219
|
widget_mode?: "full" | "small" | "min" | "off";
|
|
220
|
+
/** Reactive (graph-derived parallel) task execution within slices. Disabled by default. */
|
|
221
|
+
reactive_execution?: ReactiveExecutionConfig;
|
|
218
222
|
}
|
|
219
223
|
|
|
220
224
|
export interface LoadedGSDPreferences {
|
|
@@ -496,6 +496,47 @@ export function validatePreferences(preferences: GSDPreferences): {
|
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
// ─── Reactive Execution ─────────────────────────────────────────────────
|
|
500
|
+
if (preferences.reactive_execution !== undefined) {
|
|
501
|
+
if (typeof preferences.reactive_execution === "object" && preferences.reactive_execution !== null) {
|
|
502
|
+
const re = preferences.reactive_execution as unknown as Record<string, unknown>;
|
|
503
|
+
const validRe: Record<string, unknown> = {};
|
|
504
|
+
|
|
505
|
+
if (re.enabled !== undefined) {
|
|
506
|
+
if (typeof re.enabled === "boolean") validRe.enabled = re.enabled;
|
|
507
|
+
else errors.push("reactive_execution.enabled must be a boolean");
|
|
508
|
+
}
|
|
509
|
+
if (re.max_parallel !== undefined) {
|
|
510
|
+
const mp = typeof re.max_parallel === "number" ? re.max_parallel : Number(re.max_parallel);
|
|
511
|
+
if (Number.isFinite(mp) && mp >= 1 && mp <= 8) {
|
|
512
|
+
validRe.max_parallel = Math.floor(mp);
|
|
513
|
+
} else {
|
|
514
|
+
errors.push("reactive_execution.max_parallel must be a number between 1 and 8");
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
if (re.isolation_mode !== undefined) {
|
|
518
|
+
if (re.isolation_mode === "same-tree") {
|
|
519
|
+
validRe.isolation_mode = "same-tree";
|
|
520
|
+
} else {
|
|
521
|
+
errors.push('reactive_execution.isolation_mode must be "same-tree"');
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const knownReKeys = new Set(["enabled", "max_parallel", "isolation_mode"]);
|
|
526
|
+
for (const key of Object.keys(re)) {
|
|
527
|
+
if (!knownReKeys.has(key)) {
|
|
528
|
+
warnings.push(`unknown reactive_execution key "${key}" — ignored`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (Object.keys(validRe).length > 0) {
|
|
533
|
+
validated.reactive_execution = validRe as unknown as import("./types.js").ReactiveExecutionConfig;
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
errors.push("reactive_execution must be an object");
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
499
540
|
// ─── Verification Preferences ───────────────────────────────────────────
|
|
500
541
|
if (preferences.verification_commands !== undefined) {
|
|
501
542
|
if (Array.isArray(preferences.verification_commands)) {
|
|
@@ -61,13 +61,14 @@ Then:
|
|
|
61
61
|
- a concrete, action-oriented title
|
|
62
62
|
- the inline task entry fields defined in the plan.md template (Why / Files / Do / Verify / Done when)
|
|
63
63
|
- a matching task plan file with description, steps, must-haves, verification, inputs, and expected output
|
|
64
|
+
- **Inputs and Expected Output must list concrete backtick-wrapped file paths** (e.g. `` `src/types.ts` ``). These are machine-parsed to derive task dependencies — vague prose without paths breaks parallel execution. Every task must have at least one output file path.
|
|
64
65
|
- Observability Impact section **only if the task touches runtime boundaries, async flows, or error paths** — omit it otherwise
|
|
65
66
|
6. Write `{{outputPath}}`
|
|
66
67
|
7. Write individual task plans in `{{slicePath}}/tasks/`: `T01-PLAN.md`, `T02-PLAN.md`, etc.
|
|
67
68
|
8. **Self-audit the plan.** Walk through each check — if any fail, fix the plan files before moving on:
|
|
68
69
|
- **Completion semantics:** If every task were completed exactly as written, the slice goal/demo should actually be true.
|
|
69
70
|
- **Requirement coverage:** Every must-have in the slice maps to at least one task. No must-have is orphaned. If `REQUIREMENTS.md` exists, every Active requirement this slice owns maps to at least one task.
|
|
70
|
-
- **Task completeness:** Every task has steps, must-haves, verification, inputs, and expected output — none are blank or vague.
|
|
71
|
+
- **Task completeness:** Every task has steps, must-haves, verification, inputs, and expected output — none are blank or vague. Inputs and Expected Output list backtick-wrapped file paths, not prose descriptions.
|
|
71
72
|
- **Dependency correctness:** Task ordering is consistent. No task references work from a later task.
|
|
72
73
|
- **Key links planned:** For every pair of artifacts that must connect, there is an explicit step that wires them.
|
|
73
74
|
- **Scope sanity:** Target 2–5 steps and 3–8 files per task. 10+ steps or 12+ files — must split. Each task must be completable in a single fresh context window.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Reactive Task Execution — Parallel Dispatch
|
|
2
|
+
|
|
3
|
+
**Working directory:** `{{workingDirectory}}`
|
|
4
|
+
**Milestone:** {{milestoneId}} — {{milestoneTitle}}
|
|
5
|
+
**Slice:** {{sliceId}} — {{sliceTitle}}
|
|
6
|
+
|
|
7
|
+
## Mission
|
|
8
|
+
|
|
9
|
+
You are executing **multiple tasks in parallel** for this slice. The task graph below shows which tasks are ready for simultaneous execution based on their input/output dependencies.
|
|
10
|
+
|
|
11
|
+
**Critical rule:** Use the `subagent` tool in **parallel mode** to dispatch all ready tasks simultaneously. Each subagent gets a self-contained execute-task prompt. After all subagents return, verify each task's outputs and write summaries.
|
|
12
|
+
|
|
13
|
+
## Task Dependency Graph
|
|
14
|
+
|
|
15
|
+
{{graphContext}}
|
|
16
|
+
|
|
17
|
+
## Ready Tasks for Parallel Dispatch
|
|
18
|
+
|
|
19
|
+
{{readyTaskCount}} tasks are ready for parallel execution:
|
|
20
|
+
|
|
21
|
+
{{readyTaskList}}
|
|
22
|
+
|
|
23
|
+
## Execution Protocol
|
|
24
|
+
|
|
25
|
+
1. **Dispatch all ready tasks** using `subagent` in parallel mode. Each subagent prompt is provided below.
|
|
26
|
+
2. **Wait for all subagents** to complete.
|
|
27
|
+
3. **Verify each task's outputs** — check that expected files were created/modified and that verification commands pass.
|
|
28
|
+
4. **Write task summaries** for each completed task using the task-summary template.
|
|
29
|
+
5. **Mark completed tasks** as done in the slice plan (checkbox `[x]`).
|
|
30
|
+
6. **Commit** all changes with a clear message covering the parallel batch.
|
|
31
|
+
|
|
32
|
+
If any subagent fails:
|
|
33
|
+
- Write a summary for the failed task with `blocker_discovered: true`
|
|
34
|
+
- Continue marking the successful tasks as done
|
|
35
|
+
- The orchestrator will handle re-dispatch on the next iteration
|
|
36
|
+
|
|
37
|
+
## Subagent Prompts
|
|
38
|
+
|
|
39
|
+
{{subagentPrompts}}
|
|
40
|
+
|
|
41
|
+
{{inlinedTemplates}}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive Task Graph — derives dependency edges from task plan IO signatures.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions that build a DAG from task IO intersections and resolve
|
|
5
|
+
* which tasks are currently ready for parallel dispatch. Used by the
|
|
6
|
+
* reactive-execute dispatch path (ADR-004).
|
|
7
|
+
*
|
|
8
|
+
* Graph derivation and resolution functions are pure (no filesystem access).
|
|
9
|
+
* The `loadSliceTaskIO` loader at the bottom is the only async/IO function.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { TaskIO, DerivedTaskNode, ReactiveExecutionState } from "./types.js";
|
|
13
|
+
import { loadFile, parsePlan, parseTaskPlanIO } from "./files.js";
|
|
14
|
+
import { resolveTasksDir, resolveTaskFiles } from "./paths.js";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { loadJsonFileOrNull, saveJsonFile } from "./json-persistence.js";
|
|
17
|
+
import { existsSync, unlinkSync } from "node:fs";
|
|
18
|
+
|
|
19
|
+
// ─── Graph Construction ───────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Build a dependency graph from task IO signatures.
|
|
23
|
+
*
|
|
24
|
+
* A task T_b depends on T_a when any of T_b's inputFiles appear in T_a's
|
|
25
|
+
* outputFiles. Self-references are excluded.
|
|
26
|
+
*
|
|
27
|
+
* Tasks are returned in the same order as the input array.
|
|
28
|
+
*/
|
|
29
|
+
export function deriveTaskGraph(tasks: TaskIO[]): DerivedTaskNode[] {
|
|
30
|
+
// Build output → producer lookup
|
|
31
|
+
const outputToProducer = new Map<string, string[]>();
|
|
32
|
+
for (const task of tasks) {
|
|
33
|
+
for (const outFile of task.outputFiles) {
|
|
34
|
+
const existing = outputToProducer.get(outFile);
|
|
35
|
+
if (existing) {
|
|
36
|
+
existing.push(task.id);
|
|
37
|
+
} else {
|
|
38
|
+
outputToProducer.set(outFile, [task.id]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return tasks.map((task) => {
|
|
44
|
+
const deps = new Set<string>();
|
|
45
|
+
for (const inFile of task.inputFiles) {
|
|
46
|
+
const producers = outputToProducer.get(inFile);
|
|
47
|
+
if (producers) {
|
|
48
|
+
for (const pid of producers) {
|
|
49
|
+
if (pid !== task.id) deps.add(pid);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...task,
|
|
55
|
+
dependsOn: [...deps].sort(),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── Ready Set Resolution ─────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Return task IDs whose dependencies are all in `completed`.
|
|
64
|
+
* Excludes tasks that are already done or in-flight.
|
|
65
|
+
*/
|
|
66
|
+
export function getReadyTasks(
|
|
67
|
+
graph: DerivedTaskNode[],
|
|
68
|
+
completed: Set<string>,
|
|
69
|
+
inFlight: Set<string>,
|
|
70
|
+
): string[] {
|
|
71
|
+
return graph
|
|
72
|
+
.filter((node) => {
|
|
73
|
+
if (node.done || completed.has(node.id) || inFlight.has(node.id)) return false;
|
|
74
|
+
return node.dependsOn.every((dep) => completed.has(dep));
|
|
75
|
+
})
|
|
76
|
+
.map((node) => node.id);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ─── Conflict-Free Subset Selection ──────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Greedy selection of non-conflicting tasks up to `maxParallel`.
|
|
83
|
+
*
|
|
84
|
+
* Two tasks conflict if they share any outputFile. We also exclude tasks
|
|
85
|
+
* whose outputs overlap with `inFlightOutputs` (files being written by
|
|
86
|
+
* tasks currently in progress).
|
|
87
|
+
*/
|
|
88
|
+
export function chooseNonConflictingSubset(
|
|
89
|
+
readyIds: string[],
|
|
90
|
+
graph: DerivedTaskNode[],
|
|
91
|
+
maxParallel: number,
|
|
92
|
+
inFlightOutputs: Set<string>,
|
|
93
|
+
): string[] {
|
|
94
|
+
const nodeMap = new Map(graph.map((n) => [n.id, n]));
|
|
95
|
+
const claimed = new Set(inFlightOutputs);
|
|
96
|
+
const selected: string[] = [];
|
|
97
|
+
|
|
98
|
+
for (const id of readyIds) {
|
|
99
|
+
if (selected.length >= maxParallel) break;
|
|
100
|
+
const node = nodeMap.get(id);
|
|
101
|
+
if (!node) continue;
|
|
102
|
+
|
|
103
|
+
// Check for output overlap with already-selected or in-flight
|
|
104
|
+
const conflicts = node.outputFiles.some((f) => claimed.has(f));
|
|
105
|
+
if (conflicts) continue;
|
|
106
|
+
|
|
107
|
+
// Claim this task's outputs
|
|
108
|
+
for (const f of node.outputFiles) claimed.add(f);
|
|
109
|
+
selected.push(id);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return selected;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ─── Graph Quality Checks ─────────────────────────────────────────────────
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns true if any incomplete task has 0 inputFiles AND 0 outputFiles.
|
|
119
|
+
*
|
|
120
|
+
* An ambiguous graph means IO annotations are too sparse to derive reliable
|
|
121
|
+
* edges — the dispatcher should fall back to sequential execution.
|
|
122
|
+
*/
|
|
123
|
+
export function isGraphAmbiguous(graph: DerivedTaskNode[]): boolean {
|
|
124
|
+
return graph.some(
|
|
125
|
+
(node) =>
|
|
126
|
+
!node.done &&
|
|
127
|
+
node.inputFiles.length === 0 &&
|
|
128
|
+
node.outputFiles.length === 0,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Detect deadlock: no tasks are ready and none are in-flight, yet incomplete
|
|
134
|
+
* tasks remain. This indicates a circular dependency or impossible state.
|
|
135
|
+
*/
|
|
136
|
+
export function detectDeadlock(
|
|
137
|
+
graph: DerivedTaskNode[],
|
|
138
|
+
completed: Set<string>,
|
|
139
|
+
inFlight: Set<string>,
|
|
140
|
+
): boolean {
|
|
141
|
+
const incomplete = graph.filter(
|
|
142
|
+
(n) => !n.done && !completed.has(n.id) && !inFlight.has(n.id),
|
|
143
|
+
);
|
|
144
|
+
if (incomplete.length === 0) return false; // all done
|
|
145
|
+
if (inFlight.size > 0) return false; // something is running, wait for it
|
|
146
|
+
|
|
147
|
+
// Nothing in flight, but incomplete tasks remain — check if any are ready
|
|
148
|
+
const ready = getReadyTasks(graph, completed, inFlight);
|
|
149
|
+
return ready.length === 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ─── Graph Metrics ────────────────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
/** Compute summary metrics for logging. */
|
|
155
|
+
export function graphMetrics(graph: DerivedTaskNode[]): {
|
|
156
|
+
taskCount: number;
|
|
157
|
+
edgeCount: number;
|
|
158
|
+
readySetSize: number;
|
|
159
|
+
ambiguous: boolean;
|
|
160
|
+
} {
|
|
161
|
+
const completed = new Set(graph.filter((n) => n.done).map((n) => n.id));
|
|
162
|
+
const ready = getReadyTasks(graph, completed, new Set());
|
|
163
|
+
const edgeCount = graph.reduce((sum, n) => sum + n.dependsOn.length, 0);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
taskCount: graph.length,
|
|
167
|
+
edgeCount,
|
|
168
|
+
readySetSize: ready.length,
|
|
169
|
+
ambiguous: isGraphAmbiguous(graph),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ─── IO Loader (async, filesystem) ────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Load TaskIO for all tasks in a slice by reading the slice plan (for done
|
|
177
|
+
* status and task IDs) and individual task plan files (for IO sections).
|
|
178
|
+
*
|
|
179
|
+
* Returns [] when the slice plan or tasks directory doesn't exist.
|
|
180
|
+
*/
|
|
181
|
+
export async function loadSliceTaskIO(
|
|
182
|
+
basePath: string,
|
|
183
|
+
mid: string,
|
|
184
|
+
sid: string,
|
|
185
|
+
): Promise<TaskIO[]> {
|
|
186
|
+
const { resolveSliceFile } = await import("./paths.js");
|
|
187
|
+
const slicePlanPath = resolveSliceFile(basePath, mid, sid, "PLAN");
|
|
188
|
+
const planContent = slicePlanPath ? await loadFile(slicePlanPath) : null;
|
|
189
|
+
if (!planContent) return [];
|
|
190
|
+
|
|
191
|
+
const plan = parsePlan(planContent);
|
|
192
|
+
const tDir = resolveTasksDir(basePath, mid, sid);
|
|
193
|
+
if (!tDir) return [];
|
|
194
|
+
|
|
195
|
+
const results: TaskIO[] = [];
|
|
196
|
+
|
|
197
|
+
for (const taskEntry of plan.tasks) {
|
|
198
|
+
const planFiles = resolveTaskFiles(tDir, "PLAN");
|
|
199
|
+
const taskFileName = planFiles.find((f) =>
|
|
200
|
+
f.toUpperCase().startsWith(taskEntry.id.toUpperCase() + "-"),
|
|
201
|
+
);
|
|
202
|
+
if (!taskFileName) {
|
|
203
|
+
// Task plan file missing — include with empty IO (will trigger ambiguous)
|
|
204
|
+
results.push({
|
|
205
|
+
id: taskEntry.id,
|
|
206
|
+
title: taskEntry.title,
|
|
207
|
+
inputFiles: [],
|
|
208
|
+
outputFiles: [],
|
|
209
|
+
done: taskEntry.done,
|
|
210
|
+
});
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const taskContent = await loadFile(join(tDir, taskFileName));
|
|
215
|
+
if (!taskContent) {
|
|
216
|
+
results.push({
|
|
217
|
+
id: taskEntry.id,
|
|
218
|
+
title: taskEntry.title,
|
|
219
|
+
inputFiles: [],
|
|
220
|
+
outputFiles: [],
|
|
221
|
+
done: taskEntry.done,
|
|
222
|
+
});
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const io = parseTaskPlanIO(taskContent);
|
|
227
|
+
results.push({
|
|
228
|
+
id: taskEntry.id,
|
|
229
|
+
title: taskEntry.title,
|
|
230
|
+
inputFiles: io.inputFiles,
|
|
231
|
+
outputFiles: io.outputFiles,
|
|
232
|
+
done: taskEntry.done,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return results;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ─── State Persistence ────────────────────────────────────────────────────
|
|
240
|
+
|
|
241
|
+
function reactiveStatePath(basePath: string, mid: string, sid: string): string {
|
|
242
|
+
return join(basePath, ".gsd", "runtime", `${mid}-${sid}-reactive.json`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function isReactiveState(data: unknown): data is ReactiveExecutionState {
|
|
246
|
+
if (!data || typeof data !== "object") return false;
|
|
247
|
+
const d = data as Record<string, unknown>;
|
|
248
|
+
return typeof d.sliceId === "string" && Array.isArray(d.completed) && Array.isArray(d.dispatched);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Load persisted reactive execution state for a slice.
|
|
253
|
+
* Returns null when no state file exists or the file is invalid.
|
|
254
|
+
*/
|
|
255
|
+
export function loadReactiveState(
|
|
256
|
+
basePath: string,
|
|
257
|
+
mid: string,
|
|
258
|
+
sid: string,
|
|
259
|
+
): ReactiveExecutionState | null {
|
|
260
|
+
return loadJsonFileOrNull(reactiveStatePath(basePath, mid, sid), isReactiveState);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Save reactive execution state to disk.
|
|
265
|
+
*/
|
|
266
|
+
export function saveReactiveState(
|
|
267
|
+
basePath: string,
|
|
268
|
+
mid: string,
|
|
269
|
+
sid: string,
|
|
270
|
+
state: ReactiveExecutionState,
|
|
271
|
+
): void {
|
|
272
|
+
saveJsonFile(reactiveStatePath(basePath, mid, sid), state);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Remove the reactive state file when a slice completes.
|
|
277
|
+
*/
|
|
278
|
+
export function clearReactiveState(
|
|
279
|
+
basePath: string,
|
|
280
|
+
mid: string,
|
|
281
|
+
sid: string,
|
|
282
|
+
): void {
|
|
283
|
+
const path = reactiveStatePath(basePath, mid, sid);
|
|
284
|
+
try {
|
|
285
|
+
if (existsSync(path)) unlinkSync(path);
|
|
286
|
+
} catch {
|
|
287
|
+
// Non-fatal
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -42,11 +42,19 @@ estimated_files: {{estimatedFiles}}
|
|
|
42
42
|
|
|
43
43
|
## Inputs
|
|
44
44
|
|
|
45
|
+
<!-- Every input MUST be a backtick-wrapped file path. These paths are machine-parsed to
|
|
46
|
+
derive task dependencies — vague descriptions without paths break dependency detection.
|
|
47
|
+
For the first task in a slice with no prior task outputs, list the existing source files
|
|
48
|
+
this task reads or modifies. -->
|
|
49
|
+
|
|
45
50
|
- `{{filePath}}` — {{whatThisTaskNeedsFromPriorWork}}
|
|
46
|
-
- {{priorTaskSummaryInsight}}
|
|
47
51
|
|
|
48
52
|
## Expected Output
|
|
49
53
|
|
|
50
|
-
<!--
|
|
54
|
+
<!-- Every output MUST be a backtick-wrapped file path — the specific files this task creates
|
|
55
|
+
or modifies. These paths are machine-parsed to derive task dependencies.
|
|
56
|
+
This task should produce a real increment toward making the slice goal/demo true. A full
|
|
57
|
+
slice plan should not be able to mark every task complete while the claimed slice behavior
|
|
58
|
+
still does not work at the stated proof level. -->
|
|
51
59
|
|
|
52
|
-
- `{{filePath}}` — {{
|
|
60
|
+
- `{{filePath}}` — {{whatThisTaskCreatesOrModifies}}
|
|
@@ -184,7 +184,7 @@ test("runProviderChecks detects Anthropic key from ANTHROPIC_API_KEY env var", (
|
|
|
184
184
|
// Isolate from real HOME so loadEffectiveGSDPreferences returns null (default → anthropic)
|
|
185
185
|
// and auth.json lookups hit an empty directory.
|
|
186
186
|
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-env-test-")));
|
|
187
|
-
withEnv({ ANTHROPIC_API_KEY: "sk-ant-test-key", HOME: tmpHome }, () => {
|
|
187
|
+
withEnv({ ANTHROPIC_API_KEY: "sk-ant-test-key", ANTHROPIC_OAUTH_TOKEN: undefined, HOME: tmpHome }, () => {
|
|
188
188
|
try {
|
|
189
189
|
const results = runProviderChecks();
|
|
190
190
|
const anthropic = results.find(r => r.name === "anthropic");
|
|
@@ -199,7 +199,15 @@ test("runProviderChecks detects Anthropic key from ANTHROPIC_API_KEY env var", (
|
|
|
199
199
|
|
|
200
200
|
test("runProviderChecks returns error for Anthropic when no key present", () => {
|
|
201
201
|
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-test-")));
|
|
202
|
-
withEnv({
|
|
202
|
+
withEnv({
|
|
203
|
+
ANTHROPIC_API_KEY: undefined,
|
|
204
|
+
ANTHROPIC_OAUTH_TOKEN: undefined,
|
|
205
|
+
// Clear cross-provider routing env vars (GitHub Copilot can serve Claude models)
|
|
206
|
+
COPILOT_GITHUB_TOKEN: undefined,
|
|
207
|
+
GH_TOKEN: undefined,
|
|
208
|
+
GITHUB_TOKEN: undefined,
|
|
209
|
+
HOME: tmpHome,
|
|
210
|
+
}, () => {
|
|
203
211
|
try {
|
|
204
212
|
const results = runProviderChecks();
|
|
205
213
|
const anthropic = results.find(r => r.name === "anthropic");
|
|
@@ -275,7 +283,7 @@ test("runProviderChecks detects key from auth.json", () => {
|
|
|
275
283
|
});
|
|
276
284
|
|
|
277
285
|
test("runProviderChecks ignores empty placeholder keys in auth.json", () => {
|
|
278
|
-
withEnv({ ANTHROPIC_API_KEY: undefined }, () => {
|
|
286
|
+
withEnv({ ANTHROPIC_API_KEY: undefined, ANTHROPIC_OAUTH_TOKEN: undefined, COPILOT_GITHUB_TOKEN: undefined, GH_TOKEN: undefined, GITHUB_TOKEN: undefined }, () => {
|
|
279
287
|
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-test-")));
|
|
280
288
|
const agentDir = join(tmpHome, ".gsd", "agent");
|
|
281
289
|
mkdirSync(agentDir, { recursive: true });
|
|
@@ -296,3 +304,100 @@ test("runProviderChecks ignores empty placeholder keys in auth.json", () => {
|
|
|
296
304
|
rmSync(tmpHome, { recursive: true, force: true });
|
|
297
305
|
});
|
|
298
306
|
});
|
|
307
|
+
|
|
308
|
+
// ─── runProviderChecks — cross-provider routing ──────────────────────────────
|
|
309
|
+
|
|
310
|
+
test("runProviderChecks reports ok for Anthropic when GitHub Copilot env var is set", () => {
|
|
311
|
+
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-copilot-test-")));
|
|
312
|
+
withEnv({
|
|
313
|
+
ANTHROPIC_API_KEY: undefined,
|
|
314
|
+
ANTHROPIC_OAUTH_TOKEN: undefined,
|
|
315
|
+
COPILOT_GITHUB_TOKEN: "ghu_copilot-token",
|
|
316
|
+
GH_TOKEN: undefined,
|
|
317
|
+
GITHUB_TOKEN: undefined,
|
|
318
|
+
HOME: tmpHome,
|
|
319
|
+
}, () => {
|
|
320
|
+
try {
|
|
321
|
+
const results = runProviderChecks();
|
|
322
|
+
const anthropic = results.find(r => r.name === "anthropic");
|
|
323
|
+
assert.ok(anthropic, "anthropic result should exist");
|
|
324
|
+
assert.equal(anthropic!.status, "ok", "should be ok when Copilot auth is available");
|
|
325
|
+
assert.ok(anthropic!.message.includes("GitHub Copilot"), "should mention cross-provider source");
|
|
326
|
+
} finally {
|
|
327
|
+
rmSync(tmpHome, { recursive: true, force: true });
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("runProviderChecks reports ok for Anthropic via GITHUB_TOKEN cross-provider routing", () => {
|
|
333
|
+
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-ghtoken-test-")));
|
|
334
|
+
withEnv({
|
|
335
|
+
ANTHROPIC_API_KEY: undefined,
|
|
336
|
+
ANTHROPIC_OAUTH_TOKEN: undefined,
|
|
337
|
+
COPILOT_GITHUB_TOKEN: undefined,
|
|
338
|
+
GH_TOKEN: undefined,
|
|
339
|
+
GITHUB_TOKEN: "ghp_github-token",
|
|
340
|
+
HOME: tmpHome,
|
|
341
|
+
}, () => {
|
|
342
|
+
try {
|
|
343
|
+
const results = runProviderChecks();
|
|
344
|
+
const anthropic = results.find(r => r.name === "anthropic");
|
|
345
|
+
assert.ok(anthropic, "anthropic result should exist");
|
|
346
|
+
assert.equal(anthropic!.status, "ok", "should be ok when GITHUB_TOKEN provides Copilot access");
|
|
347
|
+
} finally {
|
|
348
|
+
rmSync(tmpHome, { recursive: true, force: true });
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("runProviderChecks detects ANTHROPIC_OAUTH_TOKEN as valid Anthropic auth", () => {
|
|
354
|
+
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-oauth-test-")));
|
|
355
|
+
withEnv({
|
|
356
|
+
ANTHROPIC_API_KEY: undefined,
|
|
357
|
+
ANTHROPIC_OAUTH_TOKEN: "oauth-token-test",
|
|
358
|
+
COPILOT_GITHUB_TOKEN: undefined,
|
|
359
|
+
GH_TOKEN: undefined,
|
|
360
|
+
GITHUB_TOKEN: undefined,
|
|
361
|
+
HOME: tmpHome,
|
|
362
|
+
}, () => {
|
|
363
|
+
try {
|
|
364
|
+
const results = runProviderChecks();
|
|
365
|
+
const anthropic = results.find(r => r.name === "anthropic");
|
|
366
|
+
assert.ok(anthropic, "anthropic result should exist");
|
|
367
|
+
assert.equal(anthropic!.status, "ok", "should be ok when ANTHROPIC_OAUTH_TOKEN is set");
|
|
368
|
+
assert.ok(anthropic!.message.includes("env"), "should report env source");
|
|
369
|
+
} finally {
|
|
370
|
+
rmSync(tmpHome, { recursive: true, force: true });
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("runProviderChecks reports ok via Copilot auth.json for Anthropic", () => {
|
|
376
|
+
withEnv({
|
|
377
|
+
ANTHROPIC_API_KEY: undefined,
|
|
378
|
+
ANTHROPIC_OAUTH_TOKEN: undefined,
|
|
379
|
+
COPILOT_GITHUB_TOKEN: undefined,
|
|
380
|
+
GH_TOKEN: undefined,
|
|
381
|
+
GITHUB_TOKEN: undefined,
|
|
382
|
+
}, () => {
|
|
383
|
+
const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-copilot-auth-test-")));
|
|
384
|
+
const agentDir = join(tmpHome, ".gsd", "agent");
|
|
385
|
+
mkdirSync(agentDir, { recursive: true });
|
|
386
|
+
|
|
387
|
+
// GitHub Copilot OAuth in auth.json
|
|
388
|
+
const authData = {
|
|
389
|
+
"github-copilot": { type: "oauth", apiKey: "ghu_copilot-key", expires: Date.now() + 3_600_000 },
|
|
390
|
+
};
|
|
391
|
+
writeFileSync(join(agentDir, "auth.json"), JSON.stringify(authData));
|
|
392
|
+
|
|
393
|
+
withEnv({ HOME: tmpHome }, () => {
|
|
394
|
+
const results = runProviderChecks();
|
|
395
|
+
const anthropic = results.find(r => r.name === "anthropic");
|
|
396
|
+
assert.ok(anthropic, "anthropic result should exist");
|
|
397
|
+
assert.equal(anthropic!.status, "ok", "should be ok when Copilot is authenticated in auth.json");
|
|
398
|
+
assert.ok(anthropic!.message.includes("GitHub Copilot"), "should mention Copilot as source");
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
rmSync(tmpHome, { recursive: true, force: true });
|
|
402
|
+
});
|
|
403
|
+
});
|