@paradow/ledge 0.20.0 → 0.22.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 (40) hide show
  1. package/dist/cli/action-WNQ3NJGD.js +27 -0
  2. package/dist/cli/{attach-JNECAG6L.js → attach-UHM7QQ4W.js} +9 -8
  3. package/dist/cli/{bridge-H3ZPGIUY.js → bridge-R37AHVXS.js} +2 -1
  4. package/dist/cli/chunk-4DEVJE4H.js +6 -0
  5. package/dist/cli/{chunk-ZQON4EV7.js → chunk-5VFFJ3ZC.js} +2 -2
  6. package/dist/cli/{chunk-CDME3WRV.js → chunk-7XMGYJTN.js} +7 -7
  7. package/dist/cli/chunk-ARB4BKZJ.js +2302 -0
  8. package/dist/cli/{chunk-24AHC55Y.js → chunk-AVKFQSRP.js} +7 -21
  9. package/dist/cli/{chunk-2VSEIOGA.js → chunk-JNLARCUC.js} +7 -4
  10. package/dist/cli/{chunk-NVSBPIXY.js → chunk-KRFXWD5S.js} +1147 -406
  11. package/dist/cli/chunk-O6FTIYJV.js +85 -0
  12. package/dist/cli/{chunk-ERN736NQ.js → chunk-PUJLMKZC.js} +7 -6
  13. package/dist/cli/{chunk-ZZMZDAF6.js → chunk-RKV5KYKL.js} +3 -3
  14. package/dist/cli/{chunk-XR42PIDL.js → chunk-RYUDIFSI.js} +15 -10
  15. package/dist/cli/{chunk-AJFC33TH.js → chunk-TOFVC6IV.js} +2 -2
  16. package/dist/cli/{chunk-KACRWFN3.js → chunk-TZBI2RVU.js} +1 -1
  17. package/dist/cli/chunk-U67V476Y.js +35 -0
  18. package/dist/cli/{chunk-35BPMR6P.js → chunk-ZDEEHFU3.js} +9 -4
  19. package/dist/cli/{daemon-DVPDCY3V.js → daemon-7IGQIDWB.js} +8 -7
  20. package/dist/cli/decide-UWJMKDR4.js +57 -0
  21. package/dist/cli/{handover-AZ35QZRK.js → handover-5JHFA5EF.js} +5 -4
  22. package/dist/cli/{hook-ERYA6BKY.js → hook-XBSMUMZ7.js} +11 -10
  23. package/dist/cli/index.js +31 -17
  24. package/dist/cli/{launch-LAER5DI6.js → launch-OVB66BZJ.js} +9 -8
  25. package/dist/cli/{send-BFPJBXXH.js → send-Y2C3BIGK.js} +5 -4
  26. package/dist/cli/{setup-47ODKJBM.js → setup-K42IVMHS.js} +1 -0
  27. package/dist/cli/{status-JPF4NZNI.js → status-5YEORNTH.js} +3 -2
  28. package/dist/cli/{task-K43WJIUX.js → task-R44VWZHR.js} +5 -4
  29. package/dist/cli/team-F7B3IG3I.js +205 -0
  30. package/dist/cli/tui-ZJDNIBIB.js +19086 -0
  31. package/dist/cli/{uninstall-QNWRD27D.js → uninstall-4IMMR55T.js} +1 -0
  32. package/dist/cli/version-EHETEZAK.js +7 -0
  33. package/dist/cli/who-YMSQI64I.js +12 -0
  34. package/package.json +2 -1
  35. package/dist/cli/chunk-EX66KH66.js +0 -1856
  36. package/dist/cli/chunk-PFBZUINN.js +0 -6
  37. package/dist/cli/team-SZJHGA7D.js +0 -101
  38. package/dist/cli/tui-AMERXSL7.js +0 -4873
  39. package/dist/cli/version-BFNXT3H4.js +0 -6
  40. package/dist/cli/who-NYPVBO64.js +0 -11
@@ -18,6 +18,7 @@ import {
18
18
  import "./chunk-NLL2EQJ2.js";
19
19
  import "./chunk-6IYPRUQG.js";
20
20
  import "./chunk-HOOHS3MX.js";
21
+ import "./chunk-U67V476Y.js";
21
22
  export {
22
23
  BIN_MARK,
23
24
  CLAUDE_EVENTS,
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-KACRWFN3.js";
4
- import "./chunk-EX66KH66.js";
3
+ } from "./chunk-TZBI2RVU.js";
4
+ import "./chunk-ARB4BKZJ.js";
5
5
  import "./chunk-HOOHS3MX.js";
6
+ import "./chunk-U67V476Y.js";
6
7
 
7
8
  // src/cli/status.ts
8
9
  async function printStatus(opts = {}) {
@@ -4,11 +4,12 @@ import {
4
4
  runTask,
5
5
  taskArgs,
6
6
  taskOnClient
7
- } from "./chunk-ERN736NQ.js";
8
- import "./chunk-35BPMR6P.js";
9
- import "./chunk-KACRWFN3.js";
10
- import "./chunk-EX66KH66.js";
7
+ } from "./chunk-PUJLMKZC.js";
8
+ import "./chunk-ZDEEHFU3.js";
9
+ import "./chunk-TZBI2RVU.js";
10
+ import "./chunk-ARB4BKZJ.js";
11
11
  import "./chunk-HOOHS3MX.js";
12
+ import "./chunk-U67V476Y.js";
12
13
  export {
13
14
  TASK_USAGE,
14
15
  formatTask,
@@ -0,0 +1,205 @@
1
+ import {
2
+ DAEMON_DOWN,
3
+ actionArgs,
4
+ callerOf,
5
+ resultLine,
6
+ runOnClient
7
+ } from "./chunk-O6FTIYJV.js";
8
+ import {
9
+ listDefinitions
10
+ } from "./chunk-JNLARCUC.js";
11
+ import "./chunk-AVKFQSRP.js";
12
+ import "./chunk-ZDEEHFU3.js";
13
+ import {
14
+ connect
15
+ } from "./chunk-TZBI2RVU.js";
16
+ import {
17
+ RoleIdSchema,
18
+ SeatsSchema,
19
+ ToolSchema
20
+ } from "./chunk-ARB4BKZJ.js";
21
+ import "./chunk-6IYPRUQG.js";
22
+ import "./chunk-HOOHS3MX.js";
23
+ import "./chunk-U67V476Y.js";
24
+
25
+ // src/cli/team.ts
26
+ import { randomUUID } from "crypto";
27
+ import { resolve } from "path";
28
+ var TEAM_USAGE = `ledge team up <mod\xE8le> [--cwd <dossier>] [--name <nom>] lancer une \xE9quipe d'apr\xE8s .ledge/teams/<mod\xE8le>.yaml
29
+ ledge team up --seat <r\xF4le>[:<outil>]\u2026 [--cwd <dossier>] [--name <nom>] lancer une \xE9quipe de si\xE8ges ad hoc
30
+ ledge team list [--cwd <dossier>] les mod\xE8les, les r\xF4les et les \xE9quipes en cours
31
+ ledge team join <\xE9quipe> <session> <@r\xF4le> faire entrer une session dans une \xE9quipe, \xE0 un r\xF4le
32
+ ledge team leave <\xE9quipe> <session> faire sortir une session d'une \xE9quipe (elle continue)
33
+ ledge team resume <\xE9quipe> reprendre une \xE9quipe au repos
34
+ ledge team dissolve <\xE9quipe> [--close-sessions] --yes dissoudre une \xE9quipe (irr\xE9versible) ; ses sessions restent, ou se ferment
35
+ ledge team save <\xE9quipe> <nom> enregistrer une \xE9quipe en cours comme mod\xE8le
36
+ --json : une ligne JSON, pour un agent ou un script. Une session agent peut se fermer et quitter son \xE9quipe ;
37
+ l'@leader d'une \xE9quipe peut aussi la dissoudre, en retirer un membre ou en fermer une session. Le reste revient \xE0 l'utilisateur.`;
38
+ var UP_MS = 6e4;
39
+ var VERBS = {
40
+ join: { action: "team.join", n: 3, args: ([team, session, role]) => ({ team, session, role: role.replace(/^@/, "") }) },
41
+ leave: { action: "team.leave", n: 2, args: ([team, session]) => ({ team, session }) },
42
+ resume: { action: "team.resume", n: 1, args: ([team]) => ({ team }) },
43
+ dissolve: { action: "team.dissolve", n: 1, args: ([team]) => ({ team }) },
44
+ save: { action: "team.save", n: 2, args: ([team, name]) => ({ team, name }) }
45
+ };
46
+ function seatOf(v) {
47
+ const [role, tool, ...more] = v.split(":");
48
+ if (more.length || !RoleIdSchema.safeParse(role).success || tool !== void 0 && !ToolSchema.safeParse(tool).success) return void 0;
49
+ return { role, ...tool !== void 0 ? { tool } : {} };
50
+ }
51
+ function teamArgs(args) {
52
+ const [op, ...rest] = args;
53
+ const positional = [];
54
+ const seats = [];
55
+ let cwd;
56
+ let name;
57
+ let json = false;
58
+ let yes = false;
59
+ let closeSessions = false;
60
+ for (let i = 0; i < rest.length; i++) {
61
+ const a = rest[i];
62
+ if (a === "--cwd") {
63
+ cwd = rest[++i];
64
+ if (!cwd) return void 0;
65
+ } else if (a === "--name") {
66
+ name = rest[++i];
67
+ if (!name) return void 0;
68
+ } else if (a === "--seat") {
69
+ const s = seatOf(rest[++i] ?? "");
70
+ if (!s) return void 0;
71
+ seats.push(s);
72
+ } else if (a === "--json") json = true;
73
+ else if (a === "--yes") yes = true;
74
+ else if (a === "--close-sessions") closeSessions = true;
75
+ else if (a.startsWith("--")) return void 0;
76
+ else positional.push(a);
77
+ }
78
+ const j = json ? { json: true } : {};
79
+ const where = { ...cwd ? { cwd } : {}, ...name ? { name } : {} };
80
+ if (op === "up" && !yes && !closeSessions) {
81
+ if (positional.length === 1 && !seats.length) return { op, template: positional[0], ...where, ...j };
82
+ if (positional.length === 0 && seats.length && SeatsSchema.safeParse(seats).success) return { op, seats, ...where, ...j };
83
+ return void 0;
84
+ }
85
+ if (op === "list") return positional.length === 0 && !name && !seats.length && !yes && !closeSessions ? { op, ...cwd ? { cwd } : {}, ...j } : void 0;
86
+ const verb = op ? VERBS[op] : void 0;
87
+ if (!verb || positional.length !== verb.n || cwd || name || seats.length || closeSessions && op !== "dissolve") return void 0;
88
+ const parsed = actionArgs(verb.action, verb.args(positional));
89
+ if (!parsed) return void 0;
90
+ return { op: "run", action: verb.action, args: parsed, ...closeSessions ? { closeSessions: true } : {}, ...yes ? { yes: true } : {}, ...j };
91
+ }
92
+ var STATE = { active: "active", resting: "au repos", dissolved: "dissoute" };
93
+ function formatTeam(t, sessions) {
94
+ const byId = new Map(sessions.map((s) => [s.id, s]));
95
+ return [`${t.id} ${t.name} ${STATE[t.state]} ${t.cwd}`, ...t.seats.map((seat) => {
96
+ const s = seat.sessionId ? byId.get(seat.sessionId) : void 0;
97
+ return ` @${seat.role.padEnd(12)} ${s ? `${s.name} (${s.tool}, ${s.state})` : "libre"}`;
98
+ })].join("\n");
99
+ }
100
+ function teamJson(t, sessions) {
101
+ const byId = new Map(sessions.map((s) => [s.id, s]));
102
+ return { ...t, seats: t.seats.map((seat) => {
103
+ const s = seat.sessionId ? byId.get(seat.sessionId) : void 0;
104
+ return { ...seat, ...s ? { session: { name: s.name, tool: s.tool, state: s.state } } : {} };
105
+ }) };
106
+ }
107
+ async function runTeam(args, opts = {}) {
108
+ const parsed = teamArgs(args);
109
+ if (!parsed) return { line: TEAM_USAGE, code: args.length ? 1 : 0 };
110
+ if (parsed.op === "run") return runVerb(parsed, opts.port, callerOf(opts.env ?? process.env));
111
+ const cwd = resolve(opts.cwd ?? process.cwd(), parsed.cwd ?? ".");
112
+ if (parsed.op === "list") {
113
+ const defs = listDefinitions(cwd);
114
+ const lines = [
115
+ "MOD\xC8LES",
116
+ ...defs.templates.length ? defs.templates.map((t) => ` ${t.id.padEnd(16)} ${t.name} \xB7 ${t.seats.map((s) => `@${s.role}`).join(" ")} (${t.source})`) : [" aucun (~/.ledge/teams/<id>.yaml)"],
117
+ "",
118
+ "R\xD4LES",
119
+ ...defs.roles.length ? defs.roles.map((r) => ` @${r.id.padEnd(15)} ${r.label}${r.tool ? ` \xB7 ${r.tool}` : ""}${r.autonomy && r.autonomy !== "ask" ? ` \xB7 autonomie ${r.autonomy}` : ""} (${r.source})`) : [" aucun (~/.ledge/roles/<id>.md)"],
120
+ ...defs.problems.length ? ["", "IGNOR\xC9S", ...defs.problems.map((p) => ` ${p.path} : ${p.reason}`)] : []
121
+ ];
122
+ const json = (teams) => ({ line: JSON.stringify({ ...defs, teams }), code: 0 });
123
+ let client2;
124
+ try {
125
+ client2 = await connect({ port: opts.port, timeoutMs: 800 });
126
+ } catch {
127
+ return parsed.json ? json(null) : { line: [...lines, "", "\xC9QUIPES", ` ${DAEMON_DOWN}`].join("\n"), code: 0 };
128
+ }
129
+ try {
130
+ const snapshot = await client2.next("snapshot");
131
+ const teams = (await client2.next("teams").catch(() => ({ teams: [] }))).teams.filter((t) => t.state !== "dissolved");
132
+ if (parsed.json) return json(teams.map((t) => teamJson(t, snapshot.sessions)));
133
+ return { line: [...lines, "", "\xC9QUIPES", ...teams.length ? teams.map((t) => formatTeam(t, snapshot.sessions)) : [" aucune"]].join("\n"), code: 0 };
134
+ } finally {
135
+ await client2.close();
136
+ }
137
+ }
138
+ let client;
139
+ try {
140
+ client = await connect({ port: opts.port, timeoutMs: 1500 });
141
+ } catch {
142
+ return { line: DAEMON_DOWN, code: 1 };
143
+ }
144
+ try {
145
+ const rid = randomUUID();
146
+ client.send({ type: "team.launch", rid, cwd, ...parsed.template ? { template: parsed.template } : {}, ...parsed.seats ? { seats: parsed.seats } : {}, ...parsed.name ? { name: parsed.name } : {} });
147
+ const r = await Promise.race([client.next("team.launched", UP_MS), client.next("team.failed", UP_MS)]);
148
+ const snapshot = await client.next("snapshot", 500).catch(() => void 0);
149
+ if (r.type === "team.failed") {
150
+ if (parsed.json) return { line: JSON.stringify({ ok: false, reason: r.reason, ...r.team ? { team: teamJson(r.team, snapshot?.sessions ?? []) } : {} }), code: 1 };
151
+ return { line: `refus\xE9 : ${r.reason}${r.team ? `
152
+ ${formatTeam(r.team, snapshot?.sessions ?? [])}` : ""}`, code: 1 };
153
+ }
154
+ client.send({ type: "snapshot.request" });
155
+ const fresh = await client.next("snapshot", 1500).catch(() => snapshot);
156
+ if (parsed.json) return { line: JSON.stringify({ ok: true, team: teamJson(r.team, fresh?.sessions ?? []) }), code: 0 };
157
+ return { line: `\xE9quipe ${r.team.name} lanc\xE9e
158
+ ${formatTeam(r.team, fresh?.sessions ?? [])}`, code: 0 };
159
+ } catch (e) {
160
+ return { line: `pas de r\xE9ponse de Ledge : ${e.message}`, code: 1 };
161
+ } finally {
162
+ await client.close();
163
+ }
164
+ }
165
+ async function runVerb(cmd, port, by) {
166
+ let client;
167
+ try {
168
+ client = await connect({ port, timeoutMs: 1500 });
169
+ } catch {
170
+ return { line: DAEMON_DOWN, code: 1 };
171
+ }
172
+ try {
173
+ if (!cmd.closeSessions || !cmd.yes) return resultLine(await runOnClient(client, cmd.action, cmd.args, { by, confirmed: cmd.yes }), cmd.json);
174
+ const snapshot = await client.next("snapshot", 1500);
175
+ const teams = (await client.next("teams", 1500).catch(() => ({ teams: [] }))).teams;
176
+ const asked = await runOnClient(client, cmd.action, cmd.args, { by });
177
+ if (asked.code !== "confirm_required") return resultLine(asked, cmd.json);
178
+ const team = teams.find((t) => t.id === asked.row?.team);
179
+ const live = (team?.seats ?? []).flatMap((seat) => {
180
+ const s = snapshot.sessions.find((x) => x.id === seat.sessionId);
181
+ return s && s.state !== "exited" && s.source !== "hook_only" ? [s] : [];
182
+ });
183
+ const self = live.find((s) => s.id === by?.by);
184
+ const lines = [];
185
+ const step = async (r) => {
186
+ const l = resultLine(r, cmd.json);
187
+ lines.push(l.line);
188
+ return l.code === 0;
189
+ };
190
+ for (const s of live) if (s !== self && !await step(await runOnClient(client, "session.close", { session: s.id }, { by }))) return { line: lines.join("\n"), code: 1 };
191
+ if (!await step(await runOnClient(client, cmd.action, cmd.args, { by, confirmed: true }))) return { line: lines.join("\n"), code: 1 };
192
+ if (self && !await step(await runOnClient(client, "session.close", { session: self.id }, { by }))) return { line: lines.join("\n"), code: 1 };
193
+ return { line: lines.join("\n"), code: 0 };
194
+ } catch (e) {
195
+ return { line: `pas de r\xE9ponse de Ledge : ${e.message}`, code: 1 };
196
+ } finally {
197
+ await client.close();
198
+ }
199
+ }
200
+ export {
201
+ TEAM_USAGE,
202
+ formatTeam,
203
+ runTeam,
204
+ teamArgs
205
+ };