pi-crew 0.1.30 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +80 -27
- package/agents/analyst.md +11 -11
- package/agents/critic.md +11 -11
- package/agents/executor.md +11 -11
- package/agents/explorer.md +11 -11
- package/agents/planner.md +11 -11
- package/agents/reviewer.md +11 -11
- package/agents/security-reviewer.md +11 -11
- package/agents/test-engineer.md +11 -11
- package/agents/verifier.md +11 -11
- package/agents/writer.md +11 -11
- package/docs/architecture.md +173 -164
- package/docs/refactor-tasks-phase3.md +394 -394
- package/docs/refactor-tasks-phase4.md +564 -564
- package/docs/refactor-tasks-phase5.md +402 -402
- package/docs/refactor-tasks-phase6.md +662 -662
- package/docs/research-extension-examples.md +297 -0
- package/docs/research-extension-system.md +324 -0
- package/docs/research-optimization-plan.md +548 -0
- package/docs/research-pi-coding-agent.md +357 -0
- package/docs/resource-formats.md +4 -3
- package/docs/runtime-flow.md +148 -148
- package/docs/source-runtime-refactor-map.md +83 -83
- package/docs/usage.md +3 -3
- package/index.ts +6 -6
- package/package.json +1 -1
- package/schema.json +53 -1
- package/skills/git-master/SKILL.md +24 -19
- package/skills/read-only-explorer/SKILL.md +26 -21
- package/skills/safe-bash/SKILL.md +21 -16
- package/skills/task-packet/SKILL.md +28 -23
- package/skills/verify-evidence/SKILL.md +27 -22
- package/src/agents/agent-serializer.ts +34 -34
- package/src/agents/discover-agents.ts +102 -102
- package/src/config/config.ts +14 -1
- package/src/config/defaults.ts +3 -2
- package/src/extension/cross-extension-rpc.ts +82 -82
- package/src/extension/import-index.ts +4 -3
- package/src/extension/management.ts +2 -2
- package/src/extension/project-init.ts +9 -7
- package/src/extension/register.ts +63 -0
- package/src/extension/registration/artifact-cleanup.ts +15 -14
- package/src/extension/registration/commands.ts +208 -208
- package/src/extension/registration/compaction-guard.ts +125 -0
- package/src/extension/registration/subagent-tools.ts +27 -8
- package/src/extension/registration/team-tool.ts +61 -44
- package/src/extension/result-watcher.ts +98 -98
- package/src/extension/run-import.ts +4 -4
- package/src/extension/run-index.ts +14 -14
- package/src/extension/run-maintenance.ts +24 -24
- package/src/extension/team-tool/api.ts +3 -0
- package/src/extension/team-tool/cancel.ts +31 -31
- package/src/extension/team-tool/doctor.ts +179 -178
- package/src/extension/team-tool/inspect.ts +41 -41
- package/src/extension/team-tool/lifecycle-actions.ts +79 -79
- package/src/extension/team-tool/plan.ts +19 -19
- package/src/extension/team-tool/status.ts +73 -73
- package/src/prompt/prompt-runtime.ts +68 -68
- package/src/runtime/agent-control.ts +64 -64
- package/src/runtime/agent-memory.ts +72 -72
- package/src/runtime/agent-observability.ts +113 -113
- package/src/runtime/async-marker.ts +26 -26
- package/src/runtime/background-runner.ts +53 -53
- package/src/runtime/crew-agent-runtime.ts +58 -58
- package/src/runtime/direct-run.ts +35 -35
- package/src/runtime/foreground-control.ts +82 -82
- package/src/runtime/green-contract.ts +46 -46
- package/src/runtime/group-join.ts +88 -88
- package/src/runtime/live-agent-control.ts +78 -78
- package/src/runtime/live-agent-manager.ts +85 -85
- package/src/runtime/live-control-realtime.ts +36 -36
- package/src/runtime/live-session-runtime.ts +299 -299
- package/src/runtime/manifest-cache.ts +212 -214
- package/src/runtime/model-fallback.ts +261 -261
- package/src/runtime/parallel-research.ts +44 -44
- package/src/runtime/parallel-utils.ts +99 -99
- package/src/runtime/pi-json-output.ts +111 -111
- package/src/runtime/pi-spawn.ts +96 -96
- package/src/runtime/policy-engine.ts +78 -78
- package/src/runtime/post-exit-stdio-guard.ts +86 -86
- package/src/runtime/process-status.ts +56 -56
- package/src/runtime/progress-event-coalescer.ts +43 -43
- package/src/runtime/recovery-recipes.ts +74 -74
- package/src/runtime/role-permission.ts +39 -39
- package/src/runtime/session-usage.ts +79 -79
- package/src/runtime/sidechain-output.ts +28 -28
- package/src/runtime/subagent-manager.ts +29 -2
- package/src/runtime/task-display.ts +38 -38
- package/src/runtime/task-output-context.ts +106 -106
- package/src/runtime/task-packet.ts +84 -84
- package/src/runtime/task-runner/live-executor.ts +98 -98
- package/src/runtime/task-runner/progress.ts +111 -111
- package/src/runtime/task-runner/prompt-builder.ts +72 -72
- package/src/runtime/task-runner/result-utils.ts +14 -14
- package/src/runtime/task-runner/state-helpers.ts +22 -22
- package/src/runtime/worker-heartbeat.ts +21 -21
- package/src/runtime/worker-startup.ts +57 -57
- package/src/schema/config-schema.ts +12 -0
- package/src/schema/team-tool-schema.ts +100 -100
- package/src/state/artifact-store.ts +108 -108
- package/src/state/contracts.ts +105 -105
- package/src/state/jsonl-writer.ts +77 -77
- package/src/state/state-store.ts +8 -9
- package/src/state/task-claims.ts +42 -42
- package/src/state/types.ts +180 -180
- package/src/state/usage.ts +29 -29
- package/src/subagents/async-entry.ts +1 -1
- package/src/subagents/index.ts +3 -3
- package/src/subagents/live/control.ts +1 -1
- package/src/subagents/live/manager.ts +1 -1
- package/src/subagents/live/realtime.ts +1 -1
- package/src/subagents/live/session-runtime.ts +1 -1
- package/src/subagents/manager.ts +1 -1
- package/src/subagents/spawn.ts +1 -1
- package/src/teams/discover-teams.ts +2 -2
- package/src/teams/team-serializer.ts +36 -36
- package/src/types/diff.d.ts +18 -0
- package/src/ui/crew-footer.ts +101 -101
- package/src/ui/crew-select-list.ts +111 -111
- package/src/ui/crew-widget.ts +285 -285
- package/src/ui/dynamic-border.ts +25 -25
- package/src/ui/layout-primitives.ts +106 -106
- package/src/ui/loaders.ts +158 -158
- package/src/ui/mascot.ts +441 -441
- package/src/ui/powerbar-publisher.ts +94 -94
- package/src/ui/render-diff.ts +119 -119
- package/src/ui/run-dashboard.ts +372 -372
- package/src/ui/status-colors.ts +54 -54
- package/src/ui/syntax-highlight.ts +116 -116
- package/src/ui/transcript-viewer.ts +302 -302
- package/src/utils/completion-dedupe.ts +63 -63
- package/src/utils/file-coalescer.ts +84 -84
- package/src/utils/frontmatter.ts +36 -36
- package/src/utils/fs-watch.ts +31 -31
- package/src/utils/git.ts +262 -262
- package/src/utils/ids.ts +12 -12
- package/src/utils/names.ts +26 -26
- package/src/utils/paths.ts +34 -7
- package/src/utils/sleep.ts +32 -32
- package/src/utils/timings.ts +31 -31
- package/src/utils/visual.ts +159 -159
- package/src/workflows/discover-workflows.ts +2 -2
- package/src/workflows/validate-workflow.ts +40 -40
- package/src/worktree/branch-freshness.ts +45 -45
- package/src/worktree/cleanup.ts +71 -69
- package/src/worktree/worktree-manager.ts +3 -1
- package/teams/default.team.md +12 -12
- package/teams/fast-fix.team.md +11 -11
- package/teams/implementation.team.md +18 -18
- package/teams/parallel-research.team.md +14 -14
- package/teams/research.team.md +11 -11
- package/teams/review.team.md +12 -12
- package/workflows/default.workflow.md +29 -29
- package/workflows/fast-fix.workflow.md +22 -22
- package/workflows/implementation.workflow.md +38 -38
- package/workflows/parallel-research.workflow.md +46 -46
- package/workflows/research.workflow.md +22 -22
- package/workflows/review.workflow.md +30 -30
package/src/utils/sleep.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sleep helper that respects abort signal.
|
|
3
|
-
*/
|
|
4
|
-
export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
if (signal?.aborted) {
|
|
7
|
-
reject(new Error("Aborted"));
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let settled = false;
|
|
12
|
-
const cleanup = (): void => {
|
|
13
|
-
if (signal) signal.removeEventListener("abort", onAbort);
|
|
14
|
-
};
|
|
15
|
-
const timeout = setTimeout(() => {
|
|
16
|
-
if (settled) return;
|
|
17
|
-
settled = true;
|
|
18
|
-
cleanup();
|
|
19
|
-
resolve();
|
|
20
|
-
}, ms);
|
|
21
|
-
|
|
22
|
-
const onAbort = (): void => {
|
|
23
|
-
if (settled) return;
|
|
24
|
-
settled = true;
|
|
25
|
-
clearTimeout(timeout);
|
|
26
|
-
cleanup();
|
|
27
|
-
reject(new Error("Aborted"));
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
signal?.addEventListener("abort", onAbort);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Sleep helper that respects abort signal.
|
|
3
|
+
*/
|
|
4
|
+
export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
if (signal?.aborted) {
|
|
7
|
+
reject(new Error("Aborted"));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let settled = false;
|
|
12
|
+
const cleanup = (): void => {
|
|
13
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
14
|
+
};
|
|
15
|
+
const timeout = setTimeout(() => {
|
|
16
|
+
if (settled) return;
|
|
17
|
+
settled = true;
|
|
18
|
+
cleanup();
|
|
19
|
+
resolve();
|
|
20
|
+
}, ms);
|
|
21
|
+
|
|
22
|
+
const onAbort = (): void => {
|
|
23
|
+
if (settled) return;
|
|
24
|
+
settled = true;
|
|
25
|
+
clearTimeout(timeout);
|
|
26
|
+
cleanup();
|
|
27
|
+
reject(new Error("Aborted"));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
signal?.addEventListener("abort", onAbort);
|
|
31
|
+
});
|
|
32
|
+
}
|
package/src/utils/timings.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Central timing instrumentation for startup profiling.
|
|
3
|
-
* Enable with PI_TIMING=1 environment variable.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const ENABLED = process.env.PI_TIMING === "1";
|
|
7
|
-
const timings: Array<{ label: string; ms: number }> = [];
|
|
8
|
-
let lastTime = Date.now();
|
|
9
|
-
|
|
10
|
-
export function resetTimings(): void {
|
|
11
|
-
if (!ENABLED) return;
|
|
12
|
-
timings.length = 0;
|
|
13
|
-
lastTime = Date.now();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function time(label: string): void {
|
|
17
|
-
if (!ENABLED) return;
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
timings.push({ label, ms: now - lastTime });
|
|
20
|
-
lastTime = now;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function printTimings(): void {
|
|
24
|
-
if (!ENABLED || timings.length === 0) return;
|
|
25
|
-
console.error("\n--- Startup Timings ---");
|
|
26
|
-
for (const t of timings) {
|
|
27
|
-
console.error(` ${t.label}: ${t.ms}ms`);
|
|
28
|
-
}
|
|
29
|
-
console.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);
|
|
30
|
-
console.error("------------------------\n");
|
|
31
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Central timing instrumentation for startup profiling.
|
|
3
|
+
* Enable with PI_TIMING=1 environment variable.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const ENABLED = process.env.PI_TIMING === "1";
|
|
7
|
+
const timings: Array<{ label: string; ms: number }> = [];
|
|
8
|
+
let lastTime = Date.now();
|
|
9
|
+
|
|
10
|
+
export function resetTimings(): void {
|
|
11
|
+
if (!ENABLED) return;
|
|
12
|
+
timings.length = 0;
|
|
13
|
+
lastTime = Date.now();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function time(label: string): void {
|
|
17
|
+
if (!ENABLED) return;
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
timings.push({ label, ms: now - lastTime });
|
|
20
|
+
lastTime = now;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function printTimings(): void {
|
|
24
|
+
if (!ENABLED || timings.length === 0) return;
|
|
25
|
+
console.error("\n--- Startup Timings ---");
|
|
26
|
+
for (const t of timings) {
|
|
27
|
+
console.error(` ${t.label}: ${t.ms}ms`);
|
|
28
|
+
}
|
|
29
|
+
console.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);
|
|
30
|
+
console.error("------------------------\n");
|
|
31
|
+
}
|
package/src/utils/visual.ts
CHANGED
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
export const ANSI_PATTERN = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
2
|
-
|
|
3
|
-
const WIDTH_CACHE_LIMIT = 256;
|
|
4
|
-
const widthCache = new Map<string, number>();
|
|
5
|
-
|
|
6
|
-
export function visibleWidth(value: string): number {
|
|
7
|
-
const cached = widthCache.get(value);
|
|
8
|
-
if (cached !== undefined) return cached;
|
|
9
|
-
let length = 0;
|
|
10
|
-
for (const char of value.replace(ANSI_PATTERN, "")) {
|
|
11
|
-
if (char !== "\n") length += 1;
|
|
12
|
-
}
|
|
13
|
-
if (widthCache.size >= WIDTH_CACHE_LIMIT) {
|
|
14
|
-
const firstKey = widthCache.keys().next().value;
|
|
15
|
-
if (firstKey !== undefined) widthCache.delete(firstKey);
|
|
16
|
-
}
|
|
17
|
-
widthCache.set(value, length);
|
|
18
|
-
return length;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function __test__clearVisibleWidthCache(): void {
|
|
22
|
-
widthCache.clear();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function __test__visibleWidthCacheSize(): number {
|
|
26
|
-
return widthCache.size;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function consumeAnsi(input: string, index: number): number {
|
|
30
|
-
const char = input[index];
|
|
31
|
-
if (!char || char !== "\u001b") return 0;
|
|
32
|
-
if (input[index + 1] !== "[") return 0;
|
|
33
|
-
let i = index + 2;
|
|
34
|
-
while (i < input.length) {
|
|
35
|
-
const code = input.charCodeAt(i);
|
|
36
|
-
if (code >= 0x40 && code <= 0x7e) return i - index + 1;
|
|
37
|
-
i++;
|
|
38
|
-
}
|
|
39
|
-
return 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function splitGraphemes(value: string): string[] {
|
|
43
|
-
return Array.from(value.replace(ANSI_PATTERN, ""));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function truncateToWidth(value: string, width: number, ellipsis = "…"): string {
|
|
47
|
-
if (width <= 0) return "";
|
|
48
|
-
if (visibleWidth(value) <= width) return value;
|
|
49
|
-
if (width <= ellipsis.length) return ellipsis.slice(0, width);
|
|
50
|
-
let output = "";
|
|
51
|
-
let renderedWidth = 0;
|
|
52
|
-
for (let i = 0; i < value.length; i++) {
|
|
53
|
-
const ansiLen = consumeAnsi(value, i);
|
|
54
|
-
if (ansiLen) {
|
|
55
|
-
output += value.slice(i, i + ansiLen);
|
|
56
|
-
i += ansiLen - 1;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const char = value[i] as string;
|
|
60
|
-
const nextIndex = i + (char.codePointAt(0) ?? 0) > 0xFFFF ? i + 2 : i + 1;
|
|
61
|
-
const segment = value.slice(i, nextIndex);
|
|
62
|
-
const charWidth = visibleWidth(segment);
|
|
63
|
-
if (renderedWidth + charWidth > width - ellipsis.length) {
|
|
64
|
-
return `${output}${ellipsis}`;
|
|
65
|
-
}
|
|
66
|
-
output += segment;
|
|
67
|
-
renderedWidth += charWidth;
|
|
68
|
-
i = nextIndex - 1;
|
|
69
|
-
}
|
|
70
|
-
return output;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const truncate = truncateToWidth;
|
|
74
|
-
|
|
75
|
-
export function pad(value: string, width: number): string {
|
|
76
|
-
const current = visibleWidth(value);
|
|
77
|
-
if (current >= width) return value;
|
|
78
|
-
return `${value}${" ".repeat(width - current)}`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function boxLine(text: string, innerWidth: number): string {
|
|
82
|
-
return `│ ${truncate(text, innerWidth - 4)} │`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function readAnsiCode(input: string, index: number): string | undefined {
|
|
86
|
-
const ansiLength = consumeAnsi(input, index);
|
|
87
|
-
if (ansiLength > 0) return input.slice(index, index + ansiLength);
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function takeCodePoint(input: string, index: number): { chunk: string; nextIndex: number } {
|
|
92
|
-
const code = input.codePointAt(index);
|
|
93
|
-
if (code === undefined) return { chunk: "", nextIndex: index + 1 };
|
|
94
|
-
if (code >= 0xD800 && code <= 0xDBFF && index + 1 < input.length) {
|
|
95
|
-
return { chunk: input.slice(index, index + 2), nextIndex: index + 2 };
|
|
96
|
-
}
|
|
97
|
-
return { chunk: input[index] ?? "", nextIndex: index + 1 };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function wrapHard(value: string, width: number): string[] {
|
|
101
|
-
if (width <= 0 || !value) return [];
|
|
102
|
-
const lines: string[] = [];
|
|
103
|
-
let current = "";
|
|
104
|
-
let currentWidth = 0;
|
|
105
|
-
let i = 0;
|
|
106
|
-
while (i < value.length) {
|
|
107
|
-
const ansi = readAnsiCode(value, i);
|
|
108
|
-
if (ansi) {
|
|
109
|
-
current += ansi;
|
|
110
|
-
i += ansi.length;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const { chunk, nextIndex } = takeCodePoint(value, i);
|
|
114
|
-
const chunkWidth = visibleWidth(chunk);
|
|
115
|
-
if (chunkWidth > width) {
|
|
116
|
-
lines.push(current ? current + chunk : chunk);
|
|
117
|
-
current = "";
|
|
118
|
-
currentWidth = 0;
|
|
119
|
-
i = nextIndex;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (currentWidth + chunkWidth > width) {
|
|
123
|
-
if (current) lines.push(current);
|
|
124
|
-
current = chunk;
|
|
125
|
-
currentWidth = chunkWidth;
|
|
126
|
-
i = nextIndex;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
current += chunk;
|
|
130
|
-
currentWidth += chunkWidth;
|
|
131
|
-
i = nextIndex;
|
|
132
|
-
}
|
|
133
|
-
if (current) lines.push(current);
|
|
134
|
-
return lines.length > 0 ? lines : [""];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface VisualTruncateResult {
|
|
138
|
-
visualLines: string[];
|
|
139
|
-
skippedCount: number;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function truncateToVisualLines(
|
|
143
|
-
text: string,
|
|
144
|
-
maxVisualLines: number,
|
|
145
|
-
width: number,
|
|
146
|
-
paddingX = 0,
|
|
147
|
-
): VisualTruncateResult {
|
|
148
|
-
if (!text) {
|
|
149
|
-
return { visualLines: [], skippedCount: 0 };
|
|
150
|
-
}
|
|
151
|
-
const effectiveWidth = Math.max(1, width - paddingX * 2);
|
|
152
|
-
const limit = Math.max(1, maxVisualLines);
|
|
153
|
-
const visualLines = text
|
|
154
|
-
.split("\n")
|
|
155
|
-
.flatMap((line) => wrapHard(pad(line, Math.max(0, effectiveWidth)).trimEnd(), effectiveWidth));
|
|
156
|
-
if (visualLines.length <= limit) return { visualLines, skippedCount: 0 };
|
|
157
|
-
const truncated = visualLines.slice(-limit);
|
|
158
|
-
return { visualLines: truncated, skippedCount: visualLines.length - limit };
|
|
159
|
-
}
|
|
1
|
+
export const ANSI_PATTERN = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
2
|
+
|
|
3
|
+
const WIDTH_CACHE_LIMIT = 256;
|
|
4
|
+
const widthCache = new Map<string, number>();
|
|
5
|
+
|
|
6
|
+
export function visibleWidth(value: string): number {
|
|
7
|
+
const cached = widthCache.get(value);
|
|
8
|
+
if (cached !== undefined) return cached;
|
|
9
|
+
let length = 0;
|
|
10
|
+
for (const char of value.replace(ANSI_PATTERN, "")) {
|
|
11
|
+
if (char !== "\n") length += 1;
|
|
12
|
+
}
|
|
13
|
+
if (widthCache.size >= WIDTH_CACHE_LIMIT) {
|
|
14
|
+
const firstKey = widthCache.keys().next().value;
|
|
15
|
+
if (firstKey !== undefined) widthCache.delete(firstKey);
|
|
16
|
+
}
|
|
17
|
+
widthCache.set(value, length);
|
|
18
|
+
return length;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function __test__clearVisibleWidthCache(): void {
|
|
22
|
+
widthCache.clear();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function __test__visibleWidthCacheSize(): number {
|
|
26
|
+
return widthCache.size;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function consumeAnsi(input: string, index: number): number {
|
|
30
|
+
const char = input[index];
|
|
31
|
+
if (!char || char !== "\u001b") return 0;
|
|
32
|
+
if (input[index + 1] !== "[") return 0;
|
|
33
|
+
let i = index + 2;
|
|
34
|
+
while (i < input.length) {
|
|
35
|
+
const code = input.charCodeAt(i);
|
|
36
|
+
if (code >= 0x40 && code <= 0x7e) return i - index + 1;
|
|
37
|
+
i++;
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function splitGraphemes(value: string): string[] {
|
|
43
|
+
return Array.from(value.replace(ANSI_PATTERN, ""));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function truncateToWidth(value: string, width: number, ellipsis = "…"): string {
|
|
47
|
+
if (width <= 0) return "";
|
|
48
|
+
if (visibleWidth(value) <= width) return value;
|
|
49
|
+
if (width <= ellipsis.length) return ellipsis.slice(0, width);
|
|
50
|
+
let output = "";
|
|
51
|
+
let renderedWidth = 0;
|
|
52
|
+
for (let i = 0; i < value.length; i++) {
|
|
53
|
+
const ansiLen = consumeAnsi(value, i);
|
|
54
|
+
if (ansiLen) {
|
|
55
|
+
output += value.slice(i, i + ansiLen);
|
|
56
|
+
i += ansiLen - 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const char = value[i] as string;
|
|
60
|
+
const nextIndex = i + (char.codePointAt(0) ?? 0) > 0xFFFF ? i + 2 : i + 1;
|
|
61
|
+
const segment = value.slice(i, nextIndex);
|
|
62
|
+
const charWidth = visibleWidth(segment);
|
|
63
|
+
if (renderedWidth + charWidth > width - ellipsis.length) {
|
|
64
|
+
return `${output}${ellipsis}`;
|
|
65
|
+
}
|
|
66
|
+
output += segment;
|
|
67
|
+
renderedWidth += charWidth;
|
|
68
|
+
i = nextIndex - 1;
|
|
69
|
+
}
|
|
70
|
+
return output;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const truncate = truncateToWidth;
|
|
74
|
+
|
|
75
|
+
export function pad(value: string, width: number): string {
|
|
76
|
+
const current = visibleWidth(value);
|
|
77
|
+
if (current >= width) return value;
|
|
78
|
+
return `${value}${" ".repeat(width - current)}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function boxLine(text: string, innerWidth: number): string {
|
|
82
|
+
return `│ ${truncate(text, innerWidth - 4)} │`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function readAnsiCode(input: string, index: number): string | undefined {
|
|
86
|
+
const ansiLength = consumeAnsi(input, index);
|
|
87
|
+
if (ansiLength > 0) return input.slice(index, index + ansiLength);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function takeCodePoint(input: string, index: number): { chunk: string; nextIndex: number } {
|
|
92
|
+
const code = input.codePointAt(index);
|
|
93
|
+
if (code === undefined) return { chunk: "", nextIndex: index + 1 };
|
|
94
|
+
if (code >= 0xD800 && code <= 0xDBFF && index + 1 < input.length) {
|
|
95
|
+
return { chunk: input.slice(index, index + 2), nextIndex: index + 2 };
|
|
96
|
+
}
|
|
97
|
+
return { chunk: input[index] ?? "", nextIndex: index + 1 };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function wrapHard(value: string, width: number): string[] {
|
|
101
|
+
if (width <= 0 || !value) return [];
|
|
102
|
+
const lines: string[] = [];
|
|
103
|
+
let current = "";
|
|
104
|
+
let currentWidth = 0;
|
|
105
|
+
let i = 0;
|
|
106
|
+
while (i < value.length) {
|
|
107
|
+
const ansi = readAnsiCode(value, i);
|
|
108
|
+
if (ansi) {
|
|
109
|
+
current += ansi;
|
|
110
|
+
i += ansi.length;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const { chunk, nextIndex } = takeCodePoint(value, i);
|
|
114
|
+
const chunkWidth = visibleWidth(chunk);
|
|
115
|
+
if (chunkWidth > width) {
|
|
116
|
+
lines.push(current ? current + chunk : chunk);
|
|
117
|
+
current = "";
|
|
118
|
+
currentWidth = 0;
|
|
119
|
+
i = nextIndex;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (currentWidth + chunkWidth > width) {
|
|
123
|
+
if (current) lines.push(current);
|
|
124
|
+
current = chunk;
|
|
125
|
+
currentWidth = chunkWidth;
|
|
126
|
+
i = nextIndex;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
current += chunk;
|
|
130
|
+
currentWidth += chunkWidth;
|
|
131
|
+
i = nextIndex;
|
|
132
|
+
}
|
|
133
|
+
if (current) lines.push(current);
|
|
134
|
+
return lines.length > 0 ? lines : [""];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface VisualTruncateResult {
|
|
138
|
+
visualLines: string[];
|
|
139
|
+
skippedCount: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function truncateToVisualLines(
|
|
143
|
+
text: string,
|
|
144
|
+
maxVisualLines: number,
|
|
145
|
+
width: number,
|
|
146
|
+
paddingX = 0,
|
|
147
|
+
): VisualTruncateResult {
|
|
148
|
+
if (!text) {
|
|
149
|
+
return { visualLines: [], skippedCount: 0 };
|
|
150
|
+
}
|
|
151
|
+
const effectiveWidth = Math.max(1, width - paddingX * 2);
|
|
152
|
+
const limit = Math.max(1, maxVisualLines);
|
|
153
|
+
const visualLines = text
|
|
154
|
+
.split("\n")
|
|
155
|
+
.flatMap((line) => wrapHard(pad(line, Math.max(0, effectiveWidth)).trimEnd(), effectiveWidth));
|
|
156
|
+
if (visualLines.length <= limit) return { visualLines, skippedCount: 0 };
|
|
157
|
+
const truncated = visualLines.slice(-limit);
|
|
158
|
+
return { visualLines: truncated, skippedCount: visualLines.length - limit };
|
|
159
|
+
}
|
|
@@ -2,7 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import type { ResourceSource } from "../agents/agent-config.ts";
|
|
4
4
|
import { parseCsv, parseFrontmatter } from "../utils/frontmatter.ts";
|
|
5
|
-
import { packageRoot,
|
|
5
|
+
import { packageRoot, projectCrewRoot, userPiRoot } from "../utils/paths.ts";
|
|
6
6
|
import type { WorkflowConfig, WorkflowStep } from "./workflow-config.ts";
|
|
7
7
|
|
|
8
8
|
export interface WorkflowDiscoveryResult {
|
|
@@ -96,7 +96,7 @@ export function discoverWorkflows(cwd: string): WorkflowDiscoveryResult {
|
|
|
96
96
|
return {
|
|
97
97
|
builtin: readWorkflowDir(path.join(packageRoot(), "workflows"), "builtin"),
|
|
98
98
|
user: readWorkflowDir(path.join(userPiRoot(), "workflows"), "user"),
|
|
99
|
-
project: readWorkflowDir(path.join(
|
|
99
|
+
project: readWorkflowDir(path.join(projectCrewRoot(cwd), "workflows"), "project"),
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import type { TeamConfig } from "../teams/team-config.ts";
|
|
2
|
-
import type { WorkflowConfig } from "./workflow-config.ts";
|
|
3
|
-
|
|
4
|
-
export function validateWorkflowForTeam(workflow: WorkflowConfig, team: TeamConfig): string[] {
|
|
5
|
-
const errors: string[] = [];
|
|
6
|
-
const roles = new Set(team.roles.map((role) => role.name));
|
|
7
|
-
const stepIds = new Set<string>();
|
|
8
|
-
|
|
9
|
-
for (const step of workflow.steps) {
|
|
10
|
-
if (stepIds.has(step.id)) errors.push(`Duplicate workflow step id '${step.id}'.`);
|
|
11
|
-
stepIds.add(step.id);
|
|
12
|
-
if (!roles.has(step.role)) errors.push(`Step '${step.id}' references unknown team role '${step.role}'.`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
for (const step of workflow.steps) {
|
|
16
|
-
for (const dep of step.dependsOn ?? []) {
|
|
17
|
-
if (!stepIds.has(dep)) errors.push(`Step '${step.id}' depends on unknown step '${dep}'.`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const visiting = new Set<string>();
|
|
22
|
-
const visited = new Set<string>();
|
|
23
|
-
const byId = new Map(workflow.steps.map((step) => [step.id, step]));
|
|
24
|
-
|
|
25
|
-
function visit(id: string, trail: string[]): void {
|
|
26
|
-
if (visited.has(id)) return;
|
|
27
|
-
if (visiting.has(id)) {
|
|
28
|
-
errors.push(`Workflow dependency cycle detected: ${[...trail, id].join(" -> ")}.`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
visiting.add(id);
|
|
32
|
-
const step = byId.get(id);
|
|
33
|
-
for (const dep of step?.dependsOn ?? []) visit(dep, [...trail, id]);
|
|
34
|
-
visiting.delete(id);
|
|
35
|
-
visited.add(id);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for (const step of workflow.steps) visit(step.id, []);
|
|
39
|
-
return [...new Set(errors)];
|
|
40
|
-
}
|
|
1
|
+
import type { TeamConfig } from "../teams/team-config.ts";
|
|
2
|
+
import type { WorkflowConfig } from "./workflow-config.ts";
|
|
3
|
+
|
|
4
|
+
export function validateWorkflowForTeam(workflow: WorkflowConfig, team: TeamConfig): string[] {
|
|
5
|
+
const errors: string[] = [];
|
|
6
|
+
const roles = new Set(team.roles.map((role) => role.name));
|
|
7
|
+
const stepIds = new Set<string>();
|
|
8
|
+
|
|
9
|
+
for (const step of workflow.steps) {
|
|
10
|
+
if (stepIds.has(step.id)) errors.push(`Duplicate workflow step id '${step.id}'.`);
|
|
11
|
+
stepIds.add(step.id);
|
|
12
|
+
if (!roles.has(step.role)) errors.push(`Step '${step.id}' references unknown team role '${step.role}'.`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
for (const step of workflow.steps) {
|
|
16
|
+
for (const dep of step.dependsOn ?? []) {
|
|
17
|
+
if (!stepIds.has(dep)) errors.push(`Step '${step.id}' depends on unknown step '${dep}'.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const visiting = new Set<string>();
|
|
22
|
+
const visited = new Set<string>();
|
|
23
|
+
const byId = new Map(workflow.steps.map((step) => [step.id, step]));
|
|
24
|
+
|
|
25
|
+
function visit(id: string, trail: string[]): void {
|
|
26
|
+
if (visited.has(id)) return;
|
|
27
|
+
if (visiting.has(id)) {
|
|
28
|
+
errors.push(`Workflow dependency cycle detected: ${[...trail, id].join(" -> ")}.`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
visiting.add(id);
|
|
32
|
+
const step = byId.get(id);
|
|
33
|
+
for (const dep of step?.dependsOn ?? []) visit(dep, [...trail, id]);
|
|
34
|
+
visiting.delete(id);
|
|
35
|
+
visited.add(id);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const step of workflow.steps) visit(step.id, []);
|
|
39
|
+
return [...new Set(errors)];
|
|
40
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
export type BranchFreshnessStatus = "fresh" | "stale" | "diverged" | "unknown";
|
|
4
|
-
export type StaleBranchPolicy = "warn" | "block" | "auto_rebase" | "auto_merge_forward";
|
|
5
|
-
|
|
6
|
-
export interface BranchFreshness {
|
|
7
|
-
status: BranchFreshnessStatus;
|
|
8
|
-
branch?: string;
|
|
9
|
-
mainRef: string;
|
|
10
|
-
ahead: number;
|
|
11
|
-
behind: number;
|
|
12
|
-
missingFixes: string[];
|
|
13
|
-
message: string;
|
|
14
|
-
error?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function git(cwd: string, args: string[]): string {
|
|
18
|
-
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function count(cwd: string, range: string): number {
|
|
22
|
-
const raw = git(cwd, ["rev-list", "--count", range]);
|
|
23
|
-
const parsed = Number.parseInt(raw, 10);
|
|
24
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function checkBranchFreshness(cwd: string, mainRef = "main"): BranchFreshness {
|
|
28
|
-
try {
|
|
29
|
-
git(cwd, ["rev-parse", "--is-inside-work-tree"]);
|
|
30
|
-
const branch = git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
31
|
-
const behind = count(cwd, `${branch}..${mainRef}`);
|
|
32
|
-
const ahead = count(cwd, `${mainRef}..${branch}`);
|
|
33
|
-
const missingFixes = behind > 0 ? git(cwd, ["log", "--format=%s", `${branch}..${mainRef}`]).split("\n").map((line) => line.trim()).filter(Boolean) : [];
|
|
34
|
-
if (behind === 0) return { status: "fresh", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' is fresh against ${mainRef}.` };
|
|
35
|
-
if (ahead > 0) return { status: "diverged", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' diverged from ${mainRef}: ahead=${ahead}, behind=${behind}.` };
|
|
36
|
-
return { status: "stale", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' is ${behind} commit(s) behind ${mainRef}.` };
|
|
37
|
-
} catch (error) {
|
|
38
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
-
return { status: "unknown", mainRef, ahead: 0, behind: 0, missingFixes: [], message: "Branch freshness could not be determined.", error: message };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function shouldBlockForBranchFreshness(freshness: BranchFreshness, policy: StaleBranchPolicy = "warn"): boolean {
|
|
44
|
-
return policy === "block" && (freshness.status === "stale" || freshness.status === "diverged");
|
|
45
|
-
}
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export type BranchFreshnessStatus = "fresh" | "stale" | "diverged" | "unknown";
|
|
4
|
+
export type StaleBranchPolicy = "warn" | "block" | "auto_rebase" | "auto_merge_forward";
|
|
5
|
+
|
|
6
|
+
export interface BranchFreshness {
|
|
7
|
+
status: BranchFreshnessStatus;
|
|
8
|
+
branch?: string;
|
|
9
|
+
mainRef: string;
|
|
10
|
+
ahead: number;
|
|
11
|
+
behind: number;
|
|
12
|
+
missingFixes: string[];
|
|
13
|
+
message: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function git(cwd: string, args: string[]): string {
|
|
18
|
+
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function count(cwd: string, range: string): number {
|
|
22
|
+
const raw = git(cwd, ["rev-list", "--count", range]);
|
|
23
|
+
const parsed = Number.parseInt(raw, 10);
|
|
24
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function checkBranchFreshness(cwd: string, mainRef = "main"): BranchFreshness {
|
|
28
|
+
try {
|
|
29
|
+
git(cwd, ["rev-parse", "--is-inside-work-tree"]);
|
|
30
|
+
const branch = git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
31
|
+
const behind = count(cwd, `${branch}..${mainRef}`);
|
|
32
|
+
const ahead = count(cwd, `${mainRef}..${branch}`);
|
|
33
|
+
const missingFixes = behind > 0 ? git(cwd, ["log", "--format=%s", `${branch}..${mainRef}`]).split("\n").map((line) => line.trim()).filter(Boolean) : [];
|
|
34
|
+
if (behind === 0) return { status: "fresh", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' is fresh against ${mainRef}.` };
|
|
35
|
+
if (ahead > 0) return { status: "diverged", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' diverged from ${mainRef}: ahead=${ahead}, behind=${behind}.` };
|
|
36
|
+
return { status: "stale", branch, mainRef, ahead, behind, missingFixes, message: `Branch '${branch}' is ${behind} commit(s) behind ${mainRef}.` };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
39
|
+
return { status: "unknown", mainRef, ahead: 0, behind: 0, missingFixes: [], message: "Branch freshness could not be determined.", error: message };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function shouldBlockForBranchFreshness(freshness: BranchFreshness, policy: StaleBranchPolicy = "warn"): boolean {
|
|
44
|
+
return policy === "block" && (freshness.status === "stale" || freshness.status === "diverged");
|
|
45
|
+
}
|