@sabaiway/agent-workflow-kit 23.2.1 → 23.3.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,32 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
4
4
  is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
5
5
  every `migrations/<version>-<slug>.md` newer than it, in semver order.
6
6
 
7
+ ## 23.3.1 — the judge prints no runtime warning under a proxy on Node 22 (AD-228)
8
+
9
+ **On Node 22, a `jev-ask` run under a proxy no longer prints Node's experimental-feature warning for its proxy agent,
10
+ so its stderr again holds only the bridge's own lines: the posture line once the request is sent, and one line on a failure.** Node 22 prints that warning (code `UNDICI-EHPA`) at
11
+ start whenever its proxy switch meets a set `HTTPS_PROXY`, as inside a sandbox; Node 24 does not. The wrapper now
12
+ starts node with `--disable-warning=UNDICI-EHPA`, which turns off exactly that warning; every other warning stays. A
13
+ placed judge refreshes from 1.0.0 to 1.0.1 on your next `init` or `/agent-workflow-kit upgrade`.
14
+
15
+ ## 23.3.0 — the kit ships the judge bridge, placed when you name it, and needs Node.js 22.21 (AD-228)
16
+
17
+ **An agent can now ask Jev a choice question through `jev-ask`: the kit carries the judge bridge
18
+ `typesafe-jev-bridge`, and `/agent-workflow-kit setup jev` places it.** The bridge sends the question with your
19
+ `TYPESAFE_API_KEY` and prints Jev's notes, never a byte of the key. A bare `/agent-workflow-kit setup` still places
20
+ only the two review bridges, so the judge reaches your machine only when you ask for it.
21
+
22
+ - **`/agent-workflow-kit backends` and `status` show the judge.** Once placed, it is ready with `node` and `jev-ask` on
23
+ `PATH` and the key set; the key's value is never printed. Otherwise the report names the next step, such as
24
+ Node.js 22.21 or newer, or the kit's connect command in a terminal of your own, then a restart of the agent.
25
+ - **Once placed, `init` and `/agent-workflow-kit upgrade` refresh it** from the kit's bundled copy, as they do the
26
+ other bridges. A ready judge alone makes no recipe offer: it is not a reviewer.
27
+ - **The request goes through a sandbox's proxy.** The wrapper switches on Node's own proxy support, so a run under a
28
+ sandbox that sets `HTTPS_PROXY` sends its request through that proxy.
29
+ - **Node.js 22.21 or newer is now required** (the release that carries that proxy support): the `engines` field of
30
+ every package, the READMEs and the CI floor job say so.
31
+ - **The role vocabulary admits `judge`**, and a bridge manifest can declare it.
32
+
7
33
  ## 23.2.1 — the gate hook's read-only list is written from the kit's own list (AD-227)
8
34
 
9
35
  **The gate hook's list of read-only commands and its list of residual shell forms are now written from the kit's own
package/README.md CHANGED
@@ -13,7 +13,7 @@ decisions. Works with Claude Code, Codex, Cursor, and any agent that reads `AGEN
13
13
  [![license](https://img.shields.io/npm/l/@sabaiway/agent-workflow-kit)](./LICENSE)
14
14
  [![node](https://img.shields.io/node/v/@sabaiway/agent-workflow-kit)](https://nodejs.org)
15
15
 
16
- `Node ≥ 22` · `dependency-free scripts` · `no telemetry in family code`
16
+ `Node ≥ 22.21` · `dependency-free scripts` · `no telemetry in family code`
17
17
 
18
18
  **One command to start:**
19
19
 
@@ -217,11 +217,11 @@ refreshes the other npm core members so a returning `init` leaves **no stale cor
217
217
  | `~/.claude/skills/agent-workflow-kit/` | the kit itself (refreshed on every `init`) |
218
218
  | `~/.claude/skills/agent-workflow-memory/` | the **memory substrate**, refreshed via `npx @sabaiway/agent-workflow-memory@latest init` — **best-effort:** a failure is a **loud degraded success** (warning + the exact recovery command + exit 0), never silent; skip with `--no-memory` |
219
219
  | `~/.claude/skills/agent-workflow-engine/` | the **methodology engine** the kit reads live, refreshed via `npx @sabaiway/agent-workflow-engine@latest init` — **required** (the live read STOPs without it); skip with `--no-engine` |
220
- | `~/.claude/skills/{codex,antigravity}-cli-bridge/` | the placed **bridges**, refreshed from the kit's bundled copies (local files, no network) — **only if `/agent-workflow-kit setup` already placed them**: an absent bridge is never placed, a newer one never downgraded; skip with `--no-bridges` |
220
+ | `~/.claude/skills/<bridge-name>/` | the placed **bridges**, refreshed from the kit's bundled copies (local files, no network) — **only if `/agent-workflow-kit setup` already placed them**: an absent bridge is never placed, a newer one never downgraded; skip with `--no-bridges` |
221
221
  | `~/.codex/skills/agent-workflow-kit` | a symlink — only if you have Codex |
222
222
  | `…/global_workflows/agent-workflow-kit.md` | a managed file — only if you have Devin Desktop |
223
223
 
224
- The **execution-backend bridges** (`codex` / `agy`) are never first **placed** by `init` — set one up
224
+ The **execution-backend bridges** (`codex` / `agy` and the judge) are never first **placed** by `init` — set one up
225
225
  on demand with `/agent-workflow-kit setup`; after that, a returning `init` keeps the placed copy
226
226
  fresh (the table row above). Your other Codex skills and Devin Desktop workflows are
227
227
  never touched. If one of those exact slots already holds a file the kit didn't write, it is **left
@@ -241,10 +241,10 @@ file), or run the guarded `/agent-workflow-kit uninstall`.
241
241
  | `/agent-workflow-kit` | new / empty project | recon → **asks visible-or-hidden** + **conversational language** + **agent attribution** (default off) → deploys `AGENTS.md` + `docs/ai/` filled with real recon data → offers enforcement (installed on a yes) → **asks before committing** |
242
242
  | `/agent-workflow-kit upgrade` | existing deployment | reads `docs/ai/.workflow-version`, shows the changelog diff, preserves your authored memory, applies migrations, re-stamps — then prints a **read-only** one-line backend-status line (what's set up vs missing); refreshes the already-placed bridges from the kit's bundled copies (never installs a new one — set one up with `/agent-workflow-kit setup`) |
243
243
  | `/agent-workflow-kit help` | any time | **read-only command index** — every command, grouped (Inspect / Configure / Orchestrate / Lifecycle) and tagged read-only / writer / guarded. The discoverable entry point, and where any unrecognized invocation lands (always read-only — a garbage invocation never writes). Never writes, never commits, never runs a subscription CLI. |
244
- | `/agent-workflow-kit backends` | any time | **read-only** check of the optional execution-backends (the `codex` / `agy` bridges): what's set up vs missing and the next step. Never writes, never commits, never runs a subscription CLI (credentials = marker-file presence, not a live login). |
244
+ | `/agent-workflow-kit backends` | any time | **read-only** check of the optional execution-backends: what's set up vs missing and the next step. Never writes, never commits, never runs a subscription CLI (credentials = marker-file presence or a key variable set, never a live login). |
245
245
  | `/agent-workflow-kit gates` | any time | **project gate runner** — runs the verification commands **your project itself declares** in `docs/ai/gates.json` (seeded at deploy; hand-editable `{ id, title, cmd }` entries plus the optional boolean `lcovProducer`, each `cmd` one bash line) as one batch: a per-gate **PASS/FAIL table** + one machine-readable summary line, exit 0 iff all green; a failing gate's own output is shown verbatim; `--only <id>` re-runs one. Honest distinct outcomes for a missing / empty / malformed declaration — never a silent green. The runner writes nothing **by default** and never commits — opt-in `--final` runs the FULL declared matrix and mints ONE final-run receipt into the git-dir core-evidence store (status green/red, pre/post tree fingerprints, the declaration, the consumed lcov's sha; the receipt the commit-guard binds); it executes only your own declared commands (a batching convenience, not a sandbox). The velocity tier auto-approves only the exact no-`--final` form — the recording run stays explicit. |
246
- | `/agent-workflow-kit setup [backend]` | opt-in, any time | **link-only** auto-setup of a bridge: places the bundled bridge skill (only into an absent / empty / managed dir — never overwrites an unmanaged one) + links its wrappers onto `PATH` via managed symlinks (idempotent; refuses to clobber a non-symlink; try `--dry-run` to preview). The binary install + the one-time subscription login stay **manual**: it prints the exact **login** command and points the binary install at each bridge's `setup/README.md`. POSIX wrappers — on Windows use WSL. Never commits, never runs a subscription CLI. |
247
- | `/agent-workflow-kit status` | any time | **read-only** single view of **versions + deployment + settings + bridges**: which members (kit / memory / engine / the two bridges) are installed and at what version (with an honest "installed on this machine" note when one is behind) and — in a project — what's deployed (`docs/ai`, the version stamps, and the **visibility**: visible / hidden / unclear), and the **feature-spec adoption state** (`not adopted` / `adopting (N draft)` / `adopted (N live, M draft)` / `could not be read`, plus `declined` when recorded), plus your settings (orchestration recipes, attribution, velocity) and the bridges' readiness. The two version axes (package number vs deployment-structure head) stay decoupled. Never writes, never commits, never runs a subscription CLI. |
246
+ | `/agent-workflow-kit setup [backend]` | opt-in, any time | **link-only** setup: a bare run places the review bridges; name another bridge to place it. Places the bundled skill only into an absent / empty / managed dir + links its wrappers onto `PATH` via managed symlinks (idempotent; refuses to clobber a non-symlink; try `--dry-run` to preview). Binary install, subscription login and a key stay **manual**: it prints guidance for each missing step. POSIX wrappers — on Windows use WSL. Never commits, never runs a subscription CLI. |
247
+ | `/agent-workflow-kit status` | any time | **read-only** single view of **versions + deployment + settings + bridges**: which members (kit / memory / engine / the bridges) are installed and at what version (with an honest "installed on this machine" note when one is behind) and — in a project — what's deployed (`docs/ai`, the version stamps, and the **visibility**: visible / hidden / unclear), and the **feature-spec adoption state** (`not adopted` / `adopting (N draft)` / `adopted (N live, M draft)` / `could not be read`, plus `declined` when recorded), plus your settings (orchestration recipes, attribution, velocity) and the bridges' readiness. The two version axes (package number vs deployment-structure head) stay decoupled. Never writes, never commits, never runs a subscription CLI. |
248
248
  | `/agent-workflow-kit now` | any time | **read-only** answer to where work stands in four blocks: **NOW** names every plan in flight, its phase, current and next step, and the tree evidence; **STEPS** gives every ledger row its evidence-derived status; **QUEUE** folds named rows under their full heading paths and calls position priority only in the judged backlog; **CAMPAIGN** shows the source-size practice figures and config state. The plan's own text never sets a status; a contradicted claim prints beside it. A block that cannot be derived is WITHHELD with its cause; NOW has two halves, plans and tree, each independently a value or WITHHELD, and NOW itself is WITHHELD only when both are. Never writes, never commits, never runs a subscription CLI. |
249
249
  | `/agent-workflow-kit tier` | any time | **read-only** guide to the epic, story and task tier: what each level is, and the next step of the walk, with the command that runs it wherever a tool does. Never writes, never commits, never runs a subscription CLI. |
250
250
  | `/agent-workflow-kit jev` | any time | **read-only** guide to Jev (TypeSafe), a decision model: what it is, why it pays here, what it is not, the two steps to a set key (the connect command, the optional vendor skill) and three prompts where it pays. Opens no connection and never prints the key. |
@@ -306,7 +306,7 @@ agent-workflow-kit — the composition root (installed via npx … init)
306
306
  ├─ injects ─▶ workflow methodology (live from the installed engine)
307
307
  ├─ deploys ─▶ AGENTS.md + docs/ai/
308
308
  │ + Node scripts + pre-commit hook (installed on a yes)
309
- ├─ detects ─▶ optional backends (codex / agy, read-only)
309
+ ├─ detects ─▶ optional backends (codex / agy / judge, read-only)
310
310
  └─ sets up ─▶ a bridge (opt-in) (place skill + link wrappers)
311
311
  ```
312
312
 
@@ -326,14 +326,14 @@ agent-workflow-kit — the composition root (installed via npx … init)
326
326
  `docs/ai/agent_rules.md` is yours: the kit lays it only where it is absent, and apart from the
327
327
  one-time `5.0.0` step, which removes the kit's old sections from it, never reads or writes it.
328
328
  `/agent-workflow-kit recipes` surfaces + plans a recipe for your environment, read-only.
329
- - **Detects & (opt-in) sets up** the optional `codex` / `agy` **bridges** — agent skills (not npm;
329
+ - **Detects & (opt-in) sets up** the optional **bridges** — agent skills (not npm;
330
330
  never first placed by `init` — `setup` places them, and once placed `init`/`upgrade` refresh
331
- them). They plug into the workflow's **execute** and **review** phases — for *what
331
+ them). The subscription CLI bridges plug into the workflow's **execute** and **review** phases — for *what
332
332
  each adds and why*, see the
333
333
  [family front door](https://github.com/sabaiway/agent-workflow#readme). `/agent-workflow-kit backends`
334
334
  reports readiness **read-only**;
335
335
  `/agent-workflow-kit setup` does the **link-only** part (place the bundled bridge skill + link its
336
- wrappers), while the binary install + the subscription login stay manual. A bridge reads the deployed
336
+ wrappers; a bare run places the review bridges), while binary install, subscription login and a key stay manual. A bridge reads the deployed
337
337
  memory only if it wins that tool's context-file priority, and the bridges call third-party services
338
338
  (so "no telemetry" covers family code, not those).
339
339
 
@@ -382,7 +382,7 @@ agent-workflow-kit/
382
382
  │ ├── family-registry.mjs ← unified family registry (status)
383
383
  │ ├── uninstall.mjs ← guarded teardown (uninstall)
384
384
  │ └── release-scan.mjs ← attribution / release gate
385
- ├── bridges/ ← bundled bridge skill mirrors (codex / antigravity)
385
+ ├── bridges/ ← bundled bridge mirrors (codex / agy / judge)
386
386
  ├── launchers/ ← Codex / Devin Desktop / Cursor entries
387
387
  └── migrations/ ← per-version upgrade steps
388
388
  ```
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: agent-workflow-kit
3
3
  description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow". New to the epic, story and task tier? Run `/agent-workflow-kit tier`. A typed decision with a confidence from Jev? Run `/agent-workflow-kit jev`.
4
4
  disable-model-invocation: true
5
5
  metadata:
6
- version: '23.2.1'
6
+ version: '23.3.1'
7
7
  ---
8
8
 
9
9
  # agent-workflow-kit
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: typesafe-jev-bridge
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
+ metadata:
5
+ version: '1.0.1'
6
+ ---
7
+
8
+ # typesafe-jev-bridge
9
+
10
+ Bridges the main agent to **Jev**, TypeSafe's decision model, through one wrapper, `jev-ask`, which is
11
+ the bridge's one role: **judge**. Every answer it prints is a **note** with a confidence; no gate,
12
+ verdict, review or commit reads it, so the wrapper writes no file and mints no receipt.
13
+
14
+ ## The model
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.
19
+
20
+ ## The key
21
+
22
+ The key is the value of the variable the first `PASSED_VARIABLE` line of this folder's
23
+ `service-facts.txt` names, read from the environment only — never from the request file or the
24
+ command line. The wrapper sends it, trimmed, in the `Authorization` header and never prints a byte of
25
+ it. To save the key on a host, follow [`setup/README.md`](setup/README.md).
26
+
27
+ A delegated codex or agy run reaching Jev on its own is not this bridge: that access is the
28
+ every-run rule of those bridges' wrappers (spec bridges/jev-every-run).
29
+
30
+ ## Usage
31
+
32
+ ```text
33
+ jev-ask <request-file>
34
+ jev-ask --help (alias -h)
35
+ ```
36
+
37
+ The request file is one UTF-8 JSON object with exactly two keys:
38
+
39
+ - `state` — a non-empty string: the situation the questions are about.
40
+ - `questions` — an object of one or more question ids, each
41
+ `{ "type": "choice", "instructions": "<non-empty>", "criteria": { "<option id>": "<non-empty>", … } }`
42
+ with 2 to 255 options. A choice is the one question type admitted.
43
+
44
+ Before any request the wrapper bounds the request locally: the UTF-8 bytes of the compact JSON of
45
+ `state` plus the largest `[id, question]` pair at most 30 000, the whole request body at most 60 000.
46
+
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:
50
+
51
+ ```json
52
+ { "model": "<answering id>", "requestId": "<request id or null>", "notes": { "<question id>": { "choice": "…", "probabilities": { "…": 0.9 }, "confidence": 0.8 } } }
53
+ ```
54
+
55
+ ## Exit statuses
56
+
57
+ A non-zero exit prints nothing on stdout and exactly one stderr line, after the posture line when
58
+ the request was sent.
59
+
60
+ | Exit | Meaning |
61
+ |------|---------|
62
+ | 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 |
64
+ | 3 | no key: the variable is unset, empty or blank; no request is made |
65
+ | 4 | timeout: no complete answer within 10 seconds |
66
+ | 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
+ | 6 | a malformed answer |
68
+ | 7 | the answer names another model than the pinned one |
69
+ | 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 |
@@ -0,0 +1,277 @@
1
+ #!/usr/bin/env bash
2
+ # spec:typesafe-jev-bridge — docs/ai/specs/bridges/typesafe-jev-bridge/index.md
3
+ set -euo pipefail
4
+
5
+ aw_script_dir() {
6
+ local src="${BASH_SOURCE[0]}" dir hops=0 max_hops=16
7
+ while :; do
8
+ case "$src" in */*) dir="${src%/*}"; dir="${dir:-/}" ;; *) dir=. ;; esac
9
+ dir="$(CDPATH= builtin cd -P -- "$dir" 2>/dev/null && builtin pwd -P)" || break
10
+ [[ -L "$src" ]] || { printf '%s\n' "$dir"; return 0; }
11
+ if (( hops >= max_hops )); then
12
+ printf 'error: exceeded %s symlink hops; could not resolve its OWN directory\n' "$max_hops" >&2
13
+ return 127
14
+ fi
15
+ hops=$((hops + 1))
16
+ src="$(command readlink -- "$src" 2>/dev/null)" || break
17
+ case "$src" in /*) ;; *) src="$dir/$src" ;; esac
18
+ done
19
+ printf 'error: could not resolve its OWN directory\n' >&2
20
+ return 127
21
+ }
22
+ aw_read_service_facts() {
23
+ local path="${1%/*}/service-facts.txt" line key value entry number=0 bad=0 valid seen=() run_lines=()
24
+ local host_re='^(\*\.)?[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-]*[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])?(\.[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-]*[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])?)+$'
25
+ local variable_re='^[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*$'
26
+ local command_re='^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-]* \*$'
27
+ local env directory segments LC_ALL=C
28
+ AW_FACT_HOST=() AW_FACT_RUN_HOST=() AW_FACT_PASSED_VARIABLE=()
29
+ if [[ -f "$path" && -r "$path" ]]; then
30
+ while IFS= read -r line; do
31
+ number=$((number + 1)); valid=1
32
+ if (( number == 1 )); then
33
+ [[ "$line" == "# generated from the kit's service fragments (agent-workflow-kit/tools/services/); do not edit" ]] || bad=1
34
+ continue
35
+ fi
36
+ key="${line%%=*}"; value="${line#*=}"
37
+ [[ "$line" == *=* ]] || valid=0
38
+ case "$key" in
39
+ HOST|RUN_HOST) [[ "$value" =~ $host_re ]] || valid=0
40
+ if [[ "$key" == RUN_HOST && "$value" == '*.'* ]]; then valid=0; fi ;;
41
+ PASSED_VARIABLE) [[ "$value" =~ $variable_re && "$value" != OPENAI_BASE_URL ]] || valid=0 ;;
42
+ EXCLUDED_COMMAND) [[ "$value" =~ $command_re ]] || valid=0 ;;
43
+ WRITABLE_DIR)
44
+ env="${value%%:*}"; directory="${value#*:}"; segments="/${directory//\\//}/"
45
+ [[ "$value" == *:* && ( -z "$env" || "$env" =~ $variable_re ) &&
46
+ ( "$directory" == '~/'* || "$directory" == /* ) && "$directory" != */ &&
47
+ "$directory" != *[\*\?\[\]]* && ! "$directory" =~ [[:cntrl:]] && "$segments" != */../* ]] || valid=0 ;;
48
+ *) valid=0 ;;
49
+ esac
50
+ for entry in ${seen[@]+"${seen[@]}"}; do [[ "$entry" != "$line" ]] || valid=0; done
51
+ if (( ! valid )); then (( bad )) || bad=$number; continue; fi
52
+ seen+=("$line")
53
+ case "$key" in
54
+ HOST) AW_FACT_HOST+=("$value") ;; RUN_HOST) AW_FACT_RUN_HOST+=("$value"); run_lines+=("$number") ;;
55
+ PASSED_VARIABLE) AW_FACT_PASSED_VARIABLE+=("$value") ;;
56
+ esac
57
+ done <"$path"
58
+ if (( ! number )); then bad=1; fi
59
+ if [[ -n "$line" ]] && (( ! bad )); then bad=$((number + 1)); fi
60
+ for ((number=0; number<${#AW_FACT_RUN_HOST[@]}; number++)); do
61
+ valid=0
62
+ for entry in ${AW_FACT_HOST[@]+"${AW_FACT_HOST[@]}"}; do [[ "$entry" != "${AW_FACT_RUN_HOST[number]}" ]] || valid=1; done
63
+ if (( ! valid && (! bad || run_lines[number] < bad) )); then bad=${run_lines[number]}; fi
64
+ done
65
+ (( bad )) || return 0
66
+ printf 'error: %s: invalid facts at line %s; remove whatever is at that path and run /agent-workflow-kit upgrade to write it again\n' "$path" "$bad" >&2
67
+ else
68
+ printf 'error: %s: not a readable regular file; remove whatever is at that path and run /agent-workflow-kit upgrade to write it again\n' "$path" >&2
69
+ fi
70
+ exit 127
71
+ }
72
+ HERE="$(aw_script_dir)" || exit 127
73
+ aw_read_service_facts "$HERE"
74
+
75
+ AW_SETTINGS_APPLIED=""
76
+ aw_settings_file() {
77
+ printf '%s/agent-workflow/bridge-settings.conf' "${XDG_CONFIG_HOME:-$HOME/.config}"
78
+ }
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
81
+ *" $1 "*) return 0 ;;
82
+ *) return 1 ;;
83
+ esac
84
+ }
85
+ aw_int_in_range() {
86
+ # All-digits $1 vs [min,max] WITHOUT 64-bit wrap (Issue-012): strip leading zeros, then a longer
87
+ # digit count than max's is unconditionally out of range — never do the arithmetic on a huge string.
88
+ # A leading-zero in-range value still passes (its stripped count is small); all-zeros collapses to
89
+ # "0" (below min>=1). Mirrors the JS settingValueValid safe-integer bound, verified by parity test.
90
+ local n="${1#"${1%%[!0]*}"}" min="$2" max="$3"
91
+ n="${n:-0}"
92
+ (( ${#n} > ${#max} )) && return 1
93
+ (( n >= min && n <= max ))
94
+ }
95
+ aw_settings_valid() {
96
+ local k="$1" v="$2" int_re='^[0-9]+$' dur_re='^[0-9]+(\.[0-9]+)?[smhd]$' zero_re='^0+(\.0+)?[smhd]$'
97
+ case "$k" in
98
+ CODEX_SERVICE_TIER) [[ "$v" == "priority" ]] ;;
99
+ CODEX_HARD_TIMEOUT) [[ "$v" =~ $int_re ]] && aw_int_in_range "$v" 1 86400 ;;
100
+ CODEX_REVIEW_MAX_TOTAL_BYTES) [[ "$v" =~ $int_re ]] && aw_int_in_range "$v" 1 100000000 ;;
101
+ AGY_HARD_TIMEOUT) [[ "$v" =~ $dur_re && ! "$v" =~ $zero_re ]] ;;
102
+ AGY_REVIEW_ALLOW_ADDDIR) [[ "$v" == "0" || "$v" == "1" ]] ;;
103
+ AGY_REVIEW_MAX_TOTAL_BYTES) [[ "$v" =~ $int_re ]] && aw_int_in_range "$v" 1 100000000 ;;
104
+ *) return 1 ;;
105
+ esac
106
+ }
107
+ aw_apply_settings() {
108
+ local file line key value warned notify
109
+ file="$(aw_settings_file)"
110
+ [[ -e "$file" ]] || return 0
111
+ notify=1
112
+ [[ -n "${AW_SETTINGS_NOTIFIED:-}" ]] && notify=0
113
+ export AW_SETTINGS_NOTIFIED=1
114
+ if [[ ! -f "$file" || ! -r "$file" ]]; then
115
+ if (( notify )); then
116
+ echo "warning: bridge settings file '$file' exists but is unreadable or not a regular file — using built-in defaults." >&2
117
+ fi
118
+ return 0
119
+ fi
120
+ if (( notify )); then
121
+ warned=" "
122
+ while IFS= read -r line || [[ -n "$line" ]]; do
123
+ [[ -z "${line//[[:space:]]/}" ]] && continue
124
+ case "${line#"${line%%[![:space:]]*}"}" in "#"*) continue ;; esac
125
+ if [[ ! "$line" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
126
+ echo "warning: malformed line in bridge settings file '$file' (ignored): $line" >&2
127
+ continue
128
+ fi
129
+ key="${line%%=*}"
130
+ if ! aw_settings_known "$key"; then
131
+ case "$warned" in
132
+ *" $key "*) : ;;
133
+ *)
134
+ warned="$warned$key "
135
+ echo "warning: unknown key '$key' in bridge settings file '$file' (ignored)." >&2
136
+ ;;
137
+ esac
138
+ fi
139
+ done <"$file"
140
+ fi
141
+ for key in $AW_SETTINGS_APPLIED; do
142
+ if [[ -n "${!key+x}" ]]; then continue; fi
143
+ value="$(grep "^${key}=" "$file" 2>/dev/null || true)"
144
+ [[ -n "$value" ]] || continue
145
+ value="${value##*$'\n'}"
146
+ value="${value#*=}"
147
+ if ! aw_settings_valid "$key" "$value"; then
148
+ if (( notify )); then
149
+ echo "warning: invalid value '$value' for $key in bridge settings file '$file' — using the built-in default." >&2
150
+ fi
151
+ continue
152
+ fi
153
+ # Normalize an all-digit (integer) value to DECIMAL before export: a leading-zero value the integer
154
+ # arms legitimately accept (000…086400 == 86400) would otherwise read as OCTAL in downstream Bash
155
+ # arithmetic ("value too great for base"). Strip leading zeros, floor "0"; enum/duration (non-digit)
156
+ # and boolean 0/1 are unaffected.
157
+ if [[ "$value" =~ ^[0-9]+$ ]]; then
158
+ value="${value#"${value%%[!0]*}"}"
159
+ value="${value:-0}"
160
+ fi
161
+ export "$key=$value"
162
+ done
163
+ return 0
164
+ }
165
+ aw_read_posture() {
166
+ local key="$1" default="$2" empty="$3" file line value notify=1
167
+ AW_HOST_VALUE="$default"
168
+ AW_HOST_SOURCE="default"
169
+ file="$(aw_settings_file)"
170
+ [[ -n "${AW_SETTINGS_NOTIFIED:-}" ]] && notify=0
171
+ if [[ -f "$file" && -r "$file" ]]; then
172
+ line="$(grep "^${key}=" "$file" 2>/dev/null || true)"
173
+ if [[ -n "$line" ]]; then
174
+ value="${line##*$'\n'}"
175
+ value="${value#*=}"
176
+ if [[ -n "$value" && "$value" != *[$'\x01'-$'\x1f'$'\x7f']* ]]; then
177
+ AW_HOST_VALUE="$value"
178
+ AW_HOST_SOURCE="setting"
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
181
+ fi
182
+ fi
183
+ fi
184
+ AW_RUN_VALUE="$AW_HOST_VALUE"
185
+ AW_RUN_SOURCE="$AW_HOST_SOURCE"
186
+ if [[ -n "${!key+x}" ]]; then
187
+ AW_RUN_VALUE="${!key:-$empty}"
188
+ AW_RUN_SOURCE="environment"
189
+ fi
190
+ return 0
191
+ }
192
+ aw_effective_timeout() {
193
+ local key="$1" default="$2" value="${!1:-}" rule="$1" intpart
194
+ [[ "$rule" == "AGY_TIMEOUT" ]] && rule="AGY_HARD_TIMEOUT"
195
+ [[ -n "$value" ]] || { printf '%s' "$default"; return 0; }
196
+ intpart="${value%%[!0-9]*}"
197
+ if ! aw_settings_valid "$rule" "$value" || (( ${#intpart} > 7 )); then
198
+ # %q escapes the raw value so a control byte in it can never forge an extra diagnostic line
199
+ # (the direct agy-run lane has no pre-spend screen — the warning itself must be injection-proof).
200
+ printf "warning: invalid value '%q' for %s — using the built-in default %s.\n" "$value" "$key" "$default" >&2
201
+ printf '%s' "$default"
202
+ return 0
203
+ fi
204
+ printf '%s' "$value"
205
+ }
206
+ aw_timeout_label() {
207
+ local bin="$1" value="$2"
208
+ [[ -n "$bin" ]] || { printf 'uncapped'; return 0; }
209
+ case "$value" in
210
+ *[!0-9]*) printf '%s' "$value" ;;
211
+ *) printf '%ss' "$value" ;;
212
+ esac
213
+ }
214
+ aw_resolve_timeout_bin() {
215
+ local bin dir base
216
+ bin="$(builtin type -P timeout 2>/dev/null || true)"
217
+ [[ -n "$bin" ]] || bin="$(builtin type -P gtimeout 2>/dev/null || true)"
218
+ [[ -n "$bin" ]] || { printf ''; return 0; }
219
+ case "$bin" in
220
+ /*) ;;
221
+ *)
222
+ case "$bin" in
223
+ */*) dir="${bin%/*}"; base="${bin##*/}" ;;
224
+ *) dir="."; base="$bin" ;;
225
+ esac
226
+ dir="$(builtin cd -- "$dir" 2>/dev/null && builtin pwd -P)" || { printf ''; return 0; }
227
+ bin="$dir/$base"
228
+ ;;
229
+ esac
230
+ [[ -f "$bin" && -x "$bin" ]] || { printf ''; return 0; }
231
+ printf '%s' "$bin"
232
+ }
233
+ aw_scrub_billing_keys() {
234
+ local name passed keep
235
+ unset OPENAI_BASE_URL 2>/dev/null || true
236
+ for name in $(compgen -v); do
237
+ [[ "$name" == *_API_KEY ]] || continue
238
+ keep=0
239
+ for passed in ${AW_FACT_PASSED_VARIABLE[@]+"${AW_FACT_PASSED_VARIABLE[@]}"}; do
240
+ [[ "$name" != "$passed" ]] || keep=1
241
+ done
242
+ if (( ! keep )); then unset "$name" 2>/dev/null || true; fi
243
+ done
244
+ return 0
245
+ }
246
+
247
+ AW_BRIDGE_VERSION="1.0.1" # aw-version-anchor
248
+ case "${1:-}" in
249
+ --help|-h)
250
+ printf '%s\n' "jev-ask — judge notes through typesafe-jev-bridge $AW_BRIDGE_VERSION." '' \
251
+ 'Usage:' ' jev-ask <request-file>' ' jev-ask --help' \
252
+ 'Request: {"state": <non-empty string>, "questions": {<id>: {"type": "choice",' \
253
+ ' "instructions": <non-empty string>, "criteria": {<option id>: <non-empty string>, ...}}}} (2..255 options)' \
254
+ 'Exit: 0 notes; 2 usage/request; 3 no key; 4 timeout; 5 HTTP; 6 malformed answer; 7 model mismatch; 8 transport; 127 installation.'
255
+ exit 0
256
+ ;;
257
+ esac
258
+
259
+ if (( $# != 1 )) || [[ "$1" == -* ]]; then
260
+ printf '%s\n' 'jev-ask: usage: jev-ask <request-file> | jev-ask --help' >&2
261
+ exit 2
262
+ fi
263
+ if (( ${#AW_FACT_RUN_HOST[@]} == 0 )); then
264
+ printf 'jev-ask: %s: no RUN_HOST line; run /agent-workflow-kit upgrade to write it again\n' "${HERE%/*}/service-facts.txt" >&2
265
+ exit 127
266
+ fi
267
+ if (( ${#AW_FACT_PASSED_VARIABLE[@]} == 0 )); then
268
+ printf 'jev-ask: %s: no PASSED_VARIABLE line; run /agent-workflow-kit upgrade to write it again\n' "${HERE%/*}/service-facts.txt" >&2
269
+ exit 127
270
+ fi
271
+ aw_scrub_billing_keys
272
+ if ! command -v node >/dev/null 2>&1; then
273
+ printf '%s\n' 'jev-ask: node not found on PATH; install Node.js 22.21 or newer' >&2
274
+ exit 127
275
+ fi
276
+ 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"