@linxiraos/pi-messenger 1.1.1 → 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.
- package/CHANGELOG.md +741 -676
- package/LICENSE +45 -0
- package/README.md +424 -424
- package/THIRD-PARTY-NOTICES.txt +22951 -0
- package/config-overlay.ts +175 -171
- package/config.ts +221 -209
- package/crew/agents/crew-plan-sync.md +66 -64
- package/crew/agents/crew-planner.md +173 -172
- package/crew/agents/crew-reviewer.md +58 -58
- package/crew/agents/crew-worker.md +130 -129
- package/crew/agents.ts +507 -434
- package/crew/handlers/coordination.ts +350 -332
- package/crew/handlers/plan.ts +988 -906
- package/crew/handlers/review.ts +354 -333
- package/crew/handlers/revise.ts +400 -376
- package/crew/handlers/status.ts +303 -295
- package/crew/handlers/sync.ts +237 -233
- package/crew/handlers/task.ts +820 -792
- package/crew/handlers/team.ts +294 -235
- package/crew/handlers/work.ts +467 -425
- package/crew/id-allocator.ts +30 -30
- package/crew/index.ts +297 -257
- package/crew/live-progress.ts +58 -58
- package/crew/lobby.ts +504 -473
- package/crew/prompt.ts +262 -252
- package/crew/registry.ts +114 -114
- package/crew/spawn.ts +135 -111
- package/crew/state-autonomous.ts +163 -164
- package/crew/state-planning.ts +264 -263
- package/crew/state.ts +20 -20
- package/crew/store.ts +646 -642
- package/crew/task-actions.ts +162 -131
- package/crew/team/store.ts +572 -479
- package/crew/team/subagent-roles.ts +105 -87
- package/crew/team/types.ts +50 -50
- package/crew/types.ts +194 -194
- package/crew/utils/artifacts.ts +57 -62
- package/crew/utils/config.ts +158 -156
- package/crew/utils/discover.ts +221 -219
- package/crew/utils/install.ts +94 -85
- package/crew/utils/migrations.ts +126 -0
- package/crew/utils/progress.ts +191 -187
- package/crew/utils/result.ts +16 -16
- package/crew/utils/risk-labels.ts +5 -7
- package/crew/utils/task-format.ts +14 -14
- package/crew/utils/team-roles.ts +44 -28
- package/crew/utils/truncate.ts +76 -79
- package/crew/utils/verdict.ts +55 -55
- package/editor-binary.ts +150 -0
- package/editor-command.ts +107 -0
- package/editor-target.ts +40 -0
- package/feed.ts +321 -268
- package/handlers.ts +1041 -1107
- package/index.ts +1314 -1206
- package/install.mjs +187 -189
- package/lib.ts +587 -467
- package/overlay-actions.ts +519 -511
- package/overlay-coordinator.ts +150 -150
- package/overlay-render.ts +770 -676
- package/overlay.ts +872 -830
- package/package.json +64 -60
- package/paths.ts +60 -0
- package/skills/pi-messenger-crew/SKILL.md +375 -347
- package/store.ts +1147 -1139
- package/teamagent-command.ts +321 -0
- package/vitest.config.ts +10 -10
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Messenger - State Directory Migrations
|
|
3
|
+
*
|
|
4
|
+
* One-time migrations that move plugin state out of the legacy ~/.pi tree into
|
|
5
|
+
* the zeta tree (see ./paths.ts). Follows the marker-file framework of
|
|
6
|
+
* runLegacyAgentCleanupMigration (crew/utils/install.ts): each migration runs
|
|
7
|
+
* at most once per machine, tracked by a marker file under the NEW messenger
|
|
8
|
+
* directory.
|
|
9
|
+
*
|
|
10
|
+
* Project-level state cannot be migrated at load time (the extension only
|
|
11
|
+
* knows about the current project), so ensureProjectStateMigrated runs lazily
|
|
12
|
+
* on the first touch of a project's state per process and is naturally
|
|
13
|
+
* idempotent: after a successful move the legacy directory is gone.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import {
|
|
19
|
+
getGlobalConfigPath,
|
|
20
|
+
getGlobalMessengerDir,
|
|
21
|
+
getLegacyGlobalConfigPath,
|
|
22
|
+
getLegacyGlobalMessengerDir,
|
|
23
|
+
getLegacyProjectConfigPath,
|
|
24
|
+
getLegacyProjectMessengerDir,
|
|
25
|
+
getProjectConfigPath,
|
|
26
|
+
getProjectMessengerDir,
|
|
27
|
+
} from "../../paths.ts";
|
|
28
|
+
|
|
29
|
+
const STATE_DIR_MIGRATION_MARKER = "zeta-state-dirs-v1.json";
|
|
30
|
+
|
|
31
|
+
export interface MigrationOptions {
|
|
32
|
+
homeDir?: string;
|
|
33
|
+
marker?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MigrationResult {
|
|
37
|
+
ran: boolean;
|
|
38
|
+
moved: string[];
|
|
39
|
+
errors: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function migrationMarkerDir(): string {
|
|
43
|
+
return path.join(getGlobalMessengerDir(), "migrations");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Move a directory/file when the source exists and the target does not. */
|
|
47
|
+
function moveIfAbsent(src: string, dest: string, moved: string[], errors: string[]): void {
|
|
48
|
+
if (!fs.existsSync(src) || fs.existsSync(dest)) return;
|
|
49
|
+
try {
|
|
50
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
51
|
+
fs.renameSync(src, dest);
|
|
52
|
+
moved.push(dest);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
errors.push(`Failed to move ${src} -> ${dest}: ${err instanceof Error ? err.message : String(err)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One-time migration: relocate global messenger state and config from
|
|
60
|
+
* ~/.pi/agent to the zeta agent directory. Safe to call on every extension
|
|
61
|
+
* load; the marker file makes repeat calls no-ops.
|
|
62
|
+
*/
|
|
63
|
+
export function runStateDirMigrations(options: MigrationOptions = {}): MigrationResult {
|
|
64
|
+
const markerPath = path.join(migrationMarkerDir(), options.marker ?? STATE_DIR_MIGRATION_MARKER);
|
|
65
|
+
if (fs.existsSync(markerPath)) {
|
|
66
|
+
return { ran: false, moved: [], errors: [] };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const moved: string[] = [];
|
|
70
|
+
const errors: string[] = [];
|
|
71
|
+
moveIfAbsent(
|
|
72
|
+
getLegacyGlobalMessengerDir(options.homeDir),
|
|
73
|
+
getGlobalMessengerDir(),
|
|
74
|
+
moved,
|
|
75
|
+
errors,
|
|
76
|
+
);
|
|
77
|
+
moveIfAbsent(
|
|
78
|
+
getLegacyGlobalConfigPath(options.homeDir),
|
|
79
|
+
getGlobalConfigPath(),
|
|
80
|
+
moved,
|
|
81
|
+
errors,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
86
|
+
fs.writeFileSync(
|
|
87
|
+
markerPath,
|
|
88
|
+
JSON.stringify({ migratedAt: new Date().toISOString(), moved, errors }, null, 2),
|
|
89
|
+
);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
errors.push(`Failed to persist migration marker: ${err}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { ran: true, moved, errors };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Project migrations are keyed per cwd and run once per process. The rename is
|
|
98
|
+
// itself one-shot on disk (the legacy directory disappears), so this guard
|
|
99
|
+
// only avoids re-stat'ing on every call.
|
|
100
|
+
const migratedProjects = new Set<string>();
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Lazy per-project counterpart of runStateDirMigrations: moves
|
|
104
|
+
* <project>/.pi/messenger and <project>/.pi/pi-messenger.json into the .zeta
|
|
105
|
+
* tree. Never throws — callers are state helpers that must keep working even
|
|
106
|
+
* if the rename fails (e.g. file lock); the legacy tree is simply left in
|
|
107
|
+
* place and the new one is used from then on.
|
|
108
|
+
*/
|
|
109
|
+
export function ensureProjectStateMigrated(cwd: string): void {
|
|
110
|
+
const projectRoot = path.resolve(cwd);
|
|
111
|
+
if (migratedProjects.has(projectRoot)) return;
|
|
112
|
+
migratedProjects.add(projectRoot);
|
|
113
|
+
|
|
114
|
+
const moved: string[] = [];
|
|
115
|
+
const errors: string[] = [];
|
|
116
|
+
moveIfAbsent(getLegacyProjectMessengerDir(projectRoot), getProjectMessengerDir(projectRoot), moved, errors);
|
|
117
|
+
moveIfAbsent(getLegacyProjectConfigPath(projectRoot), getProjectConfigPath(projectRoot), moved, errors);
|
|
118
|
+
if (errors.length > 0 && process.env.PI_MESSENGER_DEBUG) {
|
|
119
|
+
console.error("[pi-messenger] project state migration failed:", errors.join("; "));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Test seam: forget migrated projects so a test can exercise the move again. */
|
|
124
|
+
export function __resetProjectMigrationsForTests(): void {
|
|
125
|
+
migratedProjects.clear();
|
|
126
|
+
}
|
package/crew/utils/progress.ts
CHANGED
|
@@ -1,187 +1,191 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Crew - Progress Tracking
|
|
3
|
-
*
|
|
4
|
-
* Real-time visibility into agent execution via --mode json event parsing.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export interface ToolEntry {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AgentProgress {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Event types from pi's --mode json output
|
|
28
|
-
export interface PiEvent {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function createProgress(agent: string): AgentProgress {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function parseJsonlLine(line: string): PiEvent | null {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function updateProgress(progress: AgentProgress, event: PiEvent, startTime: number): void {
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function extractArgsPreview(args?: Record<string, unknown>): string {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function getAssistantText(event: PiEvent): string {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function getFinalOutput(messages: PiEvent[]): string {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function compactEventForArtifact(event: PiEvent): Record<string, unknown> {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function getTerminalProviderError(event: PiEvent): string | null {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Progress Tracking
|
|
3
|
+
*
|
|
4
|
+
* Real-time visibility into agent execution via --mode json event parsing.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface ToolEntry {
|
|
8
|
+
tool: string;
|
|
9
|
+
args: string;
|
|
10
|
+
startMs: number;
|
|
11
|
+
endMs: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AgentProgress {
|
|
15
|
+
agent: string;
|
|
16
|
+
status: "pending" | "running" | "completed" | "failed";
|
|
17
|
+
currentTool?: string;
|
|
18
|
+
currentToolArgs?: string;
|
|
19
|
+
currentToolStartMs?: number;
|
|
20
|
+
recentTools: ToolEntry[];
|
|
21
|
+
toolCallCount: number;
|
|
22
|
+
tokens: number;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Event types from pi's --mode json output
|
|
28
|
+
export interface PiEvent {
|
|
29
|
+
type: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
toolName?: string;
|
|
32
|
+
args?: Record<string, unknown>;
|
|
33
|
+
message?: {
|
|
34
|
+
role: string;
|
|
35
|
+
usage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number };
|
|
36
|
+
model?: string;
|
|
37
|
+
content?: Array<{ type: string; text?: string }>;
|
|
38
|
+
errorMessage?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createProgress(agent: string): AgentProgress {
|
|
43
|
+
return {
|
|
44
|
+
agent,
|
|
45
|
+
status: "pending",
|
|
46
|
+
recentTools: [],
|
|
47
|
+
toolCallCount: 0,
|
|
48
|
+
tokens: 0,
|
|
49
|
+
durationMs: 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function parseJsonlLine(line: string): PiEvent | null {
|
|
54
|
+
if (!line.trim()) return null;
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(line);
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function updateProgress(progress: AgentProgress, event: PiEvent, startTime: number): void {
|
|
63
|
+
progress.durationMs = Date.now() - startTime;
|
|
64
|
+
|
|
65
|
+
switch (event.type) {
|
|
66
|
+
case "tool_execution_start":
|
|
67
|
+
progress.status = "running";
|
|
68
|
+
progress.currentTool = event.toolName;
|
|
69
|
+
progress.currentToolArgs = extractArgsPreview(event.args);
|
|
70
|
+
progress.currentToolStartMs = Date.now();
|
|
71
|
+
break;
|
|
72
|
+
|
|
73
|
+
case "tool_execution_end":
|
|
74
|
+
progress.toolCallCount++;
|
|
75
|
+
if (progress.currentTool) {
|
|
76
|
+
progress.recentTools.push({
|
|
77
|
+
tool: progress.currentTool,
|
|
78
|
+
args: progress.currentToolArgs ?? "",
|
|
79
|
+
startMs: progress.currentToolStartMs ?? Date.now(),
|
|
80
|
+
endMs: Date.now(),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
progress.currentTool = undefined;
|
|
84
|
+
progress.currentToolArgs = undefined;
|
|
85
|
+
progress.currentToolStartMs = undefined;
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case "message_end":
|
|
89
|
+
if (event.message?.usage) {
|
|
90
|
+
progress.tokens += (event.message.usage.input ?? 0) + (event.message.usage.output ?? 0);
|
|
91
|
+
}
|
|
92
|
+
if (event.message?.errorMessage) {
|
|
93
|
+
progress.error = event.message.errorMessage;
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function extractArgsPreview(args?: Record<string, unknown>): string {
|
|
100
|
+
if (!args) return "";
|
|
101
|
+
const previewKeys = ["command", "path", "file_path", "pattern", "query"];
|
|
102
|
+
for (const key of previewKeys) {
|
|
103
|
+
if (args[key] && typeof args[key] === "string") {
|
|
104
|
+
const value = (args[key] as string).replaceAll("\n", " ").replaceAll("\r", "");
|
|
105
|
+
return value.length > 60 ? `${value.slice(0, 57)}...` : value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getAssistantText(event: PiEvent): string {
|
|
112
|
+
if (event.type !== "message_end" || event.message?.role !== "assistant") return "";
|
|
113
|
+
for (const part of event.message.content ?? []) {
|
|
114
|
+
if (part.type === "text" && part.text) return part.text;
|
|
115
|
+
}
|
|
116
|
+
return "";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function getFinalOutput(messages: PiEvent[]): string {
|
|
120
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
121
|
+
const text = getAssistantText(messages[i]);
|
|
122
|
+
if (text) return text;
|
|
123
|
+
}
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function compactEventForArtifact(event: PiEvent): Record<string, unknown> {
|
|
128
|
+
if (event.type !== "message_update") return event as Record<string, unknown>;
|
|
129
|
+
|
|
130
|
+
const compact: Record<string, unknown> = { ...event };
|
|
131
|
+
delete compact.message;
|
|
132
|
+
|
|
133
|
+
const assistantMessageEvent = compact.assistantMessageEvent;
|
|
134
|
+
if (assistantMessageEvent && typeof assistantMessageEvent === "object") {
|
|
135
|
+
const nested = { ...(assistantMessageEvent as Record<string, unknown>) };
|
|
136
|
+
delete nested.partial;
|
|
137
|
+
compact.assistantMessageEvent = nested;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return compact;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function getTerminalProviderError(event: PiEvent): string | null {
|
|
144
|
+
const status = findStatusCode(event);
|
|
145
|
+
if (status === undefined || ![400, 401, 402, 403, 429].includes(status)) return null;
|
|
146
|
+
|
|
147
|
+
const text = collectStrings(event).join(" ");
|
|
148
|
+
const normalized = text.toLowerCase();
|
|
149
|
+
if (
|
|
150
|
+
!/(usage|quota|credit|billing|auth|unauthor|forbidden|rate limit|invalid_request|add more|plan limits|third-party apps)/.test(
|
|
151
|
+
normalized,
|
|
152
|
+
)
|
|
153
|
+
) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const message = firstUsefulMessage(event) ?? text;
|
|
158
|
+
const concise = message.replace(/\s+/g, " ").trim().slice(0, 500);
|
|
159
|
+
return `Provider error ${status}: ${concise || "non-retryable provider error"}`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function findStatusCode(value: unknown): number | undefined {
|
|
163
|
+
if (!value || typeof value !== "object") return undefined;
|
|
164
|
+
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
|
165
|
+
if (["status", "statusCode", "httpStatus", "code"].includes(key) && typeof child === "number") return child;
|
|
166
|
+
const nested = findStatusCode(child);
|
|
167
|
+
if (nested !== undefined) return nested;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function collectStrings(value: unknown, depth = 0): string[] {
|
|
173
|
+
if (depth > 5 || value === null || value === undefined) return [];
|
|
174
|
+
if (typeof value === "string") return [value];
|
|
175
|
+
if (Array.isArray(value)) return value.flatMap(item => collectStrings(item, depth + 1));
|
|
176
|
+
if (typeof value !== "object") return [];
|
|
177
|
+
return Object.values(value as Record<string, unknown>).flatMap(item => collectStrings(item, depth + 1));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function firstUsefulMessage(value: unknown, depth = 0): string | undefined {
|
|
181
|
+
if (depth > 5 || !value || typeof value !== "object") return undefined;
|
|
182
|
+
const record = value as Record<string, unknown>;
|
|
183
|
+
for (const key of ["message", "errorMessage", "detail", "details"]) {
|
|
184
|
+
if (typeof record[key] === "string") return record[key] as string;
|
|
185
|
+
}
|
|
186
|
+
for (const child of Object.values(record)) {
|
|
187
|
+
const nested = firstUsefulMessage(child, depth + 1);
|
|
188
|
+
if (nested) return nested;
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
package/crew/utils/result.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Crew - Result Formatter
|
|
3
|
-
*
|
|
4
|
-
* Helper for consistent tool result formatting.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Format a tool result with text content and structured details.
|
|
9
|
-
* Matches the pattern used throughout pi-messenger handlers.
|
|
10
|
-
*/
|
|
11
|
-
export function result(text: string, details: Record<string, unknown>) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Crew - Result Formatter
|
|
3
|
+
*
|
|
4
|
+
* Helper for consistent tool result formatting.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Format a tool result with text content and structured details.
|
|
9
|
+
* Matches the pattern used throughout pi-messenger handlers.
|
|
10
|
+
*/
|
|
11
|
+
export function result(text: string, details: Record<string, unknown>) {
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: "text" as const, text }],
|
|
14
|
+
details,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export function normalizeRiskLabels(labels: string[] | undefined): string[] | undefined {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return normalized.length > 0 ? Array.from(new Set(normalized)) : undefined;
|
|
7
|
-
}
|
|
1
|
+
export function normalizeRiskLabels(labels: string[] | undefined): string[] | undefined {
|
|
2
|
+
if (!labels) return undefined;
|
|
3
|
+
const normalized = labels.map(label => label.trim().toLowerCase()).filter(Boolean);
|
|
4
|
+
return normalized.length > 0 ? Array.from(new Set(normalized)) : undefined;
|
|
5
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Task } from "../types.ts";
|
|
2
|
-
|
|
3
|
-
export function taskMetadataMarkers(task: Task): string {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function approvalTaskSummaries(tasks: Task[]): { id: string; title: string; approval: Task["approval"] }[] {
|
|
13
|
-
|
|
14
|
-
}
|
|
1
|
+
import type { Task } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
export function taskMetadataMarkers(task: Task): string {
|
|
4
|
+
const markers = [
|
|
5
|
+
task.role ? `[${task.role}]` : null,
|
|
6
|
+
task.risk_labels && task.risk_labels.length > 0 ? `[risk: ${task.risk_labels.join(", ")}]` : null,
|
|
7
|
+
task.approval?.required ? `[approval: ${task.approval.status}]` : null,
|
|
8
|
+
].filter(Boolean);
|
|
9
|
+
return markers.length > 0 ? ` ${markers.join(" ")}` : "";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function approvalTaskSummaries(tasks: Task[]): { id: string; title: string; approval: Task["approval"] }[] {
|
|
13
|
+
return tasks.map(task => ({ id: task.id, title: task.title, approval: task.approval }));
|
|
14
|
+
}
|
package/crew/utils/team-roles.ts
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
export const PACKAGED_TEAM_ROLES = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
export const PACKAGED_TEAM_ROLES = [
|
|
2
|
+
"context-builder",
|
|
3
|
+
"delegate",
|
|
4
|
+
"oracle",
|
|
5
|
+
"planner",
|
|
6
|
+
"researcher",
|
|
7
|
+
"reviewer",
|
|
8
|
+
"scout",
|
|
9
|
+
"worker",
|
|
10
|
+
] as const;
|
|
11
|
+
|
|
12
|
+
export const NON_EDITING_TEAM_ROLES = new Set([
|
|
13
|
+
"context-builder",
|
|
14
|
+
"oracle",
|
|
15
|
+
"planner",
|
|
16
|
+
"researcher",
|
|
17
|
+
"reviewer",
|
|
18
|
+
"scout",
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const PACKAGED_ROLE_NAMES = new Set<string>(PACKAGED_TEAM_ROLES);
|
|
22
|
+
const RESERVED_TEAM_NAMES = new Set(["__proto__", "constructor", "prototype"]);
|
|
23
|
+
|
|
24
|
+
export function canonicalPackagedTeamRole(role: string | undefined): string | undefined {
|
|
25
|
+
const trimmed = role?.trim();
|
|
26
|
+
if (!trimmed) return undefined;
|
|
27
|
+
const lower = trimmed.toLowerCase();
|
|
28
|
+
return PACKAGED_ROLE_NAMES.has(lower) ? lower : trimmed;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isReservedTeamName(name: string): boolean {
|
|
32
|
+
return RESERVED_TEAM_NAMES.has(name) || Object.hasOwn(Object.prototype, name);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isValidTeamName(name: string): boolean {
|
|
36
|
+
if (!name || name.length > 80) return false;
|
|
37
|
+
if (isReservedTeamName(name)) return false;
|
|
38
|
+
return /^[a-zA-Z0-9_][a-zA-Z0-9_-]*$/.test(name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isNonEditingTeamRole(role: string | undefined): boolean {
|
|
42
|
+
const canonical = canonicalPackagedTeamRole(role);
|
|
43
|
+
return !!canonical && NON_EDITING_TEAM_ROLES.has(canonical);
|
|
44
|
+
}
|