@sabaiway/agent-workflow-kit 23.0.0 → 23.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +1 -1
  4. package/bridges/antigravity-cli-bridge/SKILL.md +11 -10
  5. package/bridges/antigravity-cli-bridge/bin/agy-jev.test.mjs +56 -7
  6. package/bridges/antigravity-cli-bridge/bin/agy-review.sh +80 -62
  7. package/bridges/antigravity-cli-bridge/bin/agy-review.test.mjs +0 -21
  8. package/bridges/antigravity-cli-bridge/bin/agy.sh +86 -12
  9. package/bridges/antigravity-cli-bridge/capability.json +2 -2
  10. package/bridges/antigravity-cli-bridge/references/models-and-flags.md +3 -3
  11. package/bridges/antigravity-cli-bridge/setup/README.md +1 -1
  12. package/bridges/codex-cli-bridge/SKILL.md +23 -24
  13. package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +82 -47
  14. package/bridges/codex-cli-bridge/bin/codex-exec.sh +133 -52
  15. package/bridges/codex-cli-bridge/bin/codex-review-jev.test.mjs +44 -14
  16. package/bridges/codex-cli-bridge/bin/codex-review.sh +103 -30
  17. package/bridges/codex-cli-bridge/capability.json +6 -6
  18. package/bridges/codex-cli-bridge/references/driving-codex.md +6 -7
  19. package/bridges/codex-cli-bridge/references/sandbox-and-flags.md +8 -11
  20. package/bridges/codex-cli-bridge/setup/README.md +3 -3
  21. package/capability.json +1 -1
  22. package/package.json +1 -1
  23. package/references/modes/recommendations.md +2 -2
  24. package/references/modes/setup.md +2 -0
  25. package/references/modes/upgrade.md +3 -3
  26. package/references/modes/velocity.md +1 -1
  27. package/tools/apply-danger-check.mjs +1 -1
  28. package/tools/bridge-sandbox-recipe.mjs +7 -3
  29. package/tools/bridge-settings-read.mjs +2 -0
  30. package/tools/detect-backends.mjs +22 -14
  31. package/tools/fs-safe.mjs +2 -2
  32. package/tools/manifest/schema.md +2 -2
  33. package/tools/refresh-parity.mjs +3 -3
  34. package/tools/services/antigravity.json +3 -0
  35. package/tools/services/codex.json +5 -0
  36. package/tools/services/index.mjs +49 -5
  37. package/tools/services/jev.json +1 -0
  38. package/tools/setup-backends.mjs +37 -48
  39. package/tools/velocity-profile.mjs +1 -1
@@ -5,7 +5,8 @@ import { fileURLToPath } from 'node:url';
5
5
  export const SERVICE_FACTS_FILE = 'service-facts.txt';
6
6
  const SERVICES_DIRECTORY = fileURLToPath(new URL('.', import.meta.url));
7
7
  const FRAGMENT_EXTENSION = '.json';
8
- const FRAGMENT_KEYS = ['hosts', 'writableDirs', 'excludedCommands', 'passedVariables', 'runReachesHosts'];
8
+ const FRAGMENT_KEYS = ['hosts', 'writableDirs', 'excludedCommands', 'passedVariables', 'billingVariables', 'runReachesHosts'];
9
+ const SERVICE_ID_RE = /^[a-z][a-z0-9-]*$/;
9
10
  const NETWORK_HOST_RE = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/i;
10
11
  const VARIABLE_RE = /^[A-Z][A-Z0-9_]*$/;
11
12
  const EXCLUDED_COMMAND_RE = /^[A-Za-z0-9][A-Za-z0-9._-]* \*$/;
@@ -57,8 +58,13 @@ const validateFragment = (fragment, path) => {
57
58
  validateList(fragment.writableDirs, path, 'writableDirs', isDirectoryEntry, (entry) => entry.default);
58
59
  validateList(fragment.excludedCommands, path, 'excludedCommands',
59
60
  (command) => typeof command === 'string' && EXCLUDED_COMMAND_RE.test(command));
60
- validateList(fragment.passedVariables, path, 'passedVariables', isVariable);
61
+ validateList(fragment.passedVariables, path, 'passedVariables',
62
+ (value) => isVariable(value) && value !== 'OPENAI_BASE_URL');
63
+ validateList(fragment.billingVariables, path, 'billingVariables', isVariable);
61
64
  if (typeof fragment.runReachesHosts !== 'boolean') refuseSchema(path, 'runReachesHosts', 'must be a boolean');
65
+ if (fragment.runReachesHosts && fragment.hosts.some((host) => host.startsWith('*.'))) {
66
+ refuseSchema(path, 'hosts', 'must not contain a wildcard when runReachesHosts is true');
67
+ }
62
68
  return fragment;
63
69
  };
64
70
 
@@ -73,6 +79,18 @@ const readFragment = (path, readFile) => {
73
79
  return validateFragment(fragment, path);
74
80
  };
75
81
 
82
+ const validateBillingVariables = (fragments, locate) => {
83
+ const billing = new Map(Object.entries(fragments).flatMap(([id, fragment]) =>
84
+ fragment.billingVariables.map((variable) => [variable, id])));
85
+ for (const [id, fragment] of Object.entries(fragments)) {
86
+ for (const variable of fragment.passedVariables) {
87
+ if (!billing.has(variable)) continue;
88
+ const [path, key] = locate(id, billing.get(variable));
89
+ refuseSchema(path, key, `conflicts with billing variable ${variable}`);
90
+ }
91
+ }
92
+ };
93
+
76
94
  export const loadServiceFragments = (deps = {}) => {
77
95
  const servicesDir = deps.servicesDir ?? SERVICES_DIRECTORY;
78
96
  const readdir = deps.readdir ?? readdirSync;
@@ -84,9 +102,32 @@ export const loadServiceFragments = (deps = {}) => {
84
102
  throw new Error(`${servicesDir}: cannot read services directory: ${error.message}`, { cause: error });
85
103
  }
86
104
  })();
87
- return Object.fromEntries(entries.filter((name) => name.endsWith(FRAGMENT_EXTENSION)).sort().map((name) => [
105
+ const fragments = Object.fromEntries(entries.filter((name) => name.endsWith(FRAGMENT_EXTENSION)).sort().map((name) => [
88
106
  name.slice(0, -FRAGMENT_EXTENSION.length), readFragment(join(servicesDir, name), readFile),
89
107
  ]));
108
+ validateBillingVariables(fragments, (id) => [join(servicesDir, `${id}${FRAGMENT_EXTENSION}`), 'passedVariables']);
109
+ return fragments;
110
+ };
111
+
112
+ export const loadUserServices = (fragments, { file, readFile = readFileSync }) => {
113
+ const userFragments = (() => {
114
+ try {
115
+ return JSON.parse(readFile(file, 'utf8'));
116
+ } catch (error) {
117
+ if (error.code === 'ENOENT') return {};
118
+ throw new Error(`${file}: cannot read or parse user services: ${error.message}`, { cause: error });
119
+ }
120
+ })();
121
+ if (!isObject(userFragments)) refuseSchema(file, 'root', 'must be an object');
122
+ for (const [id, fragment] of Object.entries(userFragments)) {
123
+ if (!SERVICE_ID_RE.test(id) || Object.hasOwn(fragments, id)) refuseSchema(file, id, 'is not an available service id');
124
+ validateFragment(fragment, `${file}: ${id}`);
125
+ }
126
+ validateBillingVariables({ ...fragments, ...userFragments }, (passing, billed) =>
127
+ Object.hasOwn(userFragments, passing)
128
+ ? [`${file}: ${passing}`, 'passedVariables']
129
+ : [`${file}: ${billed}`, 'billingVariables']);
130
+ return userFragments;
90
131
  };
91
132
 
92
133
  const takeUnique = (entries, identify = (entry) => entry) => {
@@ -99,11 +140,11 @@ const takeUnique = (entries, identify = (entry) => entry) => {
99
140
  });
100
141
  };
101
142
 
102
- export const mergeServices = (ids, fragments) => {
143
+ export const mergeServices = (ids, fragments, userFragments = {}) => {
103
144
  const selected = ids.map((id) => {
104
145
  if (!Object.hasOwn(fragments, id)) throw new Error(`Unknown service id: ${id}`);
105
146
  return fragments[id];
106
- });
147
+ }).concat(Object.values(userFragments));
107
148
  return {
108
149
  hosts: takeUnique(selected.flatMap((fragment) => fragment.hosts)),
109
150
  dirEntries: takeUnique(selected.flatMap((fragment) => fragment.writableDirs),
@@ -121,3 +162,6 @@ export const renderServiceFacts = (merged) => [
121
162
  `${key}=${field === 'dirEntries' ? `${entry.env ?? ''}:${entry.default}` : entry}`)),
122
163
  '',
123
164
  ].join('\n');
165
+
166
+ export const placedServiceFacts = (services, fragments, userFragments) =>
167
+ renderServiceFacts(mergeServices(services, fragments, userFragments));
@@ -8,5 +8,6 @@
8
8
  "passedVariables": [
9
9
  "TYPESAFE_API_KEY"
10
10
  ],
11
+ "billingVariables": [],
11
12
  "runReachesHosts": true
12
13
  }
@@ -1,38 +1,17 @@
1
1
  #!/usr/bin/env node
2
- // setup-backends.mjs — link-only auto-setup for the execution-backend bridges (Plan B / AD-011).
3
- // The kit owns ONLY the two deterministic, secret-free steps: (1) PLACE/REFRESH the bundled bridge
4
- // skill into its canonical dir, and (2) LINK its POSIX wrappers onto PATH (~/.local/bin) via managed
5
- // symlinks. Binary install + the interactive subscription login stay GUIDED (printed, never run) —
6
- // guideFor() supplies the exact commands. The read-only detector is the reader; this is the writer.
7
- //
8
- // Two write modes: plain setup (opt-in, in-agent — the ONLY path that ever PLACES a bridge) and the
9
- // refresh-only driver (`--refresh-placed` / refreshPlacedBridges, run by `init` and Mode: upgrade) —
10
- // it refreshes what setup already placed and re-links wrappers, states an absent bridge as a skip
11
- // (never a first placement), and never downgrades: a placed bridge newer than the kit-bundled mirror
12
- // is a stated skip naming the kit update (guarded again at the write boundary in placeSkill).
13
- //
14
- // Safety posture (AD-011): drive off the decoupled axes (a per-bindir wrapper check + an independent
15
- // skill-dir inspection), never the detector's collapsed readiness. REFRESH only a dir we provably own
16
- // (valid manifest, name+kind match) or one that is absent/empty; STOP on anything else (a marker fs
17
- // error, a stub/foreign/invalid/unsupported manifest, a non-empty unknown dir, or a symlinked dir).
18
- // Clobber-risk lives only on the wrapper symlinks — replace only a symlink already pointing at our
19
- // source; STOP on a foreign symlink or a non-symlink. PREFLIGHT every dst, THEN mutate (a conflict on
20
- // the 2nd wrapper ⇒ zero mutations; no rollback — symlinks/chmod converge on re-run). Windows: the
21
- // wrappers are POSIX .sh — report unsupported / use WSL and mutate nothing. Every fs primitive is
22
- // injectable (deps.*) so the whole module is unit-testable without touching the real filesystem.
23
- //
24
- // Dependency-free, Node >= 22.
25
2
 
26
3
  import {
27
4
  existsSync, lstatSync, statSync, readdirSync, readlinkSync, symlinkSync, mkdirSync, copyFileSync,
28
- chmodSync, readFileSync, realpathSync,
5
+ chmodSync, readFileSync, realpathSync, writeFileSync,
29
6
  } from 'node:fs';
30
7
  import { join, resolve, relative, dirname, isAbsolute } from 'node:path';
31
8
  import { fileURLToPath } from 'node:url';
32
9
  import os from 'node:os';
33
10
  import { KNOWN_BACKENDS, detectBackend, detectBackends, resolveDir, guideFor, READY } from './detect-backends.mjs';
34
11
  import { isDirectRun } from './direct-run.mjs';
35
- import { copyTreeRefresh, linkManaged, isReadonlyWriteBoundary } from './fs-safe.mjs';
12
+ import { assertContainedRealPath, copyTreeRefresh, linkManaged, isReadonlyWriteBoundary, throwTaggedReadonly } from './fs-safe.mjs';
13
+ import { userServicesFile } from './bridge-settings-read.mjs';
14
+ import { loadServiceFragments, loadUserServices, placedServiceFacts, SERVICE_FACTS_FILE } from './services/index.mjs';
36
15
  import {
37
16
  READONLY_RERUN_HINT, WRAPPER_MODE, scanBundleOwnedDrift, scanWrapperParity, parityVerdict,
38
17
  unverifiableParity, readonlySkipLine,
@@ -79,6 +58,7 @@ const fsDeps = (deps = {}) => ({
79
58
  chmod: deps.chmod ?? chmodSync,
80
59
  readFile: deps.readFile ?? readFileSync,
81
60
  realpath: deps.realpath ?? realpathSync,
61
+ writeFile: deps.writeFile ?? writeFileSync,
82
62
  });
83
63
 
84
64
  // lstat without following symlinks; null when absent. A non-ENOENT error propagates (never fail open).
@@ -302,14 +282,33 @@ const assertNoDowngrade = (plan, deps = {}) => {
302
282
  if (compareSemver(placed, bundled) === 1) throw stop(downgradeReason(placed, bundled), { skillDir: plan.skillDir, wouldDowngrade: true });
303
283
  };
304
284
 
305
- // Copy the bundle over the placed skill dir (the refresh overwrite), FIRST scanning bundle-owned files
306
- // for local drift so the caller can STATE what the overwrite replaced (D5 — overwrite honesty). Scan
307
- // only on a refresh: a `place` writes into an absent/empty dir, so there is nothing local to lose. The
308
- // copy proceeds either way — bridge code is kit-owned. Returns the drift report (null for a place).
285
+ const userServicesRemedy = (step) => `fix or remove that file, then run /agent-workflow-kit ${step} again`;
286
+ const loadBridgeServices = (deps) => {
287
+ const fragments = loadServiceFragments();
288
+ try {
289
+ const userFragments = loadUserServices(fragments, {
290
+ file: userServicesFile({ env: deps.getenv ?? process.env, home: deps.home ?? os.homedir() }),
291
+ });
292
+ return { fragments, userFragments };
293
+ } catch (error) {
294
+ throw stop(`${error.message}; ${userServicesRemedy('setup')}`, { userServicesMessage: error.message });
295
+ }
296
+ };
297
+
309
298
  const copyBridgeWithHonesty = (action, bundleDir, skillDir, deps) => {
299
+ const { fragments, userFragments } = loadBridgeServices(deps);
300
+ const facts = Object.keys(userFragments).length
301
+ ? placedServiceFacts(readBundledManifest(bundleDir, deps).services ?? [], fragments, userFragments) : null;
310
302
  const fs = fsDeps(deps);
311
- const drift = action === 'refresh' ? scanBundleOwnedDrift(bundleDir, skillDir, fs) : null;
303
+ const drift = action === 'refresh' ? scanBundleOwnedDrift(bundleDir, skillDir, {
304
+ ...fs, readdir: (path) => fs.readdir(path).filter((name) => path !== bundleDir || name !== SERVICE_FACTS_FILE),
305
+ }) : null;
312
306
  copyTreeRefresh(bundleDir, skillDir, skillDir, fs);
307
+ if (facts !== null) {
308
+ const file = join(skillDir, SERVICE_FACTS_FILE);
309
+ assertContainedRealPath(skillDir, file, fs);
310
+ try { fs.writeFile(file, facts, 'utf8'); } catch (error) { throwTaggedReadonly(error, 'writeFile', file, fs.readFile); }
311
+ }
313
312
  return drift;
314
313
  };
315
314
 
@@ -557,12 +556,6 @@ const refreshSkillOnly = (entry, deps = {}) => {
557
556
  const NOT_PLACED_LINE = 'skipped — not placed (placement is opt-in: /agent-workflow-kit setup)';
558
557
  const stripPrefix = (message) => message.replace('[agent-workflow-kit] ', '');
559
558
 
560
- // The read-only degrade wording (D1, honesty-split per D4). The STATED-skip line is composed in
561
- // refresh-parity.mjs from a POST-FAILURE re-scan: the old line asserted "PARTIALLY updated" and "any
562
- // remaining drift persists" unconditionally — two claims about post-state that nothing had checked.
563
- // It still never claims a re-sync RAN (that is already-current's line). The FAILED line (a
564
- // version-behind upgrade blocked by the same read-only dir) stays loud, but its recovery points at a
565
- // writable rerun — the in-session `setup` would hit the same read-only dir.
566
559
  const readonlyRefreshFailedLine = (name, message) =>
567
560
  ` ${name}: could not refresh — ${stripPrefix(message)}; the skills directory is read-only this session — ${READONLY_RERUN_HINT}`;
568
561
 
@@ -573,7 +566,7 @@ export const REFRESH_LINES = Object.freeze({
573
566
  unsupported: (name, reason) => ` ${name}: skipped — ${reason}`,
574
567
  'kept-newer': (name, reason) => ` ${name}: skipped — ${reason}`,
575
568
  'not-placed': (name) => ` ${name}: ${NOT_PLACED_LINE}`,
576
- failed: (name, reason) => ` ${name}: could not refresh — ${reason}; recover with /agent-workflow-kit setup`,
569
+ failed: (name, reason, remedy = 'recover with /agent-workflow-kit setup') => ` ${name}: could not refresh — ${reason}; ${remedy}`,
577
570
  'failed-readonly': readonlyRefreshFailedLine,
578
571
  [SKIPPED_READONLY]: readonlySkipLine,
579
572
  'already-current': (name, label, summary) => {
@@ -583,19 +576,14 @@ export const REFRESH_LINES = Object.freeze({
583
576
  refreshed: (name, label) => ` ${name}: refreshed${label}`,
584
577
  });
585
578
 
586
- // The post-failure parity verdict behind that line (D3): a read-only re-scan of the bundle-owned
587
- // files AND the wrapper links, run AFTER the write refusal, so every clause binds to state proven
588
- // THIS run. The degrade returns before linkWrappers, so the wrapper axis is genuinely unreconciled —
589
- // a calm claim that skipped it would be unproven. Any failure raised out of the walk itself (the
590
- // bundle read is deliberately uncaught in there) collapses to could-not-verify: the calm claim is
591
- // withheld, never inverted into a false clean, and a re-scan problem never turns the stated skip
592
- // into a reported failure.
593
579
  const readonlyParity = (plan, deps) => {
594
580
  const fs = fsDeps(deps);
595
581
  try {
596
- // ONE walk feeds both halves: the wrapper axis judges a source's mode from what the walk already
597
- // reached, never from a second stat that could traverse an ancestor the walk refused.
598
- const scan = scanBundleOwnedDrift(plan.place.bundleDir, plan.skillDir, fs);
582
+ const { fragments, userFragments } = loadBridgeServices(deps);
583
+ const manifest = readBundledManifest(plan.place.bundleDir, deps);
584
+ const scan = scanBundleOwnedDrift(plan.place.bundleDir, plan.skillDir, fs, {
585
+ [SERVICE_FACTS_FILE]: placedServiceFacts(manifest.services ?? [], fragments, userFragments),
586
+ });
599
587
  return parityVerdict({
600
588
  scan,
601
589
  wrappers: scanWrapperParity(plan.links, fs, { skillDir: plan.skillDir, modes: scan.modes }),
@@ -672,7 +660,8 @@ export const refreshPlacedBridges = (deps = {}, names = KNOWN_BACKENDS.map((b) =
672
660
  if (isReadonlyWriteBoundary(err)) {
673
661
  return { name: canonical, outcome: 'failed', line: REFRESH_LINES['failed-readonly'](canonical, err.message) };
674
662
  }
675
- return { name: canonical, outcome: 'failed', line: REFRESH_LINES.failed(canonical, stripPrefix(err.message)) };
663
+ return { name: canonical, outcome: 'failed', line: REFRESH_LINES.failed(canonical,
664
+ err.userServicesMessage ?? stripPrefix(err.message), err.userServicesMessage ? userServicesRemedy('upgrade') : undefined) };
676
665
  }
677
666
  });
678
667
 
@@ -936,7 +936,7 @@ export const preflightVelocityProfile = ({ cwd }, deps = {}) => {
936
936
  const derivedBridge = (() => {
937
937
  try {
938
938
  const probe = deps.findWrapper ?? ((cmd) => findOnPath(cmd).state === WRAPPER_PLACED);
939
- return bundledSandboxRecipe(BRIDGE_REVIEW_WRAPPERS.filter(probe), deps).allow;
939
+ return bundledSandboxRecipe(BRIDGE_REVIEW_WRAPPERS.filter(probe), { ...deps, userServices: false }).allow;
940
940
  } catch {
941
941
  return [];
942
942
  }