@agentage/cli 0.81.0 → 0.81.2

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.
@@ -6,17 +6,14 @@ installs its extensions with npm, without signing in. --dry-run prints the plan,
6
6
  would change (+ add, ~ update, - remove, o off, then one summary line), and writes nothing;
7
7
  --check prints the plan and exits 1 when anything would change, the lock in the extensions
8
8
  directory does not match the installed tree, or machine.json is missing; it writes nothing.
9
- Neither signs in. Plain setup signs in, then pulls the profile from your account (creating it
10
- from this machine's profile.json, or the default, when the account has none), registers this
11
- machine in the account and installs; it never pushes a change. When the account cannot be
12
- reached it installs from the local profile.json, or, with none, installs nothing and says so on
13
- one line. With AGENTAGE_TOKEN set, setup signs in with that token and opens no browser. Then
14
- setup starts the daemon on 127.0.0.1:4243, which needs no account (--no-daemon or
15
- AGENTAGE_NO_DAEMON=1: not started). A profile from --profile stays local: setup neither pulls nor pushes it. Each package
16
- comes from the registry the profile's registries map names for its scope (default
17
- https://registry.npmjs.org) into AGENTAGE_EXTENSIONS_DIR (default ~/.agentage/extensions). After
18
- installing, setup lists the secrets extensions declare and this machine has not set (asking for
19
- them on a terminal), then loads every extension once and prints ok or failed for each; it exits
9
+ Neither signs in. Plain setup signs in, registers this machine in the account and installs
10
+ this machine's profile.json; with none it installs nothing and says so on one line. It never
11
+ reads or writes a profile in the account. With AGENTAGE_TOKEN set, setup signs in with that
12
+ token and opens no browser. Then setup starts the daemon on 127.0.0.1:4243, which needs no
13
+ account (--no-daemon or AGENTAGE_NO_DAEMON=1: not started). Each package comes from the registry the profile's registries
14
+ map names for its scope (default https://registry.npmjs.org) into AGENTAGE_EXTENSIONS_DIR
15
+ (default ~/.agentage/extensions). After installing, setup lists the secrets extensions declare
16
+ and this machine has not set (asking for them on a terminal), then loads every extension once and prints ok or failed for each; it exits
20
17
  1 when any failed. Signed in to another account than the one this machine is connected to, setup
21
18
  exits 1; run setup --disconnect first, which also marks this machine disconnected in your
22
19
  account.
@@ -24,8 +21,7 @@ account.
24
21
  --latest runs npm update in a staged copy of the installed tree: each extension moves to the
25
22
  newest version its range allows, unless that version needs another extension API (then it is
26
23
  kept, saying so). It prints one line per changed extension and a summary, loads the new tree and
27
- makes it current only when every extension loaded clean, then pushes the profile with the new
28
- lock to your account when the profile comes from it. With nothing newer it only prints
24
+ makes it current only when every extension loaded clean. With nothing newer it only prints
29
25
  "latest: nothing to update". It never signs in.`;
30
26
  const latestOption = () => new Option('--latest', 'update extensions to the newest versions their ranges allow').conflicts([
31
27
  'profile',
@@ -0,0 +1,2 @@
1
+ export declare const markParts: (text: string, kept: string[], all: string[], file: string) => string;
2
+ export declare const markFolder: (dir: string, kept: string[], all: string[]) => void;
@@ -0,0 +1,56 @@
1
+ import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ const OPEN = /^\s*<!-- part:([a-z+]+) -->\s*$/;
4
+ const CLOSE = /^\s*<!-- \/part:([a-z+]+) -->\s*$/;
5
+ // Marker pairs take whole lines; `a+b` keeps its block only when all named parts are kept. No nesting.
6
+ export const markParts = (text, kept, all, file) => {
7
+ const out = [];
8
+ let open;
9
+ let marked = false;
10
+ const fail = (why) => {
11
+ throw new Error(`${file}: ${why}`);
12
+ };
13
+ for (const line of text.split('\n')) {
14
+ const start = OPEN.exec(line)?.[1];
15
+ const end = CLOSE.exec(line)?.[1];
16
+ if (start !== undefined) {
17
+ if (open)
18
+ fail(`part:${start} opens inside part:${open.name} (no nesting)`);
19
+ const names = start.split('+');
20
+ const unknown = names.find((name) => !all.includes(name));
21
+ if (unknown)
22
+ fail(`part:${start} names unknown part ${unknown}`);
23
+ open = { name: start, drop: names.some((name) => !kept.includes(name)) };
24
+ marked = true;
25
+ }
26
+ else if (end !== undefined) {
27
+ if (open?.name !== end)
28
+ fail(`/part:${end} has no matching part:${end}`);
29
+ open = undefined;
30
+ }
31
+ else if (!open?.drop)
32
+ out.push(line);
33
+ }
34
+ if (open)
35
+ fail(`part:${open.name} is not closed`);
36
+ return marked
37
+ ? out
38
+ .join('\n')
39
+ .replace(/\n{3,}/g, '\n\n')
40
+ .replace(/\n\n$/, '\n')
41
+ : text;
42
+ };
43
+ // Every .md file of the new folder, so a marker error names the file.
44
+ export const markFolder = (dir, kept, all) => {
45
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
46
+ const path = join(dir, entry.name);
47
+ if (entry.isDirectory())
48
+ markFolder(path, kept, all);
49
+ if (!entry.isFile() || !entry.name.endsWith('.md'))
50
+ continue;
51
+ const text = readFileSync(path, 'utf8');
52
+ const next = markParts(text, kept, all, path);
53
+ if (next !== text)
54
+ writeFileSync(path, next);
55
+ }
56
+ };
@@ -0,0 +1,7 @@
1
+ export declare const PRUNE: Record<string, {
2
+ keys?: string[][];
3
+ paths?: string[];
4
+ dev?: string[];
5
+ }>;
6
+ export declare const devDropped: (kept: string[]) => string[];
7
+ export declare const syncLockRoot: (root: Record<string, unknown>, dev: Record<string, unknown>) => void;
@@ -0,0 +1,30 @@
1
+ // What else goes with a dropped part: manifest keys the kit refuses without it, the store's SQL, the contract file of api and mcp,
2
+ // and the dev dependencies no kept file imports or configures.
3
+ export const PRUNE = {
4
+ cli: { keys: [['agentage', 'commands']] },
5
+ mcp: { keys: [['agentage', 'settings', 'mcp.listing']], paths: ['template.mcpc.json'] },
6
+ api: { paths: ['openapi.json'] },
7
+ store: { paths: ['migrations', 'seeds'] },
8
+ app: {
9
+ keys: [['agentage', 'app']],
10
+ paths: ['src/app-part.test.tsx', 'src/app-lint.test.ts'],
11
+ dev: ['@agentage/components', 'jsdom'],
12
+ },
13
+ ui: { dev: ['@agentage/widget', '@axe-core/playwright'] },
14
+ };
15
+ // Used by app and by ui: dropped only when both are.
16
+ const REACT = ['react', 'react-dom', '@types/react', '@types/react-dom'];
17
+ // eslint, tsconfig and playwright config still name playwright, jsx-a11y and react-hooks: those stay.
18
+ export const devDropped = (kept) => [
19
+ ...Object.entries(PRUNE).flatMap(([part, { dev = [] }]) => (kept.includes(part) ? [] : dev)),
20
+ ...(kept.includes('app') || kept.includes('ui') ? [] : REACT),
21
+ ];
22
+ // npm ci tolerates packages left in the lock, but its root entry should match package.json.
23
+ export const syncLockRoot = (root, dev) => {
24
+ const locked = root['devDependencies'];
25
+ if (!locked)
26
+ return;
27
+ for (const name of Object.keys(locked))
28
+ if (!(name in dev))
29
+ delete locked[name];
30
+ };
@@ -4,6 +4,8 @@ import {} from 'commander';
4
4
  import { addJson, CliError } from '../../lib/json-output.js';
5
5
  import { siteFqdn } from '../../lib/net/origins.js';
6
6
  import { installCreated, trustFrom } from './create-install.js';
7
+ import { markFolder } from './create-markers.js';
8
+ import { devDropped, PRUNE, syncLockRoot } from './create-prune.js';
7
9
  import { clone, fromRefusal, repoRef, TEMPLATE } from './create-source.js';
8
10
  import { terminalIo } from './lifecycle.js';
9
11
  export { TEMPLATE };
@@ -12,14 +14,6 @@ const ROUTED = ['pages', 'ui', 'api', 'mcp'];
12
14
  // `_` is a separator here, so `template_echo` is the id too.
13
15
  const WORD = /(?<![A-Za-z0-9])template(?![A-Za-z0-9])/g;
14
16
  const LOCK = 'package-lock.json';
15
- // What else goes with a dropped part: manifest keys the kit refuses without it, the store's SQL, the contract file of api and mcp.
16
- const PRUNE = {
17
- cli: { keys: [['agentage', 'commands']] },
18
- mcp: { keys: [['agentage', 'settings', 'mcp.listing']], paths: ['template.mcpc.json'] },
19
- api: { paths: ['openapi.json'] },
20
- store: { paths: ['migrations', 'seeds'] },
21
- app: { keys: [['agentage', 'app']], paths: ['src/app-part.test.tsx', 'src/app-lint.test.ts'] },
22
- };
23
17
  // Parts come as separate words, comma lists or both: `app,api`, `app api`, `app, api`.
24
18
  export const splitParts = (parts) => parts.flatMap((part) => part.split(/[\s,]+/)).filter(Boolean);
25
19
  const refusal = ({ id, parts, from = TEMPLATE }, kept) => {
@@ -53,6 +47,8 @@ const drop = (dir, kept) => {
53
47
  delete parent[path.at(-1) ?? ''];
54
48
  }
55
49
  }
50
+ for (const name of devDropped(kept))
51
+ delete pkg['devDependencies']?.[name];
56
52
  // The new repo is the folder itself: a monorepo path of the template would point into nothing.
57
53
  delete pkg['repository']?.['directory'];
58
54
  save(join(dir, 'package.json'), pkg);
@@ -81,6 +77,9 @@ const renameLock = (dir, id) => {
81
77
  for (const at of [lock, lock['packages']?.['']])
82
78
  if (at)
83
79
  Object.assign(at, { name });
80
+ const root = lock['packages']?.[''];
81
+ if (root)
82
+ syncLockRoot(root, json(join(dir, 'package.json'))['devDependencies'] ?? {});
84
83
  save(join(dir, LOCK), lock);
85
84
  };
86
85
  const CI = join('.github', 'workflows', 'ci.yml');
@@ -102,6 +101,7 @@ const lowerFloor = (dir, kept) => {
102
101
  const shape = (dir, from, id, kept) => {
103
102
  try {
104
103
  drop(dir, kept);
104
+ markFolder(dir, kept, PARTS);
105
105
  rewrite(dir, id);
106
106
  renameLock(dir, id);
107
107
  return lowerFloor(dir, kept);
@@ -9,7 +9,7 @@ import {} from '../../core/profile/schema.js';
9
9
  import { line } from './line.js';
10
10
  import { accountProfileInstalled, NOT_EXTENSION, profilePlan, } from './profile-plan.js';
11
11
  // What setup would send to the daemon, with this machine's own entry from profile.json kept. A
12
- // file (`--profile`) is never gated; the local profile is, once the account profile was installed.
12
+ // file (`--profile`) is never gated; the local profile is, once it was installed.
13
13
  const planFor = (profile, file) => {
14
14
  const local = readProfile();
15
15
  const desired = keepMachine(profile, local?.ok ? local.profile : null, readMachine()?.id ?? '');
@@ -26,7 +26,7 @@ export const planLines = ({ extensions, summary: s, skipped }) => {
26
26
  return [...shown.map(entryLine), ...skips, `plan: ${total}`];
27
27
  };
28
28
  // --check and --dry-run read no account: the plan says which profile it is of.
29
- const sourceLine = ({ file, from }) => line('from', file ? from : `${from} on this machine; plain setup installs your account profile`);
29
+ const sourceLine = ({ file, from }) => line('from', file ? from : `${from} on this machine`);
30
30
  // One line per scope the profile routes, then the registry for everything else.
31
31
  const registryLines = (registries) => {
32
32
  const all = [...Object.entries(registries), ['default', DEFAULT_REGISTRY]];
@@ -6,7 +6,7 @@ import { readMachine } from '../../core/profile/machine.js';
6
6
  import {} from '../../core/profile/schema.js';
7
7
  import { getConfigDir } from '../../lib/fs/config.js';
8
8
  const PACKAGE_ID = /^(?:@agentage\/extension-|agentage-extension-)([a-z][a-z0-9-]*)$/;
9
- // Written once plain setup tried every entry of the account profile: once per machine.
9
+ // Written once plain setup tried every entry of the profile: once per machine.
10
10
  export const profileMarkerPath = () => join(getConfigDir(), 'setup.profile-installed');
11
11
  export const accountProfileInstalled = () => existsSync(profileMarkerPath());
12
12
  // A profile entry the daemon can never install: said once, never a change to make.
@@ -26,7 +26,7 @@ const verbOf = (entry, have, done) => {
26
26
  return entry.off ? 'off' : 'add';
27
27
  };
28
28
  // What setup would send to the daemon: add, add disabled (off), or nothing (unchanged). Reads
29
- // installation.json only; `done` is a plain setup that installed the account profile already.
29
+ // installation.json only; `done` is a plain setup that installed the profile already.
30
30
  export const profilePlan = (profile, done) => {
31
31
  const rows = new Map(installationRows().map((row) => [row.id, row]));
32
32
  const entries = profileEntries(profile);
@@ -1,13 +1,12 @@
1
1
  import chalk from 'chalk';
2
- import { localProfile, NotPushedError, pullProfile, } from '../../core/profile/cloud.js';
3
- import { forgetAccount, loadMachine, readMachine, setAccount, setCloud, } from '../../core/profile/machine.js';
4
- import { defaultProfile, mutateProfile, readProfile } from '../../core/profile/profile.js';
5
- import { pushWithReplay } from '../../core/profile/push.js';
2
+ import {} from '../../core/profile/cloud.js';
3
+ import { forgetAccount, loadMachine, readMachine, setAccount, } from '../../core/profile/machine.js';
4
+ import { defaultProfile, readProfile } from '../../core/profile/profile.js';
6
5
  import { disconnectMachine, registerMachine } from '../../core/profile/register.js';
7
6
  import {} from '../../core/profile/schema.js';
8
7
  import { line } from './line.js';
9
- import { applying, checkAccount } from './sync.js';
10
- const FILE_NOTE = 'from a file (setup --profile), not synced with your account';
8
+ import { checkAccount } from './sync.js';
9
+ const FILE_NOTE = 'from a file (setup --profile)';
11
10
  // profile.json: null when absent; an invalid one stops setup naming each problem.
12
11
  const localCopy = () => {
13
12
  const parsed = readProfile();
@@ -17,55 +16,18 @@ const localCopy = () => {
17
16
  return parsed.profile;
18
17
  throw new Error(`profile.json is invalid:\n${parsed.errors.map((e) => ` ${e}`).join('\n')}`);
19
18
  };
20
- // The etag profile.json still mirrors: sent as If-None-Match, so an unchanged profile is a 304.
21
- const mirroredEtag = (machine) => machine.profileSource === 'cloud' && readProfile()?.ok === true ? machine.profileEtag : null;
22
- // Without the account: the local profile.json; with none, nothing to install, and setup goes on.
23
- const fromLocalCopy = async (reason, deps) => {
19
+ // Plain setup installs this machine's profile.json; with none, nothing, and setup goes on.
20
+ const fromLocalCopy = async (deps) => {
24
21
  const local = localCopy();
25
- const unavailable = 'cloud profile unavailable';
26
22
  if (local === null)
27
- return console.error(chalk.dim(`${unavailable} and no local profile.json, nothing installed (${reason})`));
28
- console.error(chalk.dim(`${unavailable}, using local profile.json (${reason})`));
23
+ return console.error(chalk.dim('no local profile.json, nothing installed'));
29
24
  await deps.installProfile(local);
30
25
  };
31
- const installPulled = async (doc, deps) => {
32
- await mutateProfile(() => doc.profile);
33
- console.log(line('profile', `pulled from your account (etag ${doc.etag})`));
34
- await setCloud(doc.etag);
35
- await deps.installProfile(doc.profile);
36
- };
37
- // A create the account did not take fails nothing: the next setup creates it.
38
- const notCreated = (err) => {
39
- if (!(err instanceof NotPushedError))
40
- throw err;
41
- console.error(chalk.dim(`${err.message}; the next agentage setup tries again`));
42
- return null;
43
- };
44
- // No profile in the account yet: this machine's own, or the default, becomes it once it loaded.
45
- const createIn = async (account, deps) => {
46
- const base = localProfile(localCopy() ?? defaultProfile());
47
- const apply = applying((profile) => profile, deps);
48
- const done = await pushWithReplay(account.fetch, base, apply).catch(notCreated);
49
- if (done === null)
50
- return;
51
- await setCloud(done.etag);
52
- const where = done.pushed ? 'created in' : 'already in';
53
- console.log(line('profile', `${where} your account (etag ${done.etag})`));
54
- };
55
- // Plain setup pulls and never pushes, except to create the account's first profile.
56
- const profileFrom = async (account, machine, deps) => {
57
- if (machine.profileSource === 'file') {
58
- console.log(line('profile', FILE_NOTE));
59
- return deps.installProfile(localCopy() ?? defaultProfile());
60
- }
61
- const pulled = await pullProfile(account.fetch, mirroredEtag(machine));
62
- if (pulled.kind === 'found')
63
- return installPulled(pulled.doc, deps);
64
- if (pulled.kind === 'none')
65
- return createIn(account, deps);
66
- if (pulled.kind === 'current')
67
- return deps.installProfile(localCopy() ?? defaultProfile());
68
- return fromLocalCopy(pulled.reason, deps);
26
+ const profileFrom = async (machine, deps) => {
27
+ if (machine.profileSource !== 'file')
28
+ return fromLocalCopy(deps);
29
+ console.log(line('profile', FILE_NOTE));
30
+ return deps.installProfile(localCopy() ?? defaultProfile());
69
31
  };
70
32
  // The first signed-in setup records the account; another account is refused until --disconnect.
71
33
  const connect = async (account) => {
@@ -77,12 +39,12 @@ const connect = async (account) => {
77
39
  export const accountSetup = async (deps) => {
78
40
  const account = await deps.account();
79
41
  if (account === null)
80
- return fromLocalCopy('not signed in', deps);
42
+ return fromLocalCopy(deps);
81
43
  const platform = await account.platform();
82
44
  const machine = await connect(account);
83
45
  const registered = registerMachine(account.machines, machine);
84
46
  try {
85
- await profileFrom(account, machine, deps);
47
+ await profileFrom(machine, deps);
86
48
  }
87
49
  finally {
88
50
  if (await registered)
@@ -6,7 +6,7 @@ import { addOnce } from './install-once.js';
6
6
  import { NOT_EXTENSION, profileEntries } from './profile-plan.js';
7
7
  import { readMarker, writeMarker } from './setup-marker.js';
8
8
  const EXACT = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
9
- const KEPT = 'your account profile was installed here already; setup installs nothing (agentage extension install)';
9
+ const KEPT = 'the profile was installed here already; setup installs nothing (agentage extension install)';
10
10
  // An exact version is sent as it is; a range installs the market's newest version.
11
11
  const bodyOf = (id, range) => EXACT.test(range) ? { id, version: range } : { id };
12
12
  // One entry through POST /host/extensions; an off entry is added disabled (it never starts).
@@ -1,17 +1,13 @@
1
1
  import { type Npm } from '../../core/installer/npm.js';
2
2
  import { type Account } from '../../core/profile/cloud.js';
3
3
  import { type MachineFile } from '../../core/profile/machine.js';
4
- import { type Apply } from '../../core/profile/push.js';
5
4
  import { type Profile } from '../../core/profile/schema.js';
6
5
  import { type AccountOf } from './account.js';
7
6
  export interface EditDeps {
8
7
  npm: () => Promise<Npm>;
9
- npmMajor: () => Promise<number>;
10
8
  account: AccountOf;
11
9
  }
12
10
  export interface ProfileDeps extends EditDeps {
13
11
  installProfile: (profile: Profile) => Promise<void>;
14
12
  }
15
- export type Change = (profile: Profile) => Profile;
16
13
  export declare const checkAccount: (account: Account, machine: MachineFile) => Promise<string | null>;
17
- export declare const applying: (change: Change, deps: ProfileDeps, note?: string | null) => Apply;
@@ -1,16 +1,8 @@
1
- import { join } from 'node:path';
2
- import { parseLock } from '../../core/installer/compare-lock.js';
3
1
  import {} from '../../core/installer/npm.js';
4
- import { LOCK_FILE, readText } from '../../core/installer/tree.js';
5
- import { extensionsDir } from '../../core/paths.js';
6
2
  import {} from '../../core/profile/cloud.js';
7
3
  import { accountMismatch } from '../../core/profile/machine.js';
8
- import { mutateProfile } from '../../core/profile/profile.js';
9
- import { pushBody } from '../../core/profile/push.js';
10
4
  import {} from '../../core/profile/schema.js';
11
5
  import {} from './account.js';
12
- import { line } from './line.js';
13
- const REPLAY = 'changed in your account meanwhile, replaying this change on it';
14
6
  // The signed-in account's id, refused when this machine is connected to another account.
15
7
  export const checkAccount = async (account, machine) => {
16
8
  const userId = await account.id();
@@ -19,21 +11,3 @@ export const checkAccount = async (account, machine) => {
19
11
  throw mismatch;
20
12
  return userId;
21
13
  };
22
- // extensions/package-lock.json and the npm major that wrote it, pushed with the profile.
23
- const localLock = async (deps) => {
24
- const lock = parseLock(readText(join(extensionsDir(), LOCK_FILE)));
25
- return { lock, npmMajor: lock === null ? null : await deps.npmMajor() };
26
- };
27
- // Nothing is pushed unless the install worked: installProfile throws otherwise.
28
- export const applying = (change, deps, note = null) => {
29
- let calls = 0;
30
- return async (base) => {
31
- const next = change(base.profile);
32
- await mutateProfile(() => next);
33
- const text = calls++ === 0 ? note : line('profile', REPLAY);
34
- if (text !== null)
35
- console.log(text);
36
- await deps.installProfile(next);
37
- return pushBody(next, base, await localLock(deps));
38
- };
39
- };
@@ -7,7 +7,6 @@ export type NpmManifest = (command: LookupCommand, spec: string, registries: Rec
7
7
  export declare const configFlags: (env: NodeJS.ProcessEnv) => string[];
8
8
  export declare const npmArgs: (command: NpmCommand, tree: string, env?: NodeJS.ProcessEnv, packages?: string[]) => string[];
9
9
  export declare const manifestArgs: (command: LookupCommand, spec: string, registries: Record<string, string>, prefix: string, env?: NodeJS.ProcessEnv) => string[];
10
- export declare const npmMajor: (env?: NodeJS.ProcessEnv) => Promise<number>;
11
10
  export declare const prepareNpm: (env?: NodeJS.ProcessEnv) => Promise<Npm>;
12
11
  export declare const prepareManifest: (env?: NodeJS.ProcessEnv) => Promise<NpmManifest>;
13
12
  export declare const lastLines: (output: string, count?: number) => string;
@@ -57,8 +57,6 @@ const checkedNpm = async (env) => {
57
57
  return { npmCli, version: await requireNpm10(run) };
58
58
  };
59
59
  const checkedNpmCli = async (env) => (await checkedNpm(env)).npmCli;
60
- // The npm major that writes the lock, pushed next to it.
61
- export const npmMajor = async (env = process.env) => Number.parseInt((await checkedNpm(env)).version, 10);
62
60
  export const prepareNpm = async (env = process.env) => {
63
61
  const npmCli = await checkedNpmCli(env);
64
62
  return (command, tree, packages = []) => runNpm(npmArgs(command, tree, env, packages), {
@@ -14,12 +14,6 @@ export interface Account {
14
14
  platform: () => Promise<string>;
15
15
  id: () => Promise<string | null>;
16
16
  }
17
- export interface ProfileWrite {
18
- version: number;
19
- profile: JsonObject;
20
- lock: JsonObject | null;
21
- npmMajor: number | null;
22
- }
23
17
  export interface CloudProfile {
24
18
  profile: Profile;
25
19
  readOnly: boolean;
@@ -40,16 +34,5 @@ export type Pull = {
40
34
  kind: 'unavailable';
41
35
  reason: string;
42
36
  };
43
- export type Push = {
44
- kind: 'stored';
45
- etag: string;
46
- } | {
47
- kind: 'conflict';
48
- current: CloudProfile | null;
49
- };
50
- export declare class NotPushedError extends Error {
51
- }
52
- export declare const localProfile: (profile: Profile) => CloudProfile;
53
37
  export declare const errorCode: (res: Response) => Promise<string | null>;
54
38
  export declare const pullProfile: (fetch: CloudFetch, etag: string | null, timeoutMs?: number) => Promise<Pull>;
55
- export declare const pushProfile: (fetch: CloudFetch, body: ProfileWrite, etag: string | null) => Promise<Push>;
@@ -2,17 +2,6 @@ import { isRecord } from '../../lib/fs/json-file.js';
2
2
  import { parseProfile } from './schema.js';
3
3
  // One resource per account: the profile, npm's lock and the npm major that wrote it, one ETag.
4
4
  export const PROFILE_PATH = '/v1/profile';
5
- // The account answered a push with something other than a new ETag or a 412.
6
- export class NotPushedError extends Error {
7
- }
8
- // A profile that is not in the account yet: pushing it creates it.
9
- export const localProfile = (profile) => ({
10
- profile,
11
- readOnly: profile.version > 1,
12
- lock: null,
13
- npmMajor: null,
14
- etag: null,
15
- });
16
5
  // What a request ended with: the Response, or why there was none.
17
6
  const attempt = async (request) => {
18
7
  try {
@@ -78,32 +67,3 @@ export const pullProfile = async (fetch, etag, timeoutMs) => {
78
67
  const doc = served(await bodyOf(res), res.headers.get('etag'));
79
68
  return typeof doc === 'string' ? unavailable(doc) : { kind: 'found', doc };
80
69
  };
81
- // A 412 carries the account's current resource and etag (both null when it holds none).
82
- const conflictOf = (body) => {
83
- const error = isRecord(body) && isRecord(body['error']) ? body['error'] : {};
84
- const details = isRecord(error['details']) ? error['details'] : {};
85
- if (details['current'] === null)
86
- return { kind: 'conflict', current: null };
87
- const current = resourceOf(details['current'], details['etag']);
88
- if (typeof current === 'string')
89
- throw new NotPushedError(`not pushed to your account (412: ${current})`);
90
- return { kind: 'conflict', current };
91
- };
92
- const notPushed = (reason) => new NotPushedError(`not pushed to your account (${reason})`);
93
- // PUT the whole resource: If-Match replaces the copy it was pulled at, no etag creates it.
94
- export const pushProfile = async (fetch, body, etag) => {
95
- const precondition = etag === null ? { 'if-none-match': '*' } : { 'if-match': etag };
96
- const headers = { 'content-type': 'application/json', ...precondition };
97
- const init = { method: 'PUT', headers, body: JSON.stringify(body) };
98
- const res = await attempt(() => fetch(PROFILE_PATH, init));
99
- if (typeof res === 'string')
100
- throw notPushed(res);
101
- if (res.status === 412)
102
- return conflictOf(await bodyOf(res));
103
- if (res.status !== 200 && res.status !== 201)
104
- throw notPushed(await failureOf(res));
105
- const stored = etagOf(await bodyOf(res), res.headers.get('etag'));
106
- if (typeof stored !== 'string')
107
- throw notPushed('unexpected answer');
108
- return { kind: 'stored', etag: stored };
109
- };
@@ -11,7 +11,6 @@ export declare const NO_MACHINE: MachineFile;
11
11
  export declare const readMachine: () => MachineFile | null;
12
12
  export declare const loadMachine: () => Promise<MachineFile>;
13
13
  export declare const setProfileSource: (source: ProfileSource) => Promise<MachineFile>;
14
- export declare const setCloud: (etag: string) => Promise<MachineFile>;
15
14
  export declare const setAccount: (accountId: string) => Promise<MachineFile>;
16
15
  export declare const forgetAccount: () => Promise<MachineFile>;
17
16
  export declare const accountMismatch: (machine: MachineFile, userId: string | null) => Error | null;
@@ -61,8 +61,6 @@ const update = async (change) => withFileLock(machinePath(), () => {
61
61
  return isDeepStrictEqual(next, machine) ? machine : save(next);
62
62
  });
63
63
  export const setProfileSource = async (source) => update((machine) => ({ ...machine, profileSource: source }));
64
- // After a pull or a push: profile.json mirrors the account's profile at `etag`.
65
- export const setCloud = async (etag) => update((machine) => ({ ...machine, profileSource: 'cloud', profileEtag: etag }));
66
64
  export const setAccount = async (accountId) => update((machine) => ({ ...machine, accountId }));
67
65
  // `setup --disconnect`: no account; a copy of the account's profile becomes this machine's own.
68
66
  export const forgetAccount = async () => update((machine) => ({
@@ -1,2 +1,2 @@
1
- export declare const CODES: readonly ["already_installed", "already_running", "auth_required", "auth_unavailable", "build_failed", "cancelled", "confirmation_required", "daemon_disabled", "daemon_unavailable", "daemon_unresponsive", "disk_full", "error", "extension_failed", "integrity_drift", "invalid_argument", "invalid_manifest", "market_auth", "market_failed", "market_timeout", "market_unreachable", "needed_by_dependents", "network_unavailable", "no_discovery", "no_manifest", "no_market", "not_conforming", "not_installed", "not_pushed", "permission_denied", "port_in_use", "profile_invalid", "release_refused", "secret_refused", "stop_failed", "timeout", "token_request_failed", "uncommitted_changes", "usage"];
1
+ export declare const CODES: readonly ["already_installed", "already_running", "auth_required", "auth_unavailable", "build_failed", "cancelled", "confirmation_required", "daemon_disabled", "daemon_unavailable", "daemon_unresponsive", "disk_full", "error", "extension_failed", "integrity_drift", "invalid_argument", "invalid_manifest", "market_auth", "market_failed", "market_timeout", "market_unreachable", "needed_by_dependents", "network_unavailable", "no_discovery", "no_manifest", "no_market", "not_conforming", "not_installed", "permission_denied", "port_in_use", "profile_invalid", "release_refused", "secret_refused", "stop_failed", "timeout", "token_request_failed", "uncommitted_changes", "usage"];
2
2
  export type Code = (typeof CODES)[number];
@@ -27,7 +27,6 @@ export const CODES = [
27
27
  'no_market',
28
28
  'not_conforming',
29
29
  'not_installed',
30
- 'not_pushed',
31
30
  'permission_denied',
32
31
  'port_in_use',
33
32
  'profile_invalid',
@@ -1,5 +1,4 @@
1
1
  import { CommanderError } from 'commander';
2
- import { NotPushedError } from '../core/profile/cloud.js';
3
2
  import { AuthRequiredError, TransientAuthError } from './auth/auth-errors.js';
4
3
  import { TokenRequestError } from './auth/oauth.js';
5
4
  import {} from './json-codes.js';
@@ -29,7 +28,6 @@ export class DaemonError extends Error {
29
28
  const KNOWN = [
30
29
  [AuthRequiredError, 'auth_required'],
31
30
  [TransientAuthError, 'auth_unavailable'],
32
- [NotPushedError, 'not_pushed'],
33
31
  [TokenRequestError, 'token_request_failed'],
34
32
  ];
35
33
  // What the system says of an expected failure: a folder or file we may not use, a full disk.
@@ -23,7 +23,7 @@ import { runExtensionSetup } from './commands/extension/setup.js';
23
23
  import { runExtensionDown, runExtensionToken, runExtensionUp } from './commands/extension/up.js';
24
24
  import { runStatus, statusDeps } from './commands/status/status.js';
25
25
  import { runUpdate } from './commands/update/update.js';
26
- import { npmMajor, prepareManifest, prepareNpm } from './core/installer/npm.js';
26
+ import { prepareManifest, prepareNpm } from './core/installer/npm.js';
27
27
  import { ensureSignedIn, signOut } from './lib/auth/sign-in.js';
28
28
  import { ensureDaemon } from './lib/daemon/daemon-client.js';
29
29
  import { sealOffLine } from './lib/daemon/daemon-health.js';
@@ -42,8 +42,8 @@ const setupDeps = {
42
42
  printStatus: (opts) => runStatus(opts, statusDeps(false)),
43
43
  startDaemon: () => ensureDaemon(),
44
44
  };
45
- // What a profile edit reaches: npm, and the account it syncs with when signed in.
46
- const editDeps = { npm: () => prepareNpm(), npmMajor: () => npmMajor(), account: signedInAccount };
45
+ // What setup reaches: npm, and the account when signed in.
46
+ const editDeps = { npm: () => prepareNpm(), account: signedInAccount };
47
47
  const installer = () => cliInstaller({
48
48
  npm: () => prepareNpm(),
49
49
  manifest: () => prepareManifest(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/cli",
3
- "version": "0.81.0",
3
+ "version": "0.81.2",
4
4
  "description": "The agentage CLI - connect this machine to agentage from the terminal",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@agentage/apphost": "0.8.5",
58
- "@agentage/extension": "0.25.8",
58
+ "@agentage/extension": "0.25.9",
59
59
  "@electric-sql/pglite": "^0.6.0",
60
60
  "@tailwindcss/postcss": "^4.3.5",
61
61
  "chalk": "^6.0.0",
@@ -1,16 +0,0 @@
1
- import { type CloudFetch, type CloudProfile, type JsonObject, type ProfileWrite } from './cloud.js';
2
- import { type Profile } from './schema.js';
3
- export type Apply = (base: CloudProfile) => Promise<ProfileWrite>;
4
- export interface Pushed {
5
- etag: string;
6
- pushed: boolean;
7
- }
8
- export interface LockPair {
9
- lock: JsonObject | null;
10
- npmMajor: number | null;
11
- }
12
- export interface ReplayOptions {
13
- lockCounts?: boolean;
14
- }
15
- export declare const pushBody: (next: Profile, base: CloudProfile, local: LockPair) => ProfileWrite;
16
- export declare const pushWithReplay: (fetch: CloudFetch, base: CloudProfile, apply: Apply, { lockCounts }?: ReplayOptions) => Promise<Pushed>;
@@ -1,49 +0,0 @@
1
- import { isDeepStrictEqual } from 'node:util';
2
- import { pushProfile, } from './cloud.js';
3
- import { toDocument } from './schema.js';
4
- // A lock from another npm major than the account's is not pushed: the account keeps its own.
5
- export const pushBody = (next, base, local) => {
6
- const other = base.npmMajor !== null && local.npmMajor !== null;
7
- const keep = other && base.npmMajor !== local.npmMajor;
8
- const pair = keep ? { lock: base.lock, npmMajor: base.npmMajor } : local;
9
- return { version: next.version, profile: toDocument(next), ...pair };
10
- };
11
- const refuseNewer = (base) => {
12
- if (!base.readOnly)
13
- return;
14
- const newer = `version ${base.profile.version}, newer than this CLI understands`;
15
- throw new Error(`the profile in your account is ${newer}; it was not changed`);
16
- };
17
- // The account holds this already: the same profile and, when the lock counts, the same lock.
18
- const held = (body, base, lockCounts) => base.etag !== null &&
19
- isDeepStrictEqual(body.profile, toDocument(base.profile)) &&
20
- (!lockCounts || isDeepStrictEqual(body.lock, base.lock));
21
- const attemptOn = async (fetch, base, apply, lockCounts) => {
22
- refuseNewer(base);
23
- const body = await apply(base);
24
- if (held(body, base, lockCounts))
25
- return { kind: 'done', etag: base.etag, pushed: false };
26
- const res = await pushProfile(fetch, body, base.etag);
27
- if (res.kind === 'stored')
28
- return { kind: 'done', etag: res.etag, pushed: true };
29
- return { kind: 'conflict', body, current: res.current };
30
- };
31
- const shown = (doc) => JSON.stringify(doc, null, 2);
32
- const conflictError = (body, current) => {
33
- const theirs = current
34
- ? `in your account (etag ${current.etag}):\n${shown(toDocument(current.profile))}`
35
- : 'in your account: none';
36
- return new Error('not pushed: the profile in your account changed again while this change was pushed\n' +
37
- `yours:\n${shown(body.profile)}\n${theirs}`);
38
- };
39
- // On a 412 the change is replayed once on the account's document; a second 412 shows both.
40
- export const pushWithReplay = async (fetch, base, apply, { lockCounts = false } = {}) => {
41
- const first = await attemptOn(fetch, base, apply, lockCounts);
42
- if (first.kind === 'done')
43
- return { etag: first.etag, pushed: first.pushed };
44
- const retry = first.current ?? { ...base, etag: null };
45
- const second = await attemptOn(fetch, retry, apply, lockCounts);
46
- if (second.kind === 'done')
47
- return { etag: second.etag, pushed: second.pushed };
48
- throw conflictError(second.body, second.current);
49
- };