@socketsecurity/lib 6.0.7 → 6.0.8
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.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/dist/ai/agent-context.d.mts +103 -0
- package/dist/ai/agent-context.js +157 -0
- package/dist/ai/backends.d.mts +83 -0
- package/dist/ai/backends.js +173 -0
- package/dist/ai/credentials.d.mts +49 -0
- package/dist/ai/credentials.js +82 -0
- package/dist/ai/discover.d.mts +4 -0
- package/dist/ai/discover.js +1 -1
- package/dist/ai/exec.d.mts +52 -0
- package/dist/ai/exec.js +92 -0
- package/dist/ai/http.d.mts +132 -0
- package/dist/ai/http.js +130 -0
- package/dist/ai/profiles.d.mts +41 -6
- package/dist/ai/profiles.js +52 -10
- package/dist/ai/route.d.mts +69 -0
- package/dist/ai/route.js +156 -0
- package/dist/ai/spawn.d.mts +10 -2
- package/dist/ai/spawn.js +55 -31
- package/dist/ai/subagent-status.d.mts +48 -0
- package/dist/ai/subagent-status.js +57 -0
- package/dist/ai/tier.d.mts +60 -0
- package/dist/ai/tier.js +53 -0
- package/dist/ai/types.d.mts +15 -2
- package/dist/ai/worktree.js +4 -0
- package/dist/archives/tar.js +1 -1
- package/dist/archives/zip.js +2 -2
- package/dist/argv/parse.d.ts +19 -2
- package/dist/argv/parse.js +1 -1
- package/dist/arrays/join.js +4 -0
- package/dist/bin/find.js +4 -4
- package/dist/bin/prim.cjs +3915 -3781
- package/dist/bin/resolve.js +1 -1
- package/dist/cache/ttl/store.js +1 -1
- package/dist/cli/check-primordials.d.ts +8 -3
- package/dist/cli/check-primordials.js +4 -4
- package/dist/compression/_internal.js +1 -1
- package/dist/compression/brotli.d.ts +1 -2
- package/dist/compression/brotli.js +6 -2
- package/dist/compression/gzip.js +6 -2
- package/dist/constants/packages.d.ts +3 -0
- package/dist/constants/packages.js +2 -1
- package/dist/constants/socket.d.ts +2 -6
- package/dist/constants/socket.js +12 -14
- package/dist/cover/code.js +2 -2
- package/dist/crypto/hash.d.ts +4 -1
- package/dist/crypto/hash.js +4 -1
- package/dist/debug/caller-info.js +1 -1
- package/dist/dlx/arborist.js +13 -3
- package/dist/dlx/binary-cache.js +1 -1
- package/dist/dlx/binary-resolution.js +1 -1
- package/dist/dlx/detect.d.ts +8 -0
- package/dist/dlx/firewall.d.ts +8 -0
- package/dist/dlx/firewall.js +1 -1
- package/dist/dlx/lockfile.js +4 -1
- package/dist/dlx/manifest.js +1 -1
- package/dist/dlx/package.js +4 -0
- package/dist/eco/cargo/parse-lockfile.d.ts +1 -2
- package/dist/eco/cargo/parse-lockfile.js +3 -3
- package/dist/eco/manifest/detect-format.js +1 -1
- package/dist/eco/npm/npm/parse-lockfile.d.ts +3 -4
- package/dist/eco/npm/npm/parse-lockfile.js +2 -2
- package/dist/eco/npm/parse-package-json.d.ts +11 -0
- package/dist/eco/npm/parse-package-json.js +1 -1
- package/dist/eco/npm/pnpm/parse-lockfile.d.ts +5 -3
- package/dist/eco/npm/pnpm/parse-lockfile.js +3 -3
- package/dist/eco/npm/yarnpkg/yarn/exec.js +1 -1
- package/dist/eco/npm/yarnpkg/yarn/parse-lockfile.d.ts +1 -2
- package/dist/eco/npm/yarnpkg/yarn/parse-lockfile.js +1 -1
- package/dist/env/proxy.js +1 -1
- package/dist/env/rewire.d.ts +1 -0
- package/dist/env/rewire.js +1 -1
- package/dist/env/socket.d.ts +7 -0
- package/dist/env/socket.js +10 -0
- package/dist/errors/predicates.js +1 -1
- package/dist/external/@npmcli/promise-spawn.js +3 -1
- package/dist/external/pico-pack.js +4 -2
- package/dist/external/which.js +3 -1
- package/dist/external-tools/bazel/asset-names.d.ts +1 -1
- package/dist/external-tools/bazel/asset-names.js +5 -2
- package/dist/external-tools/bazel/from-download.d.ts +1 -1
- package/dist/external-tools/bazel/from-download.js +5 -2
- package/dist/external-tools/bazel/resolve-bazel-version.js +4 -0
- package/dist/external-tools/bazel/resolve.d.ts +3 -3
- package/dist/external-tools/bazel/resolve.js +16 -8
- package/dist/external-tools/cdxgen/asset-names.d.ts +1 -1
- package/dist/external-tools/cdxgen/asset-names.js +5 -2
- package/dist/external-tools/cdxgen/from-download.d.ts +1 -1
- package/dist/external-tools/cdxgen/from-download.js +7 -4
- package/dist/external-tools/cdxgen/resolve.d.ts +3 -3
- package/dist/external-tools/cdxgen/resolve.js +16 -8
- package/dist/external-tools/from-download.d.ts +2 -2
- package/dist/external-tools/from-download.js +11 -5
- package/dist/external-tools/from-pip-venv.d.ts +1 -1
- package/dist/external-tools/from-pip-venv.js +12 -5
- package/dist/external-tools/janus/asset-names.d.ts +1 -1
- package/dist/external-tools/janus/asset-names.js +5 -2
- package/dist/external-tools/janus/from-download.d.ts +1 -1
- package/dist/external-tools/janus/from-download.js +5 -2
- package/dist/external-tools/janus/resolve.d.ts +3 -3
- package/dist/external-tools/janus/resolve.js +16 -8
- package/dist/external-tools/jre/asset-names.d.ts +1 -1
- package/dist/external-tools/jre/asset-names.js +5 -2
- package/dist/external-tools/jre/from-download.d.ts +1 -1
- package/dist/external-tools/jre/from-download.js +7 -4
- package/dist/external-tools/jre/from-java-home.js +2 -2
- package/dist/external-tools/jre/from-vfs.js +2 -2
- package/dist/external-tools/jre/resolve.d.ts +3 -3
- package/dist/external-tools/jre/resolve.js +16 -8
- package/dist/external-tools/manifest.d.ts +18 -0
- package/dist/external-tools/manifest.js +1 -1
- package/dist/external-tools/opengrep/asset-names.d.ts +1 -1
- package/dist/external-tools/opengrep/asset-names.js +5 -2
- package/dist/external-tools/opengrep/from-download.d.ts +1 -1
- package/dist/external-tools/opengrep/from-download.js +5 -2
- package/dist/external-tools/opengrep/resolve.d.ts +3 -3
- package/dist/external-tools/opengrep/resolve.js +16 -8
- package/dist/external-tools/python/asset-names.d.ts +1 -1
- package/dist/external-tools/python/asset-names.js +10 -3
- package/dist/external-tools/python/dlx.d.ts +3 -3
- package/dist/external-tools/python/dlx.js +20 -9
- package/dist/external-tools/python/from-download.d.ts +1 -1
- package/dist/external-tools/python/from-download.js +12 -5
- package/dist/external-tools/python/pin.js +6 -3
- package/dist/external-tools/python/pip-install.js +6 -3
- package/dist/external-tools/python/resolve.d.ts +3 -3
- package/dist/external-tools/python/resolve.js +19 -11
- package/dist/external-tools/sbt/asset-names.d.ts +1 -1
- package/dist/external-tools/sbt/asset-names.js +5 -2
- package/dist/external-tools/sbt/from-download.d.ts +1 -1
- package/dist/external-tools/sbt/from-download.js +5 -2
- package/dist/external-tools/sbt/resolve.d.ts +3 -3
- package/dist/external-tools/sbt/resolve.js +16 -8
- package/dist/external-tools/skillspector/from-dlx.d.ts +1 -1
- package/dist/external-tools/skillspector/from-dlx.js +10 -3
- package/dist/external-tools/skillspector/resolve.d.ts +2 -2
- package/dist/external-tools/skillspector/resolve.js +14 -6
- package/dist/external-tools/synp/asset-names.d.ts +1 -1
- package/dist/external-tools/synp/asset-names.js +6 -2
- package/dist/external-tools/synp/from-download.d.ts +1 -1
- package/dist/external-tools/synp/from-download.js +5 -2
- package/dist/external-tools/synp/resolve.d.ts +3 -3
- package/dist/external-tools/synp/resolve.js +16 -8
- package/dist/external-tools/trivy/asset-names.d.ts +1 -1
- package/dist/external-tools/trivy/asset-names.js +5 -2
- package/dist/external-tools/trivy/from-download.d.ts +1 -1
- package/dist/external-tools/trivy/from-download.js +7 -4
- package/dist/external-tools/trivy/resolve.d.ts +3 -3
- package/dist/external-tools/trivy/resolve.js +16 -8
- package/dist/external-tools/trufflehog/asset-names.d.ts +1 -1
- package/dist/external-tools/trufflehog/asset-names.js +5 -2
- package/dist/external-tools/trufflehog/from-download.d.ts +1 -1
- package/dist/external-tools/trufflehog/from-download.js +7 -4
- package/dist/external-tools/trufflehog/resolve.d.ts +3 -3
- package/dist/external-tools/trufflehog/resolve.js +16 -8
- package/dist/fs/allowed-dirs-cache.d.ts +27 -1
- package/dist/fs/allowed-dirs-cache.js +38 -3
- package/dist/fs/find.js +1 -1
- package/dist/fs/read-json-cache.d.ts +7 -0
- package/dist/fs/resolve-module.js +6 -2
- package/dist/fs/safe.js +1 -1
- package/dist/git/_internal.js +2 -2
- package/dist/git/repo.js +2 -4
- package/dist/git/staged.js +8 -0
- package/dist/git/tracked.d.ts +84 -0
- package/dist/git/tracked.js +163 -0
- package/dist/git/unstaged.js +8 -0
- package/dist/github/refs-graphql.js +4 -0
- package/dist/github/refs-rest.js +4 -0
- package/dist/github/refs.js +15 -10
- package/dist/globs/_internal.js +1 -1
- package/dist/globs/match.js +9 -1
- package/dist/globs/matcher.js +5 -1
- package/dist/http-request/browser.js +6 -2
- package/dist/http-request/{browser-fetch.d.ts → fetch/browser.d.ts} +2 -2
- package/dist/http-request/{browser-fetch.js → fetch/browser.js} +4 -4
- package/dist/http-request/headers.js +1 -1
- package/dist/http-request/request-attempt.js +2 -2
- package/dist/http-request/user-agent.js +1 -1
- package/dist/integrity.d.ts +10 -4
- package/dist/integrity.js +10 -4
- package/dist/json/edit.js +38 -30
- package/dist/json/format.js +1 -1
- package/dist/native-messaging/install.d.ts +1 -1
- package/dist/native-messaging/install.js +7 -4
- package/dist/native-messaging/rate-limit.d.ts +7 -0
- package/dist/native-messaging/rate-limit.js +4 -0
- package/dist/node/async-hooks.js +1 -1
- package/dist/node/child-process.js +1 -1
- package/dist/node/crypto.js +1 -1
- package/dist/node/events.js +1 -1
- package/dist/node/fs-promises.js +1 -1
- package/dist/node/fs.d.ts +22 -6
- package/dist/node/fs.js +16 -3
- package/dist/node/http.js +1 -1
- package/dist/node/https.js +1 -1
- package/dist/node/module.js +1 -1
- package/dist/node/os.d.ts +10 -2
- package/dist/node/os.js +11 -4
- package/dist/node/path.d.ts +11 -2
- package/dist/node/path.js +17 -4
- package/dist/node/timers-promises.js +1 -1
- package/dist/node/url.js +1 -1
- package/dist/node/util.js +1 -1
- package/dist/objects/getters.js +1 -1
- package/dist/objects/mutate.js +2 -2
- package/dist/objects/predicates.js +1 -1
- package/dist/packages/edit-class.d.ts +2 -3
- package/dist/packages/edit-class.js +41 -35
- package/dist/packages/exports.js +4 -4
- package/dist/packages/fetch.js +1 -1
- package/dist/packages/isolation.js +1 -1
- package/dist/packages/licenses.js +2 -2
- package/dist/packages/manifest.js +4 -4
- package/dist/packages/normalize.js +1 -1
- package/dist/packages/provenance.js +2 -2
- package/dist/packages/specs.js +1 -1
- package/dist/packages/tarball.js +4 -2
- package/dist/packages/types.d.ts +1 -2
- package/dist/paths/dirnames.d.ts +1 -0
- package/dist/paths/dirnames.js +2 -0
- package/dist/paths/resolve.js +14 -19
- package/dist/paths/rewire.d.ts +5 -0
- package/dist/paths/socket.d.ts +74 -111
- package/dist/paths/socket.js +99 -132
- package/dist/primordials/process.d.ts +88 -0
- package/dist/primordials/process.js +132 -0
- package/dist/primordials/uncurry.d.ts +1 -2
- package/dist/process/spawn/child.js +8 -2
- package/dist/process/spawn/errors.js +1 -1
- package/dist/regexps/spec.js +1 -1
- package/dist/releases/github-archives.js +1 -1
- package/dist/releases/github-listing.d.ts +1 -2
- package/dist/schema/types.d.ts +3 -4
- package/dist/schema/validate.js +1 -1
- package/dist/secrets/find.d.ts +2 -2
- package/dist/secrets/find.js +10 -4
- package/dist/secrets/keychain.d.ts +1 -1
- package/dist/secrets/linux.js +32 -44
- package/dist/secrets/macos.d.ts +1 -2
- package/dist/secrets/macos.js +20 -29
- package/dist/secrets/rc.d.ts +2 -2
- package/dist/secrets/rc.js +21 -13
- package/dist/secrets/socket-api-token.js +8 -0
- package/dist/secrets/windows.js +27 -33
- package/dist/shell/parse.d.ts +32 -0
- package/dist/shell/parse.js +60 -0
- package/dist/spinner/create-spinner-class.js +2 -2
- package/dist/spinner/spinner-internals.d.ts +1 -1
- package/dist/spinner/spinner-internals.js +9 -5
- package/dist/spinner/spinner.d.ts +4 -0
- package/dist/spinner/spinner.js +1 -1
- package/dist/stdio/progress.js +5 -1
- package/dist/stdio/prompts.d.ts +2 -2
- package/dist/stdio/prompts.js +1 -1
- package/dist/temporal/instant.js +2 -2
- package/dist/url/assert-safe.d.ts +29 -0
- package/dist/url/assert-safe.js +54 -0
- package/dist/url/predicates.d.ts +31 -1
- package/dist/url/predicates.js +42 -1
- package/dist/url/types.d.ts +4 -0
- package/package.json +177 -115
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Availability-gated tier routing. `tier.mts` says which model+effort is
|
|
3
|
+
* the "perfect" choice for a unit of work; this module turns that hint into a
|
|
4
|
+
* concrete spawn target that ACTUALLY EXISTS on the machine. A tier resolves
|
|
5
|
+
* to its preferred engine only when that engine's CLI is installed AND a
|
|
6
|
+
* credential for it is resolvable; otherwise the resolver walks a
|
|
7
|
+
* cross-engine equivalence ladder (Claude → Codex → an open-weight provider
|
|
8
|
+
* via opencode) and returns the best available equivalent. Why gate on
|
|
9
|
+
* existence: a fleet machine may have Claude but no Codex, or Codex but an
|
|
10
|
+
* expired Claude key, or neither plus an opencode/synthetic seat. Hard-coding
|
|
11
|
+
* `fable` then fails at spawn time; routing here degrades gracefully and
|
|
12
|
+
* tells the caller WHY (the `reason`), so a skill can log "fell back to codex
|
|
13
|
+
* gpt-5.5 (claude unavailable)" instead of crashing. Pure given an
|
|
14
|
+
* availability/keyed context — no I/O — so callers fan out their `which` +
|
|
15
|
+
* credential probes once and pass the result in. Pairs with `buildArgs` in
|
|
16
|
+
* `spawn.mts`: a Fable candidate carries `effort: undefined` because Fable is
|
|
17
|
+
* adaptive-thinking-only and the spawn layer omits `--effort` for it anyway.
|
|
18
|
+
*/
|
|
19
|
+
import type { CredentialProvider } from './credentials.mts';
|
|
20
|
+
import type { AiAgentName, AiEffort } from './types.mts';
|
|
21
|
+
import type { AiTier } from './tier.mts';
|
|
22
|
+
/**
|
|
23
|
+
* A concrete, spawnable target: which CLI engine to run, the model id, the
|
|
24
|
+
* reasoning effort to pass (undefined when the model ignores effort, e.g.
|
|
25
|
+
* Fable), and the credential provider whose key gates it.
|
|
26
|
+
*/
|
|
27
|
+
export interface TierCandidate {
|
|
28
|
+
readonly effort: AiEffort | undefined;
|
|
29
|
+
readonly engine: AiAgentName;
|
|
30
|
+
readonly model: string;
|
|
31
|
+
readonly provider: CredentialProvider;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Why the resolver returned what it did. - `preferred` — the tier's
|
|
35
|
+
* first-choice engine was available + keyed. - `fellback` — the preferred
|
|
36
|
+
* engine was missing/unkeyed; an equivalent on another engine was used (`from`
|
|
37
|
+
* names the original tier).
|
|
38
|
+
*/
|
|
39
|
+
export type TierResolveReason = 'fellback' | 'preferred';
|
|
40
|
+
export interface TierResolution {
|
|
41
|
+
readonly candidate: TierCandidate;
|
|
42
|
+
readonly reason: TierResolveReason;
|
|
43
|
+
readonly from?: AiTier | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The context a caller probes once and passes in: which engine CLIs exist, and
|
|
47
|
+
* which credential providers have a resolvable key. Both are sets so the
|
|
48
|
+
* resolver stays pure (no `which` / keychain I/O of its own).
|
|
49
|
+
*/
|
|
50
|
+
export interface RouteContext {
|
|
51
|
+
readonly available: ReadonlySet<AiAgentName>;
|
|
52
|
+
readonly keyed: ReadonlySet<CredentialProvider>;
|
|
53
|
+
}
|
|
54
|
+
export declare const TIER_CHAINS: Readonly<Record<AiTier, readonly TierCandidate[]>>;
|
|
55
|
+
/**
|
|
56
|
+
* A candidate is usable when its engine CLI exists AND a credential for its
|
|
57
|
+
* provider is resolvable. Both gates matter: an installed Claude with an
|
|
58
|
+
* expired key is as unusable as a missing CLI.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isCandidateUsable(candidate: TierCandidate, ctx: RouteContext): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a tier to the best available concrete target. Prefers the tier's
|
|
63
|
+
* first-choice (Claude) candidate; if its engine is missing or unkeyed, walks
|
|
64
|
+
* the cross-engine equivalence ladder and returns the first usable equivalent,
|
|
65
|
+
* tagging the result `fellback` with the original tier in `from`. Returns
|
|
66
|
+
* `undefined` only when NOTHING in the chain is usable — the caller then skips
|
|
67
|
+
* the work or surfaces a "no AI engine available" message.
|
|
68
|
+
*/
|
|
69
|
+
export declare function resolveTier(tier: AiTier, ctx: RouteContext): TierResolution | undefined;
|
package/dist/ai/route.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with rolldown */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_ai_tier = require('./tier.js');
|
|
5
|
+
|
|
6
|
+
//#region src/ai/route.mts
|
|
7
|
+
/**
|
|
8
|
+
* @file Availability-gated tier routing. `tier.mts` says which model+effort is
|
|
9
|
+
* the "perfect" choice for a unit of work; this module turns that hint into a
|
|
10
|
+
* concrete spawn target that ACTUALLY EXISTS on the machine. A tier resolves
|
|
11
|
+
* to its preferred engine only when that engine's CLI is installed AND a
|
|
12
|
+
* credential for it is resolvable; otherwise the resolver walks a
|
|
13
|
+
* cross-engine equivalence ladder (Claude → Codex → an open-weight provider
|
|
14
|
+
* via opencode) and returns the best available equivalent. Why gate on
|
|
15
|
+
* existence: a fleet machine may have Claude but no Codex, or Codex but an
|
|
16
|
+
* expired Claude key, or neither plus an opencode/synthetic seat. Hard-coding
|
|
17
|
+
* `fable` then fails at spawn time; routing here degrades gracefully and
|
|
18
|
+
* tells the caller WHY (the `reason`), so a skill can log "fell back to codex
|
|
19
|
+
* gpt-5.5 (claude unavailable)" instead of crashing. Pure given an
|
|
20
|
+
* availability/keyed context — no I/O — so callers fan out their `which` +
|
|
21
|
+
* credential probes once and pass the result in. Pairs with `buildArgs` in
|
|
22
|
+
* `spawn.mts`: a Fable candidate carries `effort: undefined` because Fable is
|
|
23
|
+
* adaptive-thinking-only and the spawn layer omits `--effort` for it anyway.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Per-tier preference chain, most-preferred-first. The head is the "perfect"
|
|
27
|
+
* Claude choice from `AI_TIER`; the tail is the cross-engine equivalent ladder
|
|
28
|
+
* (Codex, then an open-weight provider reached through opencode). Effort is the
|
|
29
|
+
* shared `AiEffort` vocab; `buildArgs` translates per engine (codex clamps
|
|
30
|
+
* `max`→`xhigh`, Fable drops effort entirely).
|
|
31
|
+
*
|
|
32
|
+
* The Claude head reuses `AI_TIER` so a model-generation bump stays a single
|
|
33
|
+
* edit there. Fable's head carries `effort: undefined` — it is adaptive-only.
|
|
34
|
+
*/
|
|
35
|
+
const FABLE = require_ai_tier.AI_TIER.fable;
|
|
36
|
+
const OPUS = require_ai_tier.AI_TIER.opus;
|
|
37
|
+
const SONNET = require_ai_tier.AI_TIER.sonnet;
|
|
38
|
+
const HAIKU = require_ai_tier.AI_TIER.haiku;
|
|
39
|
+
const TIER_CHAINS = {
|
|
40
|
+
__proto__: null,
|
|
41
|
+
fable: [
|
|
42
|
+
{
|
|
43
|
+
effort: void 0,
|
|
44
|
+
engine: "claude",
|
|
45
|
+
model: FABLE.model,
|
|
46
|
+
provider: "anthropic"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
effort: "xhigh",
|
|
50
|
+
engine: "codex",
|
|
51
|
+
model: "gpt-5.5",
|
|
52
|
+
provider: "openai"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
effort: "xhigh",
|
|
56
|
+
engine: "opencode",
|
|
57
|
+
model: "fireworks-ai/accounts/fireworks/models/glm-5p1",
|
|
58
|
+
provider: "fireworks"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
opus: [
|
|
62
|
+
{
|
|
63
|
+
effort: OPUS.effort,
|
|
64
|
+
engine: "claude",
|
|
65
|
+
model: OPUS.model,
|
|
66
|
+
provider: "anthropic"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
effort: "high",
|
|
70
|
+
engine: "codex",
|
|
71
|
+
model: "gpt-5.5",
|
|
72
|
+
provider: "openai"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
effort: "high",
|
|
76
|
+
engine: "opencode",
|
|
77
|
+
model: "fireworks-ai/accounts/fireworks/models/glm-5p1",
|
|
78
|
+
provider: "fireworks"
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
sonnet: [
|
|
82
|
+
{
|
|
83
|
+
effort: SONNET.effort,
|
|
84
|
+
engine: "claude",
|
|
85
|
+
model: SONNET.model,
|
|
86
|
+
provider: "anthropic"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
effort: "medium",
|
|
90
|
+
engine: "codex",
|
|
91
|
+
model: "gpt-5.5",
|
|
92
|
+
provider: "openai"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
effort: "medium",
|
|
96
|
+
engine: "opencode",
|
|
97
|
+
model: "synthetic/hf:moonshotai/Kimi-K2.5",
|
|
98
|
+
provider: "synthetic"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
haiku: [
|
|
102
|
+
{
|
|
103
|
+
effort: HAIKU.effort,
|
|
104
|
+
engine: "claude",
|
|
105
|
+
model: HAIKU.model,
|
|
106
|
+
provider: "anthropic"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
effort: "low",
|
|
110
|
+
engine: "codex",
|
|
111
|
+
model: "gpt-5.5",
|
|
112
|
+
provider: "openai"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
effort: "low",
|
|
116
|
+
engine: "opencode",
|
|
117
|
+
model: "synthetic/hf:moonshotai/Kimi-K2.5",
|
|
118
|
+
provider: "synthetic"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* A candidate is usable when its engine CLI exists AND a credential for its
|
|
124
|
+
* provider is resolvable. Both gates matter: an installed Claude with an
|
|
125
|
+
* expired key is as unusable as a missing CLI.
|
|
126
|
+
*/
|
|
127
|
+
function isCandidateUsable(candidate, ctx) {
|
|
128
|
+
return ctx.available.has(candidate.engine) && ctx.keyed.has(candidate.provider);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Resolve a tier to the best available concrete target. Prefers the tier's
|
|
132
|
+
* first-choice (Claude) candidate; if its engine is missing or unkeyed, walks
|
|
133
|
+
* the cross-engine equivalence ladder and returns the first usable equivalent,
|
|
134
|
+
* tagging the result `fellback` with the original tier in `from`. Returns
|
|
135
|
+
* `undefined` only when NOTHING in the chain is usable — the caller then skips
|
|
136
|
+
* the work or surfaces a "no AI engine available" message.
|
|
137
|
+
*/
|
|
138
|
+
function resolveTier(tier, ctx) {
|
|
139
|
+
const chain = TIER_CHAINS[tier] ?? TIER_CHAINS.sonnet;
|
|
140
|
+
for (let i = 0, { length } = chain; i < length; i += 1) {
|
|
141
|
+
const candidate = chain[i];
|
|
142
|
+
if (isCandidateUsable(candidate, ctx)) return i === 0 ? {
|
|
143
|
+
candidate,
|
|
144
|
+
reason: "preferred"
|
|
145
|
+
} : {
|
|
146
|
+
candidate,
|
|
147
|
+
from: tier,
|
|
148
|
+
reason: "fellback"
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
exports.TIER_CHAINS = TIER_CHAINS;
|
|
155
|
+
exports.isCandidateUsable = isCandidateUsable;
|
|
156
|
+
exports.resolveTier = resolveTier;
|
package/dist/ai/spawn.d.mts
CHANGED
|
@@ -22,7 +22,15 @@ export declare function backoffFor(attempt: number): number;
|
|
|
22
22
|
* Update sites (when an agent changes its flag surface): 1. The relevant case
|
|
23
23
|
* below. 2. The agent's docs link (cited inline).
|
|
24
24
|
*/
|
|
25
|
-
export declare function buildArgs(agent: AiAgentName,
|
|
25
|
+
export declare function buildArgs(agent: AiAgentName, options: SpawnAiAgentOptions): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Fable and Mythos run adaptive thinking only — thinking is always on and there
|
|
28
|
+
* is no manual thinking-budget knob. The effort dial does not apply the way it
|
|
29
|
+
* does on Opus, so the spawn layer drops `--effort` for these models rather
|
|
30
|
+
* than passing a level they should ignore. Matches both alias and full-id
|
|
31
|
+
* shapes (`fable`, `claude-fable-5`, `mythos`, `claude-mythos-5`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function isAdaptiveOnlyModel(model: string): boolean;
|
|
26
34
|
export declare function isOverloaded(stdout: string, stderr: string): boolean;
|
|
27
35
|
export declare function pickAgent(requested: AiAgentName | undefined, cwd: string): Promise<AiAgentName>;
|
|
28
36
|
/**
|
|
@@ -46,4 +54,4 @@ export declare function pickAgent(requested: AiAgentName | undefined, cwd: strin
|
|
|
46
54
|
* Throws when the requested agent isn't on PATH (or, when no agent
|
|
47
55
|
* is requested, when none of the known agents are on PATH).
|
|
48
56
|
*/
|
|
49
|
-
export declare function spawnAiAgent(
|
|
57
|
+
export declare function spawnAiAgent(options: SpawnAiAgentOptions): Promise<AgentSpawnResult>;
|
package/dist/ai/spawn.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/* Socket Lib - Built with rolldown */
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_primordials_error = require('../primordials/error.js');
|
|
5
|
-
const require_primordials_date = require('../primordials/date.js');
|
|
6
5
|
const require_primordials_object = require('../primordials/object.js');
|
|
6
|
+
const require_primordials_date = require('../primordials/date.js');
|
|
7
7
|
const require_errors_message = require('../errors/message.js');
|
|
8
|
-
const require_ai_discover = require('./discover.js');
|
|
9
8
|
const require_process_spawn_errors = require('../process/spawn/errors.js');
|
|
10
9
|
const require_process_spawn_child = require('../process/spawn/child.js');
|
|
10
|
+
const require_ai_discover = require('./discover.js');
|
|
11
11
|
const require_primordials_promise = require('../primordials/promise.js');
|
|
12
12
|
|
|
13
13
|
//#region src/ai/spawn.mts
|
|
@@ -38,63 +38,81 @@ function backoffFor(attempt) {
|
|
|
38
38
|
* Update sites (when an agent changes its flag surface): 1. The relevant case
|
|
39
39
|
* below. 2. The agent's docs link (cited inline).
|
|
40
40
|
*/
|
|
41
|
-
function buildArgs(agent,
|
|
42
|
-
|
|
41
|
+
function buildArgs(agent, options) {
|
|
42
|
+
options = {
|
|
43
|
+
__proto__: null,
|
|
44
|
+
...options
|
|
45
|
+
};
|
|
46
|
+
const allAllowed = [...options.tools, ...options.allow ?? []];
|
|
43
47
|
switch (agent) {
|
|
44
48
|
case "claude": {
|
|
45
49
|
const args = [
|
|
46
50
|
"--print",
|
|
47
51
|
"--no-session-persistence",
|
|
48
52
|
"--permission-mode",
|
|
49
|
-
|
|
53
|
+
options.permissionMode,
|
|
50
54
|
"--add-dir",
|
|
51
|
-
|
|
55
|
+
options.cwd
|
|
52
56
|
];
|
|
53
|
-
for (const dir of
|
|
54
|
-
if (
|
|
55
|
-
if (
|
|
57
|
+
for (const dir of options.addDirs ?? []) args.push("--add-dir", dir);
|
|
58
|
+
if (options.model) args.push("--model", options.model);
|
|
59
|
+
if (options.effort && !isAdaptiveOnlyModel(options.model ?? "")) args.push("--effort", options.effort);
|
|
56
60
|
if (allAllowed.length > 0) args.push("--allowedTools", ...allAllowed);
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
61
|
+
if (options.disallow.length > 0) args.push("--disallowedTools", ...options.disallow);
|
|
62
|
+
if (options.extraArgs) args.push(...options.extraArgs);
|
|
59
63
|
return args;
|
|
60
64
|
}
|
|
61
65
|
case "codex": {
|
|
62
66
|
const args = ["--print"];
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
67
|
+
if (options.permissionMode === "plan") args.push("--read-only");
|
|
68
|
+
if (options.model) args.push("--model", options.model);
|
|
69
|
+
if (options.effort) {
|
|
70
|
+
const codexEffort = options.effort === "max" ? "xhigh" : options.effort;
|
|
71
|
+
args.push("-c", `model_reasoning_effort=${codexEffort}`);
|
|
72
|
+
}
|
|
65
73
|
if (allAllowed.length > 0) args.push("--tools", allAllowed.join(","));
|
|
66
|
-
if (
|
|
67
|
-
args.push("--cwd",
|
|
68
|
-
if (
|
|
74
|
+
if (options.disallow.length > 0) args.push("--disallow-tools", options.disallow.join(","));
|
|
75
|
+
args.push("--cwd", options.cwd);
|
|
76
|
+
if (options.extraArgs) args.push(...options.extraArgs);
|
|
69
77
|
return args;
|
|
70
78
|
}
|
|
71
79
|
case "gemini": {
|
|
72
80
|
const args = [
|
|
73
81
|
"--no-interactive",
|
|
74
82
|
"--workspace",
|
|
75
|
-
|
|
83
|
+
options.cwd
|
|
76
84
|
];
|
|
77
|
-
if (
|
|
85
|
+
if (options.model) args.push("--model", options.model);
|
|
78
86
|
if (allAllowed.length > 0) args.push("--allowed-tools", allAllowed.join(","));
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
87
|
+
if (options.disallow.length > 0) args.push("--denied-tools", options.disallow.join(","));
|
|
88
|
+
if (options.permissionMode === "plan") args.push("--read-only");
|
|
89
|
+
if (options.extraArgs) args.push(...options.extraArgs);
|
|
82
90
|
return args;
|
|
83
91
|
}
|
|
84
92
|
case "opencode": {
|
|
85
93
|
const args = [
|
|
86
94
|
"--print",
|
|
87
95
|
"--cwd",
|
|
88
|
-
|
|
96
|
+
options.cwd
|
|
89
97
|
];
|
|
90
|
-
if (
|
|
98
|
+
if (options.model) args.push("--model", options.model);
|
|
91
99
|
if (allAllowed.length > 0) args.push("--tools", allAllowed.join(","));
|
|
92
|
-
if (
|
|
93
|
-
if (
|
|
100
|
+
if (options.disallow.length > 0) args.push("--no-tools", options.disallow.join(","));
|
|
101
|
+
if (options.extraArgs) args.push(...options.extraArgs);
|
|
94
102
|
return args;
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Fable and Mythos run adaptive thinking only — thinking is always on and there
|
|
108
|
+
* is no manual thinking-budget knob. The effort dial does not apply the way it
|
|
109
|
+
* does on Opus, so the spawn layer drops `--effort` for these models rather
|
|
110
|
+
* than passing a level they should ignore. Matches both alias and full-id
|
|
111
|
+
* shapes (`fable`, `claude-fable-5`, `mythos`, `claude-mythos-5`).
|
|
112
|
+
*/
|
|
113
|
+
function isAdaptiveOnlyModel(model) {
|
|
114
|
+
return /\b(?:fable|mythos)\b/i.test(model) || /claude-(?:fable|mythos)/i.test(model);
|
|
115
|
+
}
|
|
98
116
|
function isOverloaded(stdout, stderr) {
|
|
99
117
|
const re = /API Error: 529|Overloaded/i;
|
|
100
118
|
return re.test(stdout) || re.test(stderr);
|
|
@@ -134,9 +152,13 @@ async function pickAgent(requested, cwd) {
|
|
|
134
152
|
* Throws when the requested agent isn't on PATH (or, when no agent
|
|
135
153
|
* is requested, when none of the known agents are on PATH).
|
|
136
154
|
*/
|
|
137
|
-
async function spawnAiAgent(
|
|
138
|
-
|
|
139
|
-
|
|
155
|
+
async function spawnAiAgent(options) {
|
|
156
|
+
options = {
|
|
157
|
+
__proto__: null,
|
|
158
|
+
...options
|
|
159
|
+
};
|
|
160
|
+
const agent = await pickAgent(options.agent, options.cwd);
|
|
161
|
+
const args = buildArgs(agent, options);
|
|
140
162
|
let stdout = "";
|
|
141
163
|
let stderr = "";
|
|
142
164
|
let exitCode = 0;
|
|
@@ -149,12 +171,12 @@ async function spawnAiAgent(opts) {
|
|
|
149
171
|
exitCode = 0;
|
|
150
172
|
try {
|
|
151
173
|
const child = require_process_spawn_child.spawn(agent, args, {
|
|
152
|
-
cwd:
|
|
174
|
+
cwd: options.cwd,
|
|
153
175
|
stdio: "pipe",
|
|
154
176
|
stdioString: true,
|
|
155
|
-
timeout:
|
|
177
|
+
timeout: options.timeoutMs
|
|
156
178
|
});
|
|
157
|
-
child.stdin?.end(
|
|
179
|
+
child.stdin?.end(options.prompt);
|
|
158
180
|
const result = await child;
|
|
159
181
|
stdout = String(result.stdout ?? "");
|
|
160
182
|
stderr = String(result.stderr ?? "");
|
|
@@ -176,6 +198,7 @@ async function spawnAiAgent(opts) {
|
|
|
176
198
|
attempts,
|
|
177
199
|
durationMs: require_primordials_date.DateNow() - start,
|
|
178
200
|
exitCode,
|
|
201
|
+
overloaded: isOverloaded(stdout, stderr),
|
|
179
202
|
stderr,
|
|
180
203
|
stdout
|
|
181
204
|
};
|
|
@@ -184,6 +207,7 @@ async function spawnAiAgent(opts) {
|
|
|
184
207
|
//#endregion
|
|
185
208
|
exports.backoffFor = backoffFor;
|
|
186
209
|
exports.buildArgs = buildArgs;
|
|
210
|
+
exports.isAdaptiveOnlyModel = isAdaptiveOnlyModel;
|
|
187
211
|
exports.isOverloaded = isOverloaded;
|
|
188
212
|
exports.pickAgent = pickAgent;
|
|
189
213
|
exports.spawnAiAgent = spawnAiAgent;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The terminal-status contract a delegated subagent returns to its
|
|
3
|
+
* orchestrator. Subagent-driven development depends on a SMALL, fixed status
|
|
4
|
+
* vocabulary so the orchestrator can route deterministically instead of
|
|
5
|
+
* parsing free-form prose: a subagent that "sort of finished but has a worry"
|
|
6
|
+
* must be distinguishable from one that is genuinely blocked, because they
|
|
7
|
+
* escalate differently. The four states and their escalation paths are the
|
|
8
|
+
* contract; `escalationFor` is the single place that maps a state to what the
|
|
9
|
+
* orchestrator does next. Encoding it as a typed union + map (rather than a
|
|
10
|
+
* doc convention) is the code-is-law surface: a stray status string fails the
|
|
11
|
+
* guard, and `agent-delegation.md` is checked against this union so the prose
|
|
12
|
+
* can't drift from the code.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* A subagent's terminal status.
|
|
16
|
+
*
|
|
17
|
+
* - `done` — work complete, no reservations; the orchestrator advances.
|
|
18
|
+
* - `done-with-concerns` — work complete but the subagent flagged a risk or
|
|
19
|
+
* follow-up the orchestrator should surface before advancing.
|
|
20
|
+
* - `needs-context` — the subagent lacks information it cannot obtain itself; the
|
|
21
|
+
* orchestrator supplies it and re-dispatches (a fresh attempt, not the same
|
|
22
|
+
* model retrying blind).
|
|
23
|
+
* - `blocked` — the work cannot proceed without a decision or action only the
|
|
24
|
+
* user can provide; the orchestrator escalates to the user and stops.
|
|
25
|
+
*/
|
|
26
|
+
export type SubagentStatus = 'blocked' | 'done' | 'done-with-concerns' | 'needs-context';
|
|
27
|
+
/**
|
|
28
|
+
* What the orchestrator does for each terminal status. `advance` continues to
|
|
29
|
+
* the next unit of work; `surface` advances but raises the concern first;
|
|
30
|
+
* `redispatch` re-runs the unit with the missing context added; `escalate`
|
|
31
|
+
* stops and hands the decision to the user.
|
|
32
|
+
*/
|
|
33
|
+
export type SubagentEscalation = 'advance' | 'escalate' | 'redispatch' | 'surface';
|
|
34
|
+
/**
|
|
35
|
+
* The canonical status set, sorted, for callers that need to enumerate or
|
|
36
|
+
* validate against the full vocabulary (the doc-parity check reads this).
|
|
37
|
+
*/
|
|
38
|
+
export declare const SUBAGENT_STATUSES: readonly SubagentStatus[];
|
|
39
|
+
/**
|
|
40
|
+
* Map a terminal status to the orchestrator action it requires. A status
|
|
41
|
+
* outside the vocabulary is itself a contract violation, so this throws rather
|
|
42
|
+
* than guessing — never force a retry on an unrecognized state.
|
|
43
|
+
*/
|
|
44
|
+
export declare function escalationFor(status: SubagentStatus): SubagentEscalation;
|
|
45
|
+
/**
|
|
46
|
+
* True when `value` names a status in the contract.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isSubagentStatus(value: string): value is SubagentStatus;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with rolldown */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_primordials_error = require('../primordials/error.js');
|
|
5
|
+
|
|
6
|
+
//#region src/ai/subagent-status.mts
|
|
7
|
+
/**
|
|
8
|
+
* @file The terminal-status contract a delegated subagent returns to its
|
|
9
|
+
* orchestrator. Subagent-driven development depends on a SMALL, fixed status
|
|
10
|
+
* vocabulary so the orchestrator can route deterministically instead of
|
|
11
|
+
* parsing free-form prose: a subagent that "sort of finished but has a worry"
|
|
12
|
+
* must be distinguishable from one that is genuinely blocked, because they
|
|
13
|
+
* escalate differently. The four states and their escalation paths are the
|
|
14
|
+
* contract; `escalationFor` is the single place that maps a state to what the
|
|
15
|
+
* orchestrator does next. Encoding it as a typed union + map (rather than a
|
|
16
|
+
* doc convention) is the code-is-law surface: a stray status string fails the
|
|
17
|
+
* guard, and `agent-delegation.md` is checked against this union so the prose
|
|
18
|
+
* can't drift from the code.
|
|
19
|
+
*/
|
|
20
|
+
const ESCALATION = {
|
|
21
|
+
__proto__: null,
|
|
22
|
+
blocked: "escalate",
|
|
23
|
+
done: "advance",
|
|
24
|
+
"done-with-concerns": "surface",
|
|
25
|
+
"needs-context": "redispatch"
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The canonical status set, sorted, for callers that need to enumerate or
|
|
29
|
+
* validate against the full vocabulary (the doc-parity check reads this).
|
|
30
|
+
*/
|
|
31
|
+
const SUBAGENT_STATUSES = [
|
|
32
|
+
"blocked",
|
|
33
|
+
"done",
|
|
34
|
+
"done-with-concerns",
|
|
35
|
+
"needs-context"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Map a terminal status to the orchestrator action it requires. A status
|
|
39
|
+
* outside the vocabulary is itself a contract violation, so this throws rather
|
|
40
|
+
* than guessing — never force a retry on an unrecognized state.
|
|
41
|
+
*/
|
|
42
|
+
function escalationFor(status) {
|
|
43
|
+
const action = ESCALATION[status];
|
|
44
|
+
if (!action) throw new require_primordials_error.ErrorCtor(`escalationFor: unknown subagent status "${status}". Expected one of: ${SUBAGENT_STATUSES.join(", ")}. Return a status from the SubagentStatus contract.`);
|
|
45
|
+
return action;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* True when `value` names a status in the contract.
|
|
49
|
+
*/
|
|
50
|
+
function isSubagentStatus(value) {
|
|
51
|
+
return SUBAGENT_STATUSES.includes(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
exports.SUBAGENT_STATUSES = SUBAGENT_STATUSES;
|
|
56
|
+
exports.escalationFor = escalationFor;
|
|
57
|
+
exports.isSubagentStatus = isSubagentStatus;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Canonical model + reasoning-effort ladder for AI orchestrators. The
|
|
3
|
+
* fleet's AI-fix / AI-codify orchestrators pick a capability TIER per unit of
|
|
4
|
+
* work (a lint rule, a hook, a doc edit) and resolve it to a concrete `{
|
|
5
|
+
* model, effort }` pair. Before this module each orchestrator redefined the
|
|
6
|
+
* same three-row table, so a model-generation bump (Sonnet 4.6 → 5.0, Opus
|
|
7
|
+
* 4.8 → 4.9) meant editing N files and risked drift. Import `AI_TIER` /
|
|
8
|
+
* `tierToSpawn` here instead; a generation roll is then a single edit. The
|
|
9
|
+
* mapping encodes the CLAUDE.md token-spend rule ("match model AND effort to
|
|
10
|
+
* the job"): a cheap model left on the session's default effort still burns
|
|
11
|
+
* reasoning a mechanical task never needs, and a premium model on low effort
|
|
12
|
+
* under-thinks a hard one — so effort is pinned ALONGSIDE the model per
|
|
13
|
+
* tier.
|
|
14
|
+
*/
|
|
15
|
+
import type { AiEffort } from './types.mts';
|
|
16
|
+
/**
|
|
17
|
+
* The capability tiers, least → most capable. Orchestrators classify each unit
|
|
18
|
+
* of work into one of these (a regex-shaped rewrite → `haiku`; a caller-chain
|
|
19
|
+
* rewrite → `sonnet`; a module split / new-enforcer authoring → `opus`).
|
|
20
|
+
* `fable` is the apex escalation tier — reserve it for the hardest cases (a
|
|
21
|
+
* stuck compiler / native problem, planning + decomposition of a large task),
|
|
22
|
+
* never a first reach, and prefer to ask before selecting it. It is the most
|
|
23
|
+
* expensive model on the board (~2× opus, ~10× haiku output), so an
|
|
24
|
+
* orchestrator should pick the LEAST-capable tier that does the job and
|
|
25
|
+
* escalate to `fable` only after cheaper tiers fail.
|
|
26
|
+
*/
|
|
27
|
+
export type AiTier = 'fable' | 'haiku' | 'opus' | 'sonnet';
|
|
28
|
+
/**
|
|
29
|
+
* Resolved spawn parameters for a tier — spread alongside an `AI_PROFILE` into
|
|
30
|
+
* a `spawnAiAgent` call (`{ ...AI_PROFILE.verify, ...tierToSpawn('opus'),
|
|
31
|
+
* prompt, cwd }`).
|
|
32
|
+
*/
|
|
33
|
+
export interface TierSpawn {
|
|
34
|
+
readonly effort: AiEffort;
|
|
35
|
+
readonly model: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Canonical tier → { model, effort }. The single source of truth for which
|
|
39
|
+
* Claude model + effort each tier runs. Bump here on a model generation roll;
|
|
40
|
+
* every orchestrator that imports this picks it up.
|
|
41
|
+
*
|
|
42
|
+
* - `haiku` / low — deterministic, regex-shaped rewrites (identifier rename,
|
|
43
|
+
* null→undefined, single-token substitution).
|
|
44
|
+
* - `sonnet` / medium — control-flow / caller-chain reasoning (fetch→httpJson,
|
|
45
|
+
* sync→async), a check script, a doc edit.
|
|
46
|
+
* - `opus` / high — real authoring / refactoring (module split, a brand-new hook
|
|
47
|
+
* or lint rule with its test).
|
|
48
|
+
* - `fable` / xhigh — apex escalation only: a stuck compiler / native problem
|
|
49
|
+
* after cheaper tiers fail, or planning + decomposition of a large task whose
|
|
50
|
+
* chunks then run on cheaper tiers. Most expensive model on the board; never
|
|
51
|
+
* a default.
|
|
52
|
+
*/
|
|
53
|
+
export declare const AI_TIER: Readonly<Record<AiTier, TierSpawn>>;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a tier label to its `{ model, effort }` spawn pair. A convenience
|
|
56
|
+
* over indexing `AI_TIER` directly; returns the `sonnet` row for an unknown
|
|
57
|
+
* label so a caller that hands in a stray string degrades to the safe default
|
|
58
|
+
* rather than producing `undefined` model/effort.
|
|
59
|
+
*/
|
|
60
|
+
export declare function tierToSpawn(tier: AiTier): TierSpawn;
|
package/dist/ai/tier.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Socket Lib - Built with rolldown */
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
//#region src/ai/tier.mts
|
|
6
|
+
/**
|
|
7
|
+
* Canonical tier → { model, effort }. The single source of truth for which
|
|
8
|
+
* Claude model + effort each tier runs. Bump here on a model generation roll;
|
|
9
|
+
* every orchestrator that imports this picks it up.
|
|
10
|
+
*
|
|
11
|
+
* - `haiku` / low — deterministic, regex-shaped rewrites (identifier rename,
|
|
12
|
+
* null→undefined, single-token substitution).
|
|
13
|
+
* - `sonnet` / medium — control-flow / caller-chain reasoning (fetch→httpJson,
|
|
14
|
+
* sync→async), a check script, a doc edit.
|
|
15
|
+
* - `opus` / high — real authoring / refactoring (module split, a brand-new hook
|
|
16
|
+
* or lint rule with its test).
|
|
17
|
+
* - `fable` / xhigh — apex escalation only: a stuck compiler / native problem
|
|
18
|
+
* after cheaper tiers fail, or planning + decomposition of a large task whose
|
|
19
|
+
* chunks then run on cheaper tiers. Most expensive model on the board; never
|
|
20
|
+
* a default.
|
|
21
|
+
*/
|
|
22
|
+
const AI_TIER = {
|
|
23
|
+
__proto__: null,
|
|
24
|
+
fable: {
|
|
25
|
+
effort: "xhigh",
|
|
26
|
+
model: "claude-fable-5"
|
|
27
|
+
},
|
|
28
|
+
haiku: {
|
|
29
|
+
effort: "low",
|
|
30
|
+
model: "claude-haiku-4-5"
|
|
31
|
+
},
|
|
32
|
+
opus: {
|
|
33
|
+
effort: "high",
|
|
34
|
+
model: "claude-opus-4-8"
|
|
35
|
+
},
|
|
36
|
+
sonnet: {
|
|
37
|
+
effort: "medium",
|
|
38
|
+
model: "claude-sonnet-4-6"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a tier label to its `{ model, effort }` spawn pair. A convenience
|
|
43
|
+
* over indexing `AI_TIER` directly; returns the `sonnet` row for an unknown
|
|
44
|
+
* label so a caller that hands in a stray string degrades to the safe default
|
|
45
|
+
* rather than producing `undefined` model/effort.
|
|
46
|
+
*/
|
|
47
|
+
function tierToSpawn(tier) {
|
|
48
|
+
return AI_TIER[tier] ?? AI_TIER.sonnet;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.AI_TIER = AI_TIER;
|
|
53
|
+
exports.tierToSpawn = tierToSpawn;
|
package/dist/ai/types.d.mts
CHANGED
|
@@ -26,8 +26,14 @@ export type AiAgentName = 'claude' | 'codex' | 'gemini' | 'opencode';
|
|
|
26
26
|
*/
|
|
27
27
|
export type PermissionMode = 'acceptEdits' | 'dontAsk' | 'plan';
|
|
28
28
|
/**
|
|
29
|
-
* Reasoning-effort level for the agent session.
|
|
30
|
-
*
|
|
29
|
+
* Reasoning-effort level for the agent session. Two agents consume it, each via
|
|
30
|
+
* its own flag — `buildArgs` translates per-agent:
|
|
31
|
+
*
|
|
32
|
+
* - Claude: `--effort <level>`, accepts low/medium/high/xhigh/max.
|
|
33
|
+
* - Codex: `-c model_reasoning_effort=<level>`, accepts minimal/low/medium/high/
|
|
34
|
+
* xhigh (no `max` — `buildArgs` clamps `max` → `xhigh`, codex's ceiling).
|
|
35
|
+
*
|
|
36
|
+
* Gemini / opencode have no reasoning-effort flag, so they ignore it. Pair a
|
|
31
37
|
* cheap model with low effort for mechanical work and reserve high/max for
|
|
32
38
|
* tasks that genuinely need deeper reasoning.
|
|
33
39
|
*/
|
|
@@ -41,6 +47,13 @@ export interface AgentSpawnResult {
|
|
|
41
47
|
readonly attempts: number;
|
|
42
48
|
readonly durationMs: number;
|
|
43
49
|
readonly exitCode: number;
|
|
50
|
+
/**
|
|
51
|
+
* True when the spawn failed because the API stayed overloaded (HTTP 529 /
|
|
52
|
+
* "Overloaded") through every retry. Lets a caller distinguish "back off and
|
|
53
|
+
* retry later" from "the work genuinely failed" — both surface as a non-zero
|
|
54
|
+
* `exitCode`, so this is the only way to tell them apart.
|
|
55
|
+
*/
|
|
56
|
+
readonly overloaded: boolean;
|
|
44
57
|
readonly stderr: string;
|
|
45
58
|
readonly stdout: string;
|
|
46
59
|
}
|