@getpaseo/cli 0.8.0-beta.1 → 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.
@@ -100,7 +100,7 @@ export async function runAttachCommand(id, options, _command) {
100
100
  }
101
101
  const resolvedId = fetchResult.agent.id;
102
102
  // Print header
103
- console.log(`Attaching to agent ${resolvedId.substring(0, 7)}...`);
103
+ console.log(`Fetching history for agent ${resolvedId.substring(0, 7)}...`);
104
104
  console.log(`(Press Ctrl+C to detach)\n`);
105
105
  // Print existing output from timeline fetch.
106
106
  try {
@@ -117,14 +117,16 @@ export async function runAttachCommand(id, options, _command) {
117
117
  console.warn("Warning: failed to fetch existing timeline", error);
118
118
  }
119
119
  // Subscribe to new events
120
- const unsubscribe = client.on("agent_stream", (msg) => {
121
- const message = msg;
122
- if (message.type !== "agent_stream")
123
- return;
124
- if (message.payload.agentId !== resolvedId)
125
- return;
126
- printStreamEvent(message.payload.event);
120
+ const unsubscribe = client.subscribeAgentTimeline(resolvedId, (message) => {
121
+ if (message.type === "agent.timeline.replacement") {
122
+ console.log("\n[Timeline replaced; earlier output is no longer current]");
123
+ }
124
+ else {
125
+ printStreamEvent(message.payload.event);
126
+ }
127
127
  });
128
+ await unsubscribe.ready;
129
+ console.log(`Attached to agent ${resolvedId.substring(0, 7)}.`);
128
130
  // Handle Ctrl+C to detach gracefully
129
131
  let detached = false;
130
132
  const detach = () => {
@@ -146,13 +146,11 @@ async function runFollowMode(client, agentId, options) {
146
146
  }
147
147
  // Subscribe to new events
148
148
  const tailLabel = tailCount === 0 ? "no history" : `last ${tailCount} entr${tailCount === 1 ? "y" : "ies"}`;
149
- console.log(`\n--- Following logs (${tailLabel}; Ctrl+C to stop) ---\n`);
150
- const unsubscribe = client.on("agent_stream", (msg) => {
151
- const message = msg;
152
- if (message.type !== "agent_stream")
153
- return;
154
- if (message.payload.agentId !== agentId)
149
+ const unsubscribe = client.subscribeAgentTimeline(agentId, (message) => {
150
+ if (message.type === "agent.timeline.replacement") {
151
+ console.log("\n[Timeline replaced; earlier output is no longer current]");
155
152
  return;
153
+ }
156
154
  if (message.payload.event.type === "timeline") {
157
155
  const item = message.payload.event.item;
158
156
  // Apply filter
@@ -166,6 +164,8 @@ async function runFollowMode(client, agentId, options) {
166
164
  }
167
165
  }
168
166
  });
167
+ await unsubscribe.ready;
168
+ console.log(`\n--- Following logs (${tailLabel}; Ctrl+C to stop) ---\n`);
169
169
  // Wait for interrupt
170
170
  await new Promise((resolve) => {
171
171
  const cleanup = () => {
@@ -0,0 +1,6 @@
1
+ export interface HubDeployTrigger {
2
+ path: string;
3
+ yaml: string;
4
+ }
5
+ export declare function discoverHubTriggers(cwd: string): Promise<HubDeployTrigger[]>;
6
+ //# sourceMappingURL=deploy-triggers.d.ts.map
@@ -0,0 +1,116 @@
1
+ import { lstat, readFile, readdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { HubCommandError } from "./error.js";
4
+ const TRIGGER_DIRECTORY = ".paseo/triggers";
5
+ export async function discoverHubTriggers(cwd) {
6
+ const root = path.resolve(cwd);
7
+ const directory = path.join(root, TRIGGER_DIRECTORY);
8
+ const paseoDirectory = await readStats(path.join(root, ".paseo"), {
9
+ code: "HUB_TRIGGER_DIRECTORY_MISSING",
10
+ message: `${TRIGGER_DIRECTORY} does not exist. Run this command from the project root.`,
11
+ });
12
+ if (paseoDirectory.isSymbolicLink())
13
+ throw unsafeTriggerPath(TRIGGER_DIRECTORY);
14
+ const directoryStats = await readTriggerDirectoryStats(root, directory);
15
+ if (directoryStats.isSymbolicLink())
16
+ throw unsafeTriggerPath(TRIGGER_DIRECTORY);
17
+ if (!directoryStats.isDirectory()) {
18
+ throw new HubCommandError("HUB_TRIGGER_DIRECTORY_INVALID", `${TRIGGER_DIRECTORY} must be a directory.`);
19
+ }
20
+ let entries;
21
+ try {
22
+ entries = await readdir(directory, { withFileTypes: true });
23
+ }
24
+ catch (error) {
25
+ if (!isExpectedReadError(error))
26
+ throw error;
27
+ throw unreadableTriggerPath(TRIGGER_DIRECTORY);
28
+ }
29
+ const triggers = [];
30
+ for (const entry of entries.toSorted((left, right) => left.name.localeCompare(right.name))) {
31
+ const triggerPath = `${TRIGGER_DIRECTORY}/${entry.name}`;
32
+ if (entry.isSymbolicLink())
33
+ throw unsafeTriggerPath(triggerPath);
34
+ if (!entry.isFile() || !entry.name.endsWith(".yml")) {
35
+ throw new HubCommandError("HUB_TRIGGER_PATH_UNSUPPORTED", `${triggerPath} must be a direct-child .yml trigger.`);
36
+ }
37
+ try {
38
+ triggers.push({
39
+ path: triggerPath,
40
+ yaml: await readFile(path.join(root, triggerPath), "utf8"),
41
+ });
42
+ }
43
+ catch (error) {
44
+ if (!isExpectedReadError(error))
45
+ throw error;
46
+ throw unreadableTriggerPath(triggerPath);
47
+ }
48
+ }
49
+ if (triggers.length === 0) {
50
+ throw new HubCommandError("HUB_TRIGGER_MISSING", `${TRIGGER_DIRECTORY} must contain at least one direct-child .yml trigger.`);
51
+ }
52
+ return triggers;
53
+ }
54
+ async function readTriggerDirectoryStats(root, directory) {
55
+ try {
56
+ return await lstat(directory);
57
+ }
58
+ catch (error) {
59
+ if (errorCode(error) !== "ENOENT") {
60
+ if (!isExpectedReadError(error))
61
+ throw error;
62
+ throw unreadableTriggerPath(TRIGGER_DIRECTORY);
63
+ }
64
+ if (await legacyBundleExists(root)) {
65
+ throw new HubCommandError("HUB_PROJECT_REQUIRED", "This directory contains a legacy .paseo/hub.yml bundle. Pass --project <slug> to deploy it.");
66
+ }
67
+ throw new HubCommandError("HUB_TRIGGER_DIRECTORY_MISSING", `${TRIGGER_DIRECTORY} does not exist. Run this command from the project root.`);
68
+ }
69
+ }
70
+ async function legacyBundleExists(root) {
71
+ try {
72
+ await lstat(path.join(root, ".paseo/hub.yml"));
73
+ return true;
74
+ }
75
+ catch (error) {
76
+ if (errorCode(error) === "ENOENT")
77
+ return false;
78
+ if (!isExpectedReadError(error))
79
+ throw error;
80
+ throw unreadableTriggerPath(".paseo/hub.yml");
81
+ }
82
+ }
83
+ async function readStats(target, missing) {
84
+ try {
85
+ return await lstat(target);
86
+ }
87
+ catch (error) {
88
+ if (errorCode(error) === "ENOENT")
89
+ throw new HubCommandError(missing.code, missing.message);
90
+ if (!isExpectedReadError(error))
91
+ throw error;
92
+ throw unreadableTriggerPath(TRIGGER_DIRECTORY);
93
+ }
94
+ }
95
+ function unsafeTriggerPath(triggerPath) {
96
+ return new HubCommandError("HUB_TRIGGER_UNSAFE_PATH", `${triggerPath} must not use a symlink.`);
97
+ }
98
+ function unreadableTriggerPath(triggerPath) {
99
+ return new HubCommandError("HUB_TRIGGER_UNREADABLE", `Could not read ${triggerPath}. Check the file and permissions.`);
100
+ }
101
+ function errorCode(error) {
102
+ if (typeof error !== "object" || error === null)
103
+ return undefined;
104
+ const code = Reflect.get(error, "code");
105
+ return typeof code === "string" ? code : undefined;
106
+ }
107
+ function isExpectedReadError(error) {
108
+ const code = errorCode(error);
109
+ return (code === "EACCES" ||
110
+ code === "EPERM" ||
111
+ code === "ENOENT" ||
112
+ code === "ENOTDIR" ||
113
+ code === "ELOOP" ||
114
+ code === "EISDIR");
115
+ }
116
+ //# sourceMappingURL=deploy-triggers.js.map
@@ -1,8 +1,9 @@
1
1
  import type { Command } from "commander";
2
- import { type SingleResult } from "../../output/index.js";
3
- import { HubHttpClient, type HubInstallResult, type HubValidationResult } from "./hub-client/index.js";
2
+ import { type ListResult, type SingleResult } from "../../output/index.js";
3
+ import { HubHttpClient, type HubInstallResult, type HubTriggerInstallationResult, type HubTriggerValidationResult, type HubValidationResult } from "./hub-client/index.js";
4
4
  import { type HubCredentialStore } from "./credentials.js";
5
5
  import { type HubDeployBundle } from "./deploy-bundle.js";
6
+ import { type HubDeployTrigger } from "./deploy-triggers.js";
6
7
  import { type HubReporter } from "./reporter.js";
7
8
  export interface HubDeployOptions {
8
9
  project?: string;
@@ -15,13 +16,13 @@ export interface HubDeployEnvironment {
15
16
  cwd: string;
16
17
  env: Readonly<Record<string, string | undefined>>;
17
18
  credentials?: HubCredentialStore;
18
- hub?: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration">;
19
+ hub?: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration" | "installTrigger" | "validateTrigger">;
19
20
  reporter?: HubReporter;
20
21
  }
21
22
  export interface HubDeployCommandDependencies {
22
23
  env: Readonly<Record<string, string | undefined>>;
23
24
  credentials: HubCredentialStore;
24
- hub: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration">;
25
+ hub: Pick<HubHttpClient, "installConfiguration" | "validateConfiguration" | "installTrigger" | "validateTrigger">;
25
26
  reporter: HubReporter;
26
27
  cwd(): string;
27
28
  }
@@ -33,7 +34,16 @@ interface HubDryRunResult extends HubValidationResult {
33
34
  origin: string;
34
35
  workflows: number;
35
36
  }
36
- export declare function runHubDeploy(options: HubDeployOptions, environment?: HubDeployEnvironment): Promise<SingleResult<HubDeployResult> | SingleResult<HubDryRunResult>>;
37
+ interface HubTriggerDeployResult extends HubTriggerInstallationResult {
38
+ origin: string;
39
+ path: string;
40
+ }
41
+ interface HubTriggerDryRunResult extends HubTriggerValidationResult {
42
+ origin: string;
43
+ path: string;
44
+ }
45
+ export declare function runHubDeploy(options: HubDeployOptions, environment?: HubDeployEnvironment): Promise<SingleResult<HubDeployResult> | SingleResult<HubDryRunResult> | ListResult<HubTriggerDeployResult> | ListResult<HubTriggerDryRunResult>>;
46
+ export declare function runHubDeployTriggers(options: HubDeployOptions, triggers: readonly HubDeployTrigger[], environment: HubDeployEnvironment): Promise<ListResult<HubTriggerDeployResult> | ListResult<HubTriggerDryRunResult>>;
37
47
  export declare function runHubDeployBundle(options: HubDeployOptions, deployInput: HubDeployBundle, environment: HubDeployEnvironment): Promise<SingleResult<HubDeployResult> | SingleResult<HubDryRunResult>>;
38
48
  export declare function addHubDeployCommand(hub: Command, dependencies: HubDeployCommandDependencies): void;
39
49
  export {};
@@ -1,9 +1,11 @@
1
- import { withOutput } from "../../output/index.js";
1
+ import { withOutput, } from "../../output/index.js";
2
2
  import { addJsonOption } from "../../utils/command-options.js";
3
3
  import { resolveHubCredential, resolveHubOrigin } from "./authority.js";
4
4
  import { HubHttpClient, } from "./hub-client/index.js";
5
5
  import { PrivateHubCredentialStore } from "./credentials.js";
6
6
  import { discoverHubBundle } from "./deploy-bundle.js";
7
+ import { discoverHubTriggers } from "./deploy-triggers.js";
8
+ import { HubCommandError } from "./error.js";
7
9
  import { processHubReporter, reportHubProgress } from "./reporter.js";
8
10
  import { addHubResolutionHelp } from "./help.js";
9
11
  const resultSchema = {
@@ -26,18 +28,85 @@ const validationSchema = {
26
28
  { header: "HUB", field: "origin" },
27
29
  ],
28
30
  };
31
+ const triggerResultSchema = {
32
+ idField: "triggerId",
33
+ columns: [
34
+ { header: "TRIGGER", field: "name" },
35
+ { header: "VERSION", field: "version" },
36
+ { header: "REVISION ID", field: "revisionId" },
37
+ { header: "ACTIVE", field: "active" },
38
+ { header: "PATH", field: "path" },
39
+ { header: "HUB", field: "origin" },
40
+ ],
41
+ };
42
+ const triggerValidationSchema = {
43
+ idField: "name",
44
+ columns: [
45
+ { header: "TRIGGER", field: "name" },
46
+ { header: "VALID", field: "valid" },
47
+ { header: "PATH", field: "path" },
48
+ { header: "HUB", field: "origin" },
49
+ ],
50
+ };
29
51
  export async function runHubDeploy(options, environment = {
30
52
  cwd: process.cwd(),
31
53
  env: process.env,
32
54
  credentials: new PrivateHubCredentialStore(),
33
55
  hub: new HubHttpClient(),
34
56
  }) {
57
+ if (options.project === undefined) {
58
+ return runHubDeployTriggers(options, await discoverHubTriggers(environment.cwd), environment);
59
+ }
35
60
  const deployInput = await discoverHubBundle({
36
61
  cwd: environment.cwd,
37
- ...(options.project === undefined ? {} : { project: options.project }),
62
+ project: options.project,
38
63
  });
39
64
  return runHubDeployBundle(options, deployInput, environment);
40
65
  }
66
+ export async function runHubDeployTriggers(options, triggers, environment) {
67
+ const credentials = environment.credentials ?? new PrivateHubCredentialStore(environment.env);
68
+ const resolution = {
69
+ options: { origin: options.hub, apiKey: options.apiKey },
70
+ env: environment.env,
71
+ credentials,
72
+ };
73
+ const origin = resolveHubOrigin(resolution);
74
+ const credential = resolveHubCredential({ ...resolution, origin });
75
+ const action = options.dryRun === true ? "Validating" : "Deploying";
76
+ reportHubProgress(environment.reporter ?? processHubReporter, options, `${action} ${String(triggers.length)} trigger${triggers.length === 1 ? "" : "s"} ${options.dryRun === true ? "against" : "to"} ${origin}`);
77
+ const hub = environment.hub ?? new HubHttpClient();
78
+ if (options.dryRun === true) {
79
+ const data = await Promise.all(triggers.map(async (trigger) => ({
80
+ ...(await hub.validateTrigger(origin, credential, trigger.yaml)),
81
+ origin,
82
+ path: trigger.path,
83
+ })));
84
+ return { type: "list", data, schema: triggerValidationSchema };
85
+ }
86
+ await Promise.all(triggers.map((trigger) => hub.validateTrigger(origin, credential, trigger.yaml)));
87
+ const data = [];
88
+ for (const trigger of triggers) {
89
+ try {
90
+ data.push({
91
+ ...(await hub.installTrigger(origin, credential, trigger.yaml)),
92
+ origin,
93
+ path: trigger.path,
94
+ });
95
+ }
96
+ catch (error) {
97
+ if (data.length === 0)
98
+ throw error;
99
+ throw new HubCommandError("HUB_TRIGGER_DEPLOY_PARTIAL", `Could not deploy ${trigger.path} after ${String(data.length)} trigger${data.length === 1 ? "" : "s"} had been installed.`, `${errorMessage(error)}\nInstalled before the failure:\n${data.map(({ path: installedPath }) => `- ${installedPath}`).join("\n")}`);
100
+ }
101
+ }
102
+ return { type: "list", data, schema: triggerResultSchema };
103
+ }
104
+ function errorMessage(error) {
105
+ if (error instanceof HubCommandError) {
106
+ return error.details === undefined ? error.message : `${error.message}\n${error.details}`;
107
+ }
108
+ return error instanceof Error ? error.message : String(error);
109
+ }
41
110
  export async function runHubDeployBundle(options, deployInput, environment) {
42
111
  const credentials = environment.credentials ?? new PrivateHubCredentialStore(environment.env);
43
112
  const resolution = {
@@ -72,8 +141,8 @@ export async function runHubDeployBundle(options, deployInput, environment) {
72
141
  export function addHubDeployCommand(hub, dependencies) {
73
142
  addJsonOption(addHubResolutionHelp(hub
74
143
  .command("deploy")
75
- .description("Discover, validate, and activate the canonical .paseo Hub bundle")
76
- .option("-p, --project <slug>", "Target project slug")
144
+ .description("Deploy .paseo organization triggers or a legacy project bundle")
145
+ .option("-p, --project <slug>", "Deploy a legacy bundle to this project slug")
77
146
  .option("--hub <origin>", "Paseo Hub origin")
78
147
  .option("--api-key <secret>", "Organization API key")
79
148
  .option("--dry-run", "Validate without installing or activating"))).action(withOutput(async (...args) => {
@@ -1,6 +1,6 @@
1
1
  import type { HubBundleFile } from "../deploy-bundle.js";
2
- import { type CliAuthorization, type CliAuthorizationPoll, type HubInstallResult, type HubConfigurationResources, type HubSetupResources, type HubProject, type HubTrigger, type HubValidationResult } from "./internal/contracts.js";
3
- export type { CliAuthorization, CliAuthorizationPoll, HubInstallResult, HubConfigurationResources, HubSetupResources, HubProject, HubTrigger, HubValidationResult, } from "./internal/contracts.js";
2
+ import { type CliAuthorization, type CliAuthorizationPoll, type HubInstallResult, type HubConfigurationResources, type HubProject, type HubTrigger, type HubTriggerInstallationResult, type HubTriggerValidationResult, type HubValidationResult } from "./internal/contracts.js";
3
+ export type { CliAuthorization, CliAuthorizationPoll, HubInstallResult, HubConfigurationResources, HubProject, HubTrigger, HubTriggerInstallationResult, HubTriggerValidationResult, HubValidationResult, } from "./internal/contracts.js";
4
4
  interface HubConfigurationInput {
5
5
  origin: string;
6
6
  apiKey: string;
@@ -12,8 +12,9 @@ export declare class HubHttpClient {
12
12
  pollCliAuthorization(origin: string, deviceCode: string, timeoutMilliseconds: number): Promise<CliAuthorizationPoll>;
13
13
  listProjects(origin: string, apiKey: string): Promise<HubProject[]>;
14
14
  listTriggers(origin: string, apiKey: string): Promise<HubTrigger[]>;
15
+ validateTrigger(origin: string, apiKey: string, yaml: string): Promise<HubTriggerValidationResult>;
16
+ installTrigger(origin: string, apiKey: string, yaml: string): Promise<HubTriggerInstallationResult>;
15
17
  listConfigurationResources(origin: string, apiKey: string): Promise<HubConfigurationResources>;
16
- listSetupResources(origin: string, apiKey: string): Promise<HubSetupResources>;
17
18
  installConfiguration(input: HubConfigurationInput): Promise<HubInstallResult>;
18
19
  validateConfiguration(input: HubConfigurationInput): Promise<HubValidationResult>;
19
20
  issueEnrollmentToken(origin: string, apiKey: string): Promise<string>;
@@ -1,5 +1,5 @@
1
1
  import { HubCommandError } from "../error.js";
2
- import { authorizationPollSchema, authorizationSchema, configurationResourcesSchema, enrollmentTokenSchema, installResponseSchema, projectsResponseSchema, triggersResponseSchema, validationResponseSchema, setupResourcesSchema, } from "./internal/contracts.js";
2
+ import { authorizationPollSchema, authorizationSchema, configurationResourcesSchema, enrollmentTokenSchema, installResponseSchema, projectsResponseSchema, triggersResponseSchema, triggerInstallationResponseSchema, triggerValidationResponseSchema, validationResponseSchema, } from "./internal/contracts.js";
3
3
  import { requestHub } from "./internal/transport.js";
4
4
  export class HubHttpClient {
5
5
  startCliAuthorization(origin) {
@@ -57,26 +57,39 @@ export class HubHttpClient {
57
57
  });
58
58
  return response.triggers;
59
59
  }
60
- listConfigurationResources(origin, apiKey) {
60
+ validateTrigger(origin, apiKey, yaml) {
61
61
  return requestHub({
62
62
  origin,
63
- path: "/api/v1/configuration-resources",
64
- method: "GET",
63
+ path: "/api/v1/triggers/validate",
64
+ method: "POST",
65
65
  apiKey,
66
+ body: { yaml },
66
67
  successStatus: 200,
67
- schema: configurationResourcesSchema,
68
- failureMessage: "Hub configuration resource listing failed",
68
+ schema: triggerValidationResponseSchema,
69
+ failureMessage: "Hub trigger validation failed",
69
70
  });
70
71
  }
71
- listSetupResources(origin, apiKey) {
72
+ installTrigger(origin, apiKey, yaml) {
72
73
  return requestHub({
73
74
  origin,
74
- path: "/api/v1/setup-resources",
75
+ path: "/api/v1/triggers/install",
76
+ method: "POST",
77
+ apiKey,
78
+ body: { yaml },
79
+ successStatus: 201,
80
+ schema: triggerInstallationResponseSchema,
81
+ failureMessage: "Hub trigger deployment failed",
82
+ });
83
+ }
84
+ listConfigurationResources(origin, apiKey) {
85
+ return requestHub({
86
+ origin,
87
+ path: "/api/v1/configuration-resources",
75
88
  method: "GET",
76
89
  apiKey,
77
90
  successStatus: 200,
78
- schema: setupResourcesSchema,
79
- failureMessage: "Hub guided setup resource listing failed",
91
+ schema: configurationResourcesSchema,
92
+ failureMessage: "Hub configuration resource listing failed",
80
93
  });
81
94
  }
82
95
  installConfiguration(input) {
@@ -64,6 +64,17 @@ export declare const triggersResponseSchema: z.ZodObject<{
64
64
  yaml: z.ZodString;
65
65
  }, z.core.$strict>>;
66
66
  }, z.core.$strict>;
67
+ export declare const triggerValidationResponseSchema: z.ZodObject<{
68
+ name: z.ZodString;
69
+ valid: z.ZodLiteral<true>;
70
+ }, z.core.$strict>;
71
+ export declare const triggerInstallationResponseSchema: z.ZodObject<{
72
+ triggerId: z.ZodString;
73
+ name: z.ZodString;
74
+ revisionId: z.ZodString;
75
+ version: z.ZodNumber;
76
+ active: z.ZodLiteral<true>;
77
+ }, z.core.$strict>;
67
78
  export declare const configurationResourcesSchema: z.ZodObject<{
68
79
  daemons: z.ZodArray<z.ZodObject<{
69
80
  id: z.ZodString;
@@ -83,21 +94,9 @@ export declare const configurationResourcesSchema: z.ZodObject<{
83
94
  slug: z.ZodString;
84
95
  teamName: z.ZodString;
85
96
  }, z.core.$strict>>;
86
- }, z.core.$strict>;
87
- export declare const setupResourcesSchema: z.ZodObject<{
88
- github: z.ZodArray<z.ZodObject<{
97
+ linear: z.ZodArray<z.ZodObject<{
89
98
  slug: z.ZodString;
90
- accountLogin: z.ZodString;
91
- accountType: z.ZodString;
92
- repositories: z.ZodArray<z.ZodString>;
93
- }, z.core.$strict>>;
94
- discord: z.ZodArray<z.ZodObject<{
95
- guildId: z.ZodString;
96
- guildName: z.ZodString;
97
- }, z.core.$strict>>;
98
- slack: z.ZodArray<z.ZodObject<{
99
- teamId: z.ZodString;
100
- teamName: z.ZodString;
99
+ organizationName: z.ZodString;
101
100
  }, z.core.$strict>>;
102
101
  }, z.core.$strict>;
103
102
  export declare const installResponseSchema: z.ZodObject<{
@@ -118,8 +117,9 @@ export type CliAuthorization = z.infer<typeof authorizationSchema>;
118
117
  export type CliAuthorizationPoll = z.infer<typeof authorizationPollSchema>;
119
118
  export type HubProject = z.infer<typeof projectSchema>;
120
119
  export type HubTrigger = z.infer<typeof triggerSchema>;
120
+ export type HubTriggerValidationResult = z.infer<typeof triggerValidationResponseSchema>;
121
+ export type HubTriggerInstallationResult = z.infer<typeof triggerInstallationResponseSchema>;
121
122
  export type HubConfigurationResources = z.infer<typeof configurationResourcesSchema>;
122
- export type HubSetupResources = z.infer<typeof setupResourcesSchema>;
123
123
  export type HubInstallResult = z.infer<typeof installResponseSchema>;
124
124
  export type HubValidationResult = z.infer<typeof validationResponseSchema>;
125
125
  export {};
@@ -40,6 +40,18 @@ const triggerSchema = z
40
40
  })
41
41
  .strict();
42
42
  export const triggersResponseSchema = z.object({ triggers: z.array(triggerSchema) }).strict();
43
+ export const triggerValidationResponseSchema = z
44
+ .object({ name: z.string().regex(/^[a-z][a-z0-9_-]*$/u), valid: z.literal(true) })
45
+ .strict();
46
+ export const triggerInstallationResponseSchema = z
47
+ .object({
48
+ triggerId: z.string().uuid(),
49
+ name: z.string().regex(/^[a-z][a-z0-9_-]*$/u),
50
+ revisionId: z.string().uuid(),
51
+ version: z.number().int().positive(),
52
+ active: z.literal(true),
53
+ })
54
+ .strict();
43
55
  export const configurationResourcesSchema = z
44
56
  .object({
45
57
  daemons: z.array(z.object({ id: z.string().uuid(), slug: z.string().min(1) }).strict()),
@@ -53,20 +65,7 @@ export const configurationResourcesSchema = z
53
65
  .strict()),
54
66
  discord: z.array(z.object({ slug: z.string().min(1), guildName: z.string().min(1) }).strict()),
55
67
  slack: z.array(z.object({ slug: z.string().min(1), teamName: z.string().min(1) }).strict()),
56
- })
57
- .strict();
58
- export const setupResourcesSchema = z
59
- .object({
60
- github: z.array(z
61
- .object({
62
- slug: z.string().min(1),
63
- accountLogin: z.string().min(1),
64
- accountType: z.string().min(1),
65
- repositories: z.array(z.string().min(1)),
66
- })
67
- .strict()),
68
- discord: z.array(z.object({ guildId: z.string().min(1), guildName: z.string().min(1) }).strict()),
69
- slack: z.array(z.object({ teamId: z.string().min(1), teamName: z.string().min(1) }).strict()),
68
+ linear: z.array(z.object({ slug: z.string().min(1), organizationName: z.string().min(1) }).strict()),
70
69
  })
71
70
  .strict();
72
71
  export const installResponseSchema = z
@@ -1,17 +1,6 @@
1
- import type { HubDeployBundle } from "./deploy-bundle.js";
2
- import type { HubProject } from "./hub-client/index.js";
3
1
  import type { HubStatus } from "./daemon-client.js";
4
2
  import type { HubStarterAgentRuntime } from "./starter-agent-runtime.js";
5
3
  export type HubInitProvider = "github" | "slack" | "discord";
6
- export type HubInitProjectResolution = {
7
- kind: "none";
8
- } | {
9
- kind: "selected";
10
- project: HubProject;
11
- } | {
12
- kind: "choose";
13
- projects: readonly HubProject[];
14
- };
15
4
  export type HubInitConnectionResolution = {
16
5
  kind: "connected";
17
6
  daemonId: string;
@@ -24,30 +13,21 @@ export type HubInitConnectionResolution = {
24
13
  kind: "conflict";
25
14
  origin: string;
26
15
  };
27
- export interface HubInitOpeningPlan {
28
- replaceExisting: boolean;
29
- steps: readonly ("login" | "connect" | "project" | "scaffold")[];
30
- }
31
16
  export interface HubInitScaffoldInput {
32
17
  cwd: string;
33
18
  daemonSlug: string;
34
- agent: HubStarterAgentRuntime;
19
+ agent: HubStarterAgentRuntime & {
20
+ mode: string;
21
+ };
35
22
  provider: HubInitProvider;
36
23
  providerFilters: Readonly<Record<string, string>>;
37
24
  }
38
25
  export interface HubInitScaffold {
39
- hub: string;
40
- workflowPath: string;
41
- workflow: string;
26
+ triggerPath: string;
27
+ trigger: string;
42
28
  testAction: string;
43
29
  }
44
30
  export declare function hubLoginResumeCommand(step: "connect" | "init", origin: string): string;
45
- export declare function planHubInitOpening(input: {
46
- loggedIn: boolean;
47
- paseoDirectoryExists: boolean;
48
- }): HubInitOpeningPlan;
49
- export declare function createHubInitBundle(projectSlug: string, scaffold: HubInitScaffold): HubDeployBundle;
50
- export declare function resolveHubInitProjects(projects: readonly HubProject[]): HubInitProjectResolution;
51
31
  export declare function resolveHubInitConnection(status: HubStatus, origin: string): HubInitConnectionResolution;
52
32
  export declare function createHubInitScaffold(input: HubInitScaffoldInput): HubInitScaffold;
53
33
  //# sourceMappingURL=init-plan.d.ts.map
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpaseo/cli",
3
- "version": "0.8.0-beta.1",
3
+ "version": "0.8.0",
4
4
  "description": "Paseo CLI - control your AI coding agents from the command line",
5
5
  "bin": {
6
6
  "paseo": "bin/paseo"
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@clack/prompts": "^1.0.0",
31
- "@getpaseo/client": "0.8.0-beta.1",
32
- "@getpaseo/protocol": "0.8.0-beta.1",
33
- "@getpaseo/server": "0.8.0-beta.1",
31
+ "@getpaseo/client": "0.8.0",
32
+ "@getpaseo/protocol": "0.8.0",
33
+ "@getpaseo/server": "0.8.0",
34
34
  "chalk": "^5.3.0",
35
35
  "commander": "^12.0.0",
36
36
  "mime-types": "^2.1.35",