@linxiraos/pi-messenger 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +741 -676
  2. package/LICENSE +45 -0
  3. package/README.md +424 -424
  4. package/THIRD-PARTY-NOTICES.txt +22951 -0
  5. package/config-overlay.ts +175 -171
  6. package/config.ts +221 -209
  7. package/crew/agents/crew-plan-sync.md +66 -64
  8. package/crew/agents/crew-planner.md +173 -172
  9. package/crew/agents/crew-reviewer.md +58 -58
  10. package/crew/agents/crew-worker.md +130 -129
  11. package/crew/agents.ts +507 -434
  12. package/crew/handlers/coordination.ts +350 -332
  13. package/crew/handlers/plan.ts +988 -906
  14. package/crew/handlers/review.ts +354 -333
  15. package/crew/handlers/revise.ts +400 -376
  16. package/crew/handlers/status.ts +303 -295
  17. package/crew/handlers/sync.ts +237 -233
  18. package/crew/handlers/task.ts +820 -792
  19. package/crew/handlers/team.ts +294 -235
  20. package/crew/handlers/work.ts +467 -425
  21. package/crew/id-allocator.ts +30 -30
  22. package/crew/index.ts +297 -257
  23. package/crew/live-progress.ts +58 -58
  24. package/crew/lobby.ts +504 -473
  25. package/crew/prompt.ts +262 -252
  26. package/crew/registry.ts +114 -114
  27. package/crew/spawn.ts +135 -111
  28. package/crew/state-autonomous.ts +163 -164
  29. package/crew/state-planning.ts +264 -263
  30. package/crew/state.ts +20 -20
  31. package/crew/store.ts +646 -642
  32. package/crew/task-actions.ts +162 -131
  33. package/crew/team/store.ts +572 -479
  34. package/crew/team/subagent-roles.ts +105 -87
  35. package/crew/team/types.ts +50 -50
  36. package/crew/types.ts +194 -194
  37. package/crew/utils/artifacts.ts +57 -62
  38. package/crew/utils/config.ts +158 -156
  39. package/crew/utils/discover.ts +221 -219
  40. package/crew/utils/install.ts +94 -85
  41. package/crew/utils/migrations.ts +126 -0
  42. package/crew/utils/progress.ts +191 -187
  43. package/crew/utils/result.ts +16 -16
  44. package/crew/utils/risk-labels.ts +5 -7
  45. package/crew/utils/task-format.ts +14 -14
  46. package/crew/utils/team-roles.ts +44 -28
  47. package/crew/utils/truncate.ts +76 -79
  48. package/crew/utils/verdict.ts +55 -55
  49. package/editor-binary.ts +150 -0
  50. package/editor-command.ts +107 -0
  51. package/editor-target.ts +40 -0
  52. package/feed.ts +321 -268
  53. package/handlers.ts +1041 -1107
  54. package/index.ts +1314 -1206
  55. package/install.mjs +187 -189
  56. package/lib.ts +587 -467
  57. package/overlay-actions.ts +519 -511
  58. package/overlay-coordinator.ts +150 -150
  59. package/overlay-render.ts +770 -676
  60. package/overlay.ts +872 -830
  61. package/package.json +64 -60
  62. package/paths.ts +60 -0
  63. package/skills/pi-messenger-crew/SKILL.md +375 -347
  64. package/store.ts +1147 -1139
  65. package/teamagent-command.ts +321 -0
  66. package/vitest.config.ts +10 -10
@@ -1,164 +1,163 @@
1
- /**
2
- * Crew - Autonomous Execution State
3
- *
4
- * Tracks autonomous mode, wave history, concurrency, and auto-work flag.
5
- */
6
-
7
- import { normalizeCwd } from "./state.ts";
8
-
9
- export interface WaveResult {
10
- waveNumber: number;
11
- tasksAttempted: string[];
12
- succeeded: string[];
13
- failed: string[];
14
- blocked: string[];
15
- timestamp: string;
16
- }
17
-
18
- export interface AutonomousState {
19
- active: boolean;
20
- cwd: string | null;
21
- waveNumber: number;
22
- waveHistory: WaveResult[];
23
- startedAt: string | null;
24
- stoppedAt: string | null;
25
- stopReason: "completed" | "blocked" | "manual" | null;
26
- concurrency: number;
27
- autoOverlayPending: boolean;
28
- pid: number | null;
29
- }
30
-
31
- export const autonomousState: AutonomousState = {
32
- active: false,
33
- cwd: null,
34
- waveNumber: 0,
35
- waveHistory: [],
36
- startedAt: null,
37
- stoppedAt: null,
38
- stopReason: null,
39
- concurrency: 2,
40
- autoOverlayPending: false,
41
- pid: null,
42
- };
43
-
44
- export const MIN_CONCURRENCY = 1;
45
- export const MAX_CONCURRENCY = 10;
46
-
47
- function isProcessAlive(pid: number): boolean {
48
- try {
49
- process.kill(pid, 0);
50
- return true;
51
- } catch {
52
- return false;
53
- }
54
- }
55
-
56
- export function clampConcurrency(value: number, configMax?: number): number {
57
- if (!Number.isFinite(value)) return MIN_CONCURRENCY;
58
- const whole = Math.trunc(value);
59
- const effectiveMax = configMax != null && Number.isFinite(configMax)
60
- ? Math.min(configMax, MAX_CONCURRENCY)
61
- : MAX_CONCURRENCY;
62
- return Math.max(MIN_CONCURRENCY, Math.min(effectiveMax, whole));
63
- }
64
-
65
- let concurrencyResolve: (() => void) | null = null;
66
-
67
- export function adjustConcurrency(delta: number, configMax?: number): number {
68
- autonomousState.concurrency = clampConcurrency(autonomousState.concurrency + delta, configMax);
69
- if (concurrencyResolve) {
70
- const resolve = concurrencyResolve;
71
- concurrencyResolve = null;
72
- resolve();
73
- }
74
- return autonomousState.concurrency;
75
- }
76
-
77
- export function waitForConcurrencyChange(): Promise<void> {
78
- return new Promise(resolve => {
79
- concurrencyResolve = resolve;
80
- });
81
- }
82
-
83
- export function startAutonomous(cwd: string, concurrency: number): void {
84
- autonomousState.active = true;
85
- autonomousState.cwd = normalizeCwd(cwd);
86
- autonomousState.waveNumber = 1;
87
- autonomousState.waveHistory = [];
88
- autonomousState.startedAt = new Date().toISOString();
89
- autonomousState.stoppedAt = null;
90
- autonomousState.stopReason = null;
91
- autonomousState.concurrency = clampConcurrency(concurrency);
92
- autonomousState.autoOverlayPending = true;
93
- autonomousState.pid = process.pid;
94
- }
95
-
96
- export function stopAutonomous(reason: "completed" | "blocked" | "manual"): void {
97
- autonomousState.active = false;
98
- autonomousState.autoOverlayPending = false;
99
- autonomousState.stoppedAt = new Date().toISOString();
100
- autonomousState.stopReason = reason;
101
- autonomousState.pid = null;
102
- }
103
-
104
- export function addWaveResult(result: WaveResult): void {
105
- autonomousState.waveHistory.push(result);
106
- autonomousState.waveNumber++;
107
- }
108
-
109
- export function restoreAutonomousState(data: Partial<AutonomousState>): void {
110
- if (data.active !== undefined) autonomousState.active = data.active;
111
- if (data.cwd !== undefined) {
112
- autonomousState.cwd = data.cwd ? normalizeCwd(data.cwd) : data.cwd;
113
- }
114
- if (data.waveNumber !== undefined) autonomousState.waveNumber = data.waveNumber;
115
- if (data.waveHistory !== undefined) autonomousState.waveHistory = data.waveHistory;
116
- if (data.startedAt !== undefined) autonomousState.startedAt = data.startedAt;
117
- if (data.stoppedAt !== undefined) autonomousState.stoppedAt = data.stoppedAt;
118
- if (data.stopReason !== undefined) autonomousState.stopReason = data.stopReason;
119
- if (data.concurrency !== undefined) {
120
- autonomousState.concurrency = clampConcurrency(Number(data.concurrency));
121
- }
122
- if (data.pid !== undefined) {
123
- autonomousState.pid = typeof data.pid === "number" ? data.pid : null;
124
- }
125
-
126
- if (!autonomousState.active) return;
127
-
128
- const ownerPid = autonomousState.pid;
129
- const sameProcess = ownerPid === process.pid;
130
- const ownerAlive = typeof ownerPid === "number" && isProcessAlive(ownerPid);
131
-
132
- if (!sameProcess || !ownerAlive) {
133
- autonomousState.active = false;
134
- autonomousState.autoOverlayPending = false;
135
- autonomousState.stopReason = autonomousState.stopReason ?? "manual";
136
- autonomousState.stoppedAt = autonomousState.stoppedAt ?? new Date().toISOString();
137
- autonomousState.pid = null;
138
- }
139
- }
140
-
141
- export function isAutonomousForCwd(cwd: string): boolean {
142
- if (!autonomousState.active || !autonomousState.cwd) return false;
143
- return normalizeCwd(autonomousState.cwd) === normalizeCwd(cwd);
144
- }
145
-
146
- let pendingAutoWork = false;
147
- let pendingAutoWorkCwd: string | null = null;
148
-
149
- export function isPendingAutoWork(): boolean {
150
- return pendingAutoWork;
151
- }
152
-
153
- export function setPendingAutoWork(cwd: string): void {
154
- pendingAutoWork = true;
155
- pendingAutoWorkCwd = normalizeCwd(cwd);
156
- }
157
-
158
- export function consumePendingAutoWork(): { cwd: string } | null {
159
- if (!pendingAutoWork || !pendingAutoWorkCwd) return null;
160
- const consumed = { cwd: pendingAutoWorkCwd };
161
- pendingAutoWork = false;
162
- pendingAutoWorkCwd = null;
163
- return consumed;
164
- }
1
+ /**
2
+ * Crew - Autonomous Execution State
3
+ *
4
+ * Tracks autonomous mode, wave history, concurrency, and auto-work flag.
5
+ */
6
+
7
+ import { normalizeCwd } from "./state.ts";
8
+
9
+ export interface WaveResult {
10
+ waveNumber: number;
11
+ tasksAttempted: string[];
12
+ succeeded: string[];
13
+ failed: string[];
14
+ blocked: string[];
15
+ timestamp: string;
16
+ }
17
+
18
+ export interface AutonomousState {
19
+ active: boolean;
20
+ cwd: string | null;
21
+ waveNumber: number;
22
+ waveHistory: WaveResult[];
23
+ startedAt: string | null;
24
+ stoppedAt: string | null;
25
+ stopReason: "completed" | "blocked" | "manual" | null;
26
+ concurrency: number;
27
+ autoOverlayPending: boolean;
28
+ pid: number | null;
29
+ }
30
+
31
+ export const autonomousState: AutonomousState = {
32
+ active: false,
33
+ cwd: null,
34
+ waveNumber: 0,
35
+ waveHistory: [],
36
+ startedAt: null,
37
+ stoppedAt: null,
38
+ stopReason: null,
39
+ concurrency: 2,
40
+ autoOverlayPending: false,
41
+ pid: null,
42
+ };
43
+
44
+ export const MIN_CONCURRENCY = 1;
45
+ export const MAX_CONCURRENCY = 10;
46
+
47
+ function isProcessAlive(pid: number): boolean {
48
+ try {
49
+ process.kill(pid, 0);
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ export function clampConcurrency(value: number, configMax?: number): number {
57
+ if (!Number.isFinite(value)) return MIN_CONCURRENCY;
58
+ const whole = Math.trunc(value);
59
+ const effectiveMax =
60
+ configMax != null && Number.isFinite(configMax) ? Math.min(configMax, MAX_CONCURRENCY) : MAX_CONCURRENCY;
61
+ return Math.max(MIN_CONCURRENCY, Math.min(effectiveMax, whole));
62
+ }
63
+
64
+ let concurrencyResolve: (() => void) | null = null;
65
+
66
+ export function adjustConcurrency(delta: number, configMax?: number): number {
67
+ autonomousState.concurrency = clampConcurrency(autonomousState.concurrency + delta, configMax);
68
+ if (concurrencyResolve) {
69
+ const resolve = concurrencyResolve;
70
+ concurrencyResolve = null;
71
+ resolve();
72
+ }
73
+ return autonomousState.concurrency;
74
+ }
75
+
76
+ export function waitForConcurrencyChange(): Promise<void> {
77
+ return new Promise(resolve => {
78
+ concurrencyResolve = resolve;
79
+ });
80
+ }
81
+
82
+ export function startAutonomous(cwd: string, concurrency: number): void {
83
+ autonomousState.active = true;
84
+ autonomousState.cwd = normalizeCwd(cwd);
85
+ autonomousState.waveNumber = 1;
86
+ autonomousState.waveHistory = [];
87
+ autonomousState.startedAt = new Date().toISOString();
88
+ autonomousState.stoppedAt = null;
89
+ autonomousState.stopReason = null;
90
+ autonomousState.concurrency = clampConcurrency(concurrency);
91
+ autonomousState.autoOverlayPending = true;
92
+ autonomousState.pid = process.pid;
93
+ }
94
+
95
+ export function stopAutonomous(reason: "completed" | "blocked" | "manual"): void {
96
+ autonomousState.active = false;
97
+ autonomousState.autoOverlayPending = false;
98
+ autonomousState.stoppedAt = new Date().toISOString();
99
+ autonomousState.stopReason = reason;
100
+ autonomousState.pid = null;
101
+ }
102
+
103
+ export function addWaveResult(result: WaveResult): void {
104
+ autonomousState.waveHistory.push(result);
105
+ autonomousState.waveNumber++;
106
+ }
107
+
108
+ export function restoreAutonomousState(data: Partial<AutonomousState>): void {
109
+ if (data.active !== undefined) autonomousState.active = data.active;
110
+ if (data.cwd !== undefined) {
111
+ autonomousState.cwd = data.cwd ? normalizeCwd(data.cwd) : data.cwd;
112
+ }
113
+ if (data.waveNumber !== undefined) autonomousState.waveNumber = data.waveNumber;
114
+ if (data.waveHistory !== undefined) autonomousState.waveHistory = data.waveHistory;
115
+ if (data.startedAt !== undefined) autonomousState.startedAt = data.startedAt;
116
+ if (data.stoppedAt !== undefined) autonomousState.stoppedAt = data.stoppedAt;
117
+ if (data.stopReason !== undefined) autonomousState.stopReason = data.stopReason;
118
+ if (data.concurrency !== undefined) {
119
+ autonomousState.concurrency = clampConcurrency(Number(data.concurrency));
120
+ }
121
+ if (data.pid !== undefined) {
122
+ autonomousState.pid = typeof data.pid === "number" ? data.pid : null;
123
+ }
124
+
125
+ if (!autonomousState.active) return;
126
+
127
+ const ownerPid = autonomousState.pid;
128
+ const sameProcess = ownerPid === process.pid;
129
+ const ownerAlive = typeof ownerPid === "number" && isProcessAlive(ownerPid);
130
+
131
+ if (!sameProcess || !ownerAlive) {
132
+ autonomousState.active = false;
133
+ autonomousState.autoOverlayPending = false;
134
+ autonomousState.stopReason = autonomousState.stopReason ?? "manual";
135
+ autonomousState.stoppedAt = autonomousState.stoppedAt ?? new Date().toISOString();
136
+ autonomousState.pid = null;
137
+ }
138
+ }
139
+
140
+ export function isAutonomousForCwd(cwd: string): boolean {
141
+ if (!autonomousState.active || !autonomousState.cwd) return false;
142
+ return normalizeCwd(autonomousState.cwd) === normalizeCwd(cwd);
143
+ }
144
+
145
+ let pendingAutoWork = false;
146
+ let pendingAutoWorkCwd: string | null = null;
147
+
148
+ export function isPendingAutoWork(): boolean {
149
+ return pendingAutoWork;
150
+ }
151
+
152
+ export function setPendingAutoWork(cwd: string): void {
153
+ pendingAutoWork = true;
154
+ pendingAutoWorkCwd = normalizeCwd(cwd);
155
+ }
156
+
157
+ export function consumePendingAutoWork(): { cwd: string } | null {
158
+ if (!pendingAutoWork || !pendingAutoWorkCwd) return null;
159
+ const consumed = { cwd: pendingAutoWorkCwd };
160
+ pendingAutoWork = false;
161
+ pendingAutoWorkCwd = null;
162
+ return consumed;
163
+ }