@jameslovespancakes/pi-plus 1.0.11 → 1.0.12

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.
Files changed (120) hide show
  1. package/README.md +44 -20
  2. package/config/skills/workflow-code-review-actions/SKILL.md +44 -0
  3. package/package.json +6 -3
  4. package/src/core/accounts/oauth-pool.ts +102 -0
  5. package/src/core/accounts/registry.ts +8 -25
  6. package/src/core/accounts/routing.ts +122 -0
  7. package/src/core/anthropic/client-identity.ts +9 -64
  8. package/src/core/anthropic/quota.ts +8 -53
  9. package/src/core/anthropic/routing.ts +40 -115
  10. package/src/core/anthropic/store.ts +7 -9
  11. package/src/core/catalog/quality.ts +33 -15
  12. package/src/core/codex/quota.ts +8 -2
  13. package/src/core/codex/store.ts +12 -9
  14. package/src/core/config.ts +4 -17
  15. package/src/core/store.ts +13 -12
  16. package/src/domains/models/provider-picker.ts +1 -1
  17. package/src/domains/setup/index.ts +23 -23
  18. package/src/domains/subscriptions/accounts-picker.ts +18 -37
  19. package/src/domains/subscriptions/accounts.ts +23 -29
  20. package/src/domains/subscriptions/footer.ts +48 -29
  21. package/src/domains/subscriptions/index.ts +11 -27
  22. package/src/domains/subscriptions/provider.ts +38 -103
  23. package/src/domains/subscriptions/providers/anthropic.ts +5 -17
  24. package/src/domains/subscriptions/providers/codex.ts +171 -4
  25. package/src/domains/subscriptions/providers/hosted.ts +18 -0
  26. package/src/domains/subscriptions/providers/oauth-pool.ts +273 -0
  27. package/src/domains/subscriptions/routing.ts +19 -11
  28. package/src/domains/workflows/LICENSE.md +21 -0
  29. package/src/domains/workflows/index.ts +836 -0
  30. package/src/domains/workflows/runtime/advisory-challenge.ts +75 -0
  31. package/src/domains/workflows/runtime/advisory-evidence.ts +90 -0
  32. package/src/domains/workflows/runtime/advisory-schema.ts +83 -0
  33. package/src/domains/workflows/runtime/agent-attempt.ts +147 -0
  34. package/src/domains/workflows/runtime/agent-limits.ts +43 -0
  35. package/src/domains/workflows/runtime/agent-replay.ts +399 -0
  36. package/src/domains/workflows/runtime/agent-retry.ts +116 -0
  37. package/src/domains/workflows/runtime/agent-runner-types.ts +96 -0
  38. package/src/domains/workflows/runtime/agent-runner.ts +203 -0
  39. package/src/domains/workflows/runtime/agent-session-identity.ts +256 -0
  40. package/src/domains/workflows/runtime/agent-session-providers.ts +50 -0
  41. package/src/domains/workflows/runtime/agent-session.ts +382 -0
  42. package/src/domains/workflows/runtime/agent-skills.ts +270 -0
  43. package/src/domains/workflows/runtime/agent-workspace.ts +103 -0
  44. package/src/domains/workflows/runtime/background-workflow-tool.ts +75 -0
  45. package/src/domains/workflows/runtime/background-workflows.ts +492 -0
  46. package/src/domains/workflows/runtime/budget.ts +53 -0
  47. package/src/domains/workflows/runtime/cancellation.ts +87 -0
  48. package/src/domains/workflows/runtime/command-completions.ts +36 -0
  49. package/src/domains/workflows/runtime/concurrency.ts +403 -0
  50. package/src/domains/workflows/runtime/debug.ts +3 -0
  51. package/src/domains/workflows/runtime/diff-capture.ts +81 -0
  52. package/src/domains/workflows/runtime/discovery.ts +137 -0
  53. package/src/domains/workflows/runtime/dynamax-shortcuts.ts +122 -0
  54. package/src/domains/workflows/runtime/dynamax.ts +330 -0
  55. package/src/domains/workflows/runtime/engine.ts +543 -0
  56. package/src/domains/workflows/runtime/filesystem-error.ts +4 -0
  57. package/src/domains/workflows/runtime/finalizers.ts +66 -0
  58. package/src/domains/workflows/runtime/identity-canonicalization.ts +138 -0
  59. package/src/domains/workflows/runtime/identity-fingerprint.ts +15 -0
  60. package/src/domains/workflows/runtime/inline-workflow.ts +403 -0
  61. package/src/domains/workflows/runtime/journal.ts +313 -0
  62. package/src/domains/workflows/runtime/model-profiles.ts +310 -0
  63. package/src/domains/workflows/runtime/options.ts +157 -0
  64. package/src/domains/workflows/runtime/perf.ts +146 -0
  65. package/src/domains/workflows/runtime/pi-compat.ts +32 -0
  66. package/src/domains/workflows/runtime/process-runner.ts +260 -0
  67. package/src/domains/workflows/runtime/progress-types.ts +59 -0
  68. package/src/domains/workflows/runtime/progress.ts +400 -0
  69. package/src/domains/workflows/runtime/provider-usage-limit.ts +191 -0
  70. package/src/domains/workflows/runtime/replay-path-identity.ts +48 -0
  71. package/src/domains/workflows/runtime/research-contract.ts +89 -0
  72. package/src/domains/workflows/runtime/research-evidence.ts +289 -0
  73. package/src/domains/workflows/runtime/resume-context.ts +751 -0
  74. package/src/domains/workflows/runtime/review/code-review-orchestration.ts +24 -0
  75. package/src/domains/workflows/runtime/review/github-pr-comments.ts +249 -0
  76. package/src/domains/workflows/runtime/review/patch-validation.ts +120 -0
  77. package/src/domains/workflows/runtime/review/review-actions.ts +180 -0
  78. package/src/domains/workflows/runtime/review/review-budget.ts +45 -0
  79. package/src/domains/workflows/runtime/review/review-fix-workflow.ts +153 -0
  80. package/src/domains/workflows/runtime/review/review-format.ts +133 -0
  81. package/src/domains/workflows/runtime/review/review-handoff.ts +38 -0
  82. package/src/domains/workflows/runtime/review/review-issues.ts +87 -0
  83. package/src/domains/workflows/runtime/review/review-report.ts +42 -0
  84. package/src/domains/workflows/runtime/review/review-results-flow.ts +52 -0
  85. package/src/domains/workflows/runtime/review/review-results-viewer.ts +312 -0
  86. package/src/domains/workflows/runtime/review/review-session-coordinator.ts +153 -0
  87. package/src/domains/workflows/runtime/review/review-snapshot.ts +294 -0
  88. package/src/domains/workflows/runtime/review-diff-target.ts +130 -0
  89. package/src/domains/workflows/runtime/session-identity.ts +6 -0
  90. package/src/domains/workflows/runtime/structured-output.ts +32 -0
  91. package/src/domains/workflows/runtime/tool-capabilities.ts +44 -0
  92. package/src/domains/workflows/runtime/tool-source-identity.ts +150 -0
  93. package/src/domains/workflows/runtime/tree-fingerprint.ts +404 -0
  94. package/src/domains/workflows/runtime/types.ts +255 -0
  95. package/src/domains/workflows/runtime/ui/display-text.ts +13 -0
  96. package/src/domains/workflows/runtime/ui/dynamax-editor-decoration.ts +220 -0
  97. package/src/domains/workflows/runtime/ui/workflow-format.ts +165 -0
  98. package/src/domains/workflows/runtime/ui/workflow-inspector.ts +398 -0
  99. package/src/domains/workflows/runtime/ui/workflow-result-renderer.ts +171 -0
  100. package/src/domains/workflows/runtime/ui/workflow-viewer-layout.ts +51 -0
  101. package/src/domains/workflows/runtime/ui/workflow-widget.ts +78 -0
  102. package/src/domains/workflows/runtime/unknown-error.ts +8 -0
  103. package/src/domains/workflows/runtime/usage.ts +341 -0
  104. package/src/domains/workflows/runtime/workflow-advisory-utils.ts +245 -0
  105. package/src/domains/workflows/runtime/workflow-execution.ts +121 -0
  106. package/src/domains/workflows/runtime/workflow-module.ts +75 -0
  107. package/src/domains/workflows/runtime/workflow-run-background.ts +72 -0
  108. package/src/domains/workflows/runtime/workflow-run-controller.ts +342 -0
  109. package/src/domains/workflows/runtime/workflow-run-history.ts +162 -0
  110. package/src/domains/workflows/runtime/workflow-run-record.ts +635 -0
  111. package/src/domains/workflows/runtime/workflow-run-store.ts +176 -0
  112. package/src/domains/workflows/runtime/workflow-usage-limit-scheduler.ts +80 -0
  113. package/src/domains/workflows/runtime/workflows.ts +40 -0
  114. package/src/domains/workflows/runtime/worktree.ts +581 -0
  115. package/src/domains/workflows/workflows/code-review.ts +232 -0
  116. package/src/domains/workflows/workflows/diagnose.ts +154 -0
  117. package/src/domains/workflows/workflows/perf-review.ts +149 -0
  118. package/src/domains/workflows/workflows/refactor-scout.ts +143 -0
  119. package/src/domains/workflows/workflows/research.ts +169 -0
  120. package/src/services/usage-service.ts +6 -30
@@ -0,0 +1,162 @@
1
+ import { formatWorkflowUsageLine } from "./usage.ts";
2
+ import type { WorkflowRunRecord, WorkflowRunState } from "./workflow-run-record.ts";
3
+ import { formatDuration } from "./ui/workflow-format.ts";
4
+
5
+ export const WORKFLOW_RUN_HISTORY_LIMIT = 50;
6
+ export const WORKFLOW_RUN_DETAIL_AGENT_LIMIT = 100;
7
+ export const WORKFLOW_RUN_OUTCOME_TEXT_LIMIT = 16_000;
8
+
9
+ export const WORKFLOW_RUN_ACTIONS = [
10
+ { value: "inspect", description: "Show a retained workflow run" },
11
+ { value: "stop", description: "Stop an active or paused workflow run" },
12
+ { value: "resume", description: "Resume a paused workflow run" },
13
+ { value: "restart", description: "Restart a terminal workflow run" },
14
+ ] as const;
15
+
16
+ export type WorkflowRunLifecycleAction = typeof WORKFLOW_RUN_ACTIONS[number]["value"];
17
+
18
+ const WORKFLOW_RUN_ACTION_VALUES: ReadonlySet<string> = new Set(
19
+ WORKFLOW_RUN_ACTIONS.map((action) => action.value),
20
+ );
21
+
22
+ export type WorkflowRunsCommand =
23
+ | { readonly kind: "list" }
24
+ | { readonly kind: "action"; readonly action: WorkflowRunLifecycleAction; readonly runId: string }
25
+ | { readonly kind: "error"; readonly message: string };
26
+
27
+ export function parseWorkflowRunsCommand(input: string): WorkflowRunsCommand {
28
+ const parts = input.trim().split(/\s+/).filter(Boolean);
29
+ if (parts.length === 0) return { kind: "list" };
30
+ const action = parts[0];
31
+ if (!action || !isWorkflowRunLifecycleAction(action)) {
32
+ return { kind: "error", message: workflowRunsUsage() };
33
+ }
34
+ if (parts.length !== 2 || !parts[1]) return { kind: "error", message: workflowRunsUsage() };
35
+ return { kind: "action", action, runId: parts[1] };
36
+ }
37
+
38
+ export function isWorkflowRunLifecycleAction(value: string): value is WorkflowRunLifecycleAction {
39
+ return WORKFLOW_RUN_ACTION_VALUES.has(value);
40
+ }
41
+
42
+ export function workflowRunsUsage(): string {
43
+ return "Use /workflow while a workflow is running.";
44
+ }
45
+
46
+ export function availableWorkflowRunActions(
47
+ record: WorkflowRunRecord,
48
+ active: boolean,
49
+ ): readonly WorkflowRunLifecycleAction[] {
50
+ const actions: WorkflowRunLifecycleAction[] = ["inspect"];
51
+ if ((record.state === "queued" || record.state === "running") && active) actions.push("stop");
52
+ if (record.state === "paused") {
53
+ actions.push("stop");
54
+ if (canRelaunchWorkflowRun(record)) actions.push("resume");
55
+ }
56
+ if (
57
+ (record.state === "completed" || record.state === "failed" || record.state === "stopped")
58
+ && canRelaunchWorkflowRun(record)
59
+ ) {
60
+ actions.push("restart");
61
+ }
62
+ return actions;
63
+ }
64
+
65
+ export function canRelaunchWorkflowRun(record: WorkflowRunRecord): boolean {
66
+ return record.workflow.sourceKind === "file"
67
+ && typeof record.workflow.sourceFingerprint === "string"
68
+ && record.options.argumentsPresent === false;
69
+ }
70
+
71
+ export function formatWorkflowRunHistory(
72
+ records: readonly WorkflowRunRecord[],
73
+ activeRunIds: ReadonlySet<string> = new Set(),
74
+ now = Date.now(),
75
+ ): string {
76
+ if (records.length === 0) return "No durable workflow runs are available for this project.";
77
+ const lines = ["Recent workflow runs:"];
78
+ for (const record of records.slice(0, WORKFLOW_RUN_HISTORY_LIMIT)) {
79
+ lines.push(`- ${formatWorkflowRunSummary(record, activeRunIds.has(record.runId), now)}`);
80
+ }
81
+ if (records.length > WORKFLOW_RUN_HISTORY_LIMIT) {
82
+ lines.push(`… ${records.length - WORKFLOW_RUN_HISTORY_LIMIT} older runs hidden`);
83
+ }
84
+ return lines.join("\n");
85
+ }
86
+
87
+ export function formatWorkflowRunSummary(
88
+ record: WorkflowRunRecord,
89
+ active: boolean,
90
+ now = Date.now(),
91
+ ): string {
92
+ const usage = formatWorkflowUsageLine(record.usage);
93
+ const actions = availableWorkflowRunActions(record, active).filter((action) => action !== "inspect");
94
+ return `${workflowRunStateLabel(record.state)} ${record.workflow.name} · age ${formatDuration(Math.max(0, now - record.createdAt))} · duration ${formatWorkflowRunDuration(record, now)}${usage ? ` · ${usage}` : ""} · ${record.runId}${actions.length > 0 ? ` · actions ${actions.join(", ")}` : ""}`;
95
+ }
96
+
97
+ export function formatWorkflowRunDetails(
98
+ record: WorkflowRunRecord,
99
+ active: boolean,
100
+ now = Date.now(),
101
+ ): string {
102
+ const agents = record.progress.phases.flatMap((phase) =>
103
+ phase.agents.map((agent) => `${phase.title} / ${agent.label}: ${agent.status}`)
104
+ );
105
+ const shownAgents = agents.slice(0, WORKFLOW_RUN_DETAIL_AGENT_LIMIT);
106
+ const usage = formatWorkflowUsageLine(record.usage);
107
+ const lines = [
108
+ `Workflow run ${record.runId}`,
109
+ `Workflow: ${record.workflow.name}`,
110
+ `State: ${workflowRunStateLabel(record.state)}`,
111
+ `Age: ${formatDuration(Math.max(0, now - record.createdAt))}`,
112
+ `Duration: ${formatWorkflowRunDuration(record, now)}`,
113
+ `Phase: ${record.progress.currentPhase}`,
114
+ `Actions: ${availableWorkflowRunActions(record, active).join(", ")}`,
115
+ ];
116
+ if (usage) lines.push(usage);
117
+ if (record.options.resumeEditedWorkflow) lines.push("Edited-workflow resume: enabled");
118
+ const cachedAgents = record.progress.counters.find((counter) => counter.key === "resume.cached")?.value ?? 0;
119
+ const liveAgents = record.progress.counters.find((counter) => counter.key === "resume.live")?.value ?? 0;
120
+ if (cachedAgents > 0 || liveAgents > 0) lines.push(`Resume calls: ${cachedAgents} cached, ${liveAgents} live`);
121
+ if (record.state === "paused" && record.pause?.kind === "provider_usage_limit") {
122
+ lines.push(
123
+ `Provider limit attempt: ${record.pause.attempt}/${record.pause.maxAttempts}`,
124
+ `Next eligible: ${new Date(record.pause.nextEligibleAt).toISOString()}`,
125
+ `Automatic resume: ${record.pause.autoResume ? "scheduled" : "disabled"}`,
126
+ `Provider message: ${record.pause.providerMessage}`,
127
+ );
128
+ }
129
+ if (shownAgents.length > 0) {
130
+ lines.push("Agents:", ...shownAgents.map((agent) => `- ${agent}`));
131
+ if (agents.length > shownAgents.length) lines.push(`… ${agents.length - shownAgents.length} agents hidden`);
132
+ }
133
+ lines.push("Outcome:", retainedWorkflowRunOutcome(record));
134
+ return lines.join("\n");
135
+ }
136
+
137
+ export function retainedWorkflowRunOutcome(record: WorkflowRunRecord): string {
138
+ if (record.state === "completed") {
139
+ if (record.result.kind === "unavailable") return boundedOutcome(`Result unavailable: ${record.result.reason}`);
140
+ return boundedOutcome(JSON.stringify(record.result.value, null, 2));
141
+ }
142
+ if (record.state === "failed" || record.state === "stopped" || record.state === "paused") {
143
+ return boundedOutcome(record.message);
144
+ }
145
+ return "Run is still in progress.";
146
+ }
147
+
148
+ export function formatWorkflowRunDuration(record: WorkflowRunRecord, now = Date.now()): string {
149
+ const start = record.startedAt ?? record.createdAt;
150
+ const end = record.endedAt ?? (record.state === "paused" ? record.updatedAt : now);
151
+ return formatDuration(Math.max(0, end - start));
152
+ }
153
+
154
+ export function workflowRunStateLabel(state: WorkflowRunState): string {
155
+ return state.toUpperCase();
156
+ }
157
+
158
+ function boundedOutcome(value: string): string {
159
+ return value.length <= WORKFLOW_RUN_OUTCOME_TEXT_LIMIT
160
+ ? value
161
+ : `${value.slice(0, WORKFLOW_RUN_OUTCOME_TEXT_LIMIT - 1)}…`;
162
+ }