pi-crew 0.1.41 → 0.1.44
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 +47 -0
- package/README.md +51 -0
- 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/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 -297
- package/docs/research-extension-system.md +324 -324
- package/docs/research-optimization-plan.md +548 -548
- package/docs/research-phase10-distillation.md +199 -0
- package/docs/research-phase11-distillation.md +201 -0
- package/docs/research-pi-coding-agent.md +357 -357
- package/docs/research-source-pi-crew-reference.md +174 -174
- package/docs/runtime-flow.md +148 -148
- package/docs/source-runtime-refactor-map.md +83 -83
- package/index.ts +6 -6
- package/package.json +1 -1
- package/src/agents/agent-serializer.ts +34 -34
- package/src/agents/discover-agents.ts +5 -4
- package/src/config/config.ts +28 -4
- package/src/extension/cross-extension-rpc.ts +82 -82
- package/src/extension/management.ts +37 -8
- package/src/extension/notification-router.ts +2 -2
- package/src/extension/register.ts +130 -8
- package/src/extension/registration/commands.ts +11 -9
- package/src/extension/registration/compaction-guard.ts +125 -125
- package/src/extension/registration/subagent-tools.ts +28 -19
- package/src/extension/registration/team-tool.ts +2 -1
- package/src/extension/result-watcher.ts +4 -4
- package/src/extension/run-bundle-schema.ts +8 -4
- package/src/extension/run-import.ts +4 -0
- package/src/extension/run-index.ts +23 -1
- package/src/extension/run-maintenance.ts +43 -24
- package/src/extension/team-tool/api.ts +2 -2
- package/src/extension/team-tool/cancel.ts +76 -4
- package/src/extension/team-tool/context.ts +1 -0
- package/src/extension/team-tool/doctor.ts +8 -1
- package/src/extension/team-tool/handle-settings.ts +188 -0
- 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/respond.ts +67 -0
- package/src/extension/team-tool/run.ts +6 -4
- package/src/extension/team-tool/status.ts +99 -93
- package/src/extension/team-tool-types.ts +4 -0
- package/src/extension/team-tool.ts +5 -1
- package/src/i18n.ts +184 -0
- package/src/observability/correlation.ts +2 -2
- package/src/observability/event-to-metric.ts +10 -3
- package/src/observability/exporters/adapter.ts +7 -1
- package/src/observability/exporters/otlp-exporter.ts +14 -2
- package/src/observability/exporters/prometheus-exporter.ts +9 -2
- package/src/observability/metric-registry.ts +18 -3
- package/src/observability/metric-retention.ts +11 -3
- package/src/observability/metric-sink.ts +9 -4
- package/src/observability/metrics-primitives.ts +4 -3
- package/src/prompt/prompt-runtime.ts +72 -68
- package/src/runtime/agent-control.ts +63 -63
- package/src/runtime/agent-memory.ts +72 -72
- package/src/runtime/agent-observability.ts +114 -114
- package/src/runtime/async-marker.ts +26 -26
- package/src/runtime/attention-events.ts +28 -23
- package/src/runtime/background-runner.ts +53 -53
- package/src/runtime/child-pi.ts +4 -4
- package/src/runtime/completion-guard.ts +95 -4
- package/src/runtime/concurrency.ts +1 -1
- package/src/runtime/crash-recovery.ts +32 -1
- package/src/runtime/crew-agent-runtime.ts +59 -58
- package/src/runtime/deadletter.ts +14 -4
- package/src/runtime/delivery-coordinator.ts +143 -0
- 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 +106 -106
- package/src/runtime/heartbeat-gradient.ts +28 -28
- package/src/runtime/heartbeat-watcher.ts +48 -4
- package/src/runtime/live-agent-control.ts +87 -87
- 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 +305 -305
- package/src/runtime/manifest-cache.ts +2 -2
- package/src/runtime/model-fallback.ts +272 -261
- package/src/runtime/overflow-recovery.ts +157 -0
- package/src/runtime/parallel-research.ts +44 -44
- package/src/runtime/parallel-utils.ts +1 -1
- package/src/runtime/pi-json-output.ts +111 -111
- package/src/runtime/policy-engine.ts +79 -78
- package/src/runtime/post-exit-stdio-guard.ts +2 -2
- 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/retry-executor.ts +5 -0
- package/src/runtime/role-permission.ts +39 -39
- package/src/runtime/runtime-resolver.ts +1 -1
- package/src/runtime/session-resources.ts +25 -0
- package/src/runtime/session-snapshot.ts +59 -0
- package/src/runtime/session-usage.ts +79 -79
- package/src/runtime/sidechain-output.ts +29 -29
- package/src/runtime/stale-reconciler.ts +179 -0
- package/src/runtime/subagent-manager.ts +3 -3
- package/src/runtime/supervisor-contact.ts +59 -0
- package/src/runtime/task-display.ts +38 -38
- package/src/runtime/task-output-context.ts +127 -127
- package/src/runtime/task-runner/live-executor.ts +101 -101
- package/src/runtime/task-runner/progress.ts +119 -111
- package/src/runtime/task-runner/result-utils.ts +14 -14
- package/src/runtime/task-runner/state-helpers.ts +22 -22
- package/src/runtime/task-runner.ts +14 -0
- package/src/runtime/team-runner.ts +9 -10
- package/src/runtime/worker-heartbeat.ts +21 -21
- package/src/runtime/worker-startup.ts +57 -57
- package/src/schema/config-schema.ts +2 -1
- package/src/schema/team-tool-schema.ts +115 -109
- package/src/state/artifact-store.ts +4 -2
- package/src/state/atomic-write.ts +12 -4
- package/src/state/contracts.ts +109 -105
- package/src/state/event-log.ts +3 -4
- package/src/state/jsonl-writer.ts +4 -1
- package/src/state/locks.ts +9 -1
- package/src/state/task-claims.ts +44 -42
- 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 +38 -38
- package/src/types/diff.d.ts +18 -18
- package/src/ui/crew-footer.ts +101 -101
- package/src/ui/crew-select-list.ts +111 -111
- package/src/ui/crew-widget.ts +5 -4
- package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
- package/src/ui/dynamic-border.ts +25 -25
- package/src/ui/layout-primitives.ts +106 -106
- package/src/ui/live-run-sidebar.ts +1 -1
- package/src/ui/loaders.ts +158 -158
- package/src/ui/mascot.ts +3 -2
- package/src/ui/powerbar-publisher.ts +7 -6
- package/src/ui/render-diff.ts +119 -119
- package/src/ui/render-scheduler.ts +54 -14
- package/src/ui/run-dashboard.ts +39 -11
- package/src/ui/run-snapshot-cache.ts +336 -36
- package/src/ui/spinner.ts +17 -17
- package/src/ui/status-colors.ts +58 -54
- package/src/ui/syntax-highlight.ts +116 -116
- package/src/ui/theme-adapter.ts +1 -1
- package/src/ui/transcript-viewer.ts +7 -2
- package/src/utils/atomic-write.ts +33 -0
- package/src/utils/completion-dedupe.ts +63 -63
- package/src/utils/file-coalescer.ts +5 -3
- package/src/utils/frontmatter.ts +68 -36
- package/src/utils/git.ts +262 -262
- package/src/utils/ids.ts +12 -12
- package/src/utils/internal-error.ts +1 -1
- package/src/utils/names.ts +27 -26
- package/src/utils/paths.ts +1 -1
- package/src/utils/redaction.ts +44 -41
- package/src/utils/safe-paths.ts +47 -34
- package/src/utils/sleep.ts +2 -2
- package/src/utils/timings.ts +2 -0
- package/src/utils/visual.ts +9 -1
- package/src/workflows/discover-workflows.ts +4 -1
- package/src/workflows/validate-workflow.ts +40 -40
- package/src/worktree/branch-freshness.ts +45 -45
- package/src/worktree/worktree-manager.ts +6 -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
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
|
|
2
|
+
import { withRunLockSync } from "../../state/locks.ts";
|
|
3
|
+
import { loadRunManifestById, saveRunTasks } from "../../state/state-store.ts";
|
|
4
|
+
import { saveCrewAgents, recordFromTask } from "../../runtime/crew-agent-records.ts";
|
|
5
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
6
|
+
import type { PiTeamsToolResult } from "../tool-result.ts";
|
|
7
|
+
import { result, type TeamContext } from "./context.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handle `respond` action: send a message to a waiting (interactive) task.
|
|
11
|
+
* The task must be in "waiting" status. The message is stored in the task's
|
|
12
|
+
* mailbox and the task is transitioned back to "running".
|
|
13
|
+
*/
|
|
14
|
+
export function handleRespond(params: TeamToolParamsValue, ctx: TeamContext): PiTeamsToolResult {
|
|
15
|
+
if (!params.runId) return result("Respond requires runId.", { action: "respond", status: "error" }, true);
|
|
16
|
+
if (!params.message && !params.taskId) return result("Respond requires taskId and/or message.", { action: "respond", status: "error" }, true);
|
|
17
|
+
|
|
18
|
+
const loaded = loadRunManifestById(ctx.cwd, params.runId);
|
|
19
|
+
if (!loaded) return result(`Run '${params.runId}' not found.`, { action: "respond", status: "error" }, true);
|
|
20
|
+
|
|
21
|
+
return withRunLockSync(loaded.manifest, () => {
|
|
22
|
+
const taskId = params.taskId;
|
|
23
|
+
const message = params.message ?? "";
|
|
24
|
+
|
|
25
|
+
// Find the waiting task(s)
|
|
26
|
+
const targetTasks = taskId
|
|
27
|
+
? loaded.tasks.filter((t) => t.id === taskId)
|
|
28
|
+
: loaded.tasks.filter((t) => t.status === "waiting");
|
|
29
|
+
|
|
30
|
+
if (targetTasks.length === 0) {
|
|
31
|
+
return result(
|
|
32
|
+
taskId ? `Task '${taskId}' not found or not in waiting state.` : `No waiting tasks in run ${loaded.manifest.runId}.`,
|
|
33
|
+
{ action: "respond", status: "error" },
|
|
34
|
+
true,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Transition waiting tasks back to running
|
|
39
|
+
const updatedTasks = loaded.tasks.map((task) => {
|
|
40
|
+
if (task.status !== "waiting") return task;
|
|
41
|
+
if (taskId && task.id !== taskId) return task;
|
|
42
|
+
return {
|
|
43
|
+
...task,
|
|
44
|
+
status: "running" as const,
|
|
45
|
+
// Store the response in the task's adaptive field
|
|
46
|
+
adaptive: {
|
|
47
|
+
...task.adaptive,
|
|
48
|
+
phase: "resumed",
|
|
49
|
+
task: message || task.adaptive?.task || "",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
saveRunTasks(loaded.manifest, updatedTasks);
|
|
55
|
+
try {
|
|
56
|
+
saveCrewAgents(loaded.manifest, updatedTasks.map((task) => recordFromTask(loaded.manifest, task, "child-process")));
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logInternalError("team-tool.handleRespond.crewAgents", error, `runId=${loaded.manifest.runId}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const resumedIds = targetTasks.map((t) => t.id);
|
|
62
|
+
return result(
|
|
63
|
+
`Resumed ${resumedIds.length} task(s): ${resumedIds.join(", ")}. Message: ${message || "(no message)"}`,
|
|
64
|
+
{ action: "respond", status: "ok", runId: loaded.manifest.runId, resumedIds },
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -21,8 +21,10 @@ import { effectiveRunConfig } from "./config-patch.ts";
|
|
|
21
21
|
|
|
22
22
|
function tailFile(filePath: string, maxBytes = 4096): string | undefined {
|
|
23
23
|
try {
|
|
24
|
+
// Cap at 512KB to prevent OOM from misconfigured callers.
|
|
25
|
+
const safeMaxBytes = Math.min(maxBytes, 512 * 1024);
|
|
24
26
|
const stat = fs.statSync(filePath);
|
|
25
|
-
const start = Math.max(0, stat.size -
|
|
27
|
+
const start = Math.max(0, stat.size - safeMaxBytes);
|
|
26
28
|
const fd = fs.openSync(filePath, "r");
|
|
27
29
|
try {
|
|
28
30
|
const buffer = Buffer.alloc(stat.size - start);
|
|
@@ -50,7 +52,7 @@ function scheduleBackgroundEarlyExitGuard(cwd: string, runId: string, pid: numbe
|
|
|
50
52
|
const failed = updateRunStatus(loaded.manifest, "failed", "Background runner exited within 3s; see background.log");
|
|
51
53
|
appendEvent(failed.eventsPath, { type: "async.failed", runId: failed.runId, message, data: { pid, detail: liveness.detail } });
|
|
52
54
|
}, 3000);
|
|
53
|
-
timer.unref
|
|
55
|
+
timer.unref();
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export async function handleRun(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
|
|
@@ -134,7 +136,7 @@ export async function handleRun(params: TeamToolParamsValue, ctx: TeamContext):
|
|
|
134
136
|
if (executeWorkers && ctx.startForegroundRun) {
|
|
135
137
|
ctx.onRunStarted?.(updatedManifest.runId);
|
|
136
138
|
ctx.startForegroundRun(async (signal) => {
|
|
137
|
-
await executeTeamRun({ manifest: updatedManifest, tasks, team, workflow, agents, executeWorkers, limits: executedConfig.limits, runtime, runtimeConfig: executedConfig.runtime, parentContext: buildParentContext(ctx), parentModel: ctx.model, modelRegistry: ctx.modelRegistry, modelOverride: params.model, signal, reliability: executedConfig.reliability, metricRegistry: ctx.metricRegistry });
|
|
139
|
+
await executeTeamRun({ manifest: updatedManifest, tasks, team, workflow, agents, executeWorkers, limits: executedConfig.limits, runtime, runtimeConfig: executedConfig.runtime, parentContext: buildParentContext(ctx), parentModel: ctx.model, modelRegistry: ctx.modelRegistry, modelOverride: params.model, signal, reliability: executedConfig.reliability, metricRegistry: ctx.metricRegistry, onJsonEvent: ctx.onJsonEvent });
|
|
138
140
|
}, updatedManifest.runId);
|
|
139
141
|
const text = [
|
|
140
142
|
`Started foreground pi-crew run ${updatedManifest.runId}.`,
|
|
@@ -150,7 +152,7 @@ export async function handleRun(params: TeamToolParamsValue, ctx: TeamContext):
|
|
|
150
152
|
].join("\n");
|
|
151
153
|
return result(text, { action: "run", status: "ok", runId: updatedManifest.runId, artifactsRoot: updatedManifest.artifactsRoot });
|
|
152
154
|
}
|
|
153
|
-
const executed = await executeTeamRun({ manifest: updatedManifest, tasks, team, workflow, agents, executeWorkers, limits: executedConfig.limits, runtime, runtimeConfig: executedConfig.runtime, parentContext: buildParentContext(ctx), parentModel: ctx.model, modelRegistry: ctx.modelRegistry, modelOverride: params.model, signal: ctx.signal, reliability: executedConfig.reliability, metricRegistry: ctx.metricRegistry });
|
|
155
|
+
const executed = await executeTeamRun({ manifest: updatedManifest, tasks, team, workflow, agents, executeWorkers, limits: executedConfig.limits, runtime, runtimeConfig: executedConfig.runtime, parentContext: buildParentContext(ctx), parentModel: ctx.model, modelRegistry: ctx.modelRegistry, modelOverride: params.model, signal: ctx.signal, reliability: executedConfig.reliability, metricRegistry: ctx.metricRegistry, onJsonEvent: ctx.onJsonEvent });
|
|
154
156
|
const text = [
|
|
155
157
|
`Created pi-crew run ${executed.manifest.runId}.`,
|
|
156
158
|
`Team: ${team.name}`,
|
|
@@ -1,93 +1,99 @@
|
|
|
1
|
-
import { loadConfig } from "../../config/config.ts";
|
|
2
|
-
import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
|
|
3
|
-
import { appendEvent, readEvents } from "../../state/event-log.ts";
|
|
4
|
-
import { readDeliveryState, readMailbox } from "../../state/mailbox.ts";
|
|
5
|
-
import { loadRunManifestById, updateRunStatus } from "../../state/state-store.ts";
|
|
6
|
-
import { aggregateUsage, formatUsage } from "../../state/usage.ts";
|
|
7
|
-
import { applyAttentionState, formatActivityAge, resolveCrewControlConfig } from "../../runtime/agent-control.ts";
|
|
8
|
-
import { readCrewAgents } from "../../runtime/crew-agent-records.ts";
|
|
9
|
-
import { checkProcessLiveness, isActiveRunStatus } from "../../runtime/process-status.ts";
|
|
10
|
-
import { formatTaskGraphLines, waitingReason } from "../../runtime/task-display.ts";
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
`
|
|
61
|
-
`
|
|
62
|
-
`
|
|
63
|
-
`
|
|
64
|
-
`
|
|
65
|
-
`
|
|
66
|
-
`
|
|
67
|
-
`
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
...(
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
"",
|
|
86
|
-
"
|
|
87
|
-
...(
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
...(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
import { loadConfig } from "../../config/config.ts";
|
|
2
|
+
import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
|
|
3
|
+
import { appendEvent, readEvents } from "../../state/event-log.ts";
|
|
4
|
+
import { readDeliveryState, readMailbox } from "../../state/mailbox.ts";
|
|
5
|
+
import { loadRunManifestById, updateRunStatus, saveRunTasks } from "../../state/state-store.ts";
|
|
6
|
+
import { aggregateUsage, formatUsage } from "../../state/usage.ts";
|
|
7
|
+
import { applyAttentionState, formatActivityAge, resolveCrewControlConfig } from "../../runtime/agent-control.ts";
|
|
8
|
+
import { readCrewAgents } from "../../runtime/crew-agent-records.ts";
|
|
9
|
+
import { checkProcessLiveness, isActiveRunStatus } from "../../runtime/process-status.ts";
|
|
10
|
+
import { formatTaskGraphLines, waitingReason } from "../../runtime/task-display.ts";
|
|
11
|
+
import { verifyTaskCompletion, formatOutputPreview } from "../../runtime/completion-guard.ts";
|
|
12
|
+
import type { PiTeamsToolResult } from "../tool-result.ts";
|
|
13
|
+
import { result, type TeamContext } from "./context.ts";
|
|
14
|
+
|
|
15
|
+
export function handleStatus(params: TeamToolParamsValue, ctx: TeamContext): PiTeamsToolResult {
|
|
16
|
+
if (!params.runId) return result("Status requires runId.", { action: "status", status: "error" }, true);
|
|
17
|
+
const loaded = loadRunManifestById(ctx.cwd, params.runId);
|
|
18
|
+
if (!loaded) return result(`Run '${params.runId}' not found.`, { action: "status", status: "error" }, true);
|
|
19
|
+
let { manifest, tasks } = loaded;
|
|
20
|
+
let asyncLivenessLine: string | undefined;
|
|
21
|
+
if (manifest.async) {
|
|
22
|
+
const asyncState = manifest.async;
|
|
23
|
+
const liveness = checkProcessLiveness(asyncState.pid);
|
|
24
|
+
asyncLivenessLine = `Async: pid=${asyncState.pid ?? "unknown"} alive=${liveness.alive ? "true" : "false"} detail=${liveness.detail} log=${asyncState.logPath} spawnedAt=${asyncState.spawnedAt}`;
|
|
25
|
+
if (!liveness.alive && isActiveRunStatus(manifest.status)) {
|
|
26
|
+
manifest = updateRunStatus(manifest, "failed", `Async process stale: ${liveness.detail}`);
|
|
27
|
+
tasks = tasks.map((task) => task.status === "running" ? { ...task, status: "cancelled" as const, finishedAt: new Date().toISOString(), error: "Async process died; task was not completed." } : task);
|
|
28
|
+
saveRunTasks(manifest, tasks);
|
|
29
|
+
appendEvent(manifest.eventsPath, { type: "async.stale", runId: manifest.runId, message: liveness.detail, data: { pid: asyncState.pid } });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const counts = new Map<string, number>();
|
|
33
|
+
for (const task of tasks) counts.set(task.status, (counts.get(task.status) ?? 0) + 1);
|
|
34
|
+
const allEvents = readEvents(manifest.eventsPath);
|
|
35
|
+
const events = allEvents.slice(-8);
|
|
36
|
+
const attentionByTask = new Map(allEvents.filter((event) => event.type === "task.attention" && event.taskId).map((event) => [event.taskId!, event]));
|
|
37
|
+
const controlConfig = resolveCrewControlConfig(loadConfig(ctx.cwd).config);
|
|
38
|
+
const crewAgents = readCrewAgents(manifest).map((agent) => applyAttentionState(manifest, agent, controlConfig));
|
|
39
|
+
const artifactLines = manifest.artifacts.slice(-10).map((artifact) => `- ${artifact.kind}: ${artifact.path}${artifact.sizeBytes !== undefined ? ` (${artifact.sizeBytes} bytes)` : ""}`);
|
|
40
|
+
const deliveryState = readDeliveryState(manifest);
|
|
41
|
+
const ackTimeoutMs = loadConfig(ctx.cwd).config.runtime?.groupJoinAckTimeoutMs;
|
|
42
|
+
const groupJoinLines: string[] = [];
|
|
43
|
+
for (const message of readMailbox(manifest, "outbox").filter((m) => m.data?.kind === "group_join").slice(-5)) {
|
|
44
|
+
const ack = deliveryState.messages[message.id] === "acknowledged" ? "acknowledged" : "pending";
|
|
45
|
+
const ageMs = Date.now() - new Date(message.createdAt).getTime();
|
|
46
|
+
const requestId = String(message.data?.requestId ?? "unknown");
|
|
47
|
+
const timedOut = ack === "pending" && ackTimeoutMs !== undefined && Number.isFinite(ageMs) && ageMs > ackTimeoutMs;
|
|
48
|
+
if (timedOut && !allEvents.some((event) => event.type === "agent.group_join.ack_timeout" && event.data?.requestId === requestId)) {
|
|
49
|
+
appendEvent(manifest.eventsPath, { type: "agent.group_join.ack_timeout", runId: manifest.runId, message: "Group join delivery ack timed out; mailbox delivery remains the fallback.", data: { requestId, messageId: message.id, batchId: message.data?.batchId, partial: message.data?.partial, ageMs, ackTimeoutMs } });
|
|
50
|
+
}
|
|
51
|
+
groupJoinLines.push(`- ${String(message.data?.partial) === "true" ? "partial" : "completed"} request=${requestId} message=${message.id} ack=${timedOut ? "timeout" : ack}`);
|
|
52
|
+
}
|
|
53
|
+
const totalUsage = aggregateUsage(tasks);
|
|
54
|
+
const activeAgents = crewAgents.filter((agent) => agent.status === "running");
|
|
55
|
+
const completedAgents = crewAgents.filter((agent) => agent.status !== "running");
|
|
56
|
+
const waitingTasks = tasks.filter((task) => task.status === "queued" || task.status === "waiting");
|
|
57
|
+
const agentLine = (agent: typeof crewAgents[number]): string => `- ${agent.id} [${agent.status}] ${agent.role} -> ${agent.agent} runtime=${agent.runtime}${agent.model ? ` model=${agent.model}` : ""}${agent.usage ? ` usage=${formatUsage(agent.usage)}` : ""}${agent.progress?.activityState ? ` activityState=${agent.progress.activityState}` : ""}${formatActivityAge(agent) ? ` activity=${formatActivityAge(agent)}` : ""}${agent.progress?.currentTool ? ` tool=${agent.progress.currentTool}` : ""}${agent.toolUses ? ` tools=${agent.toolUses}` : ""}${!agent.usage && agent.progress?.tokens ? ` tokens=${agent.progress.tokens}` : ""}${agent.progress?.turns ? ` turns=${agent.progress.turns}` : ""}${agent.jsonEvents !== undefined ? ` jsonEvents=${agent.jsonEvents}` : ""}${agent.outputPath ? ` output=${agent.outputPath}` : ""}${agent.transcriptPath ? ` transcript=${agent.transcriptPath}` : ""}${agent.statusPath ? ` status=${agent.statusPath}` : ""}${agent.error ? ` error=${agent.error}` : ""}`;
|
|
58
|
+
const lines = [
|
|
59
|
+
`Run: ${manifest.runId}`,
|
|
60
|
+
`Team: ${manifest.team}`,
|
|
61
|
+
`Workflow: ${manifest.workflow ?? "(none)"}`,
|
|
62
|
+
`Status: ${manifest.status}`,
|
|
63
|
+
`Workspace mode: ${manifest.workspaceMode}`,
|
|
64
|
+
`Goal: ${manifest.goal}`,
|
|
65
|
+
`Created: ${manifest.createdAt}`,
|
|
66
|
+
`Updated: ${manifest.updatedAt}`,
|
|
67
|
+
`State: ${manifest.stateRoot}`,
|
|
68
|
+
`Artifacts: ${manifest.artifactsRoot}`,
|
|
69
|
+
...(asyncLivenessLine ? [asyncLivenessLine] : []),
|
|
70
|
+
"Task graph:",
|
|
71
|
+
...formatTaskGraphLines(tasks),
|
|
72
|
+
"Tasks:",
|
|
73
|
+
...(tasks.length ? tasks.map((task) => `- ${task.id} [${task.status}] ${task.role} -> ${task.agent}${task.taskPacket ? ` scope=${task.taskPacket.scope}` : ""}${task.verification ? ` green=${task.verification.observedGreenLevel}/${task.verification.requiredGreenLevel}` : ""}${task.modelAttempts?.length ? ` attempts=${task.modelAttempts.length}` : ""}${task.modelRouting ? ` modelRouting=${task.modelRouting.requested ? `${task.modelRouting.requested}->` : ""}${task.modelRouting.resolved}${task.modelRouting.usedAttempt ? ` attempt=${task.modelRouting.usedAttempt + 1}` : ""}` : ""}${task.agentProgress?.activityState ? ` activityState=${task.agentProgress.activityState}` : ""}${attentionByTask.get(task.id)?.data?.reason ? ` attention=${String(attentionByTask.get(task.id)?.data?.reason)}` : ""}${task.jsonEvents !== undefined ? ` jsonEvents=${task.jsonEvents}` : ""}${task.usage ? ` usage=${JSON.stringify(task.usage)}` : ""}${task.resultArtifact ? ` result=${task.resultArtifact.path}` : ""}${task.transcriptArtifact ? ` transcript=${task.transcriptArtifact.path}` : ""}${task.worktree ? ` worktree=${task.worktree.path}` : ""}${task.error ? ` error=${task.error}` : ""}`) : ["- (none)"]),
|
|
74
|
+
`Task counts: ${[...counts.entries()].map(([status, count]) => `${status}=${count}`).join(", ") || "none"}`,
|
|
75
|
+
"Completion verification:",
|
|
76
|
+
...(tasks.filter((t) => t.status === "completed").length ? tasks.filter((t) => t.status === "completed").map((t) => {
|
|
77
|
+
const guard = verifyTaskCompletion(t, manifest);
|
|
78
|
+
return `- ${t.id} green=${guard.greenLevel}/3${guard.warnings.length ? ` warnings=[${guard.warnings.join(", ")}]` : ""}`;
|
|
79
|
+
}) : ["- (no completed tasks)"]),
|
|
80
|
+
"Active agents:",
|
|
81
|
+
...(activeAgents.length ? activeAgents.map(agentLine) : ["- (none)"]),
|
|
82
|
+
"Waiting tasks:",
|
|
83
|
+
...(waitingTasks.length ? waitingTasks.map((task) => `- ${task.id} [queued] ${task.role} -> ${task.agent} ${waitingReason(task, tasks) ?? "waiting"}`) : ["- (none)"]),
|
|
84
|
+
"Completed agents:",
|
|
85
|
+
...(completedAgents.length ? completedAgents.map(agentLine) : ["- (none)"]),
|
|
86
|
+
"Policy decisions:",
|
|
87
|
+
...(manifest.policyDecisions?.length ? manifest.policyDecisions.map((item) => `- ${item.action} (${item.reason})${item.taskId ? ` ${item.taskId}` : ""}: ${item.message}`) : ["- (none)"]),
|
|
88
|
+
`Total usage: ${formatUsage(totalUsage)}`,
|
|
89
|
+
"Group joins:",
|
|
90
|
+
...(groupJoinLines.length ? groupJoinLines : ["- (none)"]),
|
|
91
|
+
"",
|
|
92
|
+
"Recent artifacts:",
|
|
93
|
+
...(artifactLines.length ? artifactLines : ["- (none)"]),
|
|
94
|
+
"",
|
|
95
|
+
"Recent events:",
|
|
96
|
+
...(events.length ? events.map((event) => `- ${event.time} ${event.type}${event.taskId ? ` ${event.taskId}` : ""}${event.message ? `: ${event.message}` : ""}`) : ["- (none)"]),
|
|
97
|
+
];
|
|
98
|
+
return result(lines.join("\n"), { action: "status", status: "ok", runId: manifest.runId, artifactsRoot: manifest.artifactsRoot });
|
|
99
|
+
}
|
|
@@ -19,6 +19,7 @@ import { pruneFinishedRuns } from "./run-maintenance.ts";
|
|
|
19
19
|
import { exportRunBundle } from "./run-export.ts";
|
|
20
20
|
import { importRunBundle } from "./run-import.ts";
|
|
21
21
|
import { listImportedRuns } from "./import-index.ts";
|
|
22
|
+
import { handleSettings } from "./team-tool/handle-settings.ts";
|
|
22
23
|
import { listRuns } from "./run-index.ts";
|
|
23
24
|
import { validateWorkflowForTeam } from "../workflows/validate-workflow.ts";
|
|
24
25
|
import { formatValidationReport, validateResources } from "./validate-resources.ts";
|
|
@@ -43,6 +44,7 @@ import { handleStatus } from "./team-tool/status.ts";
|
|
|
43
44
|
import { handleArtifacts, handleEvents, handleSummary } from "./team-tool/inspect.ts";
|
|
44
45
|
import { handleCleanup, handleExport, handleForget, handleImport, handleImports, handlePrune, handleWorktrees } from "./team-tool/lifecycle-actions.ts";
|
|
45
46
|
import { handleCancel } from "./team-tool/cancel.ts";
|
|
47
|
+
import { handleRespond } from "./team-tool/respond.ts";
|
|
46
48
|
import { handlePlan } from "./team-tool/plan.ts";
|
|
47
49
|
import { logInternalError } from "../utils/internal-error.ts";
|
|
48
50
|
|
|
@@ -271,11 +273,13 @@ export async function handleTeamTool(params: TeamToolParamsValue, ctx: TeamConte
|
|
|
271
273
|
case "export": return handleExport(params, ctx);
|
|
272
274
|
case "import": return handleImport(params, ctx);
|
|
273
275
|
case "imports": return handleImports(params, ctx);
|
|
274
|
-
case "
|
|
276
|
+
case "settings": return handleSettings(params, ctx);
|
|
277
|
+
case "prune": return handlePrune(params, ctx);
|
|
275
278
|
case "forget": return handleForget(params, ctx);
|
|
276
279
|
case "run": return handleRun(params, ctx);
|
|
277
280
|
case "status": return handleStatus(params, ctx);
|
|
278
281
|
case "cancel": return handleCancel(params, ctx);
|
|
282
|
+
case "respond": return handleRespond(params, ctx);
|
|
279
283
|
case "plan": return handlePlan(params, ctx);
|
|
280
284
|
case "resume": return handleResume(params, ctx);
|
|
281
285
|
case "create": return handleCreate(params, ctx);
|
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
type Params = Record<string, string | number>;
|
|
4
|
+
|
|
5
|
+
const namespace = "pi-crew";
|
|
6
|
+
const TEMPLATE_RE = /\{(\w+)\}/g;
|
|
7
|
+
|
|
8
|
+
const fallback = {
|
|
9
|
+
"agent.requiresPrompt": "Agent requires prompt.",
|
|
10
|
+
"agent.started": "Agent {state}.",
|
|
11
|
+
"agent.id": "Agent ID: {id}",
|
|
12
|
+
"agent.type": "Type: {type}",
|
|
13
|
+
"agent.description": "Description: {description}",
|
|
14
|
+
"agent.retrieveHint": "Use get_subagent_result to retrieve output. Do not duplicate this agent's work.",
|
|
15
|
+
"agent.foregroundStatus": "Agent {id} {status}.",
|
|
16
|
+
"agent.noOutput": "No output.",
|
|
17
|
+
"result.requiresAgentId": "get_subagent_result requires agent_id.",
|
|
18
|
+
"result.notFound": "Agent not found: {id}",
|
|
19
|
+
"result.unrecoverable": "Subagent was interrupted before its durable run id was recorded; it cannot be recovered after restart.",
|
|
20
|
+
"result.waitAborted": "Waiting for subagent result was aborted.",
|
|
21
|
+
"result.waitTimeout": "Timed out waiting for subagent result.",
|
|
22
|
+
"result.stillRunning": "Agent is still running. Use wait=true or check again later.",
|
|
23
|
+
"steer.noted": "Steering request noted for {id}.",
|
|
24
|
+
"steer.unavailable": "Current default pi-crew backend is child-process, so mid-turn session.steer is not available yet.",
|
|
25
|
+
"steer.cancelHint": "Use team cancel runId={runId} if the agent must be interrupted.",
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
type Key = keyof typeof fallback;
|
|
29
|
+
|
|
30
|
+
/** Map of locale → partial translations. Keys not present fall back to English. */
|
|
31
|
+
const translations: Record<string, Partial<Record<Key, string>>> = {
|
|
32
|
+
es: {
|
|
33
|
+
"agent.requiresPrompt": "Agent requiere prompt.",
|
|
34
|
+
"agent.started": "Agent {state}.",
|
|
35
|
+
"agent.id": "ID del agente: {id}",
|
|
36
|
+
"agent.type": "Tipo: {type}",
|
|
37
|
+
"agent.description": "Descripción: {description}",
|
|
38
|
+
"agent.retrieveHint": "Usa get_subagent_result para recuperar la salida. No dupliques el trabajo de este agente.",
|
|
39
|
+
"agent.foregroundStatus": "Agent {id} {status}.",
|
|
40
|
+
"agent.noOutput": "Sin salida.",
|
|
41
|
+
"result.requiresAgentId": "get_subagent_result requiere agent_id.",
|
|
42
|
+
"result.notFound": "Agente no encontrado: {id}",
|
|
43
|
+
"result.unrecoverable": "El subagente fue interrumpido antes de registrar su ID de ejecución duradero; no se puede recuperar tras reiniciar.",
|
|
44
|
+
"result.waitAborted": "Se canceló la espera del resultado del subagente.",
|
|
45
|
+
"result.waitTimeout": "Se agotó el tiempo de espera del resultado del subagente.",
|
|
46
|
+
"result.stillRunning": "El agente sigue ejecutándose. Usa wait=true o vuelve a comprobar más tarde.",
|
|
47
|
+
"steer.noted": "Solicitud de dirección registrada para {id}.",
|
|
48
|
+
"steer.unavailable": "El backend predeterminado actual de pi-crew es child-process, así que session.steer a mitad de turno aún no está disponible.",
|
|
49
|
+
"steer.cancelHint": "Usa team cancel runId={runId} si hay que interrumpir el agente.",
|
|
50
|
+
},
|
|
51
|
+
fr: {
|
|
52
|
+
"agent.requiresPrompt": "Agent nécessite un prompt.",
|
|
53
|
+
"agent.started": "Agent {state}.",
|
|
54
|
+
"agent.id": "ID de l'agent : {id}",
|
|
55
|
+
"agent.type": "Type : {type}",
|
|
56
|
+
"agent.description": "Description : {description}",
|
|
57
|
+
"agent.retrieveHint": "Utilisez get_subagent_result pour récupérer la sortie. Ne dupliquez pas le travail de cet agent.",
|
|
58
|
+
"agent.foregroundStatus": "Agent {id} {status}.",
|
|
59
|
+
"agent.noOutput": "Aucune sortie.",
|
|
60
|
+
"result.requiresAgentId": "get_subagent_result nécessite agent_id.",
|
|
61
|
+
"result.notFound": "Agent introuvable : {id}",
|
|
62
|
+
"result.unrecoverable": "Le sous-agent a été interrompu avant l'enregistrement de son ID d'exécution durable ; il ne peut pas être récupéré après redémarrage.",
|
|
63
|
+
"result.waitAborted": "L'attente du résultat du sous-agent a été annulée.",
|
|
64
|
+
"result.waitTimeout": "Délai d'attente du résultat du sous-agent dépassé.",
|
|
65
|
+
"result.stillRunning": "L'agent est toujours en cours d'exécution. Utilisez wait=true ou réessayez plus tard.",
|
|
66
|
+
"steer.noted": "Demande de pilotage enregistrée pour {id}.",
|
|
67
|
+
"steer.unavailable": "Le backend pi-crew par défaut actuel est child-process, donc session.steer en milieu de tour n'est pas encore disponible.",
|
|
68
|
+
"steer.cancelHint": "Utilisez team cancel runId={runId} si l'agent doit être interrompu.",
|
|
69
|
+
},
|
|
70
|
+
"pt-BR": {
|
|
71
|
+
"agent.requiresPrompt": "Agent requer prompt.",
|
|
72
|
+
"agent.started": "Agent {state}.",
|
|
73
|
+
"agent.id": "ID do agente: {id}",
|
|
74
|
+
"agent.type": "Tipo: {type}",
|
|
75
|
+
"agent.description": "Descrição: {description}",
|
|
76
|
+
"agent.retrieveHint": "Use get_subagent_result para recuperar a saída. Não duplique o trabalho deste agente.",
|
|
77
|
+
"agent.foregroundStatus": "Agent {id} {status}.",
|
|
78
|
+
"agent.noOutput": "Sem saída.",
|
|
79
|
+
"result.requiresAgentId": "get_subagent_result requer agent_id.",
|
|
80
|
+
"result.notFound": "Agente não encontrado: {id}",
|
|
81
|
+
"result.unrecoverable": "O subagente foi interrompido antes que seu ID de execução durável fosse registrado; ele não pode ser recuperado após reiniciar.",
|
|
82
|
+
"result.waitAborted": "A espera pelo resultado do subagente foi abortada.",
|
|
83
|
+
"result.waitTimeout": "Tempo limite de espera pelo resultado do subagente esgotado.",
|
|
84
|
+
"result.stillRunning": "O agente ainda está em execução. Use wait=true ou verifique novamente mais tarde.",
|
|
85
|
+
"steer.noted": "Solicitação de orientação registrada para {id}.",
|
|
86
|
+
"steer.unavailable": "O backend padrão atual do pi-crew é child-process, então session.steer no meio do turno ainda não está disponível.",
|
|
87
|
+
"steer.cancelHint": "Use team cancel runId={runId} se o agente precisar ser interrompido.",
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// --- Runtime state ---
|
|
92
|
+
|
|
93
|
+
let currentLocale: string | undefined;
|
|
94
|
+
const warnedMissing = new Set<string>();
|
|
95
|
+
|
|
96
|
+
// --- Helpers ---
|
|
97
|
+
|
|
98
|
+
function format(template: string, params: Params = {}): string {
|
|
99
|
+
return template.replace(TEMPLATE_RE, (_match, key) => String(params[key] ?? `{${key}}`));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function warnOnce(key: string): void {
|
|
103
|
+
const tag = `${currentLocale}:${key}`;
|
|
104
|
+
if (warnedMissing.has(tag)) return;
|
|
105
|
+
warnedMissing.add(tag);
|
|
106
|
+
process.stderr.write(`[pi-crew] i18n: missing "${key}" in locale "${currentLocale}" — using English\n`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- Public API ---
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Translate a key for the currently active locale.
|
|
113
|
+
* Falls back to English, then to the raw key as a last resort.
|
|
114
|
+
*/
|
|
115
|
+
export function t(key: Key, params?: Params): string {
|
|
116
|
+
if (currentLocale && translations[currentLocale]) {
|
|
117
|
+
const template = translations[currentLocale]?.[key];
|
|
118
|
+
if (template) return format(template, params);
|
|
119
|
+
warnOnce(key);
|
|
120
|
+
}
|
|
121
|
+
return format(fallback[key] ?? key, params);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Register or extend translations for a locale at runtime.
|
|
126
|
+
* Useful for contributors adding new language bundles without modifying i18n.ts.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* addTranslations("vi", { "agent.requiresPrompt": "Agent cần prompt." })
|
|
130
|
+
*/
|
|
131
|
+
export function addTranslations(locale: string, bundle: Partial<Record<Key, string>>): void {
|
|
132
|
+
if (!locale) return;
|
|
133
|
+
const existing = translations[locale];
|
|
134
|
+
if (existing) {
|
|
135
|
+
Object.assign(existing, bundle);
|
|
136
|
+
} else {
|
|
137
|
+
translations[locale] = { ...bundle };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns the list of currently registered locales (excluding English, which is always available).
|
|
143
|
+
*/
|
|
144
|
+
export function listLocales(): string[] {
|
|
145
|
+
return Object.keys(translations);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// --- Initialization ---
|
|
149
|
+
|
|
150
|
+
export function initI18n(pi: ExtensionAPI): () => void {
|
|
151
|
+
try {
|
|
152
|
+
pi.events?.emit?.("pi-core/i18n/registerBundle", { namespace, defaultLocale: "en", fallback, translations });
|
|
153
|
+
} catch {
|
|
154
|
+
// Non-critical.
|
|
155
|
+
}
|
|
156
|
+
const unsubscribe = pi.events?.on?.("pi-core/i18n/localeChanged", (event: unknown) => {
|
|
157
|
+
if (!event || typeof event !== "object") return;
|
|
158
|
+
const raw = String((event as { locale?: unknown }).locale ?? "").trim();
|
|
159
|
+
currentLocale = raw && translations[raw] ? raw : undefined;
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
pi.events?.emit?.("pi-core/i18n/requestApi", { namespace, onApi(api: { getLocale?: () => string | undefined }) {
|
|
163
|
+
const raw = api.getLocale?.()?.trim();
|
|
164
|
+
if (raw && translations[raw]) currentLocale = raw;
|
|
165
|
+
} });
|
|
166
|
+
} catch {
|
|
167
|
+
// Non-critical.
|
|
168
|
+
}
|
|
169
|
+
return () => {
|
|
170
|
+
currentLocale = undefined;
|
|
171
|
+
unsubscribe?.();
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// --- Test helpers ---
|
|
176
|
+
|
|
177
|
+
export function __test__resetI18n(): void {
|
|
178
|
+
currentLocale = undefined;
|
|
179
|
+
warnedMissing.clear();
|
|
180
|
+
// Clear runtime-added translations but keep built-in ones.
|
|
181
|
+
for (const key of Object.keys(translations)) {
|
|
182
|
+
if (!["es", "fr", "pt-BR"].includes(key)) delete translations[key];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -28,8 +28,8 @@ export function childCorrelation(runId: string, taskId: string): CorrelationCont
|
|
|
28
28
|
return { traceId: parent?.traceId ?? spanId, parentSpanId: parent?.spanId, spanId };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function correlatedEvent<T extends { runId?: string; data?: Record<string, unknown> }>(event: T): T {
|
|
31
|
+
export function correlatedEvent<T extends { runId?: string; data?: Record<string, unknown> }>(event: T): T & { data: Record<string, unknown> } {
|
|
32
32
|
const ctx = getCurrentContext();
|
|
33
|
-
if (!ctx) return event;
|
|
33
|
+
if (!ctx) return event as T & { data: Record<string, unknown> };
|
|
34
34
|
return { ...event, data: { ...(event.data ?? {}), traceId: ctx.traceId, spanId: ctx.spanId, parentSpanId: ctx.parentSpanId } };
|
|
35
35
|
}
|
|
@@ -22,7 +22,11 @@ export function wireEventToMetrics(events: ExtensionAPI["events"] | undefined, r
|
|
|
22
22
|
const taskCount = registry.counter("crew.task.count", "Total tasks by status");
|
|
23
23
|
const subagentCount = registry.counter("crew.subagent.count", "Total subagent records by status");
|
|
24
24
|
const mailboxCount = registry.counter("crew.mailbox.count", "Total mailbox messages by direction");
|
|
25
|
-
registry.counter("crew.task.
|
|
25
|
+
const retryAttemptCount = registry.counter("crew.task.retry_attempt_total", "Retry attempts by run and task");
|
|
26
|
+
const deadletterCount = registry.counter("crew.task.deadletter_total", "Deadletter triggers by reason");
|
|
27
|
+
const overflowCount = registry.counter("crew.task.overflow_phase_total", "Overflow recovery phase transitions");
|
|
28
|
+
const waitingCount = registry.counter("crew.task.waiting_total", "Tasks entering waiting state");
|
|
29
|
+
const supervisorContactCount = registry.counter("crew.task.supervisor_contact_total", "Supervisor contact requests by reason");
|
|
26
30
|
registry.gauge("crew.heartbeat.staleness_ms", "Heartbeat elapsed since last seen, milliseconds");
|
|
27
31
|
const runDuration = registry.histogram("crew.run.duration_ms", "Run end-to-end duration, milliseconds");
|
|
28
32
|
const taskDuration = registry.histogram("crew.task.duration_ms", "Task duration, milliseconds");
|
|
@@ -35,8 +39,11 @@ export function wireEventToMetrics(events: ExtensionAPI["events"] | undefined, r
|
|
|
35
39
|
["crew.run.cancelled", () => runCount.inc({ status: "cancelled" })],
|
|
36
40
|
["crew.task.completed", (data) => { const item = recordValue(data); taskCount.inc({ status: "completed" }); taskDuration.observe({ role: stringValue(item.role, "unknown") }, numberValue(item.durationMs)); tokenUsage.observe({ role: stringValue(item.role, "unknown") }, numberValue(item.tokens)); }],
|
|
37
41
|
["crew.task.failed", () => taskCount.inc({ status: "failed" })],
|
|
38
|
-
["crew.task.retry_attempt", (data) => { const item = recordValue(data); taskCount.inc({ status: "retry" });
|
|
39
|
-
["crew.task.deadletter", (data) => { const item = recordValue(data);
|
|
42
|
+
["crew.task.retry_attempt", (data) => { const item = recordValue(data); taskCount.inc({ status: "retry" }); retryAttemptCount.inc({ runId: stringValue(item.runId, "unknown"), taskId: stringValue(item.taskId, "unknown") }); }],
|
|
43
|
+
["crew.task.deadletter", (data) => { const item = recordValue(data); deadletterCount.inc({ reason: stringValue(item.reason, "unknown") }); }],
|
|
44
|
+
["crew.task.overflow", (data) => { const item = recordValue(data); overflowCount.inc({ phase: stringValue(item.phase, "unknown"), previous_phase: stringValue(item.previousPhase, "none") }); }],
|
|
45
|
+
["task.waiting", (data) => { const item = recordValue(data); waitingCount.inc({ taskId: stringValue(item.taskId, "unknown"), runId: stringValue(item.runId, "unknown") }); }],
|
|
46
|
+
["supervisor.contact", (data) => { const item = recordValue(data); supervisorContactCount.inc({ reason: stringValue(item.reason, "unknown"), taskId: stringValue(item.taskId, "unknown") }); }],
|
|
40
47
|
["crew.subagent.completed", (data) => { const item = recordValue(data); subagentCount.inc({ status: stringValue(item.status, "completed") }); }],
|
|
41
48
|
["crew.subagent.failed", () => subagentCount.inc({ status: "failed" })],
|
|
42
49
|
["crew.mailbox.message", (data) => { const item = recordValue(data); mailboxCount.inc({ direction: stringValue(item.direction, "unknown") }); }],
|
|
@@ -19,6 +19,12 @@ export class CompositeExporter implements MetricExporter {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
dispose(): void {
|
|
22
|
-
for (const exporter of this.exporters)
|
|
22
|
+
for (const exporter of this.exporters) {
|
|
23
|
+
try {
|
|
24
|
+
exporter.dispose();
|
|
25
|
+
} catch {
|
|
26
|
+
// Best-effort cleanup; one exporter failing shouldn't prevent others.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
}
|