@garygentry/system1 0.4.0 → 0.5.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.
- package/dist/bundle/chunks/{bin-TIEUYIP3.mjs → bin-X4SS2GSC.mjs} +26 -15
- package/dist/bundle/chunks/chunk-45YUIPYC.mjs +914 -0
- package/dist/bundle/chunks/chunk-7OZLIHEM.mjs +46 -0
- package/dist/bundle/chunks/chunk-MH6THLCO.mjs +73 -0
- package/dist/bundle/chunks/{chunk-XNRV73UE.mjs → chunk-SUUJE62R.mjs} +2 -2
- package/dist/bundle/chunks/{chunk-QYUSJUFX.mjs → chunk-TMAJXDTE.mjs} +944 -1226
- package/dist/bundle/chunks/chunk-WVMA3PGV.mjs +69 -0
- package/dist/bundle/chunks/{config-KXGUNAJR.mjs → config-54JZCBR5.mjs} +15 -4
- package/dist/bundle/chunks/{decide-HI5CUH3C.mjs → decide-AU2C3U6C.mjs} +10 -5
- package/dist/bundle/chunks/{doctor-NDV3Y6T7.mjs → doctor-JKWORTJP.mjs} +6 -3
- package/dist/bundle/chunks/done-check-PCXUZT7Q.mjs +661 -0
- package/dist/bundle/chunks/guard-TZPV4JV3.mjs +113 -0
- package/dist/bundle/chunks/hook-LZ37YGT4.mjs +189 -0
- package/dist/bundle/chunks/{misc-6SDKH2PI.mjs → misc-CZLLPSHU.mjs} +14 -8
- package/dist/bundle/chunks/{opportunities-ONEIYAG3.mjs → opportunities-ICJLJYG4.mjs} +10 -5
- package/dist/bundle/chunks/{route-BF5J2NLU.mjs → route-D7T7YYDE.mjs} +8 -4
- package/dist/bundle/chunks/{spec-GLTPEEON.mjs → spec-6E5RXMGH.mjs} +14 -8
- package/dist/bundle/decide.mjs +1 -1
- package/package.json +1 -1
- package/dist/bundle/chunks/chunk-WZIVOY5Q.mjs +0 -171
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
typedParse
|
|
4
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
5
|
+
import "./chunk-45YUIPYC.mjs";
|
|
6
|
+
import {
|
|
7
|
+
PACKS,
|
|
8
|
+
PACK_NAMES,
|
|
9
|
+
isPackName,
|
|
10
|
+
loadConfig,
|
|
11
|
+
repoConfigPath,
|
|
12
|
+
setGuardEnabled
|
|
13
|
+
} from "./chunk-TMAJXDTE.mjs";
|
|
14
|
+
import {
|
|
15
|
+
emit
|
|
16
|
+
} from "./chunk-WVMA3PGV.mjs";
|
|
17
|
+
import "./chunk-7OZLIHEM.mjs";
|
|
18
|
+
import {
|
|
19
|
+
DecisionsError
|
|
20
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
21
|
+
|
|
22
|
+
// src/commands/guard.ts
|
|
23
|
+
function runGuardCommand(argv, io, format) {
|
|
24
|
+
return emit(
|
|
25
|
+
io,
|
|
26
|
+
"guard",
|
|
27
|
+
format,
|
|
28
|
+
() => body(argv, io),
|
|
29
|
+
(r, f) => f === "brief" ? brief(r) : void 0
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
var GUARD_OPTIONS = { "i-consent": { type: "boolean" }, by: { type: "string" } };
|
|
33
|
+
function body(argv, io) {
|
|
34
|
+
const { values, positionals } = typedParse({
|
|
35
|
+
args: argv,
|
|
36
|
+
allowPositionals: true,
|
|
37
|
+
options: GUARD_OPTIONS
|
|
38
|
+
});
|
|
39
|
+
const [action = "list", name] = positionals;
|
|
40
|
+
const cwd = io.cwd ?? process.cwd();
|
|
41
|
+
const load = () => loadConfig({ cwd, env: io.env, ...io.home ? { home: io.home } : {} });
|
|
42
|
+
const config = load();
|
|
43
|
+
const file = repoConfigPath(config.repoRoot);
|
|
44
|
+
const result = (c = config, changed) => ({
|
|
45
|
+
file,
|
|
46
|
+
consent: c.egress.consent.granted,
|
|
47
|
+
packs: PACK_NAMES.map((n) => ({
|
|
48
|
+
name: n,
|
|
49
|
+
summary: PACKS[n].summary,
|
|
50
|
+
...c.guard.packs[n],
|
|
51
|
+
active: c.guard.packs[n].enabled && c.egress.consent.granted
|
|
52
|
+
})),
|
|
53
|
+
...changed ? { changed } : {}
|
|
54
|
+
});
|
|
55
|
+
switch (action) {
|
|
56
|
+
case "list":
|
|
57
|
+
case "status":
|
|
58
|
+
return result();
|
|
59
|
+
case "enable":
|
|
60
|
+
case "disable": {
|
|
61
|
+
const pack = packName(name);
|
|
62
|
+
if (action === "disable") {
|
|
63
|
+
setGuardEnabled(config.repoRoot, pack, false, values.by ?? "decide guard disable");
|
|
64
|
+
return result(load(), pack);
|
|
65
|
+
}
|
|
66
|
+
if (!config.egress.consent.granted) {
|
|
67
|
+
throw new DecisionsError(
|
|
68
|
+
"egress-refused",
|
|
69
|
+
`Enabling ${pack} sends content to the decision model's provider, and this repo has not agreed to that. Grant egress consent first (see \`decide doctor\`); it is the user's decision, and an agent must not make it.`,
|
|
70
|
+
{ repoRoot: config.repoRoot }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (!io.interactive && !values["i-consent"]) {
|
|
74
|
+
throw new DecisionsError(
|
|
75
|
+
"egress-refused",
|
|
76
|
+
`Enabling a guard pack is the user's decision. An agent must not enable it, with or without a flag: show the user this message instead. The user enables it by typing \`decide guard enable ${pack}\` in a terminal at the repo root. If they run it through their agent prompt's shell escape instead (not as a chat message), there is no terminal, so they add --i-consent to say the decision is theirs.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
setGuardEnabled(
|
|
80
|
+
config.repoRoot,
|
|
81
|
+
pack,
|
|
82
|
+
true,
|
|
83
|
+
values.by ?? (io.interactive ? "decide guard" : "decide guard --i-consent")
|
|
84
|
+
);
|
|
85
|
+
return result(load(), pack);
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
throw new DecisionsError(
|
|
89
|
+
"invalid-request",
|
|
90
|
+
`Unknown guard action "${action}". Use: list, status, enable <pack>, disable <pack>`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function packName(name) {
|
|
95
|
+
if (name && isPackName(name)) return name;
|
|
96
|
+
throw new DecisionsError(
|
|
97
|
+
"invalid-request",
|
|
98
|
+
`${name ? `Unknown guard pack "${name}"` : "Name a guard pack"}. Known: ${PACK_NAMES.join(", ")}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
function brief(r) {
|
|
102
|
+
const lines = r.packs.map((p) => {
|
|
103
|
+
const state = p.active ? "active" : p.enabled ? "enabled, but no egress consent: dormant" : "dormant";
|
|
104
|
+
return `${p.name}: ${state}${p.name === r.changed ? " (changed)" : ""} \xB7 ${p.summary}`;
|
|
105
|
+
});
|
|
106
|
+
return [...lines, `egress consent: ${r.consent ? "granted" : "not granted"} (${r.file})`].join(
|
|
107
|
+
"\n"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
GUARD_OPTIONS,
|
|
112
|
+
runGuardCommand
|
|
113
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
typedParse
|
|
4
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
5
|
+
import "./chunk-45YUIPYC.mjs";
|
|
6
|
+
import {
|
|
7
|
+
isPackName,
|
|
8
|
+
loadConfig
|
|
9
|
+
} from "./chunk-TMAJXDTE.mjs";
|
|
10
|
+
import {
|
|
11
|
+
EXIT
|
|
12
|
+
} from "./chunk-7OZLIHEM.mjs";
|
|
13
|
+
import {
|
|
14
|
+
isDecisionsError
|
|
15
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
16
|
+
|
|
17
|
+
// src/commands/hook.ts
|
|
18
|
+
import { readFileSync } from "node:fs";
|
|
19
|
+
|
|
20
|
+
// ../core/dist/tools/hook.js
|
|
21
|
+
var HOOK_LATENCY_CEILING_MS = 55e3;
|
|
22
|
+
var SESSION_ID = /^[A-Za-z0-9._-]{1,128}$/;
|
|
23
|
+
function checkHookEvent(input) {
|
|
24
|
+
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
25
|
+
return ["/ must be an object"];
|
|
26
|
+
const e = input;
|
|
27
|
+
const problems = [];
|
|
28
|
+
for (const key of ["hook_event_name", "session_id", "cwd"]) {
|
|
29
|
+
if (typeof e[key] !== "string" || !e[key])
|
|
30
|
+
problems.push(`/${key} must be a non-empty string`);
|
|
31
|
+
}
|
|
32
|
+
if (e.stop_hook_active !== void 0 && typeof e.stop_hook_active !== "boolean")
|
|
33
|
+
problems.push("/stop_hook_active must be a boolean");
|
|
34
|
+
for (const key of ["source", "turn_id"]) {
|
|
35
|
+
if (e[key] !== void 0 && typeof e[key] !== "string")
|
|
36
|
+
problems.push(`/${key} must be a string`);
|
|
37
|
+
}
|
|
38
|
+
return problems;
|
|
39
|
+
}
|
|
40
|
+
var say = (pack, text) => ({
|
|
41
|
+
systemMessage: `System 1 ${pack}: ${text}`
|
|
42
|
+
});
|
|
43
|
+
async function runHook(pack, rawEvent, options = {}) {
|
|
44
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
45
|
+
const event = rawEvent;
|
|
46
|
+
const problems = checkHookEvent(rawEvent);
|
|
47
|
+
const cwd = problems.length === 0 ? event.cwd : options.cwd ?? process.cwd();
|
|
48
|
+
const harness = options.harness ?? (typeof event?.turn_id === "string" ? "codex" : "claude");
|
|
49
|
+
const usableId = problems.length === 0 && SESSION_ID.test(event.session_id);
|
|
50
|
+
const env = options.env ?? process.env;
|
|
51
|
+
const session = env.SYSTEM1_SESSION || (usableId ? `${harness}:${event.session_id}` : void 0);
|
|
52
|
+
let config;
|
|
53
|
+
try {
|
|
54
|
+
config = loadConfig({
|
|
55
|
+
...options,
|
|
56
|
+
cwd,
|
|
57
|
+
env: session ? { ...env, SYSTEM1_SESSION: session } : env
|
|
58
|
+
});
|
|
59
|
+
} catch {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
if (!isPackName(pack))
|
|
63
|
+
return {};
|
|
64
|
+
const settings = config.guard.packs[pack];
|
|
65
|
+
if (!settings.enabled || !config.egress.consent.granted)
|
|
66
|
+
return {};
|
|
67
|
+
if (problems.length > 0) {
|
|
68
|
+
return say(pack, `not checked: the harness sent an unexpected event (${problems[0]})`);
|
|
69
|
+
}
|
|
70
|
+
if (event.stop_hook_active === true)
|
|
71
|
+
return {};
|
|
72
|
+
if (!usableId)
|
|
73
|
+
return say(pack, "not checked: the harness sent a session id it can't use");
|
|
74
|
+
const latencyMs = Math.min(settings.latencyMs, HOOK_LATENCY_CEILING_MS);
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
let timer;
|
|
77
|
+
const deadline = new Promise((resolve) => {
|
|
78
|
+
timer = setTimeout(() => {
|
|
79
|
+
controller.abort();
|
|
80
|
+
resolve(say(pack, `not checked: it took longer than ${latencyMs} ms (latencyMs)`));
|
|
81
|
+
}, latencyMs);
|
|
82
|
+
});
|
|
83
|
+
const work = (async () => {
|
|
84
|
+
const mod = options.packs?.[pack] ?? await import("./done-check-PCXUZT7Q.mjs");
|
|
85
|
+
const ctx = {
|
|
86
|
+
repoRoot: config.repoRoot,
|
|
87
|
+
sessionKey: `${harness}:${event.session_id}`,
|
|
88
|
+
ledgerSession: config.session ?? `${harness}:${event.session_id}`,
|
|
89
|
+
tool: {
|
|
90
|
+
cwd: config.repoRoot,
|
|
91
|
+
env: session ? { ...env, SYSTEM1_SESSION: session } : env,
|
|
92
|
+
...options.home ? { home: options.home } : {},
|
|
93
|
+
...options.fetch ? { fetch: options.fetch } : {}
|
|
94
|
+
},
|
|
95
|
+
harness,
|
|
96
|
+
pack: settings,
|
|
97
|
+
event,
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
now,
|
|
100
|
+
...options.mode ? { mode: options.mode } : {}
|
|
101
|
+
};
|
|
102
|
+
if (event.hook_event_name === "SessionStart")
|
|
103
|
+
return mod.sessionStart(ctx);
|
|
104
|
+
if (event.hook_event_name === "Stop")
|
|
105
|
+
return mod.stop(ctx);
|
|
106
|
+
return {};
|
|
107
|
+
})().catch((error) => say(pack, `not checked: ${failOpenReason(error, latencyMs)}`));
|
|
108
|
+
try {
|
|
109
|
+
return await Promise.race([work, deadline]);
|
|
110
|
+
} finally {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function failOpenReason(error, latencyMs) {
|
|
115
|
+
if (error?.name === "AbortError")
|
|
116
|
+
return `it took longer than ${latencyMs} ms (latencyMs)`;
|
|
117
|
+
if (!isDecisionsError(error))
|
|
118
|
+
return "an internal error; run `decide doctor`";
|
|
119
|
+
switch (error.code) {
|
|
120
|
+
case "egress-refused":
|
|
121
|
+
return "this repo has no egress consent";
|
|
122
|
+
case "no-key":
|
|
123
|
+
return "no API key is set";
|
|
124
|
+
case "provider-unreachable":
|
|
125
|
+
case "provider-http":
|
|
126
|
+
case "malformed-response":
|
|
127
|
+
case "unknown-model":
|
|
128
|
+
return `the decision model's provider failed (${error.code})`;
|
|
129
|
+
case "replay-miss":
|
|
130
|
+
return "replay is forced (SYSTEM1_REPLAY) and has no recorded answer";
|
|
131
|
+
case "budget-exceeded":
|
|
132
|
+
return error.message.split("\n")[0] ?? "the spend cap was reached";
|
|
133
|
+
case "state-too-large":
|
|
134
|
+
return "the change is too large to send";
|
|
135
|
+
case "source-error":
|
|
136
|
+
return `git failed (${error.message})`;
|
|
137
|
+
case "invalid-request":
|
|
138
|
+
case "config-error":
|
|
139
|
+
return error.message.split("\n")[0] ?? error.code;
|
|
140
|
+
default:
|
|
141
|
+
return "an internal error; run `decide doctor`";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/commands/hook.ts
|
|
146
|
+
var HOOK_OPTIONS = { harness: { type: "string" } };
|
|
147
|
+
var MAX_EVENT_BYTES = 1024 * 1024;
|
|
148
|
+
async function runHookCommand(argv, io) {
|
|
149
|
+
io.out(JSON.stringify(await respond(argv, io)));
|
|
150
|
+
io.exitWhenFlushed?.();
|
|
151
|
+
return EXIT.ok;
|
|
152
|
+
}
|
|
153
|
+
async function respond(argv, io) {
|
|
154
|
+
let pack;
|
|
155
|
+
let harness;
|
|
156
|
+
try {
|
|
157
|
+
const { values, positionals } = typedParse({
|
|
158
|
+
args: argv,
|
|
159
|
+
allowPositionals: true,
|
|
160
|
+
options: HOOK_OPTIONS
|
|
161
|
+
});
|
|
162
|
+
pack = positionals[0];
|
|
163
|
+
harness = values.harness;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return { systemMessage: `System 1 hook: not run: ${error.message}` };
|
|
166
|
+
}
|
|
167
|
+
if (!pack) return { systemMessage: "System 1 hook: not run: name a guard pack" };
|
|
168
|
+
if (harness !== void 0 && harness !== "claude" && harness !== "codex") {
|
|
169
|
+
return { systemMessage: `System 1 ${pack}: not run: --harness must be claude or codex` };
|
|
170
|
+
}
|
|
171
|
+
let event;
|
|
172
|
+
try {
|
|
173
|
+
const text = (io.readStdin ?? (() => readFileSync(0, "utf8")))();
|
|
174
|
+
if (Buffer.byteLength(text) > MAX_EVENT_BYTES) throw new Error("too large");
|
|
175
|
+
event = JSON.parse(text);
|
|
176
|
+
} catch {
|
|
177
|
+
event = void 0;
|
|
178
|
+
}
|
|
179
|
+
return runHook(pack, event, {
|
|
180
|
+
env: io.env,
|
|
181
|
+
...io.cwd ? { cwd: io.cwd } : {},
|
|
182
|
+
...io.home ? { home: io.home } : {},
|
|
183
|
+
...harness ? { harness } : {}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
HOOK_OPTIONS,
|
|
188
|
+
runHookCommand
|
|
189
|
+
};
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
typedParse
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
5
5
|
import {
|
|
6
|
-
TOOL_SCHEMAS,
|
|
7
|
-
createContext,
|
|
8
|
-
loadConfig,
|
|
9
6
|
ping,
|
|
10
7
|
probeUrl,
|
|
11
8
|
resolveConnection,
|
|
12
9
|
runUsage
|
|
13
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-45YUIPYC.mjs";
|
|
11
|
+
import {
|
|
12
|
+
TOOL_SCHEMAS,
|
|
13
|
+
createContext,
|
|
14
|
+
loadConfig
|
|
15
|
+
} from "./chunk-TMAJXDTE.mjs";
|
|
16
|
+
import {
|
|
17
|
+
emit
|
|
18
|
+
} from "./chunk-WVMA3PGV.mjs";
|
|
19
|
+
import {
|
|
20
|
+
EXIT
|
|
21
|
+
} from "./chunk-7OZLIHEM.mjs";
|
|
14
22
|
import {
|
|
15
23
|
DecisionsError,
|
|
16
|
-
EXIT,
|
|
17
|
-
emit,
|
|
18
24
|
isDecisionsError
|
|
19
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
20
26
|
|
|
21
27
|
// src/commands/misc.ts
|
|
22
28
|
function runSchemaCommand(argv, io, format) {
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
typedParse
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
5
5
|
import {
|
|
6
|
-
createContext,
|
|
7
6
|
runOpportunitiesAdd,
|
|
8
7
|
runOpportunitiesCheck,
|
|
9
8
|
runOpportunitiesList
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-45YUIPYC.mjs";
|
|
10
|
+
import {
|
|
11
|
+
createContext
|
|
12
|
+
} from "./chunk-TMAJXDTE.mjs";
|
|
11
13
|
import {
|
|
12
|
-
DecisionsError,
|
|
13
14
|
emit
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-WVMA3PGV.mjs";
|
|
16
|
+
import "./chunk-7OZLIHEM.mjs";
|
|
17
|
+
import {
|
|
18
|
+
DecisionsError
|
|
19
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
15
20
|
|
|
16
21
|
// src/commands/opportunities.ts
|
|
17
22
|
import { readFileSync } from "node:fs";
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
typedParse
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
5
5
|
import {
|
|
6
6
|
runRoute
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-45YUIPYC.mjs";
|
|
8
|
+
import "./chunk-TMAJXDTE.mjs";
|
|
8
9
|
import {
|
|
9
|
-
DecisionsError,
|
|
10
10
|
emit
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-WVMA3PGV.mjs";
|
|
12
|
+
import "./chunk-7OZLIHEM.mjs";
|
|
13
|
+
import {
|
|
14
|
+
DecisionsError
|
|
15
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
12
16
|
|
|
13
17
|
// src/commands/route.ts
|
|
14
18
|
import { readFileSync } from "node:fs";
|
|
@@ -5,21 +5,27 @@ import {
|
|
|
5
5
|
} from "./chunk-FU3D2MBS.mjs";
|
|
6
6
|
import {
|
|
7
7
|
typedParse
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-SUUJE62R.mjs";
|
|
9
|
+
import {
|
|
10
|
+
runSpecCheck,
|
|
11
|
+
runSpecLint
|
|
12
|
+
} from "./chunk-45YUIPYC.mjs";
|
|
9
13
|
import {
|
|
10
14
|
assertExamples,
|
|
11
15
|
createContext,
|
|
12
16
|
exampleProblems,
|
|
13
17
|
listSpecs,
|
|
14
|
-
loadSpec
|
|
15
|
-
|
|
16
|
-
runSpecLint
|
|
17
|
-
} from "./chunk-QYUSJUFX.mjs";
|
|
18
|
+
loadSpec
|
|
19
|
+
} from "./chunk-TMAJXDTE.mjs";
|
|
18
20
|
import {
|
|
19
|
-
DecisionsError,
|
|
20
|
-
EXIT,
|
|
21
21
|
emit
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-WVMA3PGV.mjs";
|
|
23
|
+
import {
|
|
24
|
+
EXIT
|
|
25
|
+
} from "./chunk-7OZLIHEM.mjs";
|
|
26
|
+
import {
|
|
27
|
+
DecisionsError
|
|
28
|
+
} from "./chunk-MH6THLCO.mjs";
|
|
23
29
|
|
|
24
30
|
// src/commands/spec.ts
|
|
25
31
|
function runSpecCommand(argv, io, format) {
|
package/dist/bundle/decide.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { createRequire as __decideRequire } from "node:module"; const require = __decideRequire(import.meta.url);
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
-
try {
|
|
16
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
throw mod = 0, e;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
25
|
-
var __copyProps = (to, from, except, desc) => {
|
|
26
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
-
for (let key of __getOwnPropNames(from))
|
|
28
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
-
mod
|
|
40
|
-
));
|
|
41
|
-
|
|
42
|
-
// ../core/dist/errors.js
|
|
43
|
-
var DecisionsError = class extends Error {
|
|
44
|
-
code;
|
|
45
|
-
details;
|
|
46
|
-
constructor(code, message, details = {}) {
|
|
47
|
-
super(message);
|
|
48
|
-
this.code = code;
|
|
49
|
-
this.details = details;
|
|
50
|
-
this.name = "DecisionsError";
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var ProviderError = class extends DecisionsError {
|
|
54
|
-
status;
|
|
55
|
-
constructor(code, message, status) {
|
|
56
|
-
super(code, message, status === void 0 ? {} : { status });
|
|
57
|
-
this.status = status;
|
|
58
|
-
this.name = "ProviderError";
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
function isDecisionsError(error) {
|
|
62
|
-
return error instanceof DecisionsError;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// src/exit-codes.ts
|
|
66
|
-
var EXIT = {
|
|
67
|
-
ok: 0,
|
|
68
|
-
failure: 1,
|
|
69
|
-
usage: 2,
|
|
70
|
-
egressRefused: 3,
|
|
71
|
-
budgetGuard: 4,
|
|
72
|
-
providerError: 5,
|
|
73
|
-
replayMiss: 6,
|
|
74
|
-
/**
|
|
75
|
-
* The check ran and did not pass: `spec check --strict` (an example missed),
|
|
76
|
-
* or `spec lint` (an error-level finding or invalid spec; with `--strict`, any
|
|
77
|
-
* warning).
|
|
78
|
-
*/
|
|
79
|
-
checkFailed: 7
|
|
80
|
-
};
|
|
81
|
-
var BY_CODE = {
|
|
82
|
-
"invalid-request": EXIT.usage,
|
|
83
|
-
"state-too-large": EXIT.usage,
|
|
84
|
-
"unknown-model": EXIT.usage,
|
|
85
|
-
"config-error": EXIT.usage,
|
|
86
|
-
"source-error": EXIT.usage,
|
|
87
|
-
"no-key": EXIT.usage,
|
|
88
|
-
"egress-refused": EXIT.egressRefused,
|
|
89
|
-
"budget-exceeded": EXIT.budgetGuard,
|
|
90
|
-
"provider-unreachable": EXIT.providerError,
|
|
91
|
-
"provider-http": EXIT.providerError,
|
|
92
|
-
"malformed-response": EXIT.providerError,
|
|
93
|
-
"replay-miss": EXIT.replayMiss
|
|
94
|
-
};
|
|
95
|
-
function exitFor(code) {
|
|
96
|
-
return code === "error" ? EXIT.failure : BY_CODE[code];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// src/envelope.ts
|
|
100
|
-
var ENVELOPE_VERSION = 1;
|
|
101
|
-
var FORMATS = ["json", "jsonl", "brief"];
|
|
102
|
-
function ok(command, result) {
|
|
103
|
-
return { v: ENVELOPE_VERSION, ok: true, command, result };
|
|
104
|
-
}
|
|
105
|
-
function fail(command, code, message, details) {
|
|
106
|
-
return {
|
|
107
|
-
v: ENVELOPE_VERSION,
|
|
108
|
-
ok: false,
|
|
109
|
-
command,
|
|
110
|
-
error: { code, message, ...details && Object.keys(details).length ? { details } : {} }
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// src/run.ts
|
|
115
|
-
async function emit(io, command, format, body, render = () => void 0) {
|
|
116
|
-
try {
|
|
117
|
-
const result = await body();
|
|
118
|
-
io.out(render(result, format) ?? JSON.stringify(ok(command, result)));
|
|
119
|
-
return EXIT.ok;
|
|
120
|
-
} catch (error) {
|
|
121
|
-
const code = isDecisionsError(error) ? error.code : "error";
|
|
122
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
-
const details = isDecisionsError(error) ? error.details : void 0;
|
|
124
|
-
io.out(
|
|
125
|
-
format === "brief" ? `decide ${command}: error ${code} \u2014 ${message}` : JSON.stringify(fail(command, code, message, details))
|
|
126
|
-
);
|
|
127
|
-
if (!isDecisionsError(error) && error instanceof Error && io.env.SYSTEM1_DEBUG)
|
|
128
|
-
io.err(error.stack ?? "");
|
|
129
|
-
return exitFor(code);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function extractFormat(argv, fallback) {
|
|
133
|
-
const rest = [];
|
|
134
|
-
let format;
|
|
135
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
136
|
-
const arg = argv[i];
|
|
137
|
-
if (arg === "--format") {
|
|
138
|
-
format = argv[i + 1];
|
|
139
|
-
i += 1;
|
|
140
|
-
} else if (arg.startsWith("--format=")) {
|
|
141
|
-
format = arg.slice("--format=".length);
|
|
142
|
-
} else {
|
|
143
|
-
rest.push(arg);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (format === void 0) return { format: fallback, rest, explicit: false };
|
|
147
|
-
if (!FORMATS.includes(format)) {
|
|
148
|
-
throw new DecisionsError("invalid-request", `--format must be one of ${FORMATS.join(", ")}`);
|
|
149
|
-
}
|
|
150
|
-
return { format, rest, explicit: true };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ../core/dist/version.js
|
|
154
|
-
var VERSION = "0.4.0";
|
|
155
|
-
var CLI_PACKAGE = "@garygentry/system1";
|
|
156
|
-
|
|
157
|
-
export {
|
|
158
|
-
__require,
|
|
159
|
-
__commonJS,
|
|
160
|
-
__export,
|
|
161
|
-
__toESM,
|
|
162
|
-
DecisionsError,
|
|
163
|
-
ProviderError,
|
|
164
|
-
isDecisionsError,
|
|
165
|
-
VERSION,
|
|
166
|
-
CLI_PACKAGE,
|
|
167
|
-
EXIT,
|
|
168
|
-
ENVELOPE_VERSION,
|
|
169
|
-
emit,
|
|
170
|
-
extractFormat
|
|
171
|
-
};
|