@cargo-ai/cli 1.0.115 → 1.0.116

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.
@@ -1,4 +1,4 @@
1
- import { cdkProjectRoot } from "@cargo-ai/cdk/cli";
1
+ import { findProjectDir } from "@cargo-ai/cdk/cli";
2
2
  import { buildReleaseInstructionAppendix } from "./release.js";
3
3
  const LOCAL_WORKING_COPY_INSTRUCTIONS = `You are working in the user's local working copy, not a sandbox. Prefer plan over deploy.
4
4
 
@@ -21,7 +21,7 @@ const LOCAL_CDK_RAILS_SKILL = {
21
21
  * Exported for tests.
22
22
  */
23
23
  export function localHarnessInstructions(dir, release) {
24
- const rails = cdkProjectRoot(dir) !== undefined
24
+ const rails = findProjectDir(dir) !== undefined
25
25
  ? `${LOCAL_WORKING_COPY_INSTRUCTIONS}\n\n${CDK_RAILS_INSTRUCTIONS}`
26
26
  : LOCAL_WORKING_COPY_INSTRUCTIONS;
27
27
  if (release === undefined) {
@@ -36,7 +36,7 @@ export function localHarnessInstructions(dir, release) {
36
36
  }
37
37
  /** Exported for tests. */
38
38
  export function localHarnessSkills(dir) {
39
- if (cdkProjectRoot(dir) !== undefined) {
39
+ if (findProjectDir(dir) !== undefined) {
40
40
  return [LOCAL_CDK_RAILS_SKILL];
41
41
  }
42
42
  return [];
@@ -15,7 +15,7 @@
15
15
  // or a docs snippet, and every step leaves a valid machine behind: cancel after
16
16
  // signing in and you are signed in.
17
17
  import { spawnSync } from "node:child_process";
18
- import { askText, availableCodingAgents, cdkProjectRoot, COMPANY_CONTEXT_PATH, hasCompanyContext, installedCookbooks, isInteractive, launchBriefed, requireAnswer, selectOne, skillsInstalledFor, } from "@cargo-ai/cdk/cli";
18
+ import { askText, availableCodingAgents, COMPANY_CONTEXT_PATH, findProjectDir, hasCompanyContext, installedCookbooks, isInteractive, launchBriefed, requireAnswer, selectOne, skillsInstalledFor, } from "@cargo-ai/cdk/cli";
19
19
  import { AGENT_SKILLS_NEXT_STEP } from "../../agentSkills.js";
20
20
  import { isSignedIn } from "../../setupIssues.js";
21
21
  import { parseBooleanOption } from "../../utils/booleanOption.js";
@@ -35,7 +35,7 @@ const EMAIL = "email";
35
35
  * Exported for tests; `go` is the only production caller.
36
36
  */
37
37
  export function resolveProjectContext(cwd) {
38
- const root = cdkProjectRoot(cwd);
38
+ const root = findProjectDir(cwd);
39
39
  if (root === undefined) {
40
40
  return { kind: "none" };
41
41
  }
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
- import { availableCodingAgents, BRAND, canRunPalette, cdkProjectRoot, creditsLeftOf, declareSources, fetchSubscription, fetchWorkspaceName, formatWorkspaceSuffix, isInteractive, isUnpaidPlan, printSetupIssues, registerCommands as registerCdkCommands, runPalette, SessionExpiredError, } from "@cargo-ai/cdk/cli";
3
+ import { availableCodingAgents, BRAND, canRunPalette, creditsLeftOf, declareSources, fetchSubscription, fetchWorkspaceName, findProjectDir, formatWorkspaceSuffix, isInteractive, isUnpaidPlan, printSetupIssues, registerCommands as registerCdkCommands, runPalette, SessionExpiredError, } from "@cargo-ai/cdk/cli";
4
4
  import { Command } from "commander";
5
5
  import { AGENT_SKILLS_HINT } from "./agentSkills.js";
6
6
  import { createApi } from "./api.js";
@@ -290,11 +290,11 @@ async function openPalette(startPath) {
290
290
  // Read once: a layout describing two different directories could offer to
291
291
  // deploy one and name the other.
292
292
  const cwd = process.cwd();
293
- const root = cdkProjectRoot(cwd);
293
+ const root = findProjectDir(cwd);
294
294
  return buildPaletteLayout({
295
295
  signedIn: isSignedIn(),
296
296
  agents,
297
- cdkProjectRoot: root,
297
+ projectDir: root,
298
298
  cwd,
299
299
  unpaidPlan,
300
300
  });
@@ -2,8 +2,8 @@ import { type CodingAgent, type PaletteLayout, type PinnedRow } from "@cargo-ai/
2
2
  export type PaletteLayoutInput = {
3
3
  signedIn: boolean;
4
4
  agents: readonly CodingAgent[];
5
- /** The CDK repo root the palette is standing in, or undefined when none. */
6
- cdkProjectRoot: string | undefined;
5
+ /** The project (`cargo.json`) folder the palette is in, or undefined when none. */
6
+ projectDir: string | undefined;
7
7
  /**
8
8
  * Where the palette is standing. The project rows are resolved by walking
9
9
  * *up* from here, so this is what says whether they point at the directory
@@ -1 +1 @@
1
- {"version":3,"file":"paletteLayout.d.ts","sourceRoot":"","sources":["../src/paletteLayout.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AA+E3B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B,4EAA4E;IAC5E,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAS3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,EAAE,CA+DjE"}
1
+ {"version":3,"file":"paletteLayout.d.ts","sourceRoot":"","sources":["../src/paletteLayout.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AA+E3B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B,mFAAmF;IACnF,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAS3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,EAAE,CA+DjE"}
@@ -113,8 +113,8 @@ export function pinnedRows(input) {
113
113
  // for a workspace you have not built yet, and this one is open on screen.
114
114
  // Outside, there is no project to add to or deploy, so offer the tour and the
115
115
  // scaffold instead.
116
- const projectRows = input.cdkProjectRoot !== undefined
117
- ? cdkRows(input.cdkProjectRoot, input.cwd)
116
+ const projectRows = input.projectDir !== undefined
117
+ ? cdkRows(input.projectDir, input.cwd)
118
118
  : [
119
119
  {
120
120
  value: DEMO,
@@ -163,9 +163,8 @@ function cdkRows(root, cwd) {
163
163
  value: ADD,
164
164
  label: "Add",
165
165
  hint: "a connector or a cookbook into this project",
166
- // `--dir` because `project add` refuses a directory with no package.json,
167
- // and the palette is as often open in `infra/` — where the scaffold's
168
- // README sends people — as at the root.
166
+ // `--dir` pins the project the palette found, so the command adds to
167
+ // the one on screen whichever folder of it the palette is open in.
169
168
  argv: ["project", "add", "--dir", root],
170
169
  },
171
170
  {
@@ -17,21 +17,18 @@ export declare function importModuleDefault(file: string, subject: string): Prom
17
17
  /**
18
18
  * The CDK project directory a `--file` module belongs to — the directory `cdk
19
19
  * plan` and `cdk deploy` run in, which is what a harness agent's inferred
20
- * `rootDirectory` is measured from. Walk up to the repo, then back down to the
21
- * project (`infra/` in a scaffolded repo); a file in no recognisable project
22
- * answers its own directory.
23
- *
24
- * Deliberately NOT the nearest cargo.state.json. That file's position is
25
- * incidental — a repo deployed before `cdk deploy` ran from the project has one
26
- * at the repo root — so measuring from it would report no `rootDirectory` and
27
- * clone the repo root, while the deployed agent clones `infra/`.
20
+ * `rootDirectory` is measured from: the resources of the nearest `cargo.json`
21
+ * above the file, else above the cwd (a scratch file run from inside a
22
+ * project). With neither, the command stops, as `cdk plan` does: building from
23
+ * the file's own folder instead would load part of the project and bind the
24
+ * agent to a folder the deployed one does not clone, with nothing said.
28
25
  */
29
26
  export declare function cdkProjectDirFor(file: string): string;
30
27
  /**
31
28
  * Deep-resolve every `@cargo-ai/cdk` handle token in `value` to its real uuid
32
- * using the nearest cargo.state.json (searched from `file`'s directory upward,
33
- * then the cwd). `subject` names the thing under test in error messages (e.g. a
34
- * workflow or agent slug). A value with no tokens (literal-uuid refs, or a pure
29
+ * using the deploy state of the project `file` belongs to (`cdkProjectDirFor`).
30
+ * `subject` names the thing under test in error messages (e.g. a workflow or
31
+ * agent slug). A value with no tokens (literal-uuid refs, or a pure
35
32
  * body) is returned unchanged — no state needed. Fails with an actionable error
36
33
  * when state is missing or a referenced resource isn't deployed yet.
37
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"cdkState.d.ts","sourceRoot":"","sources":["../../src/utils/cdkState.ts"],"names":[],"mappings":"AAoBA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CASxE;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CAyBtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOrD;AAaD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CA2CT"}
1
+ {"version":3,"file":"cdkState.d.ts","sourceRoot":"","sources":["../../src/utils/cdkState.ts"],"names":[],"mappings":"AAoBA,wBAAgB,oBAAoB,CAAC,GAAG,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CASxE;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CAyBtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBrD;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAkCT"}
@@ -5,10 +5,10 @@
5
5
  // `@cargo-ai/cdk` handle tokens the module references to their real uuids from
6
6
  // this project's deploy state — without deploying the module itself.
7
7
  import { existsSync } from "node:fs";
8
- import { dirname, isAbsolute, join, resolve } from "node:path";
8
+ import { dirname, isAbsolute, resolve } from "node:path";
9
9
  import { pathToFileURL } from "node:url";
10
10
  import { dependenciesOf, readStateOffline, resolveTokens } from "@cargo-ai/cdk";
11
- import { cdkProjectDir, cdkProjectRoot } from "@cargo-ai/cdk/cli";
11
+ import { cdkResourceDir, missingProjectFile } from "@cargo-ai/cdk/cli";
12
12
  import { ExitCodes, failWith } from "../commands/runHandler.js";
13
13
  // Peel the extra interop layer tsx adds when a TS source is transpiled to CJS:
14
14
  // the ESM namespace's `default` is then the CJS `module.exports`
@@ -53,41 +53,30 @@ export async function importModuleDefault(file, subject) {
53
53
  /**
54
54
  * The CDK project directory a `--file` module belongs to — the directory `cdk
55
55
  * plan` and `cdk deploy` run in, which is what a harness agent's inferred
56
- * `rootDirectory` is measured from. Walk up to the repo, then back down to the
57
- * project (`infra/` in a scaffolded repo); a file in no recognisable project
58
- * answers its own directory.
59
- *
60
- * Deliberately NOT the nearest cargo.state.json. That file's position is
61
- * incidental — a repo deployed before `cdk deploy` ran from the project has one
62
- * at the repo root — so measuring from it would report no `rootDirectory` and
63
- * clone the repo root, while the deployed agent clones `infra/`.
56
+ * `rootDirectory` is measured from: the resources of the nearest `cargo.json`
57
+ * above the file, else above the cwd (a scratch file run from inside a
58
+ * project). With neither, the command stops, as `cdk plan` does: building from
59
+ * the file's own folder instead would load part of the project and bind the
60
+ * agent to a folder the deployed one does not clone, with nothing said.
64
61
  */
65
62
  export function cdkProjectDirFor(file) {
66
63
  const absPath = isAbsolute(file) ? file : resolve(process.cwd(), file);
67
- const fileDir = dirname(absPath);
68
- const repoRoot = cdkProjectRoot(fileDir);
69
- if (repoRoot === undefined)
70
- return fileDir;
71
- const project = cdkProjectDir(repoRoot);
72
- return project === undefined ? repoRoot : project;
73
- }
74
- // Walk up from `startDir` looking for a directory that holds cargo.state.json.
75
- function findStateRoot(startDir) {
76
- let dir = startDir;
77
- for (;;) {
78
- if (existsSync(join(dir, "cargo.state.json")))
79
- return dir;
80
- const parent = dirname(dir);
81
- if (parent === dir)
82
- return undefined;
83
- dir = parent;
64
+ const fileProject = cdkResourceDir(dirname(absPath));
65
+ const project = fileProject !== undefined ? fileProject : cdkResourceDir(process.cwd());
66
+ if (project === undefined) {
67
+ const missing = missingProjectFile(dirname(absPath));
68
+ failWith(missing.message, {
69
+ code: ExitCodes.InvalidUsage,
70
+ extra: { run: missing.run },
71
+ });
84
72
  }
73
+ return project;
85
74
  }
86
75
  /**
87
76
  * Deep-resolve every `@cargo-ai/cdk` handle token in `value` to its real uuid
88
- * using the nearest cargo.state.json (searched from `file`'s directory upward,
89
- * then the cwd). `subject` names the thing under test in error messages (e.g. a
90
- * workflow or agent slug). A value with no tokens (literal-uuid refs, or a pure
77
+ * using the deploy state of the project `file` belongs to (`cdkProjectDirFor`).
78
+ * `subject` names the thing under test in error messages (e.g. a workflow or
79
+ * agent slug). A value with no tokens (literal-uuid refs, or a pure
91
80
  * body) is returned unchanged — no state needed. Fails with an actionable error
92
81
  * when state is missing or a referenced resource isn't deployed yet.
93
82
  */
@@ -95,20 +84,15 @@ export function resolveTokensFromState(value, file, subject) {
95
84
  const deps = dependenciesOf(value);
96
85
  if (deps.size === 0)
97
86
  return value;
98
- const absPath = isAbsolute(file) ? file : resolve(process.cwd(), file);
99
- const stateRoot = findStateRoot(dirname(absPath)) ?? findStateRoot(process.cwd());
100
- if (stateRoot === undefined) {
101
- failWith(`${subject} references ${String(deps.size)} deployed resource(s) ` +
102
- `(${[...deps].join(", ")}), but no cargo.state.json was found near ` +
103
- `${absPath} or the current directory. Deploy the resources first with ` +
104
- "`cargo-ai project deploy`, or reference them by literal uuid " +
105
- "(toolRef / agentRef / connectorRef).", { code: ExitCodes.NotFound });
106
- }
87
+ // The project's own state file, beside its cargo.json, rather than the
88
+ // nearest cargo.state.json: in a repository of several projects that could
89
+ // be another project's.
90
+ const project = cdkProjectDirFor(file);
107
91
  // A project whose state lives in the workspace has a pointer here, not a
108
92
  // resource map, so the cache the last plan or deploy left behind is what
109
93
  // answers this offline. Resolving a handle is a read of what is already
110
94
  // deployed — worth a stale answer, not worth a round trip on every run.
111
- const state = readStateOffline(stateRoot);
95
+ const state = readStateOffline(project);
112
96
  const outputs = new Map();
113
97
  if (state !== undefined) {
114
98
  for (const [id, entry] of Object.entries(state.resources)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cargo-ai/cli",
3
- "version": "1.0.115",
3
+ "version": "1.0.116",
4
4
  "mcpName": "io.github.getcargohq/cargo",
5
5
  "private": false,
6
6
  "license": "UNLICENSED",
@@ -74,9 +74,9 @@
74
74
  "dependencies": {
75
75
  "@ai-sdk/harness": "^1.0.144",
76
76
  "@ai-sdk/harness-claude-code": "^1.0.148",
77
- "@cargo-ai/api": "^1.0.95",
77
+ "@cargo-ai/api": "^1.0.96",
78
78
  "@cargo-ai/app-sdk": "^1.0.11",
79
- "@cargo-ai/cdk": "^1.0.111",
79
+ "@cargo-ai/cdk": "^1.0.112",
80
80
  "@cargo-ai/types": "^1.0.96",
81
81
  "@cargo-ai/utils": "^1.0.32",
82
82
  "@cargo-ai/worker-sdk": "^1.0.20",