@getpaseo/cli 0.7.2 → 0.8.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 (44) hide show
  1. package/dist/cli.js +4 -3
  2. package/dist/commands/agent/attach.js +10 -8
  3. package/dist/commands/agent/index.js +3 -3
  4. package/dist/commands/agent/logs.js +6 -6
  5. package/dist/commands/agent/run.js +2 -0
  6. package/dist/commands/hub/deploy-triggers.d.ts +6 -0
  7. package/dist/commands/hub/deploy-triggers.js +116 -0
  8. package/dist/commands/hub/deploy.d.ts +15 -5
  9. package/dist/commands/hub/deploy.js +73 -4
  10. package/dist/commands/hub/hub-client/index.d.ts +4 -3
  11. package/dist/commands/hub/hub-client/index.js +23 -10
  12. package/dist/commands/hub/hub-client/internal/contracts.d.ts +15 -15
  13. package/dist/commands/hub/hub-client/internal/contracts.js +13 -14
  14. package/dist/commands/hub/init-plan.d.ts +5 -25
  15. package/dist/commands/hub/init-plan.js +39 -85
  16. package/dist/commands/hub/init.js +81 -112
  17. package/dist/commands/hub/starter-trigger.d.ts +2 -2
  18. package/dist/commands/hub/starter-trigger.js +11 -9
  19. package/dist/commands/plugin/index.d.ts +1 -1
  20. package/dist/commands/plugin/index.js +11 -20
  21. package/dist/commands/plugin/scaffold.js +92 -14
  22. package/dist/commands/schedule/shared.js +2 -2
  23. package/dist/commands/terminal/capture.js +3 -3
  24. package/dist/commands/terminal/create.d.ts +1 -0
  25. package/dist/commands/terminal/create.js +13 -22
  26. package/dist/commands/terminal/index.js +9 -7
  27. package/dist/commands/terminal/kill.js +5 -5
  28. package/dist/commands/terminal/ls.d.ts +1 -0
  29. package/dist/commands/terminal/ls.js +6 -6
  30. package/dist/commands/terminal/schema.d.ts +2 -10
  31. package/dist/commands/terminal/schema.js +1 -7
  32. package/dist/commands/terminal/send-keys.js +5 -36
  33. package/dist/commands/terminal/shared.d.ts +3 -3
  34. package/dist/commands/terminal/shared.js +4 -3
  35. package/dist/commands/workspace/index.js +5 -0
  36. package/dist/commands/workspace/setup.d.ts +11 -0
  37. package/dist/commands/workspace/setup.js +41 -0
  38. package/dist/output/render.js +2 -1
  39. package/dist/output/with-output.js +4 -6
  40. package/dist/utils/client.d.ts +1 -0
  41. package/dist/utils/client.js +6 -2
  42. package/dist/utils/command-options.d.ts +1 -0
  43. package/dist/utils/command-options.js +8 -0
  44. package/package.json +4 -4
@@ -3,29 +3,6 @@ import YAML from "yaml";
3
3
  export function hubLoginResumeCommand(step, origin) {
4
4
  return step === "connect" ? `paseo hub connect ${origin}` : "paseo hub init";
5
5
  }
6
- export function planHubInitOpening(input) {
7
- return {
8
- replaceExisting: input.paseoDirectoryExists,
9
- steps: [...(input.loggedIn ? [] : ["login"]), "connect", "project", "scaffold"],
10
- };
11
- }
12
- export function createHubInitBundle(projectSlug, scaffold) {
13
- return {
14
- projectSlug,
15
- workflowCount: 1,
16
- files: [
17
- { path: ".paseo/hub.yml", content: scaffold.hub },
18
- { path: scaffold.workflowPath, content: scaffold.workflow },
19
- ],
20
- };
21
- }
22
- export function resolveHubInitProjects(projects) {
23
- if (projects.length === 0)
24
- return { kind: "none" };
25
- if (projects.length === 1)
26
- return { kind: "selected", project: projects[0] };
27
- return { kind: "choose", projects };
28
- }
29
6
  export function resolveHubInitConnection(status, origin) {
30
7
  if (status.state === "connected" && status.hubOrigin === origin && status.daemonId !== null) {
31
8
  return { kind: "connected", daemonId: status.daemonId };
@@ -40,95 +17,72 @@ export function resolveHubInitConnection(status, origin) {
40
17
  return { kind: "connect" };
41
18
  }
42
19
  export function createHubInitScaffold(input) {
43
- const environmentName = input.daemonSlug;
44
- const hub = YAML.stringify({
45
- environments: {
46
- [environmentName]: {
47
- kind: "daemon",
48
- daemon: input.daemonSlug,
49
- cwd: path.resolve(input.cwd),
50
- },
51
- },
52
- agents: {
53
- starter: {
20
+ const provider = providerScaffold(input.provider, input.providerFilters);
21
+ return {
22
+ triggerPath: `.paseo/triggers/${input.provider}-help.yml`,
23
+ trigger: YAML.stringify(triggerDocument({
24
+ ...provider,
25
+ target: { daemon: input.daemonSlug, cwd: path.resolve(input.cwd) },
26
+ agent: {
54
27
  provider: input.agent.provider,
55
28
  model: input.agent.model,
56
- ...(input.agent.mode === undefined ? {} : { mode: input.agent.mode }),
29
+ mode: input.agent.mode,
57
30
  },
58
- },
59
- }, { lineWidth: 0 });
60
- const provider = providerScaffold(input.provider, input.providerFilters, environmentName);
61
- return {
62
- hub,
63
- workflowPath: `.paseo/workflows/${input.provider}-help.yml`,
64
- workflow: YAML.stringify(provider.workflow, { lineWidth: 0 }),
31
+ }), { lineWidth: 0 }),
65
32
  testAction: provider.testAction,
66
33
  };
67
34
  }
68
- function providerScaffold(provider, filters, environment) {
35
+ function providerScaffold(provider, filters) {
36
+ const connection = requireFilter(filters, "connection");
69
37
  if (provider === "github") {
70
38
  const repo = requireFilter(filters, "repo");
71
39
  const user = requireFilter(filters, "user");
72
40
  return {
73
- workflow: workflow({
74
- name: "github-help",
75
- on: "github.issue_comment",
76
- filters: { repo, contains: "@paseo", from_users: [user] },
77
- environment,
78
- }),
41
+ name: "github-help",
42
+ event: "github.issue_comment",
43
+ connection,
44
+ filters: { repo, contains: "@paseo", from_users: [user] },
79
45
  testAction: `Comment \`@paseo have a look\` on ${repo}.`,
80
46
  };
81
47
  }
82
48
  const user = requireFilter(filters, "user");
83
49
  if (provider === "slack") {
84
- const workspace = requireFilter(filters, "workspace");
85
50
  return {
86
- workflow: workflow({
87
- name: "slack-help",
88
- on: "slack.mention",
89
- filters: { workspace, from_users: [user] },
90
- environment,
91
- reply: "slack.reply",
92
- }),
51
+ name: "slack-help",
52
+ event: "slack.mention",
53
+ connection,
54
+ filters: { from_users: [user] },
55
+ reply: "slack.reply",
93
56
  testAction: "Mention `@Paseo have a look` in Slack.",
94
57
  };
95
58
  }
96
- const guild = requireFilter(filters, "guild");
97
59
  return {
98
- workflow: workflow({
99
- name: "discord-help",
100
- on: "discord.mention",
101
- filters: { guild, from_users: [user] },
102
- environment,
103
- reply: "discord.reply",
104
- }),
60
+ name: "discord-help",
61
+ event: "discord.mention",
62
+ connection,
63
+ filters: { from_users: [user] },
64
+ reply: "discord.reply",
105
65
  testAction: "Mention `@Paseo have a look` in Discord.",
106
66
  };
107
67
  }
108
- function workflow(input) {
68
+ function triggerDocument(input) {
109
69
  const replyInstruction = input.reply === undefined ? "" : "Answer with hub.reply, then ";
110
70
  return {
111
71
  name: input.name,
112
- on: input.on,
72
+ enabled: true,
73
+ on: { [input.event]: { connection: input.connection, filters: input.filters } },
113
74
  max_runtime: "2h",
114
- filters: input.filters,
115
- steps: [
116
- {
117
- id: "work",
118
- environment: input.environment,
119
- max_runtime: "90m",
120
- idle_timeout: "10m",
121
- agent: "starter",
122
- prompt: [
123
- {
124
- text: `${replyInstruction}complete this request and call hub.finish_execution when done.\n\n<user-prompt>\n\${{ paseo.prompt }}\n</user-prompt>\n`,
125
- },
126
- ],
127
- ...(input.reply === undefined
128
- ? {}
129
- : { allow_outputs: [{ type: input.reply, max: 1, required: true }] }),
130
- },
131
- ],
75
+ run: {
76
+ target: input.target,
77
+ agent: input.agent,
78
+ continuation: { mode: "conversation" },
79
+ max_runtime: "90m",
80
+ idle_timeout: "10m",
81
+ prompt: `${replyInstruction}complete this request and call hub.finish_execution when done.\n\n<user-prompt>\n\${{ paseo.prompt }}\n</user-prompt>\n`,
82
+ ...(input.reply === undefined
83
+ ? {}
84
+ : { outputs: { [input.reply]: { max: 1, required: true } } }),
85
+ },
132
86
  };
133
87
  }
134
88
  function requireFilter(filters, name) {
@@ -1,16 +1,14 @@
1
1
  import { cancel, confirm, intro, isCancel, log, note, outro, select, spinner, text, } from "@clack/prompts";
2
2
  import { execFile } from "node:child_process";
3
3
  import { randomUUID } from "node:crypto";
4
- import { lstat, mkdir, rename, rm, writeFile } from "node:fs/promises";
4
+ import { link, lstat, mkdir, rename, rm, writeFile } from "node:fs/promises";
5
5
  import path from "node:path";
6
6
  import { promisify } from "node:util";
7
7
  import { DEFAULT_HUB_ORIGIN, resolveHubCredential } from "./authority.js";
8
8
  import { withHubDaemon } from "./daemon-client.js";
9
9
  import { HubCommandError } from "./error.js";
10
- import { createHubInitBundle, createHubInitScaffold, hubLoginResumeCommand, planHubInitOpening, resolveHubInitConnection, resolveHubInitProjects, } from "./init-plan.js";
10
+ import { createHubInitScaffold, hubLoginResumeCommand, resolveHubInitConnection, } from "./init-plan.js";
11
11
  import { runHubConnect } from "./connect.js";
12
- import { runHubDeployBundle } from "./deploy.js";
13
- import { runHubProjects } from "./projects.js";
14
12
  import { normalizeHubOrigin } from "./origin.js";
15
13
  import { selectedStarterAgentRuntime, starterAgentProviderSnapshotState, suggestedStarterAgentChoice, } from "./starter-agent-runtime.js";
16
14
  import { availableStarterTriggerConnections, } from "./starter-trigger.js";
@@ -29,7 +27,7 @@ function initErrorMessage(error) {
29
27
  export function addHubInitCommand(parent, environment) {
30
28
  parent
31
29
  .command("init")
32
- .description("Create and optionally deploy a safe starter Hub bundle")
30
+ .description("Create and optionally deploy a safe starter Hub trigger")
33
31
  .action(async () => {
34
32
  try {
35
33
  await runHubInit(environment);
@@ -52,22 +50,16 @@ export async function runHubGuidedSetup(environment, state = {}) {
52
50
  intro("Set up Paseo Hub");
53
51
  const cwd = environment.cwd();
54
52
  const activeLogin = environment.credentials.active();
55
- const opening = planHubInitOpening({
56
- loggedIn: activeLogin !== null,
57
- paseoDirectoryExists: await pathExists(path.join(cwd, ".paseo")),
58
- });
59
- if (opening.replaceExisting &&
60
- !(await requiredConfirm(environment, "Replace the existing .paseo/ Hub bundle?", false))) {
61
- throw new HubInitCancelledError("Existing .paseo/ bundle left unchanged.");
62
- }
63
53
  const origin = state.origin ?? (await ensureLogin(activeLogin?.origin, environment));
64
54
  const daemonId = state.daemonId ?? (await ensureDaemonConnection(origin, environment));
65
- const project = await chooseProject(origin, environment);
66
- const resources = await loadSetupResources(origin, environment);
55
+ const resources = await loadConfigurationResources(origin, environment);
67
56
  const triggerConnections = await resolveStarterTriggerConnections(resources, cwd);
68
57
  reportStarterTriggerConnections(environment, triggerConnections);
69
58
  const trigger = await chooseStarterTriggerConnection(environment, triggerConnections);
70
- const daemon = await loadDaemonResource(origin, daemonId, environment);
59
+ const daemon = resources.daemons.find(({ id }) => id === daemonId);
60
+ if (daemon === undefined) {
61
+ throw new HubCommandError("HUB_DAEMON_RESOURCE_MISSING", "The connected daemon is not available in this Hub organization. Reconnect it and try again.");
62
+ }
71
63
  log.success(`Connected as ${daemon.slug}`);
72
64
  const agent = await chooseStarterAgentRuntime(environment, cwd);
73
65
  const providerFilters = await collectProviderIdentity(trigger, environment);
@@ -78,38 +70,36 @@ export async function runHubGuidedSetup(environment, state = {}) {
78
70
  provider: trigger.provider,
79
71
  providerFilters,
80
72
  });
81
- const bundle = createHubInitBundle(project.slug, scaffold);
82
- await withSpinner("Validating bundle", async () => {
83
- await runHubDeployBundle({ project: project.slug, hub: origin, dryRun: true }, bundle, {
84
- cwd,
85
- env: environment.env,
86
- credentials: environment.credentials,
87
- hub: environment.hub,
88
- reporter: { progress() { } },
89
- });
73
+ const credential = resolveHubCredential({
74
+ options: { origin },
75
+ env: environment.env,
76
+ credentials: environment.credentials,
77
+ origin,
78
+ });
79
+ await withSpinner("Validating trigger", async () => {
80
+ await environment.hub.validateTrigger(origin, credential, scaffold.trigger);
90
81
  });
91
82
  log.success("Dry run passed");
92
- await writeScaffold(cwd, scaffold, opening.replaceExisting);
93
- log.success(`Created .paseo/hub.yml and ${scaffold.workflowPath}`);
83
+ const triggerExists = await prepareScaffoldDestination(cwd, scaffold.triggerPath);
84
+ if (triggerExists &&
85
+ !(await requiredConfirm(environment, `Replace the existing ${scaffold.triggerPath}?`, false))) {
86
+ throw new HubInitCancelledError(`${scaffold.triggerPath} left unchanged.`);
87
+ }
88
+ await writeScaffold(cwd, scaffold, triggerExists);
89
+ log.success(`Created ${scaffold.triggerPath}`);
94
90
  const deploy = state.deploy ?? (await requiredConfirm(environment, "Deploy now?", true));
95
91
  if (deploy) {
96
- await withSpinner("Deploying bundle", async () => {
97
- await runHubDeployBundle({ project: project.slug, hub: origin }, bundle, {
98
- cwd,
99
- env: environment.env,
100
- credentials: environment.credentials,
101
- hub: environment.hub,
102
- reporter: { progress() { } },
103
- });
92
+ await withSpinner("Deploying trigger", async () => {
93
+ await environment.hub.installTrigger(origin, credential, scaffold.trigger);
104
94
  });
105
95
  log.success("Deployed");
106
96
  }
107
97
  else {
108
- reportMessage(environment, `Skipped deployment. Run: paseo hub deploy -p ${project.slug}`);
98
+ reportMessage(environment, "Skipped deployment. Run `paseo hub deploy` when ready.");
109
99
  }
110
- const activityUrl = new URL(`/projects/${project.slug}/activity`, origin).toString();
111
- note(`${scaffold.testAction}\nWatch it at ${activityUrl}`, "Test your workflow");
112
- outro(deploy ? "Hub is ready" : "Hub bundle is ready");
100
+ const triggersUrl = new URL("/triggers", origin).toString();
101
+ note(`${scaffold.testAction}\nManage it at ${triggersUrl}`, "Test your trigger");
102
+ outro(deploy ? "Hub is ready" : "Hub trigger is ready");
113
103
  }
114
104
  export async function continueHubGuidedSetup(origin, environment) {
115
105
  const currentStatus = await withHubDaemon(environment.daemon, undefined, async (daemon) => daemon.getHubStatus().then((response) => response.status));
@@ -189,7 +179,7 @@ async function ensureDaemonConnection(origin, environment, confirmed = false, pe
189
179
  }
190
180
  if (!confirmed &&
191
181
  !(await requiredConfirm(environment, `Connect this daemon to ${origin} and allow Hub workflows to create and control workspaces and agents?`, true))) {
192
- throw new HubInitCancelledError("A connected daemon is required to create the bundle.");
182
+ throw new HubInitCancelledError("A connected daemon is required to create the trigger.");
193
183
  }
194
184
  return connectDaemon(origin, environment, permissions);
195
185
  }
@@ -225,50 +215,22 @@ async function waitForDaemonReady(origin, connection) {
225
215
  }
226
216
  }));
227
217
  }
228
- async function chooseProject(origin, environment) {
229
- const result = await runHubProjects({ hub: origin }, {
230
- env: environment.env,
231
- credentials: environment.credentials,
232
- hub: environment.hub,
233
- reporter: { progress() { } },
234
- });
235
- const resolution = resolveHubInitProjects(result.data.projects);
236
- if (resolution.kind === "none") {
237
- throw new HubInitCancelledError(`No Hub projects exist yet. Create one at ${new URL("/projects/new", origin).toString()}, then run paseo hub init again.`);
238
- }
239
- if (resolution.kind === "selected") {
240
- return resolution.project;
241
- }
242
- const slug = await requiredSelect(environment, {
243
- message: "Project",
244
- options: resolution.projects.map((project) => ({
245
- value: project.slug,
246
- label: project.name,
247
- hint: project.slug,
248
- })),
249
- });
250
- const project = resolution.projects.find((candidate) => candidate.slug === slug);
251
- if (project === undefined) {
252
- throw new HubCommandError("HUB_PROJECT_SELECTION_INVALID", "The selected Hub project is unavailable.");
253
- }
254
- return project;
255
- }
256
218
  async function resolveStarterTriggerConnections(resources, cwd) {
257
219
  const remote = await readCommandValue("git", ["remote", "get-url", "origin"], cwd);
258
220
  const repository = remote === undefined ? undefined : githubRepositoryFromRemote(remote);
259
221
  const connections = availableStarterTriggerConnections(resources, repository);
260
222
  if (connections.length === 0) {
261
- throw new HubInitCancelledError("No Hub app connection is ready for this workflow.\nConnect GitHub, Slack, or Discord in Hub → Apps, then run `paseo hub init` again.");
223
+ throw new HubInitCancelledError("No Hub app connection is ready for this trigger.\nConnect GitHub, Slack, or Discord in Hub → Apps, then run `paseo hub init` again.");
262
224
  }
263
225
  return connections;
264
226
  }
265
227
  function reportStarterTriggerConnections(environment, connections) {
266
228
  const details = `${connections.map(({ label }) => label).join("\n")}\n\nOnly configured connections are shown. To add another, open Hub → Apps, then run \`paseo hub init\` again.`;
267
229
  if (environment.prompts === undefined) {
268
- note(details, "Hub app connections ready for this workflow");
230
+ note(details, "Hub app connections ready for this trigger");
269
231
  return;
270
232
  }
271
- environment.prompts.message(`Hub app connections ready for this workflow:\n${details}`);
233
+ environment.prompts.message(`Hub app connections ready for this trigger:\n${details}`);
272
234
  }
273
235
  async function chooseStarterTriggerConnection(environment, connections) {
274
236
  if (connections.length === 1) {
@@ -292,10 +254,10 @@ async function chooseStarterAgentRuntime(environment, cwd) {
292
254
  const model = await chooseStarterAgentModel(environment, provider);
293
255
  const mode = await chooseStarterAgentMode(environment, provider);
294
256
  const runtime = selectedStarterAgentRuntime(provider, model, mode);
295
- if (runtime === undefined) {
257
+ if (runtime?.mode === undefined) {
296
258
  throw new HubCommandError("HUB_AGENT_RUNTIME_SELECTION_INVALID", "The selected starter agent runtime is no longer available. Run paseo hub init again.");
297
259
  }
298
- return runtime;
260
+ return { ...runtime, mode: runtime.mode };
299
261
  }
300
262
  async function waitForStarterAgentProviders(environment, cwd) {
301
263
  return withSpinner("Discovering agent runtimes", async (reporter) => withHubDaemon(environment.daemon, undefined, async (daemon) => {
@@ -303,8 +265,12 @@ async function waitForStarterAgentProviders(environment, cwd) {
303
265
  while (true) {
304
266
  const snapshot = await daemon.getProvidersSnapshot({ cwd });
305
267
  const state = starterAgentProviderSnapshotState(snapshot.entries);
306
- if (state.kind === "ready")
307
- return state.providers;
268
+ if (state.kind === "ready") {
269
+ const providers = state.providers.filter(({ modes }) => modes.length > 0);
270
+ if (providers.length > 0)
271
+ return providers;
272
+ throw new HubCommandError("HUB_AGENT_RUNTIME_REQUIRED", "No agent runtime with an execution mode is available from this daemon. Configure one, then run paseo hub init again.");
273
+ }
308
274
  if (state.kind === "unavailable") {
309
275
  throw new HubCommandError("HUB_AGENT_RUNTIME_REQUIRED", "No usable agent runtime is available from this daemon. Configure an enabled provider with a selectable model, then run paseo hub init again.");
310
276
  }
@@ -390,9 +356,9 @@ async function collectProviderIdentity(trigger, environment) {
390
356
  }),
391
357
  };
392
358
  }
393
- async function loadSetupResources(origin, environment) {
359
+ async function loadConfigurationResources(origin, environment) {
394
360
  try {
395
- return await withSpinner("Loading Hub connections", () => environment.hub.listSetupResources(origin, resolveHubCredential({
361
+ return await withSpinner("Loading Hub connections", () => environment.hub.listConfigurationResources(origin, resolveHubCredential({
396
362
  options: { origin },
397
363
  env: environment.env,
398
364
  credentials: environment.credentials,
@@ -400,55 +366,40 @@ async function loadSetupResources(origin, environment) {
400
366
  })));
401
367
  }
402
368
  catch (error) {
403
- if (error instanceof HubCommandError && error.code === "HUB_NOT_FOUND") {
404
- throw new HubCommandError("HUB_UPDATE_REQUIRED", "This Hub needs an update before guided setup can use provider IDs. Update Hub and try again.");
369
+ if (error instanceof HubCommandError &&
370
+ (error.code === "HUB_NOT_FOUND" || error.code === "HUB_INVALID_RESPONSE")) {
371
+ throw new HubCommandError("HUB_UPDATE_REQUIRED", "This Hub needs an update before guided setup can use organization triggers. Update Hub and try again.");
405
372
  }
406
373
  throw error;
407
374
  }
408
375
  }
409
- async function loadDaemonResource(origin, daemonId, environment) {
410
- const resources = await environment.hub.listConfigurationResources(origin, resolveHubCredential({
411
- options: { origin },
412
- env: environment.env,
413
- credentials: environment.credentials,
414
- origin,
415
- }));
416
- const daemon = resources.daemons.find(({ id }) => id === daemonId);
417
- if (daemon === undefined) {
418
- throw new HubCommandError("HUB_DAEMON_RESOURCE_MISSING", "The connected daemon is not available in this Hub organization. Reconnect it and try again.");
419
- }
420
- return daemon;
421
- }
422
376
  async function writeScaffold(cwd, scaffold, replaceExisting) {
423
- const root = path.join(cwd, ".paseo");
424
- const staging = path.join(cwd, `.paseo-init-${randomUUID()}`);
425
- const backup = path.join(cwd, `.paseo-backup-${randomUUID()}`);
426
- let movedExisting = false;
377
+ const destination = path.join(cwd, scaffold.triggerPath);
378
+ const temporary = path.join(path.dirname(destination), `.${path.basename(destination)}.${process.pid}.${randomUUID()}.tmp`);
427
379
  try {
428
- await mkdir(path.join(staging, "workflows"), { recursive: true });
429
- await writeFile(path.join(staging, "hub.yml"), scaffold.hub, { flag: "wx" });
430
- await writeFile(path.join(staging, "workflows", path.basename(scaffold.workflowPath)), scaffold.workflow, {
431
- flag: "wx",
432
- });
380
+ await writeFile(temporary, scaffold.trigger, { flag: "wx" });
433
381
  if (replaceExisting) {
434
- await rename(root, backup);
435
- movedExisting = true;
382
+ await rename(temporary, destination);
383
+ }
384
+ else {
385
+ await link(temporary, destination);
386
+ await rm(temporary);
436
387
  }
437
- await rename(staging, root);
438
- if (movedExisting)
439
- await rm(backup, { recursive: true, force: true });
440
388
  }
441
389
  catch (error) {
442
- await rm(staging, { recursive: true, force: true });
443
- if (movedExisting) {
444
- await rename(backup, root).catch(() => undefined);
445
- }
390
+ await rm(temporary, { force: true });
446
391
  throw error;
447
392
  }
448
393
  }
449
- async function pathExists(target) {
394
+ async function prepareScaffoldDestination(cwd, triggerPath) {
395
+ const root = path.resolve(cwd);
396
+ await requireSafeScaffoldDirectory(path.join(root, ".paseo"), ".paseo");
397
+ await requireSafeScaffoldDirectory(path.join(root, ".paseo", "triggers"), ".paseo/triggers");
398
+ const destination = path.join(root, triggerPath);
450
399
  try {
451
- await lstat(target);
400
+ const stats = await lstat(destination);
401
+ if (stats.isSymbolicLink())
402
+ throw unsafeScaffoldPath(triggerPath);
452
403
  return true;
453
404
  }
454
405
  catch (error) {
@@ -457,6 +408,24 @@ async function pathExists(target) {
457
408
  throw error;
458
409
  }
459
410
  }
411
+ async function requireSafeScaffoldDirectory(target, displayPath) {
412
+ try {
413
+ const stats = await lstat(target);
414
+ if (stats.isSymbolicLink())
415
+ throw unsafeScaffoldPath(displayPath);
416
+ if (!stats.isDirectory()) {
417
+ throw new HubCommandError("HUB_TRIGGER_DIRECTORY_INVALID", `${displayPath} must be a directory.`);
418
+ }
419
+ }
420
+ catch (error) {
421
+ if (errorCode(error) !== "ENOENT")
422
+ throw error;
423
+ await mkdir(target);
424
+ }
425
+ }
426
+ function unsafeScaffoldPath(triggerPath) {
427
+ return new HubCommandError("HUB_TRIGGER_UNSAFE_PATH", `${triggerPath} must not use a symlink.`);
428
+ }
460
429
  function errorCode(error) {
461
430
  return error instanceof Error && "code" in error && typeof error.code === "string"
462
431
  ? error.code
@@ -1,4 +1,4 @@
1
- import type { HubSetupResources } from "./hub-client/index.js";
1
+ import type { HubConfigurationResources } from "./hub-client/index.js";
2
2
  import type { HubInitProvider } from "./init-plan.js";
3
3
  export interface HubStarterTriggerConnection {
4
4
  id: string;
@@ -6,5 +6,5 @@ export interface HubStarterTriggerConnection {
6
6
  provider: HubInitProvider;
7
7
  filters: Readonly<Record<string, string>>;
8
8
  }
9
- export declare function availableStarterTriggerConnections(resources: HubSetupResources, githubRepository?: string): HubStarterTriggerConnection[];
9
+ export declare function availableStarterTriggerConnections(resources: HubConfigurationResources, githubRepository?: string): HubStarterTriggerConnection[];
10
10
  //# sourceMappingURL=starter-trigger.d.ts.map
@@ -1,27 +1,29 @@
1
1
  export function availableStarterTriggerConnections(resources, githubRepository) {
2
2
  return [
3
- ...(githubRepository !== undefined &&
4
- resources.github.some(({ repositories }) => repositories.includes(githubRepository))
3
+ ...resources.github.flatMap((connection) => githubRepository !== undefined && connection.repositories.includes(githubRepository)
5
4
  ? [
6
5
  {
7
6
  id: `github:${githubRepository}`,
8
7
  label: `GitHub — ${githubRepository}`,
9
8
  provider: "github",
10
- filters: { repo: githubRepository },
9
+ filters: {
10
+ connection: connection.slug,
11
+ repo: githubRepository,
12
+ },
11
13
  },
12
14
  ]
13
15
  : []),
14
- ...resources.slack.map(({ teamId, teamName }) => ({
15
- id: `slack:${teamId}`,
16
+ ...resources.slack.map(({ slug, teamName }) => ({
17
+ id: `slack:${slug}`,
16
18
  label: `Slack — ${teamName}`,
17
19
  provider: "slack",
18
- filters: { workspace: teamId },
20
+ filters: { connection: slug },
19
21
  })),
20
- ...resources.discord.map(({ guildId, guildName }) => ({
21
- id: `discord:${guildId}`,
22
+ ...resources.discord.map(({ slug, guildName }) => ({
23
+ id: `discord:${slug}`,
22
24
  label: `Discord — ${guildName}`,
23
25
  provider: "discord",
24
- filters: { guild: guildId },
26
+ filters: { connection: slug },
25
27
  })),
26
28
  ];
27
29
  }
@@ -10,7 +10,7 @@ interface PluginOptions extends CommandOptions {
10
10
  all?: boolean;
11
11
  }
12
12
  export declare function runPluginInitCommand(directory: string, options: PluginOptions, _command: Command): Promise<SingleResult<PluginScaffold>>;
13
- export declare function runPluginListCommand(options: PluginOptions, _command: Command): Promise<ListResult<PluginListItem>>;
13
+ export declare function runPluginListCommand(pluginId: string | undefined, options: PluginOptions, _command: Command): Promise<ListResult<PluginListItem>>;
14
14
  export declare function runPluginLogsCommand(pluginId: string, options: PluginOptions, _command: Command): Promise<ListResult<PluginLogEntry>>;
15
15
  export declare function createPluginCommand(): Command;
16
16
  export {};
@@ -11,6 +11,9 @@ const pluginSchema = {
11
11
  { header: "PLUGIN", field: "id", width: 20 },
12
12
  { header: "STATUS", field: "status", width: 10 },
13
13
  { header: "ENABLED", field: (plugin) => (plugin.enabled ? "yes" : "no"), width: 8 },
14
+ { header: "SOURCE", field: (plugin) => plugin.source ?? "directory", width: 10 },
15
+ { header: "COMMIT", field: (plugin) => shortCommit(plugin.commit), width: 14 },
16
+ { header: "REF", field: (plugin) => plugin.ref ?? "-", width: 24 },
14
17
  { header: "DIRECTORY", field: "path", width: 40 },
15
18
  { header: "ERROR", field: (plugin) => plugin.error ?? "", width: 40 },
16
19
  ],
@@ -33,17 +36,6 @@ const pluginLogsSchema = {
33
36
  function shortCommit(commit) {
34
37
  return commit?.slice(0, 12) ?? "-";
35
38
  }
36
- const pluginStatusSchema = {
37
- idField: "id",
38
- columns: [
39
- { header: "PLUGIN", field: "id", width: 20 },
40
- { header: "SOURCE", field: "source", width: 10 },
41
- { header: "CURRENT", field: (plugin) => shortCommit(plugin.currentCommit), width: 14 },
42
- { header: "LATEST", field: (plugin) => shortCommit(plugin.latestCommit), width: 14 },
43
- { header: "COMMITS", field: (plugin) => String(plugin.commitsBehind ?? 0), width: 8 },
44
- { header: "REF", field: (plugin) => plugin.ref ?? "-", width: 24 },
45
- ],
46
- };
47
39
  const pluginUpdateSchema = {
48
40
  idField: "id",
49
41
  columns: [
@@ -61,8 +53,11 @@ export async function runPluginInitCommand(directory, options, _command) {
61
53
  schema: scaffoldSchema,
62
54
  };
63
55
  }
64
- export async function runPluginListCommand(options, _command) {
65
- const data = await withPluginManagementClient(options.host, (client) => client.listPlugins());
56
+ export async function runPluginListCommand(pluginId, options, _command) {
57
+ const plugins = await withPluginManagementClient(options.host, (client) => client.listPlugins());
58
+ const data = pluginId ? plugins.filter((plugin) => plugin.id === pluginId) : plugins;
59
+ if (pluginId && data.length === 0)
60
+ throw new Error(`Plugin is not configured: ${pluginId}`);
66
61
  return { type: "list", data, schema: pluginSchema };
67
62
  }
68
63
  export async function runPluginLogsCommand(pluginId, options, _command) {
@@ -90,10 +85,6 @@ async function install(source, options, _command) {
90
85
  }));
91
86
  return { type: "single", data, schema: pluginSchema };
92
87
  }
93
- async function status(pluginId, options, _command) {
94
- const data = await withPluginSourceClient(options.host, (client) => client.getPluginSourceStatus(pluginId));
95
- return { type: "list", data, schema: pluginStatusSchema };
96
- }
97
88
  async function update(pluginId, options, _command) {
98
89
  if ((pluginId === undefined) === (options.all !== true)) {
99
90
  throw new Error("Choose one plugin ID or pass --all");
@@ -122,7 +113,8 @@ export function createPluginCommand() {
122
113
  .description("Create a typecheckable local plugin")
123
114
  .argument("<directory>")
124
115
  .option("--id <id>", "Manifest plugin ID (defaults to the directory name)")).action(withOutput(runPluginInitCommand));
125
- addJsonAndDaemonHostOptions(plugin.command("ls").description("List configured plugins")).action(withOutput(runPluginListCommand));
116
+ addJsonAndDaemonHostOptions(plugin.command("ls").description("List configured plugins").argument("[id]")).action(withOutput(runPluginListCommand));
117
+ addJsonAndDaemonHostOptions(plugin.command("status", { hidden: true }).argument("[id]")).action(withOutput(runPluginListCommand));
126
118
  addJsonAndDaemonHostOptions(plugin.command("logs").description("Show recent plugin output").argument("<id>")).action(withOutput(runPluginLogsCommand));
127
119
  addJsonAndDaemonHostOptions(plugin
128
120
  .command("install")
@@ -132,10 +124,9 @@ export function createPluginCommand() {
132
124
  .option("--id <id>", "Runtime plugin ID (defaults to paseo-plugin.json id)")
133
125
  .option("--ref <ref>", "Git branch, tag, or commit")
134
126
  .option("--path <path>", "Legacy form of the :plugin/path source suffix")).action(withOutput(install));
135
- addJsonAndDaemonHostOptions(plugin.command("status").description("Check plugin source updates").argument("[id]")).action(withOutput(status));
136
127
  addJsonAndDaemonHostOptions(plugin
137
128
  .command("update")
138
- .description("Update a Git-managed plugin")
129
+ .description("Fetch and install Git-managed plugin updates")
139
130
  .argument("[id]")
140
131
  .option("--all", "Update every Git-managed plugin")).action(withOutput(update));
141
132
  for (const action of ["reload", "enable", "disable"]) {