@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,150 +1,150 @@
1
- import type { OverlayHandle, TUI } from "@earendil-works/pi-tui";
2
-
3
- const QUIET_PERIOD_MS = 80;
4
- const RENDER_THROTTLE_MS = 32;
5
- const STDOUT_GUARD_MS = 32;
6
-
7
- type StdoutWrite = typeof process.stdout.write;
8
-
9
- function hasRenderableOutput(chunk: unknown): boolean {
10
- if (typeof chunk === "string") return chunk.length > 0;
11
- if (chunk instanceof Uint8Array) return chunk.length > 0;
12
- return false;
13
- }
14
-
15
- /**
16
- * Coordinates overlay rendering with main agent stdout to prevent visual collision.
17
- *
18
- * Strategy: Keep overlay visible, but schedule a "repair" render after foreign
19
- * output settles. Brief visual corruption is acceptable if it self-heals quickly.
20
- */
21
- export class OverlayRenderCoordinator {
22
- private tui: TUI | null = null;
23
- private handle: OverlayHandle | null = null;
24
- private originalRequestRender: TUI["requestRender"] | null = null;
25
- private originalStdoutWrite: StdoutWrite | null = null;
26
- private repairTimer: ReturnType<typeof setTimeout> | null = null;
27
- private lastRenderAt = 0;
28
- private stdoutGuardUntil = 0;
29
- private foreignOutputDetected = false;
30
-
31
- installStdoutInterceptor(): void {
32
- if (this.originalStdoutWrite) return;
33
-
34
- const original = process.stdout.write.bind(process.stdout) as StdoutWrite;
35
- this.originalStdoutWrite = original;
36
-
37
- const coordinator = this;
38
- (process.stdout.write as StdoutWrite) = function writeIntercept(
39
- chunk: Parameters<StdoutWrite>[0],
40
- ...args: Parameters<StdoutWrite> extends [unknown, ...infer Rest] ? Rest : never
41
- ) {
42
- const result = original(chunk, ...args);
43
- coordinator.handleStdoutWrite(chunk);
44
- return result;
45
- } as StdoutWrite;
46
- }
47
-
48
- uninstallStdoutInterceptor(): void {
49
- if (!this.originalStdoutWrite) return;
50
- (process.stdout.write as StdoutWrite) = this.originalStdoutWrite;
51
- this.originalStdoutWrite = null;
52
- }
53
-
54
- attach(tui: TUI): void {
55
- if (this.tui === tui && this.originalRequestRender) return;
56
-
57
- this.detach();
58
- this.tui = tui;
59
- this.originalRequestRender = tui.requestRender.bind(tui);
60
- tui.requestRender = ((force?: boolean) => {
61
- this.requestRender(force);
62
- }) as TUI["requestRender"];
63
- }
64
-
65
- setHandle(handle: OverlayHandle | null): void {
66
- this.handle = handle;
67
- }
68
-
69
- detach(): void {
70
- if (this.repairTimer) {
71
- clearTimeout(this.repairTimer);
72
- this.repairTimer = null;
73
- }
74
- if (this.tui && this.originalRequestRender) {
75
- this.tui.requestRender = this.originalRequestRender;
76
- }
77
- this.tui = null;
78
- this.handle = null;
79
- this.originalRequestRender = null;
80
- this.lastRenderAt = 0;
81
- this.stdoutGuardUntil = 0;
82
- this.foreignOutputDetected = false;
83
- }
84
-
85
- dispose(): void {
86
- this.detach();
87
- this.uninstallStdoutInterceptor();
88
- }
89
-
90
- /** Called by hooks when main agent activity is expected */
91
- noteForegroundActivity(): void {
92
- if (!this.tui || !this.handle) return;
93
- if (this.handle.isHidden()) return;
94
-
95
- this.foreignOutputDetected = true;
96
- this.scheduleRepair();
97
- }
98
-
99
- private handleStdoutWrite(chunk: unknown): void {
100
- if (!this.tui || !this.handle) return;
101
- if (!hasRenderableOutput(chunk)) return;
102
- if (Date.now() <= this.stdoutGuardUntil) return;
103
- if (this.handle.isHidden()) return;
104
-
105
- this.foreignOutputDetected = true;
106
- this.scheduleRepair();
107
- }
108
-
109
- private scheduleRepair(): void {
110
- if (this.repairTimer) clearTimeout(this.repairTimer);
111
- this.repairTimer = setTimeout(() => {
112
- this.repairTimer = null;
113
- this.repair();
114
- }, QUIET_PERIOD_MS);
115
- }
116
-
117
- private repair(): void {
118
- if (!this.tui || !this.handle) return;
119
- if (this.handle.isHidden()) return;
120
- if (!this.foreignOutputDetected) return;
121
-
122
- this.foreignOutputDetected = false;
123
- this.flushRender(true);
124
- }
125
-
126
- requestRender(force = false): void {
127
- if (!this.originalRequestRender) return;
128
- if (this.handle?.isHidden()) return;
129
-
130
- const now = Date.now();
131
- if (!force) {
132
- const elapsed = now - this.lastRenderAt;
133
- if (elapsed < RENDER_THROTTLE_MS) {
134
- // Skip this render, repair timer will catch up
135
- return;
136
- }
137
- }
138
-
139
- this.flushRender(force);
140
- }
141
-
142
- private flushRender(force: boolean): void {
143
- if (!this.originalRequestRender) return;
144
- if (this.handle?.isHidden()) return;
145
-
146
- this.lastRenderAt = Date.now();
147
- this.stdoutGuardUntil = this.lastRenderAt + STDOUT_GUARD_MS;
148
- this.originalRequestRender(force);
149
- }
150
- }
1
+ import type { OverlayHandle, TUI } from "@linxiraos/pi-tui";
2
+
3
+ const QUIET_PERIOD_MS = 80;
4
+ const RENDER_THROTTLE_MS = 32;
5
+ const STDOUT_GUARD_MS = 32;
6
+
7
+ type StdoutWrite = typeof process.stdout.write;
8
+
9
+ function hasRenderableOutput(chunk: unknown): boolean {
10
+ if (typeof chunk === "string") return chunk.length > 0;
11
+ if (chunk instanceof Uint8Array) return chunk.length > 0;
12
+ return false;
13
+ }
14
+
15
+ /**
16
+ * Coordinates overlay rendering with main agent stdout to prevent visual collision.
17
+ *
18
+ * Strategy: Keep overlay visible, but schedule a "repair" render after foreign
19
+ * output settles. Brief visual corruption is acceptable if it self-heals quickly.
20
+ */
21
+ export class OverlayRenderCoordinator {
22
+ private tui: TUI | null = null;
23
+ private handle: OverlayHandle | null = null;
24
+ private originalRequestRender: TUI["requestRender"] | null = null;
25
+ private originalStdoutWrite: StdoutWrite | null = null;
26
+ private repairTimer: ReturnType<typeof setTimeout> | null = null;
27
+ private lastRenderAt = 0;
28
+ private stdoutGuardUntil = 0;
29
+ private foreignOutputDetected = false;
30
+
31
+ installStdoutInterceptor(): void {
32
+ if (this.originalStdoutWrite) return;
33
+
34
+ const original = process.stdout.write.bind(process.stdout) as StdoutWrite;
35
+ this.originalStdoutWrite = original;
36
+
37
+ const coordinator = this;
38
+ (process.stdout.write as StdoutWrite) = function writeIntercept(
39
+ chunk: Parameters<StdoutWrite>[0],
40
+ ...args: Parameters<StdoutWrite> extends [unknown, ...infer Rest] ? Rest : never
41
+ ) {
42
+ const result = original(chunk, ...args);
43
+ coordinator.handleStdoutWrite(chunk);
44
+ return result;
45
+ } as StdoutWrite;
46
+ }
47
+
48
+ uninstallStdoutInterceptor(): void {
49
+ if (!this.originalStdoutWrite) return;
50
+ (process.stdout.write as StdoutWrite) = this.originalStdoutWrite;
51
+ this.originalStdoutWrite = null;
52
+ }
53
+
54
+ attach(tui: TUI): void {
55
+ if (this.tui === tui && this.originalRequestRender) return;
56
+
57
+ this.detach();
58
+ this.tui = tui;
59
+ this.originalRequestRender = tui.requestRender.bind(tui);
60
+ tui.requestRender = ((force?: boolean) => {
61
+ this.requestRender(force);
62
+ }) as TUI["requestRender"];
63
+ }
64
+
65
+ setHandle(handle: OverlayHandle | null): void {
66
+ this.handle = handle;
67
+ }
68
+
69
+ detach(): void {
70
+ if (this.repairTimer) {
71
+ clearTimeout(this.repairTimer);
72
+ this.repairTimer = null;
73
+ }
74
+ if (this.tui && this.originalRequestRender) {
75
+ this.tui.requestRender = this.originalRequestRender;
76
+ }
77
+ this.tui = null;
78
+ this.handle = null;
79
+ this.originalRequestRender = null;
80
+ this.lastRenderAt = 0;
81
+ this.stdoutGuardUntil = 0;
82
+ this.foreignOutputDetected = false;
83
+ }
84
+
85
+ dispose(): void {
86
+ this.detach();
87
+ this.uninstallStdoutInterceptor();
88
+ }
89
+
90
+ /** Called by hooks when main agent activity is expected */
91
+ noteForegroundActivity(): void {
92
+ if (!this.tui || !this.handle) return;
93
+ if (this.handle.isHidden()) return;
94
+
95
+ this.foreignOutputDetected = true;
96
+ this.scheduleRepair();
97
+ }
98
+
99
+ private handleStdoutWrite(chunk: unknown): void {
100
+ if (!this.tui || !this.handle) return;
101
+ if (!hasRenderableOutput(chunk)) return;
102
+ if (Date.now() <= this.stdoutGuardUntil) return;
103
+ if (this.handle.isHidden()) return;
104
+
105
+ this.foreignOutputDetected = true;
106
+ this.scheduleRepair();
107
+ }
108
+
109
+ private scheduleRepair(): void {
110
+ if (this.repairTimer) clearTimeout(this.repairTimer);
111
+ this.repairTimer = setTimeout(() => {
112
+ this.repairTimer = null;
113
+ this.repair();
114
+ }, QUIET_PERIOD_MS);
115
+ }
116
+
117
+ private repair(): void {
118
+ if (!this.tui || !this.handle) return;
119
+ if (this.handle.isHidden()) return;
120
+ if (!this.foreignOutputDetected) return;
121
+
122
+ this.foreignOutputDetected = false;
123
+ this.flushRender(true);
124
+ }
125
+
126
+ requestRender(force = false): void {
127
+ if (!this.originalRequestRender) return;
128
+ if (this.handle?.isHidden()) return;
129
+
130
+ const now = Date.now();
131
+ if (!force) {
132
+ const elapsed = now - this.lastRenderAt;
133
+ if (elapsed < RENDER_THROTTLE_MS) {
134
+ // Skip this render, repair timer will catch up
135
+ return;
136
+ }
137
+ }
138
+
139
+ this.flushRender(force);
140
+ }
141
+
142
+ private flushRender(force: boolean): void {
143
+ if (!this.originalRequestRender) return;
144
+ if (this.handle?.isHidden()) return;
145
+
146
+ this.lastRenderAt = Date.now();
147
+ this.stdoutGuardUntil = this.lastRenderAt + STDOUT_GUARD_MS;
148
+ this.originalRequestRender(force);
149
+ }
150
+ }