@laburen/delta-cli 0.0.0-stage → 0.2.0-canary.9

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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/dist/bin.d.ts +2 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/bin.js.map +1 -0
  6. package/dist/commands/agent-checks.d.ts +3 -0
  7. package/dist/commands/agent-checks.js +36 -0
  8. package/dist/commands/agent-checks.js.map +1 -0
  9. package/dist/commands/agent-run/body.d.ts +22 -0
  10. package/dist/commands/agent-run/body.js +88 -0
  11. package/dist/commands/agent-run/body.js.map +1 -0
  12. package/dist/commands/agent-run/render.d.ts +40 -0
  13. package/dist/commands/agent-run/render.js +271 -0
  14. package/dist/commands/agent-run/render.js.map +1 -0
  15. package/dist/commands/agent-run.d.ts +10 -0
  16. package/dist/commands/agent-run.js +205 -0
  17. package/dist/commands/agent-run.js.map +1 -0
  18. package/dist/commands/agent-tools/add.d.ts +5 -0
  19. package/dist/commands/agent-tools/add.js +80 -0
  20. package/dist/commands/agent-tools/add.js.map +1 -0
  21. package/dist/commands/agent-tools/remove.d.ts +5 -0
  22. package/dist/commands/agent-tools/remove.js +126 -0
  23. package/dist/commands/agent-tools/remove.js.map +1 -0
  24. package/dist/commands/agent-tools/shared.d.ts +276 -0
  25. package/dist/commands/agent-tools/shared.js +94 -0
  26. package/dist/commands/agent-tools/shared.js.map +1 -0
  27. package/dist/commands/agent-tools.d.ts +5 -0
  28. package/dist/commands/agent-tools.js +11 -0
  29. package/dist/commands/agent-tools.js.map +1 -0
  30. package/dist/commands/auth.d.ts +14 -0
  31. package/dist/commands/auth.js +161 -0
  32. package/dist/commands/auth.js.map +1 -0
  33. package/dist/commands/completion.d.ts +4 -0
  34. package/dist/commands/completion.js +50 -0
  35. package/dist/commands/completion.js.map +1 -0
  36. package/dist/commands/config-sources.d.ts +22 -0
  37. package/dist/commands/config-sources.js +46 -0
  38. package/dist/commands/config-sources.js.map +1 -0
  39. package/dist/commands/config-wizard.d.ts +9 -0
  40. package/dist/commands/config-wizard.js +332 -0
  41. package/dist/commands/config-wizard.js.map +1 -0
  42. package/dist/commands/orgs.d.ts +11 -0
  43. package/dist/commands/orgs.js +179 -0
  44. package/dist/commands/orgs.js.map +1 -0
  45. package/dist/commands/skill-dir.d.ts +18 -0
  46. package/dist/commands/skill-dir.js +97 -0
  47. package/dist/commands/skill-dir.js.map +1 -0
  48. package/dist/commands/token-notice.d.ts +4 -0
  49. package/dist/commands/token-notice.js +13 -0
  50. package/dist/commands/token-notice.js.map +1 -0
  51. package/dist/commands/whoami.d.ts +8 -0
  52. package/dist/commands/whoami.js +38 -0
  53. package/dist/commands/whoami.js.map +1 -0
  54. package/dist/commands/wizards.d.ts +4 -0
  55. package/dist/commands/wizards.js +210 -0
  56. package/dist/commands/wizards.js.map +1 -0
  57. package/dist/completion/bash.d.ts +3 -0
  58. package/dist/completion/bash.js +60 -0
  59. package/dist/completion/bash.js.map +1 -0
  60. package/dist/completion/files.d.ts +33 -0
  61. package/dist/completion/files.js +171 -0
  62. package/dist/completion/files.js.map +1 -0
  63. package/dist/completion/powershell.d.ts +9 -0
  64. package/dist/completion/powershell.js +83 -0
  65. package/dist/completion/powershell.js.map +1 -0
  66. package/dist/completion/tree.d.ts +25 -0
  67. package/dist/completion/tree.js +53 -0
  68. package/dist/completion/tree.js.map +1 -0
  69. package/dist/completion/zsh.d.ts +3 -0
  70. package/dist/completion/zsh.js +76 -0
  71. package/dist/completion/zsh.js.map +1 -0
  72. package/dist/config/auth.d.ts +26 -0
  73. package/dist/config/auth.js +223 -0
  74. package/dist/config/auth.js.map +1 -0
  75. package/dist/config/link.d.ts +16 -0
  76. package/dist/config/link.js +74 -0
  77. package/dist/config/link.js.map +1 -0
  78. package/dist/config/paths.d.ts +3 -0
  79. package/dist/config/paths.js +20 -0
  80. package/dist/config/paths.js.map +1 -0
  81. package/dist/config/settings.d.ts +8 -0
  82. package/dist/config/settings.js +24 -0
  83. package/dist/config/settings.js.map +1 -0
  84. package/dist/confirm.d.ts +35 -0
  85. package/dist/confirm.js +51 -0
  86. package/dist/confirm.js.map +1 -0
  87. package/dist/context.d.ts +27 -0
  88. package/dist/context.js +15 -0
  89. package/dist/context.js.map +1 -0
  90. package/dist/errors.d.ts +54 -0
  91. package/dist/errors.js +184 -0
  92. package/dist/errors.js.map +1 -0
  93. package/dist/generated/commands.d.ts +47 -0
  94. package/dist/generated/commands.js +52 -0
  95. package/dist/generated/commands.js.map +1 -0
  96. package/dist/generated/schemas.d.ts +5 -0
  97. package/dist/generated/schemas.js +18 -0
  98. package/dist/generated/schemas.js.map +1 -0
  99. package/dist/invocation.d.ts +64 -0
  100. package/dist/invocation.js +325 -0
  101. package/dist/invocation.js.map +1 -0
  102. package/dist/mode.d.ts +17 -0
  103. package/dist/mode.js +22 -0
  104. package/dist/mode.js.map +1 -0
  105. package/dist/operations/call.d.ts +6 -0
  106. package/dist/operations/call.js +14 -0
  107. package/dist/operations/call.js.map +1 -0
  108. package/dist/operations/extensions.d.ts +46 -0
  109. package/dist/operations/extensions.js +29 -0
  110. package/dist/operations/extensions.js.map +1 -0
  111. package/dist/operations/json-input.d.ts +7 -0
  112. package/dist/operations/json-input.js +50 -0
  113. package/dist/operations/json-input.js.map +1 -0
  114. package/dist/operations/params.d.ts +17 -0
  115. package/dist/operations/params.js +95 -0
  116. package/dist/operations/params.js.map +1 -0
  117. package/dist/operations/register.d.ts +10 -0
  118. package/dist/operations/register.js +102 -0
  119. package/dist/operations/register.js.map +1 -0
  120. package/dist/operations/run-operation.d.ts +8 -0
  121. package/dist/operations/run-operation.js +146 -0
  122. package/dist/operations/run-operation.js.map +1 -0
  123. package/dist/operations/schema-flag.d.ts +8 -0
  124. package/dist/operations/schema-flag.js +12 -0
  125. package/dist/operations/schema-flag.js.map +1 -0
  126. package/dist/operations/skeleton.d.ts +16 -0
  127. package/dist/operations/skeleton.js +116 -0
  128. package/dist/operations/skeleton.js.map +1 -0
  129. package/dist/operations/tables.d.ts +3 -0
  130. package/dist/operations/tables.js +52 -0
  131. package/dist/operations/tables.js.map +1 -0
  132. package/dist/operations.d.ts +5 -0
  133. package/dist/operations.js +7 -0
  134. package/dist/operations.js.map +1 -0
  135. package/dist/output.d.ts +22 -0
  136. package/dist/output.js +169 -0
  137. package/dist/output.js.map +1 -0
  138. package/dist/pickers.d.ts +51 -0
  139. package/dist/pickers.js +277 -0
  140. package/dist/pickers.js.map +1 -0
  141. package/dist/program.d.ts +31 -0
  142. package/dist/program.js +251 -0
  143. package/dist/program.js.map +1 -0
  144. package/dist/prompter.d.ts +54 -0
  145. package/dist/prompter.js +129 -0
  146. package/dist/prompter.js.map +1 -0
  147. package/dist/session.d.ts +45 -0
  148. package/dist/session.js +170 -0
  149. package/dist/session.js.map +1 -0
  150. package/dist/update-check.d.ts +4 -0
  151. package/dist/update-check.js +60 -0
  152. package/dist/update-check.js.map +1 -0
  153. package/docs/SKILL.md +108 -0
  154. package/docs/references/auth-and-organizations.md +72 -0
  155. package/docs/references/commands.md +186 -0
  156. package/docs/references/output-and-errors.md +87 -0
  157. package/package.json +39 -5
@@ -0,0 +1,276 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../../context.js";
3
+ import type { OperationCommand } from "../../generated/commands.js";
4
+ import type { Mode } from "../../mode.js";
5
+ import type { PickDeps } from "../../pickers.js";
6
+ import { type Prompter } from "../../prompter.js";
7
+ import type { Session } from "../../session.js";
8
+ export type Tool = Record<string, unknown>;
9
+ /** Lo que reciben los comandos de tools: el `fetch` de la puerta y quién pregunta. */
10
+ export interface ToolCommandDeps {
11
+ fetch?: typeof fetch;
12
+ prompter: Prompter;
13
+ }
14
+ export declare const TOOLS_ADD: OperationCommand;
15
+ export declare const TOOLS_REMOVE: OperationCommand;
16
+ /** Última versión del agente con sus tools; `versionId` es undefined si el agente no tiene versiones. */
17
+ export declare function latestTools(session: Session, agentId: string): Promise<{
18
+ versionId?: string;
19
+ tools: Tool[];
20
+ }>;
21
+ /**
22
+ * Manda `config: { tools }` (y `activate: true` si se pidió) con la versión que se leyó como base (E21); la API crea
23
+ * la versión nueva sobre la última (R13). `baseVersionId` es null si el agente no tenía versiones.
24
+ */
25
+ export declare function updateTools(session: Session, agentId: string, tools: Tool[], activate: boolean, baseVersionId: string | null): Promise<{
26
+ active_version_id: string | null;
27
+ created_at: string;
28
+ description: string;
29
+ harness_type: "legacy" | "mastra";
30
+ id: string;
31
+ name: string;
32
+ type: "agent";
33
+ updated_at: string;
34
+ version: {
35
+ agent_id: string;
36
+ change_message: string | null;
37
+ changed_fields: string[];
38
+ config: {
39
+ attachments?: {
40
+ access?: "inline";
41
+ allow_reread?: boolean;
42
+ keep_in_history?: boolean;
43
+ max_tokens_per_attachment?: number;
44
+ max_tokens_per_message?: number;
45
+ } & {
46
+ [key: string]: unknown;
47
+ };
48
+ history?: {
49
+ exchanges?: number;
50
+ reasoning?: boolean;
51
+ tool_calls?: ({
52
+ mode: "off";
53
+ } & {
54
+ [key: string]: unknown;
55
+ }) | ({
56
+ exclude_tools?: string[];
57
+ mode: "all";
58
+ } & {
59
+ [key: string]: unknown;
60
+ }) | ({
61
+ exclude_tools?: string[];
62
+ mode: "recent";
63
+ turns: number;
64
+ } & {
65
+ [key: string]: unknown;
66
+ });
67
+ } & {
68
+ [key: string]: unknown;
69
+ };
70
+ knowledge?: {
71
+ mode?: "vector";
72
+ project_ids?: string[];
73
+ } & {
74
+ [key: string]: unknown;
75
+ };
76
+ model?: {
77
+ id: string;
78
+ reasoning_effort?: "off" | "low" | "medium" | "high" | "max";
79
+ } & {
80
+ [key: string]: unknown;
81
+ };
82
+ prompt?: unknown[];
83
+ tools?: (({
84
+ body?: unknown[];
85
+ description?: string;
86
+ headers?: unknown[];
87
+ id?: string;
88
+ method?: string;
89
+ name?: unknown;
90
+ path_variables?: unknown[];
91
+ query_parameters?: unknown[];
92
+ type: "http";
93
+ url: string;
94
+ with_approval?: unknown;
95
+ } & {
96
+ [key: string]: unknown;
97
+ }) | ({
98
+ id?: string;
99
+ instructions?: string;
100
+ max_thoughts?: number;
101
+ type: "thinking";
102
+ } & {
103
+ [key: string]: unknown;
104
+ }) | ({
105
+ id?: string;
106
+ type: "send_files";
107
+ } & {
108
+ [key: string]: unknown;
109
+ }) | ({
110
+ id?: string;
111
+ type: "request_human";
112
+ } & {
113
+ [key: string]: unknown;
114
+ }))[];
115
+ } & {
116
+ [key: string]: unknown;
117
+ };
118
+ created_at: string;
119
+ created_by: string;
120
+ harness_type: "legacy" | "mastra";
121
+ id: string;
122
+ is_active: boolean;
123
+ mcp_connections: {
124
+ connection_id: string;
125
+ pinned_version_id: string | null;
126
+ strategy: "pin" | "latest";
127
+ tools: string[];
128
+ }[];
129
+ skills: {
130
+ pinned_version_id: string | null;
131
+ skill_id: string;
132
+ strategy: "pin" | "latest";
133
+ }[];
134
+ type: "agent_version";
135
+ version_number: number;
136
+ warnings?: {
137
+ code: "mcp_tools_unverified";
138
+ connection_id: string;
139
+ message: string;
140
+ }[];
141
+ } | null;
142
+ }>;
143
+ /**
144
+ * Edita las tools sobre la última versión leída. Si alguien creó otra versión mientras tanto (409
145
+ * `base_version_mismatch`), vuelve a leer, rearma la lista con `rebuild` y reintenta una sola vez; un segundo
146
+ * 409 sale como cualquier error de la API (E21).
147
+ */
148
+ export declare function updateToolsOnLatest(session: Session, agentId: string, read: {
149
+ versionId?: string;
150
+ tools: Tool[];
151
+ }, rebuild: (tools: Tool[], versionId?: string) => Tool[], activate: boolean): Promise<{
152
+ active_version_id: string | null;
153
+ created_at: string;
154
+ description: string;
155
+ harness_type: "legacy" | "mastra";
156
+ id: string;
157
+ name: string;
158
+ type: "agent";
159
+ updated_at: string;
160
+ version: {
161
+ agent_id: string;
162
+ change_message: string | null;
163
+ changed_fields: string[];
164
+ config: {
165
+ attachments?: {
166
+ access?: "inline";
167
+ allow_reread?: boolean;
168
+ keep_in_history?: boolean;
169
+ max_tokens_per_attachment?: number;
170
+ max_tokens_per_message?: number;
171
+ } & {
172
+ [key: string]: unknown;
173
+ };
174
+ history?: {
175
+ exchanges?: number;
176
+ reasoning?: boolean;
177
+ tool_calls?: ({
178
+ mode: "off";
179
+ } & {
180
+ [key: string]: unknown;
181
+ }) | ({
182
+ exclude_tools?: string[];
183
+ mode: "all";
184
+ } & {
185
+ [key: string]: unknown;
186
+ }) | ({
187
+ exclude_tools?: string[];
188
+ mode: "recent";
189
+ turns: number;
190
+ } & {
191
+ [key: string]: unknown;
192
+ });
193
+ } & {
194
+ [key: string]: unknown;
195
+ };
196
+ knowledge?: {
197
+ mode?: "vector";
198
+ project_ids?: string[];
199
+ } & {
200
+ [key: string]: unknown;
201
+ };
202
+ model?: {
203
+ id: string;
204
+ reasoning_effort?: "off" | "low" | "medium" | "high" | "max";
205
+ } & {
206
+ [key: string]: unknown;
207
+ };
208
+ prompt?: unknown[];
209
+ tools?: (({
210
+ body?: unknown[];
211
+ description?: string;
212
+ headers?: unknown[];
213
+ id?: string;
214
+ method?: string;
215
+ name?: unknown;
216
+ path_variables?: unknown[];
217
+ query_parameters?: unknown[];
218
+ type: "http";
219
+ url: string;
220
+ with_approval?: unknown;
221
+ } & {
222
+ [key: string]: unknown;
223
+ }) | ({
224
+ id?: string;
225
+ instructions?: string;
226
+ max_thoughts?: number;
227
+ type: "thinking";
228
+ } & {
229
+ [key: string]: unknown;
230
+ }) | ({
231
+ id?: string;
232
+ type: "send_files";
233
+ } & {
234
+ [key: string]: unknown;
235
+ }) | ({
236
+ id?: string;
237
+ type: "request_human";
238
+ } & {
239
+ [key: string]: unknown;
240
+ }))[];
241
+ } & {
242
+ [key: string]: unknown;
243
+ };
244
+ created_at: string;
245
+ created_by: string;
246
+ harness_type: "legacy" | "mastra";
247
+ id: string;
248
+ is_active: boolean;
249
+ mcp_connections: {
250
+ connection_id: string;
251
+ pinned_version_id: string | null;
252
+ strategy: "pin" | "latest";
253
+ tools: string[];
254
+ }[];
255
+ skills: {
256
+ pinned_version_id: string | null;
257
+ skill_id: string;
258
+ strategy: "pin" | "latest";
259
+ }[];
260
+ type: "agent_version";
261
+ version_number: number;
262
+ warnings?: {
263
+ code: "mcp_tools_unverified";
264
+ connection_id: string;
265
+ message: string;
266
+ }[];
267
+ } | null;
268
+ }>;
269
+ /** Suma `--activate` / `--no-activate` a `tools add` y `tools remove` (I3). */
270
+ export declare function addActivateOption(command: Command): Command;
271
+ /** Si se activa la versión nueva: lo que dijo el flag; si no vino y se puede preguntar, un `confirm` con No por defecto (I3). */
272
+ export declare function chooseActivate(ctx: CliContext, mode: Mode, prompter: Prompter, flag: boolean | undefined): Promise<boolean>;
273
+ /** Si la versión que creó el update quedó sin activar, avisa por stderr cuál es y el comando que la activa (I3). */
274
+ export declare function noticeInactiveVersion(ctx: CliContext, mode: Mode, agentId: string, result: unknown): void;
275
+ /** Lo que necesita elegir el agente de la lista; en `remove` se pregunta aunque haya uno solo (C27). */
276
+ export declare function pickDeps(ctx: CliContext, deps: ToolCommandDeps, session: Session, mode: Mode, op: OperationCommand, given: string[]): PickDeps;
@@ -0,0 +1,94 @@
1
+ import { ConflictError } from "@laburen/delta-sdk/platform";
2
+ import { commandText, suggestedCommand } from "../../invocation.js";
3
+ import { escapeControl, notice } from "../../output.js";
4
+ import { canPrompt } from "../../prompter.js";
5
+ /**
6
+ * Ficha de los comandos de tools con la forma de los generados, para reusar la elección de ids (C28): el agente sale
7
+ * de `agents.list`; la tool, de la última versión (no hay un `list` de tools).
8
+ */
9
+ function toolsCommand(verb, positionals) {
10
+ return {
11
+ id: `agents.tools.${verb}`,
12
+ path: ["agents", "tools", verb],
13
+ summary: "",
14
+ positionals,
15
+ queryFlags: [],
16
+ // `--tool` lleva valor: al insertar un id en la invocación se saltea, como los flags de los generados.
17
+ bodyFlags: verb === "add" ? [{ name: "tool", flag: "--tool", type: "json", required: true }] : [],
18
+ hasBody: false,
19
+ organizationHeader: true,
20
+ paginated: false,
21
+ destructive: verb === "remove",
22
+ idSources: { agent_id: { list: "agents.list", needs: [] } },
23
+ };
24
+ }
25
+ export const TOOLS_ADD = toolsCommand("add", ["agent_id"]);
26
+ export const TOOLS_REMOVE = toolsCommand("remove", ["agent_id", "tool_id"]);
27
+ /** Última versión del agente con sus tools; `versionId` es undefined si el agente no tiene versiones. */
28
+ export async function latestTools(session, agentId) {
29
+ const page = await session.platform.agents.versions.list(agentId, { limit: 1 });
30
+ const latest = page.data[0];
31
+ const tools = latest?.config?.tools ?? [];
32
+ return { versionId: latest?.id, tools };
33
+ }
34
+ /**
35
+ * Manda `config: { tools }` (y `activate: true` si se pidió) con la versión que se leyó como base (E21); la API crea
36
+ * la versión nueva sobre la última (R13). `baseVersionId` es null si el agente no tenía versiones.
37
+ */
38
+ export function updateTools(session, agentId, tools, activate, baseVersionId) {
39
+ const config = { tools };
40
+ const body = activate
41
+ ? { config, activate: true, base_version_id: baseVersionId }
42
+ : { config, base_version_id: baseVersionId };
43
+ return session.platform.agents.update(agentId, body);
44
+ }
45
+ /**
46
+ * Edita las tools sobre la última versión leída. Si alguien creó otra versión mientras tanto (409
47
+ * `base_version_mismatch`), vuelve a leer, rearma la lista con `rebuild` y reintenta una sola vez; un segundo
48
+ * 409 sale como cualquier error de la API (E21).
49
+ */
50
+ export async function updateToolsOnLatest(session, agentId, read, rebuild, activate) {
51
+ try {
52
+ return await updateTools(session, agentId, rebuild(read.tools, read.versionId), activate, read.versionId ?? null);
53
+ }
54
+ catch (error) {
55
+ if (!(error instanceof ConflictError) || error.code !== "base_version_mismatch")
56
+ throw error;
57
+ const fresh = await latestTools(session, agentId);
58
+ return updateTools(session, agentId, rebuild(fresh.tools, fresh.versionId), activate, fresh.versionId ?? null);
59
+ }
60
+ }
61
+ /** Suma `--activate` / `--no-activate` a `tools add` y `tools remove` (I3). */
62
+ export function addActivateOption(command) {
63
+ return command
64
+ .option("--activate", "activate the new version")
65
+ .option("--no-activate", "leave the new version inactive without asking");
66
+ }
67
+ /** Si se activa la versión nueva: lo que dijo el flag; si no vino y se puede preguntar, un `confirm` con No por defecto (I3). */
68
+ export async function chooseActivate(ctx, mode, prompter, flag) {
69
+ if (flag !== undefined)
70
+ return flag;
71
+ if (!canPrompt(ctx, mode))
72
+ return false;
73
+ return prompter.confirm({ message: "Activate the new version?", initialValue: false });
74
+ }
75
+ /** Si la versión que creó el update quedó sin activar, avisa por stderr cuál es y el comando que la activa (I3). */
76
+ export function noticeInactiveVersion(ctx, mode, agentId, result) {
77
+ const version = result?.version;
78
+ if (!version || version.is_active === true || typeof version.id !== "string")
79
+ return;
80
+ const activate = suggestedCommand(ctx, commandText(["agents", "versions", "activate", agentId, version.id]));
81
+ notice(ctx, mode, `Created version ${escapeControl(String(version.version_number))} (not active). Activate it with: ${escapeControl(activate)}`);
82
+ }
83
+ /** Lo que necesita elegir el agente de la lista; en `remove` se pregunta aunque haya uno solo (C27). */
84
+ export function pickDeps(ctx, deps, session, mode, op, given) {
85
+ return {
86
+ ctx,
87
+ mode,
88
+ prompter: deps.prompter,
89
+ platform: session.platform,
90
+ alwaysAsk: op.destructive,
91
+ typed: given,
92
+ };
93
+ }
94
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/commands/agent-tools/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAI5D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAiB,MAAM,mBAAmB,CAAC;AAW7D;;;GAGG;AACH,SAAS,YAAY,CAAC,IAAsB,EAAE,WAAqB;IAClE,OAAO;QACN,EAAE,EAAE,gBAAgB,IAAI,EAAE;QAC1B,IAAI,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;QAC/B,OAAO,EAAE,EAAE;QAC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5 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../context.js";
3
+ import type { ToolCommandDeps } from "./agent-tools/shared.js";
4
+ /** Registra `agents tools add` y `agents tools remove` dentro del grupo `agents` ya generado. */
5
+ export declare function registerAgentToolCommands(program: Command, ctx: CliContext, deps: ToolCommandDeps): void;
@@ -0,0 +1,11 @@
1
+ import { groupFor } from "../operations.js";
2
+ import { registerToolsAdd } from "./agent-tools/add.js";
3
+ import { registerToolsRemove } from "./agent-tools/remove.js";
4
+ /** Registra `agents tools add` y `agents tools remove` dentro del grupo `agents` ya generado. */
5
+ export function registerAgentToolCommands(program, ctx, deps) {
6
+ const tools = groupFor(groupFor(program, "agents"), "tools");
7
+ tools.description("Add or remove a tool of an agent");
8
+ registerToolsAdd(tools, ctx, deps);
9
+ registerToolsRemove(tools, ctx, deps);
10
+ }
11
+ //# sourceMappingURL=agent-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-tools.js","sourceRoot":"","sources":["../../src/commands/agent-tools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,iGAAiG;AACjG,MAAM,UAAU,yBAAyB,CACxC,OAAgB,EAChB,GAAe,EACf,IAAqB;IAErB,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;IAC7D,KAAK,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;IACtD,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACnC,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../context.js";
3
+ /** Piezas reemplazables en tests: el `fetch` de la puerta, el navegador, el Ctrl-C y el nombre de usuario. */
4
+ export interface AuthDeps {
5
+ fetch?: typeof fetch;
6
+ openBrowser?: (url: string) => Promise<void>;
7
+ /** Registra el handler de SIGINT y devuelve la función que lo saca. */
8
+ onSigint?: (handler: () => void) => () => void;
9
+ username?: string;
10
+ }
11
+ /** Cuánto espera el logout a que el servidor revoque cada token. */
12
+ export declare const REVOKE_TIMEOUT_MS = 5000;
13
+ /** Registra `login` y `logout` en el programa. */
14
+ export declare function registerAuthCommands(program: Command, ctx: CliContext, deps?: AuthDeps): void;
@@ -0,0 +1,161 @@
1
+ import { spawn } from "node:child_process";
2
+ import { userInfo } from "node:os";
3
+ import { revokeToken, startDeviceLogin, waitForDeviceToken } from "@laburen/delta-sdk/platform";
4
+ import { deleteAuth, lockWaitNotice, readAuth, withAuthLock, writeAuth } from "../config/auth.js";
5
+ import { resolveConfigDir } from "../config/paths.js";
6
+ import { CliError } from "../errors.js";
7
+ import { suggestedCommand } from "../invocation.js";
8
+ import { escapeControl, notice, writeResult } from "../output.js";
9
+ import { readVersion, runStandalone } from "../program.js";
10
+ import { resolveApiUrl } from "../session.js";
11
+ /** Abre `url` en el navegador del sistema sin esperar a que cierre; rechaza si no se pudo lanzar. */
12
+ function defaultOpenBrowser(url) {
13
+ const [cmd, args] = process.platform === "darwin"
14
+ ? ["open", [url]]
15
+ : process.platform === "win32"
16
+ ? ["rundll32", ["url.dll,FileProtocolHandler", url]]
17
+ : ["xdg-open", [url]];
18
+ return new Promise((resolve, reject) => {
19
+ const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
20
+ child.once("error", reject);
21
+ child.once("spawn", () => {
22
+ child.unref();
23
+ resolve();
24
+ });
25
+ });
26
+ }
27
+ function defaultOnSigint(handler) {
28
+ process.once("SIGINT", handler);
29
+ return () => process.off("SIGINT", handler);
30
+ }
31
+ function defaultUsername(ctx) {
32
+ try {
33
+ return userInfo().username;
34
+ }
35
+ catch {
36
+ return ctx.env.USER ?? "unknown";
37
+ }
38
+ }
39
+ /** Arma el `client_info` que ve quien aprueba el login (P29). */
40
+ function buildClientInfo(username) {
41
+ return `${username} @ laburen-cli ${readVersion()} node-${process.versions.node} ${process.platform} (${process.arch})`;
42
+ }
43
+ /** Devuelve si `value` es una URL http o https válida. */
44
+ function isHttpUrl(value) {
45
+ try {
46
+ const { protocol } = new URL(value);
47
+ return protocol === "http:" || protocol === "https:";
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ /** Intenta abrir el navegador salvo en CI; devuelve si pudo lanzarlo (no si hay pantalla). Un error al abrirlo no corta el login. */
54
+ async function tryOpenBrowser(ctx, url, open) {
55
+ if (ctx.env.CI)
56
+ return false;
57
+ // Solo http(s): la URL viene del servidor y no debe llegar a un lanzador con otro esquema.
58
+ if (!isHttpUrl(url))
59
+ return false;
60
+ try {
61
+ await open(url);
62
+ return true;
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
68
+ /** Login por device code (C21): imprime link y código, espera la aprobación y guarda auth.json. */
69
+ async function login(ctx, flags, mode, deps) {
70
+ const apiUrl = resolveApiUrl(ctx, flags);
71
+ const configDir = resolveConfigDir(ctx, flags.globalConfig);
72
+ if (ctx.env.LABUREN_TOKEN) {
73
+ notice(ctx, mode, "LABUREN_TOKEN is set and overrides saved credentials in other commands.");
74
+ }
75
+ // El Ctrl-C corta la espera con un error propio, para salir con código 1 sin dejar nada a medias.
76
+ const controller = new AbortController();
77
+ const removeSigint = (deps.onSigint ?? defaultOnSigint)(() => controller.abort(new CliError("login_cancelled", "Login cancelled.", 1)));
78
+ try {
79
+ const device = await startDeviceLogin({
80
+ clientInfo: buildClientInfo(deps.username ?? defaultUsername(ctx)),
81
+ baseUrl: apiUrl,
82
+ fetch: deps.fetch,
83
+ signal: controller.signal,
84
+ });
85
+ // La URL y el código vienen del servidor: van escapados como todo lo que llega de afuera.
86
+ notice(ctx, mode, `Visit this URL to sign in:\n ${escapeControl(device.verification_uri_complete)}\nConfirmation code: ${escapeControl(device.user_code)}`);
87
+ // `open` no avisa si hay pantalla (en Linux sin escritorio "abre" igual): a un agente se lo pedimos siempre.
88
+ await tryOpenBrowser(ctx, device.verification_uri_complete, deps.openBrowser ?? defaultOpenBrowser);
89
+ if (mode.isAgent && mode.nonInteractive) {
90
+ notice(ctx, mode, "Please ask the user to visit the URL above and approve the login.");
91
+ }
92
+ notice(ctx, mode, "Waiting for approval... (Ctrl-C to cancel)");
93
+ const token = await waitForDeviceToken({
94
+ deviceCode: device.device_code,
95
+ interval: device.interval,
96
+ expiresIn: device.expires_in,
97
+ baseUrl: apiUrl,
98
+ fetch: deps.fetch,
99
+ signal: controller.signal,
100
+ });
101
+ await withAuthLock(configDir, () => writeAuth(configDir, {
102
+ token: token.access_token,
103
+ refresh_token: token.refresh_token,
104
+ expires_at: ctx.now() / 1000 + token.expires_in,
105
+ api_url: apiUrl,
106
+ }), { onWait: lockWaitNotice(ctx.stderr) });
107
+ }
108
+ finally {
109
+ removeSigint();
110
+ }
111
+ notice(ctx, mode, `You are now signed in.\nRun ${escapeControl(suggestedCommand(ctx, "laburen orgs switch", ["--org"]))} to choose an organization.`);
112
+ if (mode.json)
113
+ writeResult(ctx, mode, { status: "ok", api_url: apiUrl }, "item");
114
+ }
115
+ /** Cuánto espera el logout a que el servidor revoque cada token. */
116
+ export const REVOKE_TIMEOUT_MS = 5_000;
117
+ /** Logout: revoca el token guardado (si el servidor no contesta igual sigue) y borra auth.json. */
118
+ async function logout(ctx, flags, mode, deps) {
119
+ if (ctx.env.LABUREN_TOKEN) {
120
+ notice(ctx, mode, "LABUREN_TOKEN is set: there is no saved session to sign out of. Unset the variable to stop using it.");
121
+ return;
122
+ }
123
+ const configDir = resolveConfigDir(ctx, flags.globalConfig);
124
+ const auth = await readAuth(configDir);
125
+ if (!auth) {
126
+ notice(ctx, mode, "You are not signed in.");
127
+ }
128
+ else {
129
+ // Se revocan los dos tokens a la vez y con un timeout corto: un servidor que no contesta no frena la salida.
130
+ await Promise.all([auth.refresh_token, auth.token].map((token) => revokeToken({
131
+ token,
132
+ baseUrl: auth.api_url,
133
+ fetch: deps.fetch,
134
+ timeout: REVOKE_TIMEOUT_MS,
135
+ }).catch(() => { })));
136
+ await withAuthLock(configDir, () => deleteAuth(configDir), {
137
+ onWait: lockWaitNotice(ctx.stderr),
138
+ });
139
+ notice(ctx, mode, "You are now signed out.");
140
+ }
141
+ if (mode.json)
142
+ writeResult(ctx, mode, { status: "ok" }, "item");
143
+ }
144
+ /** Registra `login` y `logout` en el programa. */
145
+ export function registerAuthCommands(program, ctx, deps = {}) {
146
+ program
147
+ .command("login")
148
+ .description("Sign in with your browser and save credentials")
149
+ .action(async (_opts, self) => {
150
+ const flags = self.optsWithGlobals();
151
+ await runStandalone(ctx, flags, (mode) => login(ctx, flags, mode, deps));
152
+ });
153
+ program
154
+ .command("logout")
155
+ .description("Revoke the saved token and delete the saved credentials")
156
+ .action(async (_opts, self) => {
157
+ const flags = self.optsWithGlobals();
158
+ await runStandalone(ctx, flags, (mode) => logout(ctx, flags, mode, deps));
159
+ });
160
+ }
161
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEhG,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAA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AAC;QACpD,MAAM,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IACJ,OAAO;SACL,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,yDAAyD,CAAC;SACtE,MAAM,CAAC,KAAK,EAAE,KAAc,EAAE,IAAa,EAAE,EAAE;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAiB,CAAC;QACpD,MAAM,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Command } from "commander";
2
+ import type { CliContext } from "../context.js";
3
+ /** Registra `completion`: imprime el script de Tab para zsh o bash, o con `--install` lo guarda y lo engancha al rc. */
4
+ export declare function registerCompletionCommand(program: Command, ctx: CliContext): void;
@@ -0,0 +1,50 @@
1
+ import { detectShell, generateScript, installCompletion, isShell, SHELLS, } from "../completion/files.js";
2
+ import { CliError } from "../errors.js";
3
+ import { notice } from "../output.js";
4
+ import { readVersion, runStandalone } from "../program.js";
5
+ const SUPPORTED = SHELLS.join(", ");
6
+ /** Registra `completion`: imprime el script de Tab para zsh o bash, o con `--install` lo guarda y lo engancha al rc. */
7
+ export function registerCompletionCommand(program, ctx) {
8
+ program
9
+ .command("completion [shell]")
10
+ .description("Print the shell completion script (zsh, bash, powershell) or install it with --install")
11
+ .option("--install", "save the script and add one line to your shell startup file")
12
+ .option("--shell <shell>", "shell to install for (zsh, bash, powershell); default: detected from $SHELL")
13
+ .action(async (shellArg, opts, self) => {
14
+ const flags = self.optsWithGlobals();
15
+ await runStandalone(ctx, flags, async (mode) => {
16
+ const version = readVersion();
17
+ if (!opts.install) {
18
+ const shell = shellArg ?? opts.shell;
19
+ if (!shell || !isShell(shell)) {
20
+ throw new CliError("invalid_shell", shell
21
+ ? `Unsupported shell "${shell}". Supported: ${SUPPORTED}.`
22
+ : `Pass a shell: ${SUPPORTED}.`, 2, [{ command: "laburen completion zsh", when: "to print the script for zsh" }]);
23
+ }
24
+ ctx.stdout.write(generateScript(program, shell, version));
25
+ return;
26
+ }
27
+ const shell = opts.shell ?? shellArg ?? detectShell(ctx);
28
+ if (!shell || !isShell(shell)) {
29
+ throw new CliError("invalid_shell", `${shell ? `Unsupported shell "${shell}"` : "Could not detect your shell from $SHELL"}. Supported: ${SUPPORTED}.`, 2, [
30
+ {
31
+ command: "laburen completion --install --shell zsh",
32
+ when: "to choose the shell yourself",
33
+ },
34
+ ]);
35
+ }
36
+ const result = await installCompletion(ctx, program, shell, version, flags.globalConfig);
37
+ notice(ctx, mode, `Saved the ${shell} completion script to ${result.scriptFile}.`);
38
+ for (const rc of result.rcFiles) {
39
+ notice(ctx, mode, rc.updated
40
+ ? `Added one line to ${rc.file} to load it.`
41
+ : `${rc.file} already loads it; nothing to add.`);
42
+ }
43
+ if (result.profileGuessed) {
44
+ notice(ctx, mode, "Could not ask PowerShell for its profile path, so the default one was used. To check where yours is, run `$PROFILE` in PowerShell; if it differs, add the line there.");
45
+ }
46
+ notice(ctx, mode, "Open a new terminal to use Tab completion.");
47
+ });
48
+ });
49
+ }
50
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.js","sourceRoot":"","sources":["../../src/commands/completion.ts"],"names":[],"mappings":"AACA,OAAO,EACN,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,OAAO,EACP,MAAM,GACN,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE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