@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,87 +1,105 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { homedir } from "node:os";
4
- import type { TeamRoleDefinition } from "./types.ts";
5
- import { canonicalPackagedTeamRole, isValidTeamName } from "../utils/team-roles.ts";
6
-
7
- export interface DiscoverSubagentRoleOptions {
8
- homeDir?: string;
9
- }
10
-
11
- function listMarkdownFiles(dir: string): string[] {
12
- if (!fs.existsSync(dir)) return [];
13
- const out: string[] = [];
14
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
15
- const full = path.join(dir, entry.name);
16
- if (entry.isDirectory()) {
17
- out.push(...listMarkdownFiles(full));
18
- } else if (entry.isFile() && entry.name.endsWith(".md")) {
19
- out.push(full);
20
- }
21
- }
22
- return out.sort();
23
- }
24
-
25
- function splitList(value: string): string[] {
26
- const trimmed = value.trim();
27
- if (!trimmed) return [];
28
- if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
29
- return trimmed.slice(1, -1).split(",").map(v => v.trim().replace(/^['\"]|['\"]$/g, "")).filter(Boolean);
30
- }
31
- return trimmed.split(",").map(v => v.trim()).filter(Boolean);
32
- }
33
-
34
- function parseFrontmatter(content: string): { data: Record<string, string>; body: string } {
35
- const normalized = content.replace(/\r\n/g, "\n");
36
- if (!normalized.startsWith("---\n")) return { data: {}, body: normalized };
37
- const end = normalized.indexOf("\n---", 4);
38
- if (end === -1) return { data: {}, body: content };
39
- const raw = normalized.slice(4, end);
40
- const data: Record<string, string> = {};
41
- for (const line of raw.split("\n")) {
42
- const idx = line.indexOf(":");
43
- if (idx <= 0) continue;
44
- const key = line.slice(0, idx).trim();
45
- const value = line.slice(idx + 1).trim().replace(/^['\"]|['\"]$/g, "");
46
- if (key) data[key] = value;
47
- }
48
- const bodyStart = normalized.indexOf("\n", end + 4);
49
- return { data, body: bodyStart === -1 ? "" : normalized.slice(bodyStart + 1).trim() };
50
- }
51
-
52
- function readRoleFile(filePath: string, sourceLabel: string): TeamRoleDefinition | null {
53
- const content = fs.readFileSync(filePath, "utf-8");
54
- const { data, body } = parseFrontmatter(content);
55
- const rawName = data.name || path.basename(filePath, ".md");
56
- if (!isValidTeamName(rawName)) return null;
57
- const name = canonicalPackagedTeamRole(rawName) ?? rawName;
58
-
59
- return {
60
- name,
61
- ...(data.description ? { description: data.description } : {}),
62
- ...(data.model ? { model: data.model } : {}),
63
- ...(data.thinking ? { thinking: data.thinking } : {}),
64
- ...(data.skills ? { skills: splitList(data.skills) } : {}),
65
- ...(body ? { prompt: body.slice(0, 4000) } : {}),
66
- promptSource: `${sourceLabel}:${name}`,
67
- };
68
- }
69
-
70
- export function discoverSubagentRoles(cwd: string, options?: DiscoverSubagentRoleOptions): Record<string, TeamRoleDefinition> {
71
- const home = options?.homeDir ?? homedir();
72
- const sources = [
73
- { dir: path.join(home, ".pi", "agent", "extensions", "subagent", "agents"), label: "subagent:builtin" },
74
- { dir: path.join(home, ".pi", "agent", "agents"), label: "subagent:user" },
75
- { dir: path.join(cwd, ".pi", "agents"), label: "subagent:project" },
76
- { dir: path.join(cwd, ".agents"), label: "subagent:legacy-project" },
77
- ];
78
-
79
- const roles: Record<string, TeamRoleDefinition> = {};
80
- for (const source of sources) {
81
- for (const file of listMarkdownFiles(source.dir)) {
82
- const role = readRoleFile(file, source.label);
83
- if (role) roles[role.name] = { ...roles[role.name], ...role };
84
- }
85
- }
86
- return roles;
87
- }
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import type { TeamRoleDefinition } from "./types.ts";
4
+ import { canonicalPackagedTeamRole, isValidTeamName } from "../utils/team-roles.ts";
5
+ import { getAgentDir } from "@linxiraos/pi-utils/dirs";
6
+
7
+ export interface DiscoverSubagentRoleOptions {
8
+ homeDir?: string;
9
+ }
10
+
11
+ function listMarkdownFiles(dir: string): string[] {
12
+ if (!fs.existsSync(dir)) return [];
13
+ const out: string[] = [];
14
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
15
+ const full = path.join(dir, entry.name);
16
+ if (entry.isDirectory()) {
17
+ out.push(...listMarkdownFiles(full));
18
+ } else if (entry.isFile() && entry.name.endsWith(".md")) {
19
+ out.push(full);
20
+ }
21
+ }
22
+ return out.sort();
23
+ }
24
+
25
+ function splitList(value: string): string[] {
26
+ const trimmed = value.trim();
27
+ if (!trimmed) return [];
28
+ if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
29
+ return trimmed
30
+ .slice(1, -1)
31
+ .split(",")
32
+ .map(v => v.trim().replace(/^['"]|['"]$/g, ""))
33
+ .filter(Boolean);
34
+ }
35
+ return trimmed
36
+ .split(",")
37
+ .map(v => v.trim())
38
+ .filter(Boolean);
39
+ }
40
+
41
+ function parseFrontmatter(content: string): { data: Record<string, string>; body: string } {
42
+ const normalized = content.replace(/\r\n/g, "\n");
43
+ if (!normalized.startsWith("---\n")) return { data: {}, body: normalized };
44
+ const end = normalized.indexOf("\n---", 4);
45
+ if (end === -1) return { data: {}, body: content };
46
+ const raw = normalized.slice(4, end);
47
+ const data: Record<string, string> = {};
48
+ for (const line of raw.split("\n")) {
49
+ const idx = line.indexOf(":");
50
+ if (idx <= 0) continue;
51
+ const key = line.slice(0, idx).trim();
52
+ const value = line
53
+ .slice(idx + 1)
54
+ .trim()
55
+ .replace(/^['"]|['"]$/g, "");
56
+ if (key) data[key] = value;
57
+ }
58
+ const bodyStart = normalized.indexOf("\n", end + 4);
59
+ return { data, body: bodyStart === -1 ? "" : normalized.slice(bodyStart + 1).trim() };
60
+ }
61
+
62
+ function readRoleFile(filePath: string, sourceLabel: string): TeamRoleDefinition | null {
63
+ const content = fs.readFileSync(filePath, "utf-8");
64
+ const { data, body } = parseFrontmatter(content);
65
+ const rawName = data.name || path.basename(filePath, ".md");
66
+ if (!isValidTeamName(rawName)) return null;
67
+ const name = canonicalPackagedTeamRole(rawName) ?? rawName;
68
+
69
+ return {
70
+ name,
71
+ ...(data.description ? { description: data.description } : {}),
72
+ ...(data.model ? { model: data.model } : {}),
73
+ ...(data.thinking ? { thinking: data.thinking } : {}),
74
+ ...((data.skills ?? data.autoloadSkills) ? { skills: splitList(data.skills ?? data.autoloadSkills) } : {}),
75
+ ...(body ? { prompt: body.slice(0, 4000) } : {}),
76
+ promptSource: `${sourceLabel}:${name}`,
77
+ };
78
+ }
79
+
80
+ export function discoverSubagentRoles(
81
+ cwd: string,
82
+ options?: DiscoverSubagentRoleOptions,
83
+ ): Record<string, TeamRoleDefinition> {
84
+ // Under zeta, user agents live in ~/.zeta/agent/agents and project agents
85
+ // in <project>/.zeta/agents — the same directories runtime discovery
86
+ // reads. (.agents is the pre-zeta upstream layout, kept for compatibility.)
87
+ // An explicit homeDir is a test seam mirroring the default layout.
88
+ const userAgentsDir = options?.homeDir
89
+ ? path.join(options.homeDir, ".zeta", "agent", "agents")
90
+ : path.join(getAgentDir(), "agents");
91
+ const sources = [
92
+ { dir: userAgentsDir, label: "subagent:user" },
93
+ { dir: path.join(cwd, ".zeta", "agents"), label: "subagent:project" },
94
+ { dir: path.join(cwd, ".agents"), label: "subagent:legacy-project" },
95
+ ];
96
+
97
+ const roles: Record<string, TeamRoleDefinition> = {};
98
+ for (const source of sources) {
99
+ for (const file of listMarkdownFiles(source.dir)) {
100
+ const role = readRoleFile(file, source.label);
101
+ if (role) roles[role.name] = { ...roles[role.name], ...role };
102
+ }
103
+ }
104
+ return roles;
105
+ }
@@ -1,50 +1,50 @@
1
- export const TEAM_MEMORY_TYPES = ["decision", "interface", "risk", "handoff"] as const;
2
-
3
- export type TeamMemoryType = typeof TEAM_MEMORY_TYPES[number];
4
-
5
- export interface TeamState {
6
- name: string;
7
- profile?: string;
8
- created_at: string;
9
- updated_at: string;
10
- }
11
-
12
- export interface TeamRoleDefinition {
13
- name: string;
14
- description?: string;
15
- model?: string;
16
- thinking?: string;
17
- skills?: string[];
18
- prompt?: string;
19
- promptSource?: string;
20
- }
21
-
22
- export interface TeamProfile {
23
- name: string;
24
- description?: string;
25
- roles?: Record<string, Partial<TeamRoleDefinition>>;
26
- approval?: {
27
- mode?: "off" | "risk-labels";
28
- labels?: string[];
29
- };
30
- memory?: {
31
- inject?: TeamMemoryType[];
32
- maxCharsPerType?: number;
33
- };
34
- }
35
-
36
- export interface TeamMemoryEntry {
37
- ts: string;
38
- agent: string;
39
- type: TeamMemoryType;
40
- message: string;
41
- taskId?: string;
42
- }
43
-
44
- export interface TeamPromptContext {
45
- team?: TeamState;
46
- profile?: TeamProfile;
47
- role?: TeamRoleDefinition;
48
- charter?: string;
49
- memory: Partial<Record<TeamMemoryType, TeamMemoryEntry[]>>;
50
- }
1
+ export const TEAM_MEMORY_TYPES = ["decision", "interface", "risk", "handoff"] as const;
2
+
3
+ export type TeamMemoryType = (typeof TEAM_MEMORY_TYPES)[number];
4
+
5
+ export interface TeamState {
6
+ name: string;
7
+ profile?: string;
8
+ created_at: string;
9
+ updated_at: string;
10
+ }
11
+
12
+ export interface TeamRoleDefinition {
13
+ name: string;
14
+ description?: string;
15
+ model?: string;
16
+ thinking?: string;
17
+ skills?: string[];
18
+ prompt?: string;
19
+ promptSource?: string;
20
+ }
21
+
22
+ export interface TeamProfile {
23
+ name: string;
24
+ description?: string;
25
+ roles?: Record<string, Partial<TeamRoleDefinition>>;
26
+ approval?: {
27
+ mode?: "off" | "risk-labels";
28
+ labels?: string[];
29
+ };
30
+ memory?: {
31
+ inject?: TeamMemoryType[];
32
+ maxCharsPerType?: number;
33
+ };
34
+ }
35
+
36
+ export interface TeamMemoryEntry {
37
+ ts: string;
38
+ agent: string;
39
+ type: TeamMemoryType;
40
+ message: string;
41
+ taskId?: string;
42
+ }
43
+
44
+ export interface TeamPromptContext {
45
+ team?: TeamState;
46
+ profile?: TeamProfile;
47
+ role?: TeamRoleDefinition;
48
+ charter?: string;
49
+ memory: Partial<Record<TeamMemoryType, TeamMemoryEntry[]>>;
50
+ }