@sabaiway/agent-workflow-kit 23.3.1 → 23.4.1

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 (54) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +1 -1
  4. package/bridges/antigravity-cli-bridge/SKILL.md +2 -2
  5. package/bridges/antigravity-cli-bridge/bin/agy-review-harness.test.mjs +7 -1
  6. package/bridges/antigravity-cli-bridge/bin/agy-review-honesty.test.mjs +2 -1
  7. package/bridges/antigravity-cli-bridge/bin/agy-review-model-screen.test.mjs +2 -1
  8. package/bridges/antigravity-cli-bridge/bin/agy-review.sh +18 -10
  9. package/bridges/antigravity-cli-bridge/bin/agy-review.test.mjs +50 -50
  10. package/bridges/antigravity-cli-bridge/bin/agy.sh +6 -2
  11. package/bridges/antigravity-cli-bridge/bin/agy.test.mjs +5 -5
  12. package/bridges/antigravity-cli-bridge/capability.json +2 -2
  13. package/bridges/antigravity-cli-bridge/references/models-and-flags.md +1 -1
  14. package/bridges/antigravity-cli-bridge/setup/README.md +1 -1
  15. package/bridges/codex-cli-bridge/SKILL.md +1 -1
  16. package/bridges/codex-cli-bridge/bin/codex-exec-jev.test.mjs +73 -93
  17. package/bridges/codex-cli-bridge/bin/codex-exec.sh +7 -3
  18. package/bridges/codex-cli-bridge/bin/codex-exec.test.mjs +6 -10
  19. package/bridges/codex-cli-bridge/bin/codex-fixtures-harness.test.mjs +77 -0
  20. package/bridges/codex-cli-bridge/bin/codex-fixtures.test.mjs +215 -0
  21. package/bridges/codex-cli-bridge/bin/codex-model-posture.test.mjs +18 -18
  22. package/bridges/codex-cli-bridge/bin/codex-review-honesty.test.mjs +2 -1
  23. package/bridges/codex-cli-bridge/bin/codex-review-jev.test.mjs +13 -13
  24. package/bridges/codex-cli-bridge/bin/codex-review.sh +17 -10
  25. package/bridges/codex-cli-bridge/bin/codex-review.test.mjs +30 -29
  26. package/bridges/codex-cli-bridge/capability.json +1 -1
  27. package/bridges/typesafe-jev-bridge/SKILL.md +19 -12
  28. package/bridges/typesafe-jev-bridge/bin/jev-ask-harness.test.mjs +109 -0
  29. package/bridges/typesafe-jev-bridge/bin/jev-ask.sh +9 -4
  30. package/bridges/typesafe-jev-bridge/bin/jev-ask.test.mjs +108 -104
  31. package/bridges/typesafe-jev-bridge/bin/jev-client.mjs +27 -13
  32. package/bridges/typesafe-jev-bridge/capability.json +11 -1
  33. package/capability.json +1 -1
  34. package/package.json +2 -1
  35. package/references/modes/bridge-settings.md +6 -5
  36. package/references/modes/coverage-check.md +1 -1
  37. package/tools/apply-danger-check.mjs +2 -2
  38. package/tools/bridge-settings-read.mjs +8 -3
  39. package/tools/bridge-settings.mjs +28 -43
  40. package/tools/coverage-check.mjs +9 -8
  41. package/tools/detect-backends.mjs +1 -1
  42. package/tools/distribution-files/retired.mjs +7 -7
  43. package/tools/distribution-files/scripts.mjs +10 -11
  44. package/tools/ensure-ops.mjs +21 -21
  45. package/tools/ensure-specs.mjs +10 -9
  46. package/tools/family-registry.mjs +4 -4
  47. package/tools/git-hooks.mjs +5 -5
  48. package/tools/manifest/schema.md +4 -1
  49. package/tools/manifest/validate.mjs +10 -0
  50. package/tools/node-evidence.mjs +14 -12
  51. package/tools/recommendations.mjs +2 -2
  52. package/tools/review-state-build.mjs +3 -2
  53. package/tools/review-state.mjs +1 -1
  54. package/tools/write-lanes.mjs +2 -2
@@ -2,7 +2,7 @@
2
2
  name: typesafe-jev-bridge
3
3
  description: Ask TypeSafe's Jev decision model a set of choice questions about a stated situation and get back typed notes, each with a choice, the probability of every option and a confidence. Use when a step wants a second, calibrated opinion as a note — never a verdict: the bridge moves no gate, review or commit.
4
4
  metadata:
5
- version: '1.0.1'
5
+ version: '1.1.0'
6
6
  ---
7
7
 
8
8
  # typesafe-jev-bridge
@@ -13,9 +13,14 @@ verdict, review or commit reads it, so the wrapper writes no file and mints no r
13
13
 
14
14
  ## The model
15
15
 
16
- The model is pinned in this folder's `capability.json`, at `posture.model`, and every request names
17
- it. No environment value, flag or request field moves it. An answer naming another model is refused
18
- (exit 7) and prints no note.
16
+ The model is the host setting `JEV_MODEL`, with this folder's `capability.json` `posture.model` as
17
+ the default and the calibrated version. `/agent-workflow-kit bridge-settings` shows the offered
18
+ versions and sets one. An environment value overrides the saved setting; an explicitly empty
19
+ `JEV_MODEL=` selects the default. Every request names the effective model, which must be offered
20
+ by the manifest. An answer naming another model is refused (exit 7) and prints no note.
21
+
22
+ Notes on another offered version are marked uncalibrated: the posture line carries `uncalibrated`
23
+ and the output document's `calibrated` is false. A run on `posture.model` carries `calibrated: true`.
19
24
 
20
25
  ## The key
21
26
 
@@ -44,27 +49,29 @@ The request file is one UTF-8 JSON object with exactly two keys:
44
49
  Before any request the wrapper bounds the request locally: the UTF-8 bytes of the compact JSON of
45
50
  `state` plus the largest `[id, question]` pair at most 30 000, the whole request body at most 60 000.
46
51
 
47
- When the request is sent, stderr opens with one posture line:
48
- `judge posture: model=<pinned id> host=<endpoint host> timeout=10s`. On exit 0 stdout carries one
49
- JSON document and one newline:
52
+ Before the request, stderr carries one posture line:
53
+ `judge posture: model=<requested id> source=model:<source> host=<endpoint host> timeout=10s`, where
54
+ the source is `default`, `setting` or `environment`. On an uncalibrated run, `uncalibrated` appears
55
+ between the source and `host=`. On exit 0 stdout carries one JSON document and one newline:
50
56
 
51
57
  ```json
52
- { "model": "<answering id>", "requestId": "<request id or null>", "notes": { "<question id>": { "choice": "…", "probabilities": { "…": 0.9 }, "confidence": 0.8 } } }
58
+ { "model": "<answering id>", "calibrated": true, "requestId": "<request id or null>", "notes": { "<question id>": { "choice": "…", "probabilities": { "…": 0.9 }, "confidence": 0.8 } } }
53
59
  ```
54
60
 
55
61
  ## Exit statuses
56
62
 
57
63
  A non-zero exit prints nothing on stdout and exactly one stderr line, after the posture line when
58
- the request was sent.
64
+ the request was sent. Any warning from the shared posture reader precedes these lines and is
65
+ outside that count.
59
66
 
60
67
  | Exit | Meaning |
61
68
  |------|---------|
62
69
  | 0 | the notes printed |
63
- | 2 | usage, or a request stopped before it is sent: an operand, a flag, an unreadable file, the request grammar or the size bound |
70
+ | 2 | usage, or a request stopped before it is sent: an operand, a flag, a model the manifest does not offer, an unreadable file, the request grammar or the size bound |
64
71
  | 3 | no key: the variable is unset, empty or blank; no request is made |
65
72
  | 4 | timeout: no complete answer within 10 seconds |
66
73
  | 5 | an HTTP status outside 2xx, a redirect included; the line names the status, the request id when the vendor sent one and, for 401, 422, 429 and 529, the cause |
67
74
  | 6 | a malformed answer |
68
- | 7 | the answer names another model than the pinned one |
75
+ | 7 | the answer names another model than the requested one |
69
76
  | 8 | the request failed before any status (name lookup, connection, TLS) |
70
- | 127 | the wrapper's own folder, its `service-facts.txt`, `node` on PATH or the pinned model could not be read |
77
+ | 127 | the wrapper's own folder, its `service-facts.txt`, `node` on PATH or the manifest's model could not be read, or the manifest lacks the `JEV_MODEL` entry or its non-empty offered list of strings |
@@ -0,0 +1,109 @@
1
+ import { after } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { chmodSync, cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
+ import { spawnSync } from 'node:child_process';
8
+
9
+ export const HERE = dirname(fileURLToPath(import.meta.url));
10
+ export const BRIDGE = resolve(HERE, '..');
11
+ export const REPO = resolve(BRIDGE, '..');
12
+ export const HOST = 'api.jev.invalid';
13
+ export const ENDPOINT = `https://${HOST}/v1/systemone`;
14
+ export const KEY_VARIABLE = 'TYPESAFE_API_KEY';
15
+ export const REQUEST_ID = 'req-1';
16
+ export const STATE_LIMIT = 30000;
17
+ export const BODY_LIMIT = 60000;
18
+ const made = [];
19
+ export const client = () => import('./jev-client.mjs');
20
+ export const read = (path) => readFileSync(path, 'utf8');
21
+ export const readManifest = () => JSON.parse(read(join(BRIDGE, 'capability.json')));
22
+ export const getModel = () => { const model = readManifest().posture?.model; assert.ok(model, 'capability.json posture.model is absent'); return model; };
23
+ export const getFacts = () => [read(join(REPO, 'codex-cli-bridge/service-facts.txt')).split('\n')[0], `HOST=${HOST}`, `RUN_HOST=${HOST}`, `PASSED_VARIABLE=${KEY_VARIABLE}`, ''].join('\n');
24
+ export const makeQuestion = (instructions = 'Choose the supported option.') => ({ type: 'choice', instructions, criteria: { yes: 'Supported', no: 'Unsupported' } });
25
+ export const makeRequest = () => ({ state: 'The build passed and the change is ready for review.', questions: { ready: makeQuestion(), safe: { ...makeQuestion(), criteria: { yes: 'Safe', no: 'Unsafe', unsure: 'Unclear' } } } });
26
+ export const makeAnswer = (model, request = makeRequest()) => ({ model, answers: Object.fromEntries(Object.entries(request.questions).map(([id, question]) => [id, { type: 'choice', choice: Object.keys(question.criteria)[0], probabilities: Object.fromEntries(Object.keys(question.criteria).map((option, index) => [option, index === 0 ? 1 : 0])), confidence: 0.9 }])) });
27
+ export const makeResponse = (body, status = 200, headers = { 'x-typesafe-request-id': REQUEST_ID }) => new Response(typeof body === 'string' ? body : JSON.stringify(body), { status, headers });
28
+ export const neverCall = () => assert.fail('transport must not be called');
29
+ export const makeArgv = (fixture, { model = '', source = 'default' } = {}) => ['--host', HOST, '--key-variable', KEY_VARIABLE, '--model', model, '--model-source', source, fixture.path];
30
+ export const makePosture = (model, source, calibrated = true) => `judge posture: model=${model} source=model:${source} ${calibrated ? '' : 'uncalibrated '}host=${HOST} timeout=10s`;
31
+ export const writeManifest = (fixture, manifest) => writeFileSync(join(fixture.root, 'capability.json'), typeof manifest === 'string' ? manifest : JSON.stringify(manifest));
32
+ export const writeSettings = (fixture, text) => {
33
+ const folder = join(fixture.env.HOME, '.config/agent-workflow');
34
+ mkdirSync(folder, { recursive: true });
35
+ const path = join(folder, 'bridge-settings.conf');
36
+ writeFileSync(path, text);
37
+ return path;
38
+ };
39
+ export const makeFixture = (context, wrapper = false) => {
40
+ if (wrapper) read(join(HERE, 'jev-ask.sh'));
41
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'jev-ask-')));
42
+ made.push(root);
43
+ const home = join(root, 'home');
44
+ mkdirSync(home);
45
+ if (wrapper) cpSync(HERE, join(root, 'bin'), { recursive: true });
46
+ cpSync(join(BRIDGE, 'capability.json'), join(root, 'capability.json'));
47
+ writeFileSync(join(root, 'service-facts.txt'), getFacts());
48
+ const path = join(root, 'request.json');
49
+ writeFileSync(path, JSON.stringify(makeRequest()));
50
+ const key = `tsk-test-${Buffer.from(context.name).toString('hex')}-${'Q7xZp3'.repeat(6)}`;
51
+ const preload = join(root, 'no-network.mjs');
52
+ writeFileSync(preload, "globalThis.fetch = async () => { throw new Error('unexpected transport call'); };\n");
53
+ const env = { PATH: process.env.PATH ?? '', HOME: home, LC_ALL: 'C', [KEY_VARIABLE]: key, NODE_OPTIONS: `--import=${pathToFileURL(preload).href}` };
54
+ return { root, path, key, env, argv: makeArgv({ path }) };
55
+ };
56
+ after(() => made.forEach((root) => rmSync(root, { recursive: true, force: true })));
57
+ export const assertOutcome = (result, key, code, posture = false, shared = false, warnings = 0) => {
58
+ assert.equal(result.code, code, result.stderr);
59
+ for (const stream of [result.stdout, result.stderr]) { assert.equal(typeof stream, 'string'); assert.equal(stream.includes(key.trim()), false, 'key leaked'); }
60
+ const lines = result.stderr === '' ? [] : result.stderr.split('\n').slice(0, -1);
61
+ assert.equal(result.stderr, lines.length ? `${lines.join('\n')}\n` : '');
62
+ assert.equal(lines.length, warnings + Number(posture) + Number(code !== 0), result.stderr);
63
+ for (const line of lines.slice(0, warnings)) {
64
+ assert.match(line, /^warning: /);
65
+ assert.doesNotMatch(line, /[\x00-\x1f\x7f-\x9f\u2028\u2029]/u);
66
+ }
67
+ if (posture) assert.match(lines[warnings], /^judge posture: /);
68
+ if (code !== 0) { assert.equal(result.stdout, ''); assert.match(lines.at(-1), shared ? /^error: / : /^jev-ask: /); }
69
+ return result;
70
+ };
71
+ export const runClient = async (cli, fixture, code, options = {}, posture = false, warnings = 0) => {
72
+ const calls = [];
73
+ const transport = (...args) => { calls.push(args); return (options.transport ?? neverCall)(...args); };
74
+ const result = await cli.runJudgeCli({ argv: fixture.argv, env: fixture.env, folder: fixture.root, ...options, transport });
75
+ assertOutcome(result, fixture.key, code, posture, false, warnings);
76
+ assert.equal(calls.length, Number(posture), 'one request only after posture');
77
+ return result;
78
+ };
79
+ export const runWrapper = (fixture, argv, code, overrides = {}, posture = false, shared = false, bash = 'bash', warnings = 0) => {
80
+ const result = spawnSync(bash, [join(fixture.root, 'bin/jev-ask.sh'), ...argv], { cwd: fixture.root, env: { ...fixture.env, ...overrides }, encoding: 'utf8', timeout: 5000 });
81
+ assert.ifError(result.error);
82
+ assert.equal(result.signal, null, result.stderr);
83
+ return assertOutcome({ code: result.status, stdout: result.stdout, stderr: result.stderr }, fixture.key, code, posture, shared, warnings);
84
+ };
85
+ export const addPreload = (fixture, body, status = 200) => {
86
+ const log = join(fixture.root, 'fetch.log');
87
+ const preload = join(fixture.root, 'preload.mjs');
88
+ writeFileSync(preload, `import { appendFileSync } from 'node:fs';\nglobalThis.fetch = async (url, init) => { appendFileSync(${JSON.stringify(log)}, JSON.stringify({ url: String(url), model: JSON.parse(init.body).model }) + '\\n'); return new Response(${JSON.stringify(typeof body === 'string' ? body : JSON.stringify(body))}, { status: ${status}, headers: { 'x-typesafe-request-id': '${REQUEST_ID}' } }); };\n`);
89
+ return { NODE_OPTIONS: `--import=${pathToFileURL(preload).href}`, log };
90
+ };
91
+ export const addRecordingNode = (fixture) => {
92
+ const bin = join(fixture.root, 'recording');
93
+ mkdirSync(bin);
94
+ const argv = join(fixture.root, 'node.argv');
95
+ const env = join(fixture.root, 'node.env');
96
+ const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
97
+ writeFileSync(join(bin, 'node'), `#!/usr/bin/env bash\nprintf '%s\\n' "$@" > ${quote(argv)}\nprintf '%s' "\${TYPESAFE_API_KEY-}" > ${quote(env)}\nexec ${quote(process.execPath)} "$@"\n`);
98
+ chmodSync(join(bin, 'node'), 0o755);
99
+ return { PATH: `${bin}:${fixture.env.PATH}`, argv, env };
100
+ };
101
+ export const listFiles = (root, relative = '') => readdirSync(join(root, relative), { withFileTypes: true }).flatMap((entry) => entry.name === 'node_modules' ? [] : entry.isDirectory() ? listFiles(root, join(relative, entry.name)) : [join(relative, entry.name)]).sort();
102
+ export const scanFolder = (root) => {
103
+ const files = listFiles(root).filter((file) => !file.endsWith('.test.mjs'));
104
+ const hits = files.flatMap((file) => {
105
+ const text = read(join(root, file));
106
+ return [file !== 'service-facts.txt' && /[a-z0-9.-]*typesafe\.ai\b/i.test(text) ? `${file}: host` : null, file !== 'capability.json' && /\bjev-(?:\d+(?:\.\d+)*|latest|preview)\b/i.test(text) ? `${file}: model` : null].filter(Boolean);
107
+ });
108
+ return { files, hits };
109
+ };
@@ -77,7 +77,7 @@ aw_settings_file() {
77
77
  printf '%s/agent-workflow/bridge-settings.conf' "${XDG_CONFIG_HOME:-$HOME/.config}"
78
78
  }
79
79
  aw_settings_known() {
80
- case " CODEX_SERVICE_TIER CODEX_HARD_TIMEOUT CODEX_REVIEW_MAX_TOTAL_BYTES AGY_HARD_TIMEOUT AGY_REVIEW_ALLOW_ADDDIR AGY_REVIEW_MAX_TOTAL_BYTES CODEX_MODEL CODEX_EFFORT AGY_MODEL " in
80
+ case " CODEX_SERVICE_TIER CODEX_HARD_TIMEOUT CODEX_REVIEW_MAX_TOTAL_BYTES AGY_HARD_TIMEOUT AGY_REVIEW_ALLOW_ADDDIR AGY_REVIEW_MAX_TOTAL_BYTES CODEX_MODEL CODEX_EFFORT AGY_MODEL JEV_MODEL " in
81
81
  *" $1 "*) return 0 ;;
82
82
  *) return 1 ;;
83
83
  esac
@@ -177,7 +177,11 @@ aw_read_posture() {
177
177
  AW_HOST_VALUE="$value"
178
178
  AW_HOST_SOURCE="setting"
179
179
  elif (( notify )); then
180
- echo "warning: $key in bridge settings file '$file' is empty or carries a control byte — using the built-in default '$default'." >&2
180
+ if [[ -n "$default" ]]; then
181
+ echo "warning: $key in bridge settings file '$file' is empty or carries a control byte — using the built-in default '$default'." >&2
182
+ else
183
+ echo "warning: $key in bridge settings file '$file' is empty or carries a control byte — using the manifest's default." >&2
184
+ fi
181
185
  fi
182
186
  fi
183
187
  fi
@@ -244,7 +248,7 @@ aw_scrub_billing_keys() {
244
248
  return 0
245
249
  }
246
250
 
247
- AW_BRIDGE_VERSION="1.0.1" # aw-version-anchor
251
+ AW_BRIDGE_VERSION="1.1.0" # aw-version-anchor
248
252
  case "${1:-}" in
249
253
  --help|-h)
250
254
  printf '%s\n' "jev-ask — judge notes through typesafe-jev-bridge $AW_BRIDGE_VERSION." '' \
@@ -269,9 +273,10 @@ if (( ${#AW_FACT_PASSED_VARIABLE[@]} == 0 )); then
269
273
  exit 127
270
274
  fi
271
275
  aw_scrub_billing_keys
276
+ aw_read_posture JEV_MODEL "" ""
272
277
  if ! command -v node >/dev/null 2>&1; then
273
278
  printf '%s\n' 'jev-ask: node not found on PATH; install Node.js 22.21 or newer' >&2
274
279
  exit 127
275
280
  fi
276
281
  export NODE_USE_ENV_PROXY=1
277
- exec node --disable-warning=UNDICI-EHPA "$HERE/jev-client.mjs" --host "${AW_FACT_RUN_HOST[0]}" --key-variable "${AW_FACT_PASSED_VARIABLE[0]}" "$1"
282
+ exec node --disable-warning=UNDICI-EHPA "$HERE/jev-client.mjs" --host "${AW_FACT_RUN_HOST[0]}" --key-variable "${AW_FACT_PASSED_VARIABLE[0]}" --model "$AW_RUN_VALUE" --model-source "$AW_RUN_SOURCE" "$1"
@@ -1,100 +1,16 @@
1
- import { describe, it, after } from 'node:test';
1
+ import { describe, it } from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import { chmodSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { dirname, join, resolve } from 'node:path';
6
- import { fileURLToPath, pathToFileURL } from 'node:url';
7
- import { spawn, spawnSync } from 'node:child_process';
3
+ import { existsSync, mkdirSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { spawn } from 'node:child_process';
8
6
  import { createServer } from 'node:http';
9
7
  import { once } from 'node:events';
10
-
11
- const HERE = dirname(fileURLToPath(import.meta.url));
12
- const BRIDGE = resolve(HERE, '..');
13
- const REPO = resolve(BRIDGE, '..');
14
- const HOST = 'api.jev.invalid';
15
- const ENDPOINT = `https://${HOST}/v1/systemone`;
16
- const KEY_VARIABLE = 'TYPESAFE_API_KEY';
17
- const REQUEST_ID = 'req-1';
18
- const STATE_LIMIT = 30000;
19
- const BODY_LIMIT = 60000;
20
- const made = [];
21
- const client = () => import('./jev-client.mjs');
22
- const read = (path) => readFileSync(path, 'utf8');
23
- const readManifest = () => JSON.parse(read(join(BRIDGE, 'capability.json')));
24
- const getModel = () => { const model = readManifest().posture?.model; assert.ok(model, 'capability.json posture.model is absent'); return model; };
25
- const getFacts = () => [read(join(REPO, 'codex-cli-bridge/service-facts.txt')).split('\n')[0], `HOST=${HOST}`, `RUN_HOST=${HOST}`, `PASSED_VARIABLE=${KEY_VARIABLE}`, ''].join('\n');
26
- const makeQuestion = (instructions = 'Choose the supported option.') => ({ type: 'choice', instructions, criteria: { yes: 'Supported', no: 'Unsupported' } });
27
- const makeRequest = () => ({ state: 'The build passed and the change is ready for review.', questions: { ready: makeQuestion(), safe: { ...makeQuestion(), criteria: { yes: 'Safe', no: 'Unsafe', unsure: 'Unclear' } } } });
28
- const makeAnswer = (model, request = makeRequest()) => ({ model, answers: Object.fromEntries(Object.entries(request.questions).map(([id, question]) => [id, { type: 'choice', choice: Object.keys(question.criteria)[0], probabilities: Object.fromEntries(Object.keys(question.criteria).map((option, index) => [option, index === 0 ? 1 : 0])), confidence: 0.9 }])) });
29
- const makeResponse = (body, status = 200, headers = { 'x-typesafe-request-id': REQUEST_ID }) => new Response(typeof body === 'string' ? body : JSON.stringify(body), { status, headers });
30
- const neverCall = () => assert.fail('transport must not be called');
31
- const makeFixture = (context, wrapper = false) => {
32
- if (wrapper) read(join(HERE, 'jev-ask.sh'));
33
- const root = realpathSync(mkdtempSync(join(tmpdir(), 'jev-ask-')));
34
- made.push(root);
35
- const home = join(root, 'home');
36
- mkdirSync(home);
37
- if (wrapper) cpSync(HERE, join(root, 'bin'), { recursive: true });
38
- cpSync(join(BRIDGE, 'capability.json'), join(root, 'capability.json'));
39
- writeFileSync(join(root, 'service-facts.txt'), getFacts());
40
- const path = join(root, 'request.json');
41
- writeFileSync(path, JSON.stringify(makeRequest()));
42
- const key = `tsk-test-${Buffer.from(context.name).toString('hex')}-${'Q7xZp3'.repeat(6)}`;
43
- const preload = join(root, 'no-network.mjs');
44
- writeFileSync(preload, "globalThis.fetch = async () => { throw new Error('unexpected transport call'); };\n");
45
- const env = { PATH: process.env.PATH ?? '', HOME: home, LC_ALL: 'C', [KEY_VARIABLE]: key, NODE_OPTIONS: `--import=${pathToFileURL(preload).href}` };
46
- return { root, path, key, env, argv: ['--host', HOST, '--key-variable', KEY_VARIABLE, path] };
47
- };
48
- after(() => made.forEach((root) => rmSync(root, { recursive: true, force: true })));
49
- const assertOutcome = (result, key, code, posture = false, shared = false) => {
50
- assert.equal(result.code, code, result.stderr);
51
- for (const stream of [result.stdout, result.stderr]) { assert.equal(typeof stream, 'string'); assert.equal(stream.includes(key.trim()), false, 'key leaked'); }
52
- const lines = result.stderr === '' ? [] : result.stderr.split('\n').slice(0, -1);
53
- assert.equal(result.stderr, lines.length ? `${lines.join('\n')}\n` : '');
54
- assert.equal(lines.length, Number(posture) + Number(code !== 0), result.stderr);
55
- if (posture) assert.match(lines[0], /^judge posture: /);
56
- if (code !== 0) { assert.equal(result.stdout, ''); assert.match(lines.at(-1), shared ? /^error: / : /^jev-ask: /); }
57
- return result;
58
- };
59
- const runClient = async (cli, fixture, code, options = {}, posture = false) => {
60
- const calls = [];
61
- const transport = (...args) => { calls.push(args); return (options.transport ?? neverCall)(...args); };
62
- const result = await cli.runJudgeCli({ argv: fixture.argv, env: fixture.env, folder: fixture.root, ...options, transport });
63
- assertOutcome(result, fixture.key, code, posture);
64
- assert.equal(calls.length, Number(posture), 'one request only after posture');
65
- return result;
66
- };
67
- const runWrapper = (fixture, argv, code, overrides = {}, posture = false, shared = false, bash = 'bash') => {
68
- const result = spawnSync(bash, [join(fixture.root, 'bin/jev-ask.sh'), ...argv], { cwd: fixture.root, env: { ...fixture.env, ...overrides }, encoding: 'utf8', timeout: 5000 });
69
- assert.ifError(result.error);
70
- assert.equal(result.signal, null, result.stderr);
71
- return assertOutcome({ code: result.status, stdout: result.stdout, stderr: result.stderr }, fixture.key, code, posture, shared);
72
- };
73
- const addPreload = (fixture, body, status = 200) => {
74
- const log = join(fixture.root, 'fetch.log');
75
- const preload = join(fixture.root, 'preload.mjs');
76
- writeFileSync(preload, `import { appendFileSync } from 'node:fs';\nglobalThis.fetch = async (url) => { appendFileSync(${JSON.stringify(log)}, String(url) + '\\n'); return new Response(${JSON.stringify(JSON.stringify(body))}, { status: ${status}, headers: { 'x-typesafe-request-id': '${REQUEST_ID}' } }); };\n`);
77
- return { NODE_OPTIONS: `--import=${pathToFileURL(preload).href}`, log };
78
- };
79
- const addRecordingNode = (fixture) => {
80
- const bin = join(fixture.root, 'recording');
81
- mkdirSync(bin);
82
- const argv = join(fixture.root, 'node.argv');
83
- const env = join(fixture.root, 'node.env');
84
- const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
85
- writeFileSync(join(bin, 'node'), `#!/usr/bin/env bash\nprintf '%s\\n' "$@" > ${quote(argv)}\nprintf '%s' "\${TYPESAFE_API_KEY-}" > ${quote(env)}\nexec ${quote(process.execPath)} "$@"\n`);
86
- chmodSync(join(bin, 'node'), 0o755);
87
- return { PATH: `${bin}:${fixture.env.PATH}`, argv, env };
88
- };
89
- const listFiles = (root, relative = '') => readdirSync(join(root, relative), { withFileTypes: true }).flatMap((entry) => entry.name === 'node_modules' ? [] : entry.isDirectory() ? listFiles(root, join(relative, entry.name)) : [join(relative, entry.name)]).sort();
90
- const scanFolder = (root) => {
91
- const files = listFiles(root).filter((file) => !file.endsWith('.test.mjs'));
92
- const hits = files.flatMap((file) => {
93
- const text = read(join(root, file));
94
- return [file !== 'service-facts.txt' && /[a-z0-9.-]*typesafe\.ai\b/i.test(text) ? `${file}: host` : null, file !== 'capability.json' && /\bjev-(?:\d+(?:\.\d+)*|latest)\b/i.test(text) ? `${file}: model` : null].filter(Boolean);
95
- });
96
- return { files, hits };
97
- };
8
+ import {
9
+ HERE, BRIDGE, REPO, HOST, ENDPOINT, KEY_VARIABLE, REQUEST_ID, STATE_LIMIT, BODY_LIMIT,
10
+ client, read, readManifest, getModel, getFacts, makeQuestion, makeRequest, makeAnswer, makeResponse,
11
+ neverCall, makeArgv, makePosture, writeManifest, writeSettings, makeFixture, assertOutcome,
12
+ runClient, runWrapper, addPreload, addRecordingNode, listFiles, scanFolder,
13
+ } from './jev-ask-harness.test.mjs';
98
14
 
99
15
  it('spec:typesafe-jev-bridge/S1 posts the pinned two-question request and prints only normalized notes', async (context) => {
100
16
  const cli = await client();
@@ -105,9 +21,9 @@ it('spec:typesafe-jev-bridge/S1 posts the pinned two-question request and prints
105
21
  const answer = makeAnswer(model);
106
22
  const transport = async (...args) => { calls.push(args); return makeResponse(answer, 200, requestId ? { 'x-typesafe-request-id': requestId } : {}); };
107
23
  const result = await runClient(cli, fixture, 0, { env: { [KEY_VARIABLE]: ` ${fixture.key} ` }, transport }, true);
108
- assert.equal(result.stderr, `judge posture: model=${model} host=${HOST} timeout=10s\n`);
24
+ assert.equal(result.stderr, `${makePosture(model, 'default')}\n`);
109
25
  assert.match(result.stdout, /[^\n]\n$/);
110
- assert.deepEqual(JSON.parse(result.stdout), { model, requestId, notes: Object.fromEntries(Object.entries(answer.answers).map(([id, { type, ...note }]) => [id, note])) });
26
+ assert.deepEqual(JSON.parse(result.stdout), { model, calibrated: true, requestId, notes: Object.fromEntries(Object.entries(answer.answers).map(([id, { type, ...note }]) => [id, note])) });
111
27
  assert.equal(calls.length, 1);
112
28
  const [url, init] = calls[0];
113
29
  assert.equal(String(url), ENDPOINT);
@@ -266,8 +182,13 @@ describe('spec:typesafe-jev-bridge/S10 every missing facts line, manifest model
266
182
  const cli = await client();
267
183
  const fixture = makeFixture(context);
268
184
  const path = join(fixture.root, 'capability.json');
269
- for (const body of [null, '{not json', '{}', JSON.stringify({ posture: { model: '' } })]) {
270
- if (body === null) rmSync(path); else writeFileSync(path, body);
185
+ const manifest = { ...readManifest(), settings: [{ key: 'JEV_MODEL', kind: 'posture', default: getModel(), appliesTo: ['jev-ask'], effect: 'Selects the judge model.', offered: [getModel(), 'jev-1.14.0'] }] };
186
+ const { settings, ...withoutSettings } = manifest;
187
+ const { offered, ...withoutOffered } = settings[0];
188
+ const invalid = [null, '{not json', {}, { posture: { model: '' } }, withoutSettings, { ...manifest, settings: [] },
189
+ { ...manifest, settings: [withoutOffered] }, ...[[], 'jev-1.14.0', [13]].map((offered) => ({ ...manifest, settings: [{ ...settings[0], offered }] }))];
190
+ for (const body of invalid) {
191
+ if (body === null) rmSync(path); else writeManifest(fixture, body);
271
192
  const result = await runClient(cli, fixture, 127);
272
193
  assert.ok(result.stderr.includes(path));
273
194
  }
@@ -278,7 +199,7 @@ describe('spec:typesafe-jev-bridge/S11 the posture line precedes the request and
278
199
  const cli = await client();
279
200
  const fixture = makeFixture(context);
280
201
  const result = await runClient(cli, fixture, 8, { transport: async () => { throw new TypeError(`failed ${fixture.key}\nagain`, { cause: new Error(`cause ${fixture.key}\nagain`) }); } }, true);
281
- assert.equal(result.stderr.split('\n')[0], `judge posture: model=${getModel()} host=${HOST} timeout=10s`);
202
+ assert.equal(result.stderr.split('\n')[0], makePosture(getModel(), 'default'));
282
203
  });
283
204
  it('removes a key of any bytes from outside text before it is made one line or encoded', async (context) => {
284
205
  const cli = await client();
@@ -309,7 +230,7 @@ describe('spec:typesafe-jev-bridge/S11 the posture line precedes the request and
309
230
  const argv = read(recording.argv);
310
231
  assert.equal(argv.includes(fixture.key), false);
311
232
  assert.deepEqual(argv.split('\n').slice(0, -1), ['--disable-warning=UNDICI-EHPA', join(fixture.root, 'bin/jev-client.mjs'), ...fixture.argv]);
312
- assert.equal(read(preload.log), `${ENDPOINT}\n`);
233
+ assert.equal(read(preload.log), `${JSON.stringify({ url: ENDPOINT, model: getModel() })}\n`);
313
234
  });
314
235
  });
315
236
  it('spec:typesafe-jev-bridge/S12 prints help and keeps the version and exact bundle consistent', (context) => {
@@ -321,7 +242,7 @@ it('spec:typesafe-jev-bridge/S12 prints help and keeps the version and exact bun
321
242
  assert.ok(frontmatter);
322
243
  assert.match(frontmatter, /^name:\s*['"]?typesafe-jev-bridge['"]?\s*$/m);
323
244
  assert.equal(frontmatter.match(/^metadata:\s*\n(?:[ \t]+[^\n]*\n)*?[ \t]+version:\s*['"]?([^\s'"\n]+)['"]?\s*$/m)?.[1], version);
324
- assert.deepEqual(listFiles(BRIDGE), ['SKILL.md', 'bin/jev-ask.sh', 'bin/jev-ask.test.mjs', 'bin/jev-client.mjs', 'capability.json', 'service-facts.txt', 'setup/README.md']);
245
+ assert.deepEqual(listFiles(BRIDGE), ['SKILL.md', 'bin/jev-ask-harness.test.mjs', 'bin/jev-ask.sh', 'bin/jev-ask.test.mjs', 'bin/jev-client.mjs', 'capability.json', 'service-facts.txt', 'setup/README.md']);
325
246
  const setup = read(join(BRIDGE, 'setup/README.md'));
326
247
  assert.ok(setup.includes('jev-connect.mjs'));
327
248
  assert.match(setup, /restart/i);
@@ -331,8 +252,10 @@ it('spec:typesafe-jev-bridge/S13 scans every shipped file and catches planted ho
331
252
  const fixture = makeFixture(context);
332
253
  mkdirSync(join(fixture.root, 'bin'));
333
254
  writeFileSync(join(fixture.root, 'SKILL.md'), 'API.TypeSafe.AI');
334
- writeFileSync(join(fixture.root, 'bin/jev-client.mjs'), 'jev-1.13.0');
335
- assert.deepEqual(scanFolder(fixture.root).hits, ['SKILL.md: host', 'bin/jev-client.mjs: model']);
255
+ for (const model of ['jev-1.13.0', 'jev-latest', 'jev-preview']) {
256
+ writeFileSync(join(fixture.root, 'bin/jev-client.mjs'), model);
257
+ assert.deepEqual(scanFolder(fixture.root).hits, ['SKILL.md: host', 'bin/jev-client.mjs: model']);
258
+ }
336
259
  const scanned = scanFolder(BRIDGE);
337
260
  assert.deepEqual(scanned.hits, []);
338
261
  for (const file of ['SKILL.md', 'bin/jev-ask.sh', 'bin/jev-client.mjs', 'setup/README.md']) assert.ok(scanned.files.includes(file), `scan did not read ${file}`);
@@ -347,7 +270,7 @@ it('spec:typesafe-jev-bridge/S15 forwards client outcomes unchanged for success
347
270
  const wrapped = runWrapper(fixture, [fixture.path], code, { NODE_OPTIONS: preload.NODE_OPTIONS }, true);
348
271
  const direct = await runClient(cli, fixture, code, { transport: async () => makeResponse(body, status) }, true);
349
272
  assert.deepEqual(wrapped, direct);
350
- assert.equal(read(preload.log), `${ENDPOINT}\n`);
273
+ assert.equal(read(preload.log), `${JSON.stringify({ url: ENDPOINT, model: getModel() })}\n`);
351
274
  rmSync(preload.log);
352
275
  }
353
276
  });
@@ -390,3 +313,84 @@ it('spec:typesafe-jev-bridge/S16 the wrapper reaches a loopback CONNECT proxy by
390
313
  await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
391
314
  }
392
315
  });
316
+ describe('spec:typesafe-jev-bridge/S17 the wrapper selects the host model and reports its source', () => {
317
+ const cases = [
318
+ ['no setting', undefined, {}, getModel(), 'default', 0],
319
+ ['file setting', 'jev-1.14.0', {}, 'jev-1.14.0', 'setting', 0],
320
+ ['environment overrides file', 'jev-1.13.0', { JEV_MODEL: 'jev-1.14.0' }, 'jev-1.14.0', 'environment', 0],
321
+ ['empty environment selects default', 'jev-1.14.0', { JEV_MODEL: '' }, getModel(), 'environment', 0],
322
+ ['empty file warns', '', {}, getModel(), 'default', 1],
323
+ ['control-byte file warns', 'jev-1.14.0\x01', {}, getModel(), 'default', 1],
324
+ ];
325
+ for (const [name, setting, overrides, model, source, warnings] of cases) it(name, (context) => {
326
+ const fixture = makeFixture(context, true);
327
+ if (setting !== undefined) writeSettings(fixture, `JEV_MODEL=${setting}\n`);
328
+ const preload = addPreload(fixture, makeAnswer(model));
329
+ const calibrated = model === getModel();
330
+ const result = runWrapper(fixture, [fixture.path], 0, { ...overrides, NODE_OPTIONS: preload.NODE_OPTIONS }, true, false, 'bash', warnings);
331
+ assert.equal(result.stderr.split('\n')[warnings], makePosture(model, source, calibrated));
332
+ assert.deepEqual(read(preload.log).trim().split('\n').map((line) => JSON.parse(line)), [{ url: ENDPOINT, model }]);
333
+ assert.equal(JSON.parse(result.stdout).model, model);
334
+ assert.equal(JSON.parse(result.stdout).calibrated, calibrated);
335
+ if (warnings) assert.doesNotMatch(result.stderr.split('\n')[0], /[\x00-\x1f\x7f-\x9f\u2028\u2029]|''/u);
336
+ });
337
+ });
338
+ describe('spec:typesafe-jev-bridge/S18 unoffered models fail before reading the request and invalid sources fail usage', () => {
339
+ for (const source of ['setting', 'environment']) for (const model of ['jev-0.0.1', 'jev-latest', 'jev-preview']) it(`${source}: ${model}`, (context) => {
340
+ const fixture = makeFixture(context, true);
341
+ const path = join(fixture.root, 'absent-request.json');
342
+ if (source === 'setting') writeSettings(fixture, `JEV_MODEL=${model}\n`);
343
+ const result = runWrapper(fixture, [path], 2, source === 'environment' ? { JEV_MODEL: model } : {});
344
+ assert.match(result.stderr, /^jev-ask: /);
345
+ for (const text of [model, getModel(), 'jev-1.14.0', 'JEV_MODEL=', '/agent-workflow-kit bridge-settings']) assert.ok(result.stderr.includes(text), result.stderr);
346
+ if (source === 'environment') assert.ok(result.stderr.includes('unset'), result.stderr);
347
+ assert.equal(result.stderr.includes(path), false, result.stderr);
348
+ assert.doesNotMatch(result.stderr, /request file/i);
349
+ });
350
+ for (const source of ['setting', 'environment']) it(`the client names the offered list and the remedy for ${source}`, async (context) => {
351
+ const cli = await client();
352
+ const fixture = makeFixture(context);
353
+ const result = await runClient(cli, fixture, 2, { argv: makeArgv(fixture, { model: 'jev-0.0.1', source }) });
354
+ for (const text of ['jev-0.0.1', getModel(), 'jev-1.14.0', 'JEV_MODEL=', '/agent-workflow-kit bridge-settings']) assert.ok(result.stderr.includes(text), result.stderr);
355
+ assert.equal(result.stderr.includes('unset JEV_MODEL'), source === 'environment', result.stderr);
356
+ });
357
+ it('refuses a source outside default, setting and environment', async (context) => {
358
+ const cli = await client();
359
+ const fixture = makeFixture(context);
360
+ await runClient(cli, fixture, 2, { argv: makeArgv(fixture, { source: 'flag' }) });
361
+ });
362
+ });
363
+ it('spec:typesafe-jev-bridge/S19 offered versions mark only the default model as calibrated', async (context) => {
364
+ const cli = await client();
365
+ const fixture = makeFixture(context);
366
+ for (const [model, source, calibrated] of [['jev-1.14.0', 'setting', false], [getModel(), 'default', true]]) {
367
+ const models = [];
368
+ const result = await runClient(cli, fixture, 0, { argv: makeArgv(fixture, { model, source }), transport: async (url, init) => {
369
+ models.push(JSON.parse(init.body).model);
370
+ return makeResponse(makeAnswer(model));
371
+ } }, true);
372
+ assert.deepEqual(models, [model]);
373
+ assert.equal(result.stderr, `${makePosture(model, source, calibrated)}\n`);
374
+ assert.equal(JSON.parse(result.stdout).model, model);
375
+ assert.equal(JSON.parse(result.stdout).calibrated, calibrated);
376
+ if (calibrated) assert.doesNotMatch(result.stderr, /uncalibrated/);
377
+ }
378
+ });
379
+ it('spec:typesafe-jev-bridge/S20 the manifest offers pinned judge versions and rejects aliases', () => {
380
+ const checkManifest = (manifest) => {
381
+ const setting = manifest.settings?.find((entry) => entry.key === 'JEV_MODEL');
382
+ assert.ok(setting, 'capability.json JEV_MODEL entry is absent');
383
+ assert.equal(setting.kind, 'posture');
384
+ assert.equal(setting.default, manifest.posture.model);
385
+ assert.deepEqual(setting.appliesTo, ['jev-ask']);
386
+ assert.ok(Array.isArray(setting.offered));
387
+ assert.ok(setting.offered.includes(manifest.posture.model));
388
+ for (const model of setting.offered) { assert.equal(typeof model, 'string'); assert.match(model, /^jev-\d+\.\d+\.\d+$/); }
389
+ for (const alias of ['jev-latest', 'jev-preview']) assert.equal(setting.offered.includes(alias), false);
390
+ };
391
+ const manifest = readManifest();
392
+ checkManifest(manifest);
393
+ const copy = structuredClone(manifest);
394
+ copy.settings.find((entry) => entry.key === 'JEV_MODEL').offered.push('jev-latest');
395
+ assert.throws(() => checkManifest(copy), assert.AssertionError);
396
+ });
@@ -24,9 +24,15 @@ const HTTP_MAX = 299;
24
24
  const PROBABILITY_MIN = 0;
25
25
  const PROBABILITY_MAX = 1;
26
26
  const MILLISECONDS_PER_SECOND = 1000;
27
- const ARGUMENT_COUNT = 5;
27
+ const ARGUMENT_COUNT = 9;
28
28
  const HOST_FLAG = '--host';
29
29
  const KEY_FLAG = '--key-variable';
30
+ const MODEL_FLAG = '--model';
31
+ const MODEL_SOURCE_FLAG = '--model-source';
32
+ const ENVIRONMENT_SOURCE = 'environment';
33
+ const MODEL_SOURCES = ['default', 'setting', ENVIRONMENT_SOURCE];
34
+ const MODEL_SETTING = 'JEV_MODEL';
35
+ const MIN_OFFERED_MODELS = 1;
30
36
  const MANIFEST_FILE = 'capability.json';
31
37
  const REQUEST_ID_HEADER = 'x-typesafe-request-id';
32
38
  const AUTHORIZATION_HEADER = 'authorization';
@@ -83,7 +89,7 @@ const checkAnswer = (answer, questions) => isPlainObject(answer) && typeof answe
83
89
  });
84
90
  const makeNotes = (answers) => Object.fromEntries(Object.entries(answers).map(([id, { choice, probabilities, confidence }]) =>
85
91
  [id, { choice, probabilities, confidence }]));
86
- const readAnswer = async (response, model, questions, key) => {
92
+ const readAnswer = async (response, model, calibratedModel, questions, key) => {
87
93
  const header = response.headers.get(REQUEST_ID_HEADER);
88
94
  const requestId = header === null ? null : cleanOutsideText(header, key);
89
95
  if (response.status < HTTP_MIN || response.status > HTTP_MAX) return makeFailure(EXIT.HTTP,
@@ -91,11 +97,11 @@ const readAnswer = async (response, model, questions, key) => {
91
97
  const body = await response.text();
92
98
  const answer = (() => { try { return JSON.parse(body); } catch { return null; } })();
93
99
  if (!checkAnswer(answer, questions)) return makeFailure(EXIT.ANSWER, 'malformed answer');
94
- if (answer.model !== model) return makeFailure(EXIT.MODEL, `requested model ${model}; answering model ${cleanOutsideText(answer.model, key)}`);
95
- return { code: EXIT.OK, stdout: JSON.stringify({ model, requestId, notes: makeNotes(answer.answers) }) + NEWLINE, stderr: EMPTY };
100
+ if (answer.model !== model) return makeFailure(EXIT.MODEL, `requested model ${cleanOutsideText(model, key)}; answering model ${cleanOutsideText(answer.model, key)}`);
101
+ return { code: EXIT.OK, stdout: JSON.stringify({ model: cleanOutsideText(model, key), calibrated: answer.model === calibratedModel, requestId, notes: makeNotes(answer.answers) }) + NEWLINE, stderr: EMPTY };
96
102
  };
97
103
 
98
- export const askJudge = async ({ host, key, model, state, questions, transport, timeoutMs = JUDGE_TIMEOUT_MS }) => {
104
+ export const askJudge = async ({ host, key, model, calibratedModel = model, state, questions, transport, timeoutMs = JUDGE_TIMEOUT_MS }) => {
99
105
  const trimmedKey = key.trim();
100
106
  const controller = new AbortController();
101
107
  const deadline = { timer: null };
@@ -107,7 +113,7 @@ export const askJudge = async ({ host, key, model, state, questions, transport,
107
113
  method: REQUEST_METHOD, headers: { [AUTHORIZATION_HEADER]: `Bearer ${trimmedKey}`, [CONTENT_TYPE_HEADER]: JSON_CONTENT_TYPE },
108
114
  body: JSON.stringify({ state, model, questions }), redirect: REDIRECT_MODE, signal: controller.signal,
109
115
  });
110
- return readAnswer(response, model, questions, trimmedKey);
116
+ return readAnswer(response, model, calibratedModel, questions, trimmedKey);
111
117
  })().catch((error) => makeFailure(EXIT.TRANSPORT, describeError(error, trimmedKey)));
112
118
  try {
113
119
  return scrubOutcome(await Promise.race([timeout, work]), trimmedKey);
@@ -118,17 +124,25 @@ export const askJudge = async ({ host, key, model, state, questions, transport,
118
124
  };
119
125
 
120
126
  export const runJudgeCli = async ({ argv, env, folder, transport, timeoutMs = JUDGE_TIMEOUT_MS }) => {
121
- const [hostFlag, host, keyFlag, variable, path] = Array.isArray(argv) ? argv : [];
127
+ const [hostFlag, host, keyFlag, variable, modelFlag, handedModel, sourceFlag, source, path] = Array.isArray(argv) ? argv : [];
122
128
  const key = typeof env?.[variable] === STRING_TYPE ? env[variable].trim() : EMPTY;
123
129
  const finish = (outcome) => scrubOutcome(outcome, key);
124
130
  try {
125
131
  if (!Array.isArray(argv) || argv.length !== ARGUMENT_COUNT || hostFlag !== HOST_FLAG || keyFlag !== KEY_FLAG ||
126
- ![host, variable, path].every(isNonemptyString)) return finish(makeFailure(EXIT.REQUEST, 'usage: --host <host> --key-variable <variable> <request-file>'));
132
+ modelFlag !== MODEL_FLAG || sourceFlag !== MODEL_SOURCE_FLAG || typeof handedModel !== STRING_TYPE ||
133
+ !MODEL_SOURCES.includes(source) || ![host, variable, path].every(isNonemptyString)) return finish(makeFailure(EXIT.REQUEST, 'usage: --host <host> --key-variable <variable> --model <value> --model-source <source> <request-file>'));
127
134
  const manifestPath = resolve(folder, MANIFEST_FILE);
128
- const model = await readFile(manifestPath, UTF8).then((text) => {
129
- try { return JSON.parse(text)?.posture?.model; } catch { return null; }
135
+ const manifest = await readFile(manifestPath, UTF8).then((text) => {
136
+ try { return JSON.parse(text); } catch { return null; }
130
137
  }, () => null);
131
- if (!isNonemptyString(model)) return finish(makeFailure(EXIT.INSTALL, `${manifestPath}: no readable posture.model; ${REMEDY}`));
138
+ const calibratedModel = manifest?.posture?.model;
139
+ if (!isNonemptyString(calibratedModel)) return finish(makeFailure(EXIT.INSTALL, `${manifestPath}: no readable posture.model; ${REMEDY}`));
140
+ const offered = Array.isArray(manifest.settings) ? manifest.settings.find((entry) => entry?.key === MODEL_SETTING)?.offered : null;
141
+ if (!Array.isArray(offered) || offered.length < MIN_OFFERED_MODELS || !offered.every((value) => typeof value === STRING_TYPE)) return finish(makeFailure(EXIT.INSTALL, `${manifestPath}: no readable ${MODEL_SETTING} offered list; ${REMEDY}`));
142
+ const model = handedModel === EMPTY ? calibratedModel : handedModel;
143
+ if (!offered.includes(model)) return finish(makeFailure(EXIT.REQUEST,
144
+ `model ${cleanOutsideText(model, key)} is not offered; offered: ${cleanOutsideText(offered.join(', '), key)}; set ${MODEL_SETTING}=<an offered version> through /agent-workflow-kit bridge-settings${source === ENVIRONMENT_SOURCE ? `; unset ${MODEL_SETTING} in the environment` : EMPTY}`));
145
+ const calibrated = model === calibratedModel;
132
146
  const text = await readFile(path, UTF8).catch(() => null);
133
147
  if (text === null) return finish(makeFailure(EXIT.REQUEST, `${path}: cannot read request file`));
134
148
  const parsed = (() => {
@@ -143,8 +157,8 @@ export const runJudgeCli = async ({ argv, env, folder, transport, timeoutMs = JU
143
157
  const bodyBytes = measureBytes({ state, model, questions });
144
158
  if (bodyBytes > BODY_LIMIT) return finish(makeFailure(EXIT.REQUEST, `request measures ${bodyBytes} bytes; bound ${BODY_LIMIT}`));
145
159
  if (!keyIsSet(env, variable)) return finish(makeFailure(EXIT.KEY, `${variable} is unset or blank`));
146
- const posture = flattenText(`judge posture: model=${model} host=${host} timeout=${renderTimeout(timeoutMs)}`) + NEWLINE;
147
- const outcome = await askJudge({ host, key, model, state, questions, transport, timeoutMs });
160
+ const posture = flattenText(`judge posture: model=${cleanOutsideText(model, key)} source=model:${source} ${calibrated ? EMPTY : 'uncalibrated '}host=${host} timeout=${renderTimeout(timeoutMs)}`) + NEWLINE;
161
+ const outcome = await askJudge({ host, key, model, calibratedModel, state, questions, transport, timeoutMs });
148
162
  return finish({ ...outcome, stderr: posture + outcome.stderr });
149
163
  } catch (error) {
150
164
  return finish(makeFailure(EXIT.TRANSPORT, describeError(error, key)));
@@ -3,7 +3,7 @@
3
3
  "schema": 1,
4
4
  "name": "typesafe-jev-bridge",
5
5
  "kind": "execution-backend",
6
- "version": "1.0.1",
6
+ "version": "1.1.0",
7
7
  "available": true,
8
8
  "provides": ["judge"],
9
9
  "roles": {
@@ -17,6 +17,16 @@
17
17
  "posture": {
18
18
  "model": "jev-1.13.0"
19
19
  },
20
+ "settings": [
21
+ {
22
+ "key": "JEV_MODEL",
23
+ "kind": "posture",
24
+ "default": "jev-1.13.0",
25
+ "appliesTo": ["jev-ask"],
26
+ "offered": ["jev-1.13.0", "jev-1.14.0"],
27
+ "effect": "the judge model every run uses (the host posture); a set value is checked against the manifest's offered versions before the request file is read. /agent-workflow-kit bridge-settings shows the versions offered."
28
+ }
29
+ ],
20
30
  "detect": {
21
31
  "installed": {
22
32
  "env": "TYPESAFE_JEV_BRIDGE_DIR",
package/capability.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schema": 1,
4
4
  "name": "agent-workflow-kit",
5
5
  "kind": "composition-root",
6
- "version": "23.3.1",
6
+ "version": "23.4.1",
7
7
  "provides": [],
8
8
  "roles": {},
9
9
  "detect": {