@mmerterden/multi-agent-pipeline 23.7.0 → 24.1.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/CHANGELOG.md +60 -1
- package/README.md +59 -24
- package/README.tr.md +43 -8
- package/SECURITY.md +3 -3
- package/docs/architecture.md +41 -4
- package/docs/ecosystem.md +15 -13
- package/docs/facts.json +5 -4
- package/docs/features.md +67 -15
- package/install/_codex-agents.mjs +13 -8
- package/install/_common.mjs +24 -0
- package/install/_dev-only-files.mjs +5 -0
- package/install/_mcp-register.mjs +6 -2
- package/install/_rewrite-tree.mjs +197 -0
- package/install/codex.mjs +96 -180
- package/install/copilot.mjs +24 -54
- package/install/index.mjs +29 -11
- package/install/templates/codex-instructions.md +21 -5
- package/install/templates/copilot-instructions.md +21 -14
- package/manifest.json +2083 -0
- package/package.json +8 -2
- package/pipeline/commands/multi-agent/SKILL.md +5 -4
- package/pipeline/commands/multi-agent/analysis/SKILL.md +5 -1
- package/pipeline/commands/multi-agent/autopilot-on/SKILL.md +31 -3
- package/pipeline/commands/multi-agent/autopilot-status/SKILL.md +5 -1
- package/pipeline/commands/multi-agent/channels/SKILL.md +16 -8
- package/pipeline/commands/multi-agent/log/SKILL.md +2 -0
- package/pipeline/commands/multi-agent/stack/SKILL.md +1 -1
- package/pipeline/contract/CHANGELOG.md +15 -0
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +6 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +21 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +18 -3
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +31 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +31 -1
- package/pipeline/contract/fixtures/runs-running.json +16 -1
- package/pipeline/contract/manifest.json +14 -14
- package/pipeline/contract/types/index.d.ts +20 -1
- package/pipeline/lib/_jira-auth.sh +50 -78
- package/pipeline/lib/_service-account.sh +191 -0
- package/pipeline/lib/credential-inventory.sh +49 -37
- package/pipeline/lib/credential-store.sh +48 -3
- package/pipeline/lib/fetch-confluence.sh +76 -92
- package/pipeline/lib/fetch-crashlytics.sh +30 -59
- package/pipeline/lib/fetch-figma-annotations.sh +9 -9
- package/pipeline/lib/fetch-fortify.sh +77 -81
- package/pipeline/lib/fetch-graylog.sh +38 -77
- package/pipeline/lib/figma-mcp-refresh.sh +23 -4
- package/pipeline/lib/figma-screenshot.sh +7 -8
- package/pipeline/lib/figma-token.sh +39 -46
- package/pipeline/lib/host.mjs +138 -0
- package/pipeline/lib/host.sh +48 -0
- package/pipeline/lib/issue-fetcher.sh +25 -41
- package/pipeline/lib/jira-publish.sh +23 -21
- package/pipeline/lib/local-model.mjs +93 -0
- package/pipeline/lib/md2confluence-v3.py +37 -30
- package/pipeline/lib/model-dispatch.sh +41 -4
- package/pipeline/lib/model-resolve.mjs +58 -0
- package/pipeline/lib/post-pr-review.sh +38 -53
- package/pipeline/lib/reviewer-families.mjs +70 -0
- package/pipeline/lib/service-account.mjs +2131 -0
- package/pipeline/lib/service-account.sh +35 -0
- package/pipeline/lib/usage-token.mjs +64 -24
- package/pipeline/lib/usage-vocab.mjs +1 -1
- package/pipeline/lib/user-facing.mjs +11 -3
- package/pipeline/lib/vercel-deploy.sh +17 -26
- package/pipeline/multi-agent-refs/_entry-picker.md +62 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -0
- package/pipeline/multi-agent-refs/analysis/render.md +12 -1
- package/pipeline/multi-agent-refs/analysis/reusable-refs.md +1 -0
- package/pipeline/multi-agent-refs/analysis/unattended.md +135 -0
- package/pipeline/multi-agent-refs/autopilot-on/details.md +16 -0
- package/pipeline/multi-agent-refs/channels/generator.md +10 -2
- package/pipeline/multi-agent-refs/channels/menu.md +3 -1
- package/pipeline/multi-agent-refs/channels/preview.md +3 -1
- package/pipeline/multi-agent-refs/channels/reference.md +16 -2
- package/pipeline/multi-agent-refs/channels/report-file.md +188 -0
- package/pipeline/multi-agent-refs/cross-cli-contract.md +35 -27
- package/pipeline/multi-agent-refs/features/doctor.md +37 -11
- package/pipeline/multi-agent-refs/features/free-models.md +3 -3
- package/pipeline/multi-agent-refs/features/local-model.md +87 -0
- package/pipeline/multi-agent-refs/features/model-fallback.md +25 -10
- package/pipeline/multi-agent-refs/features/product-context.md +6 -5
- package/pipeline/multi-agent-refs/features/service-accounts.md +233 -0
- package/pipeline/multi-agent-refs/features/unattended-security.md +10 -1
- package/pipeline/multi-agent-refs/help/en.md +36 -1
- package/pipeline/multi-agent-refs/help/tr.md +34 -1
- package/pipeline/multi-agent-refs/orchestrator/copilot-pipeline.md +2 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -1
- package/pipeline/multi-agent-refs/phases/modes.md +20 -1
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +1 -0
- package/pipeline/multi-agent-refs/phases/phase-4-commit.md +1 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +13 -11
- package/pipeline/multi-agent-refs/phases.md +4 -3
- package/pipeline/multi-agent-refs/review/panel.md +30 -18
- package/pipeline/multi-agent-refs/setup/discovery.md +17 -5
- package/pipeline/multi-agent-refs/setup/token-save-flow.md +21 -2
- package/pipeline/multi-agent-refs/sync/overview.md +11 -5
- package/pipeline/multi-agent-refs/tracker-contract.md +64 -20
- package/pipeline/office/index.html +77 -4
- package/pipeline/schemas/activity.schema.json +63 -4
- package/pipeline/schemas/autopilot-config.schema.json +29 -4
- package/pipeline/schemas/hosts.json +512 -0
- package/pipeline/schemas/hosts.schema.json +310 -0
- package/pipeline/schemas/launch.json +22 -2
- package/pipeline/schemas/launch.schema.json +2 -1
- package/pipeline/schemas/now-lines.json +103 -0
- package/pipeline/schemas/now-lines.schema.json +42 -0
- package/pipeline/schemas/phases.json +19 -1
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +331 -4
- package/pipeline/schemas/runs-index.schema.json +22 -1
- package/pipeline/scripts/_autopilot-config.mjs +67 -4
- package/pipeline/scripts/_autopilot-item.mjs +67 -0
- package/pipeline/scripts/_autopilot-outcomes.mjs +6 -0
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_cost.mjs +75 -3
- package/pipeline/scripts/activity-snapshot.mjs +27 -1
- package/pipeline/scripts/analysis-sources.mjs +22 -5
- package/pipeline/scripts/analysis-unattended.mjs +360 -0
- package/pipeline/scripts/anonymize-findings.mjs +3 -7
- package/pipeline/scripts/autopilot-arming.mjs +19 -10
- package/pipeline/scripts/autopilot-intake.mjs +124 -27
- package/pipeline/scripts/autopilot-menubar.swift +7 -0
- package/pipeline/scripts/autopilot-runner.mjs +77 -48
- package/pipeline/scripts/autopilot-status.sh +32 -9
- package/pipeline/scripts/bulk-read.sh +37 -5
- package/pipeline/scripts/confluence-readback.mjs +15 -7
- package/pipeline/scripts/cost-table.json +65 -25
- package/pipeline/scripts/doctor.mjs +119 -32
- package/pipeline/scripts/entry-mode.mjs +101 -0
- package/pipeline/scripts/estimate.mjs +30 -16
- package/pipeline/scripts/feedback-send.mjs +11 -8
- package/pipeline/scripts/gen-facts.mjs +7 -9
- package/pipeline/scripts/jira-attach.sh +23 -28
- package/pipeline/scripts/jira-search.sh +5 -21
- package/pipeline/scripts/launch-request.mjs +15 -9
- package/pipeline/scripts/migrate-prefs.mjs +56 -0
- package/pipeline/scripts/phase-tracker.sh +226 -50
- package/pipeline/scripts/priority-review.mjs +14 -7
- package/pipeline/scripts/product-context.mjs +26 -7
- package/pipeline/scripts/prune-logs.sh +4 -2
- package/pipeline/scripts/render-work-summary.sh +51 -1
- package/pipeline/scripts/report-file.mjs +285 -0
- package/pipeline/scripts/rework-escalation.mjs +19 -4
- package/pipeline/scripts/runs-index.mjs +2 -1
- package/pipeline/scripts/service-read.mjs +19 -17
- package/pipeline/scripts/skill-siblings.mjs +17 -1
- package/pipeline/scripts/status-overview.mjs +20 -10
- package/pipeline/scripts/uninstall.mjs +145 -57
- package/pipeline/scripts/usage-register.mjs +34 -11
- package/pipeline/scripts/usage-report.mjs +31 -26
- package/pipeline/scripts/validate-triage.mjs +11 -1
- package/pipeline/scripts/work-items.mjs +25 -28
- package/pipeline/scripts/write-store-config.mjs +37 -11
- package/pipeline/skills/.skill-manifest.json +4 -4
- package/pipeline/skills/.skills-index.json +1 -1
- package/pipeline/skills/shared/core/multi-agent/SKILL.md +11 -3
- package/pipeline/skills/shared/core/multi-agent-analysis/SKILL.md +2 -0
- package/pipeline/skills/shared/core/multi-agent-channels/SKILL.md +11 -8
- package/pipeline/lib/credential-resolve.mjs +0 -75
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* host.mjs - which host this code is installed under, and what that host is
|
|
3
|
+
* called.
|
|
4
|
+
*
|
|
5
|
+
* `pipeline/schemas/hosts.json` is the single source. Everything here reads a
|
|
6
|
+
* field off it; nothing here compares a host name to a literal. A new host is a
|
|
7
|
+
* record in that file plus an installer module, not a branch added in each
|
|
8
|
+
* consumer.
|
|
9
|
+
*
|
|
10
|
+
* The registry is packaged data, never user input: it names install roots and
|
|
11
|
+
* argv, so opening it to extension would be a path-traversal and
|
|
12
|
+
* command-injection surface.
|
|
13
|
+
*
|
|
14
|
+
* @module pipeline/lib/host
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, readFileSync } from "fs";
|
|
18
|
+
import { basename, dirname, join } from "path";
|
|
19
|
+
import { fileURLToPath } from "url";
|
|
20
|
+
|
|
21
|
+
// `fileURLToPath`, not `new URL(...).pathname`: the pathname keeps its
|
|
22
|
+
// percent-encoding, so an install under a home directory with a space in it
|
|
23
|
+
// would look for a file whose name contains `%20`. This module is imported by
|
|
24
|
+
// `user-facing.mjs`, which most of the pipeline imports, so that failure is not
|
|
25
|
+
// one script refusing to run - it is all of them.
|
|
26
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
|
|
28
|
+
// What answers when the registry is not on disk. An install missing its schemas
|
|
29
|
+
// tree is broken, and the check that SAYS so lives in a script that imports this
|
|
30
|
+
// module, so throwing here would silence the only thing able to report the
|
|
31
|
+
// cause. The fallback describes the state root and the host the paths are
|
|
32
|
+
// authored against; `install-present` then names the missing tree.
|
|
33
|
+
const FALLBACK = Object.freeze({
|
|
34
|
+
version: "0",
|
|
35
|
+
order: ["claude"],
|
|
36
|
+
stateRoot: ".claude",
|
|
37
|
+
hosts: {
|
|
38
|
+
claude: {
|
|
39
|
+
label: "Claude Code",
|
|
40
|
+
install: { root: ".claude", subtrees: ["scripts", "lib", "schemas"] },
|
|
41
|
+
detect: { rootSegment: ".claude" },
|
|
42
|
+
command: { template: "/multi-agent:{sub}" },
|
|
43
|
+
models: { rungs: {} },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function loadRegistry() {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(readFileSync(join(HERE, "..", "schemas", "hosts.json"), "utf8"));
|
|
51
|
+
} catch {
|
|
52
|
+
return FALLBACK;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @type {{version: string, order: string[], stateRoot: string, hosts: Record<string, any>}} */
|
|
57
|
+
export const REGISTRY = loadRegistry();
|
|
58
|
+
|
|
59
|
+
/** Host ids in the order the installer and every user-facing listing uses them. */
|
|
60
|
+
export const HOST_IDS = Object.freeze([...REGISTRY.order]);
|
|
61
|
+
|
|
62
|
+
/** The tree shared state lives in, whichever hosts are installed. `.claude`. */
|
|
63
|
+
export const STATE_ROOT = REGISTRY.stateRoot;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The host record, or null for an unknown id.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} id
|
|
69
|
+
* @returns {object|null}
|
|
70
|
+
*/
|
|
71
|
+
export function host(id) {
|
|
72
|
+
return REGISTRY.hosts[id] ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The directory a host installs into, e.g. `/Users/x/.copilot`.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} home
|
|
79
|
+
* @param {string} id
|
|
80
|
+
* @returns {string|null} null for an unknown id
|
|
81
|
+
*/
|
|
82
|
+
export function hostRoot(home, id) {
|
|
83
|
+
const h = host(id);
|
|
84
|
+
return h ? join(home, h.install.root) : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Which host a file belongs to, read from the path it sits at.
|
|
89
|
+
*
|
|
90
|
+
* Takes the directory a tree lives in - `~/.copilot/scripts`, `~/.codex/lib` -
|
|
91
|
+
* and answers with the host id, or null when the path is outside every install
|
|
92
|
+
* (a repo checkout, most often).
|
|
93
|
+
*
|
|
94
|
+
* @param {string} dir
|
|
95
|
+
* @returns {string|null}
|
|
96
|
+
*/
|
|
97
|
+
function hostIdFromDir(dir) {
|
|
98
|
+
const segment = basename(dirname(dir));
|
|
99
|
+
for (const id of HOST_IDS) {
|
|
100
|
+
if (REGISTRY.hosts[id].detect.rootSegment === segment) return id;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Which host this module is running from, or null in a repo checkout.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} [dir] - defaults to this file's own directory
|
|
109
|
+
* @returns {string|null}
|
|
110
|
+
*/
|
|
111
|
+
export function currentHostId(dir = HERE) {
|
|
112
|
+
return hostIdFromDir(dir);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* How the user types a pipeline sub-command on a host.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} id
|
|
119
|
+
* @param {string} sub
|
|
120
|
+
* @returns {string}
|
|
121
|
+
*/
|
|
122
|
+
export function hostCommandFor(id, sub) {
|
|
123
|
+
const h = host(id) ?? host(HOST_IDS[0]);
|
|
124
|
+
return h.command.template.replace("{sub}", sub);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The hosts that actually have an install under `home`.
|
|
129
|
+
*
|
|
130
|
+
* Presence is the version stamp, not the directory: `~/.codex` exists on any
|
|
131
|
+
* machine with Codex CLI, installed pipeline or not.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} home
|
|
134
|
+
* @returns {string[]} ids, in registry order
|
|
135
|
+
*/
|
|
136
|
+
export function installedHostIds(home) {
|
|
137
|
+
return HOST_IDS.filter((id) => existsSync(join(hostRoot(home, id), ".pipeline-version")));
|
|
138
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# host.sh - which host a shell script is running under, and what the registry
|
|
3
|
+
# says about it.
|
|
4
|
+
#
|
|
5
|
+
# The mjs side is pipeline/lib/host.mjs and reads the same file. Source this
|
|
6
|
+
# rather than matching a host name: `pipeline/schemas/hosts.json` is the single
|
|
7
|
+
# source, and a script that compares `$HOST` to a literal is a script that has
|
|
8
|
+
# to be edited again when a host is added.
|
|
9
|
+
#
|
|
10
|
+
# Usage:
|
|
11
|
+
# . "$(dirname "${BASH_SOURCE[0]}")/host.sh"
|
|
12
|
+
# id=$(ma_host_id) # a host id, or empty off an install
|
|
13
|
+
# ma_host_has_provider anthropic && ...
|
|
14
|
+
#
|
|
15
|
+
# Every function answers from the registry that shipped with THIS install, so a
|
|
16
|
+
# script copied into another host's tree answers for that host. Without jq there
|
|
17
|
+
# is no answer at all rather than a wrong one: callers treat an empty answer the
|
|
18
|
+
# way they treat a missing preference.
|
|
19
|
+
|
|
20
|
+
# The registry, resolved from this file's own location so it works in the repo
|
|
21
|
+
# (pipeline/lib -> pipeline/schemas) and in an install (<root>/lib -> <root>/schemas).
|
|
22
|
+
ma_host_registry() {
|
|
23
|
+
printf '%s\n' "$(cd "$(dirname "${BASH_SOURCE[0]}")/../schemas" 2>/dev/null && pwd)/hosts.json"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# The host whose tree this file sits in, or empty from a repo checkout.
|
|
27
|
+
ma_host_id() {
|
|
28
|
+
local reg seg
|
|
29
|
+
reg=$(ma_host_registry)
|
|
30
|
+
[ -f "$reg" ] || return 0
|
|
31
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
32
|
+
seg=$(basename "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." 2>/dev/null && pwd)")
|
|
33
|
+
jq -r --arg seg "$seg" \
|
|
34
|
+
'[.hosts | to_entries[] | select(.value.detect.rootSegment == $seg) | .key][0] // ""' \
|
|
35
|
+
"$reg" 2>/dev/null || true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# True when this host dispatches to the named provider.
|
|
39
|
+
ma_host_has_provider() {
|
|
40
|
+
local reg id
|
|
41
|
+
reg=$(ma_host_registry)
|
|
42
|
+
id=$(ma_host_id)
|
|
43
|
+
[ -f "$reg" ] || return 1
|
|
44
|
+
command -v jq >/dev/null 2>&1 || return 1
|
|
45
|
+
[ -n "$id" ] || id=$(jq -r '.order[0]' "$reg" 2>/dev/null)
|
|
46
|
+
jq -e --arg id "$id" --arg p "$1" \
|
|
47
|
+
'(.hosts[$id].models.providers // []) | index($p) != null' "$reg" >/dev/null 2>&1
|
|
48
|
+
}
|
|
@@ -200,51 +200,35 @@ def bound_comments(rows):
|
|
|
200
200
|
return kept
|
|
201
201
|
'
|
|
202
202
|
|
|
203
|
-
#
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
# shellcheck source=_service-account.sh
|
|
204
|
+
if [ -f "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/_service-account.sh" ]; then
|
|
205
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/_service-account.sh"
|
|
206
|
+
elif [ -f "$HOME/.claude/lib/_service-account.sh" ]; then
|
|
207
|
+
# shellcheck source=/dev/null
|
|
208
|
+
. "$HOME/.claude/lib/_service-account.sh"
|
|
209
|
+
fi
|
|
206
210
|
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
#
|
|
211
|
+
# One authenticated GET. Split out of fetch_jira so the sibling search reuses
|
|
212
|
+
# the same resolution instead of duplicating it. The credential is written into
|
|
213
|
+
# a config that carries the URL too, so a redirect cannot carry the header and
|
|
214
|
+
# the token never reaches argv or a shell variable.
|
|
210
215
|
jira_curl() {
|
|
211
|
-
local path="$1"
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
local path="$1" cfg host
|
|
217
|
+
# The account answers both halves of the question: which instance this run
|
|
218
|
+
# talks to, and the credential for it. ACCOUNT_JIRA_HOST and
|
|
219
|
+
# ACCOUNT_JIRA_TOKEN_KEY still name one when a caller sets them.
|
|
220
|
+
local -a sel=()
|
|
221
|
+
[ -n "${JIRA_HOST:-}" ] && sel+=(--host "$JIRA_HOST")
|
|
222
|
+
[ -n "${JIRA_TOKEN_KEY:-}" ] && sel+=(--item "$JIRA_TOKEN_KEY")
|
|
223
|
+
host="$(sa_host jira "${sel[@]+"${sel[@]}"}")" || {
|
|
224
|
+
echo "ERR: no Jira account for this run: $(sa_explain)" >&2
|
|
214
225
|
return 1
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
# A pre-set CRED_STORE (tests, custom installs) is honored as-is.
|
|
219
|
-
if [ -z "${CRED_STORE:-}" ]; then
|
|
220
|
-
# shellcheck disable=SC1090,SC1091
|
|
221
|
-
# Existence check before sourcing: `. <missing>` aborts the shell under `set -e`,
|
|
222
|
-
# `||` included, so a `.`-chain reaches neither its later candidates nor its error
|
|
223
|
-
# branch. The loop also covers all three hosts - the chain it replaced knew only
|
|
224
|
-
# .claude and .copilot, so a Codex-only install could not resolve at all.
|
|
225
|
-
for _cred_resolver in \
|
|
226
|
-
"$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/credential-store-resolver.sh" \
|
|
227
|
-
"$HOME/.claude/lib/credential-store-resolver.sh" \
|
|
228
|
-
"$HOME/.copilot/lib/credential-store-resolver.sh" \
|
|
229
|
-
"$HOME/.codex/lib/credential-store-resolver.sh"; do
|
|
230
|
-
[ -f "$_cred_resolver" ] || continue
|
|
231
|
-
# shellcheck source=/dev/null
|
|
232
|
-
. "$_cred_resolver" 2>/dev/null || true
|
|
233
|
-
if [ -n "${CRED_STORE:-}" ]; then break; fi
|
|
234
|
-
done
|
|
235
|
-
unset _cred_resolver
|
|
236
|
-
if [ -z "${CRED_STORE:-}" ]; then
|
|
237
|
-
echo "ERR: credential helper not found" >&2
|
|
238
|
-
return 1
|
|
239
|
-
fi
|
|
240
|
-
fi
|
|
241
|
-
local token
|
|
242
|
-
token=$("$CRED_STORE" get "$JIRA_TOKEN_KEY" 2>/dev/null || true)
|
|
243
|
-
if [ -z "$token" ]; then
|
|
244
|
-
echo "ERR: Jira token not found in credential store ($JIRA_TOKEN_KEY)" >&2
|
|
226
|
+
}
|
|
227
|
+
cfg="$(sa_cfg jira "https://$host$path" bearer "${sel[@]+"${sel[@]}"}")" || {
|
|
228
|
+
echo "ERR: $(sa_explain)" >&2
|
|
245
229
|
return 1
|
|
246
|
-
|
|
247
|
-
curl -sf -m 30
|
|
230
|
+
}
|
|
231
|
+
curl -sf -m 30 --config "$cfg"
|
|
248
232
|
}
|
|
249
233
|
|
|
250
234
|
# The field list is a parameter because the related-issue lookup wants a
|
|
@@ -89,7 +89,6 @@ ma_outbound_gate() {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
92
|
-
PREFS="${MULTI_AGENT_PREFS:-$HOME/.claude/multi-agent-preferences.json}"
|
|
93
92
|
CURL="${JIRA_PUBLISH_CURL:-curl}"
|
|
94
93
|
|
|
95
94
|
ISSUE=""
|
|
@@ -135,26 +134,29 @@ for cand in "$SELF_DIR/../scripts/jira-wiki-escape.mjs" "$HOME/.claude/scripts/j
|
|
|
135
134
|
done
|
|
136
135
|
[ -n "$ESCAPER" ] || die "jira-wiki-escape.mjs not found next to lib/ or in ~/.claude/scripts" 4
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
137
|
+
# shellcheck source=_jira-auth.sh
|
|
138
|
+
. "$SELF_DIR/_jira-auth.sh"
|
|
139
|
+
jira_auth_resolve || exit 4
|
|
140
|
+
HOST="$JIRA_API_HOST"
|
|
141
|
+
|
|
142
|
+
# The URL is the last argument, as every call site already writes it, and it is
|
|
143
|
+
# the one thing that decides which credential may go out. It is handed to the
|
|
144
|
+
# resolver rather than to curl: the config that comes back carries the URL, the
|
|
145
|
+
# scheme lock and the header together, so nothing can point curl elsewhere
|
|
146
|
+
# between the check and the request. The token never reaches a variable here.
|
|
147
|
+
api() {
|
|
148
|
+
local -a args=("$@")
|
|
149
|
+
local last=$((${#args[@]} - 1))
|
|
150
|
+
local url="${args[$last]}"
|
|
151
|
+
unset "args[$last]"
|
|
152
|
+
local cfg
|
|
153
|
+
cfg="$(sa_cfg jira "$url" bearer "${JIRA_AUTH_SELECTORS[@]+"${JIRA_AUTH_SELECTORS[@]}"}")" || {
|
|
154
|
+
echo "ERR: $(sa_explain)" >&2
|
|
155
|
+
return 4
|
|
156
|
+
}
|
|
157
|
+
"$CURL" -sS -m 30 --config "$cfg" -H "Content-Type: application/json" \
|
|
158
|
+
"${args[@]+"${args[@]}"}"
|
|
159
|
+
}
|
|
158
160
|
|
|
159
161
|
WORK="$(mktemp -d)"
|
|
160
162
|
trap 'rm -rf "$WORK"' EXIT
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* local-model.mjs - the one place a user-chosen local model and server
|
|
3
|
+
* address are read and checked.
|
|
4
|
+
*
|
|
5
|
+
* The host registry is packaged data and names install roots and argv, so it is
|
|
6
|
+
* not extensible. The two things that ARE the user's - which model answers, and
|
|
7
|
+
* where it is served - live in preferences, and everything they reach is
|
|
8
|
+
* validated here before it is written into a config file or an agent TOML.
|
|
9
|
+
*
|
|
10
|
+
* The address is loopback by default and an address off this machine takes an
|
|
11
|
+
* explicit opt-in: a base URL is where every prompt in a run is sent, so a typo
|
|
12
|
+
* that resolves is a silent exfiltration path rather than an error.
|
|
13
|
+
*
|
|
14
|
+
* @module pipeline/lib/local-model
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, readFileSync } from "fs";
|
|
18
|
+
|
|
19
|
+
/** Model ids this writes: a narrow set, because the value reaches a TOML file. */
|
|
20
|
+
const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
21
|
+
|
|
22
|
+
/** Hosts that are this machine. Anything else needs `allowRemote`. */
|
|
23
|
+
const LOOPBACK = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `prefs.global.localModel`, or null when the file does not read.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} prefsPath
|
|
29
|
+
* @returns {{baseUrl?: string, model?: string, contextWindow?: number, allowRemote?: boolean}|null}
|
|
30
|
+
*/
|
|
31
|
+
function readLocalModel(prefsPath) {
|
|
32
|
+
if (!prefsPath || !existsSync(prefsPath)) return null;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(readFileSync(prefsPath, "utf8"));
|
|
35
|
+
const cfg = parsed?.global?.localModel;
|
|
36
|
+
return cfg && typeof cfg === "object" ? cfg : null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Why this configuration cannot be used, or null when it can.
|
|
44
|
+
*
|
|
45
|
+
* Every answer names the field and what it has to be, because the person
|
|
46
|
+
* reading it is editing a JSON file by hand.
|
|
47
|
+
*
|
|
48
|
+
* @param {object|null} cfg
|
|
49
|
+
* @returns {string|null}
|
|
50
|
+
*/
|
|
51
|
+
export function localModelProblem(cfg) {
|
|
52
|
+
if (!cfg) return "global.localModel is not set in preferences";
|
|
53
|
+
if (typeof cfg.model !== "string" || !MODEL_NAME.test(cfg.model)) {
|
|
54
|
+
return "global.localModel.model must be a model id of letters, digits and . _ : / -";
|
|
55
|
+
}
|
|
56
|
+
if (typeof cfg.baseUrl !== "string" || !cfg.baseUrl) {
|
|
57
|
+
return "global.localModel.baseUrl must be the server's base URL";
|
|
58
|
+
}
|
|
59
|
+
let url;
|
|
60
|
+
try {
|
|
61
|
+
url = new URL(cfg.baseUrl);
|
|
62
|
+
} catch {
|
|
63
|
+
return `global.localModel.baseUrl is not a URL: ${cfg.baseUrl}`;
|
|
64
|
+
}
|
|
65
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
66
|
+
return `global.localModel.baseUrl must be http or https, not ${url.protocol}`;
|
|
67
|
+
}
|
|
68
|
+
if (!LOOPBACK.has(url.hostname) && cfg.allowRemote !== true) {
|
|
69
|
+
return `global.localModel.baseUrl points at ${url.hostname}, which is not this machine; set global.localModel.allowRemote to true to send prompts there on purpose`;
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isInteger(cfg.contextWindow) || cfg.contextWindow < 8192) {
|
|
72
|
+
// Measured, not guessed: a trivial one-turn request already carries about
|
|
73
|
+
// 45 KB of instructions before the task itself, and a phase spec is larger
|
|
74
|
+
// again. Below this the diff is truncated and the run reports on a file it
|
|
75
|
+
// never saw.
|
|
76
|
+
return "global.localModel.contextWindow must be an integer of at least 8192 tokens";
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The model id to bind agents to, or null when the configuration is unusable.
|
|
83
|
+
*
|
|
84
|
+
* Null is a working answer: agents are written without a model and the children
|
|
85
|
+
* inherit the session's.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} prefsPath
|
|
88
|
+
* @returns {string|null}
|
|
89
|
+
*/
|
|
90
|
+
export function localModelName(prefsPath) {
|
|
91
|
+
const cfg = readLocalModel(prefsPath);
|
|
92
|
+
return localModelProblem(cfg) === null ? cfg.model : null;
|
|
93
|
+
}
|
|
@@ -21,8 +21,8 @@ Authentication:
|
|
|
21
21
|
CONFLUENCE_BASE_URL - base URL, e.g. https://confluence.example.com
|
|
22
22
|
CONFLUENCE_USER - user (informational; bearer token auth is used)
|
|
23
23
|
Token is resolved from ~/.claude/lib/credential-store.sh using the logical key
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
resolved by the account resolver for the host CONFLUENCE_BASE_URL names.
|
|
25
|
+
An account that does not cover that host is refused, not used.
|
|
26
26
|
|
|
27
27
|
Output:
|
|
28
28
|
JSON envelope on stdout describing what happened (page id, url, attachments,
|
|
@@ -578,31 +578,38 @@ class ConfluenceAuth:
|
|
|
578
578
|
user: str | None = None
|
|
579
579
|
|
|
580
580
|
|
|
581
|
-
def
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
581
|
+
def _resolver() -> Path | None:
|
|
582
|
+
for candidate in (
|
|
583
|
+
Path(__file__).resolve().parent / "service-account.sh",
|
|
584
|
+
Path.home() / ".claude" / "lib" / "service-account.sh",
|
|
585
|
+
):
|
|
586
|
+
if candidate.is_file():
|
|
587
|
+
return candidate
|
|
588
|
+
return None
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def resolve_token(base_url: str) -> str | None:
|
|
592
|
+
"""The credential for this base URL, or None when no account covers it.
|
|
593
|
+
|
|
594
|
+
The destination is part of the question, not something checked afterwards:
|
|
595
|
+
CONFLUENCE_BASE_URL comes from the caller, and an account that does not
|
|
596
|
+
name that host is refused rather than used.
|
|
597
|
+
"""
|
|
598
|
+
script = _resolver()
|
|
599
|
+
if script is None:
|
|
600
|
+
return None
|
|
601
|
+
try:
|
|
602
|
+
proc = subprocess.run(
|
|
603
|
+
[str(script), "token", "--service", "confluence", "--url", base_url],
|
|
604
|
+
capture_output=True,
|
|
605
|
+
text=True,
|
|
606
|
+
timeout=15,
|
|
607
|
+
)
|
|
608
|
+
except (OSError, subprocess.SubprocessError):
|
|
609
|
+
return None
|
|
610
|
+
if proc.returncode != 0:
|
|
611
|
+
return None
|
|
612
|
+
return proc.stdout or None
|
|
606
613
|
|
|
607
614
|
|
|
608
615
|
def resolve_auth() -> ConfluenceAuth:
|
|
@@ -610,11 +617,11 @@ def resolve_auth() -> ConfluenceAuth:
|
|
|
610
617
|
if not base:
|
|
611
618
|
sys.stderr.write("error: CONFLUENCE_BASE_URL is not set\n")
|
|
612
619
|
sys.exit(2)
|
|
613
|
-
token = resolve_token()
|
|
620
|
+
token = resolve_token(base)
|
|
614
621
|
if not token:
|
|
615
622
|
sys.stderr.write(
|
|
616
|
-
"error: no Confluence
|
|
617
|
-
"
|
|
623
|
+
"error: no Confluence account answers for "
|
|
624
|
+
f"{base} - add one with /multi-agent:setup\n"
|
|
618
625
|
)
|
|
619
626
|
sys.exit(2)
|
|
620
627
|
return ConfluenceAuth(base_url=base, token=token, user=os.environ.get("CONFLUENCE_USER"))
|
|
@@ -125,6 +125,24 @@ esac
|
|
|
125
125
|
|
|
126
126
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
127
127
|
COST_TABLE="$HERE/../scripts/cost-table.json"
|
|
128
|
+
HOSTS_JSON="$HERE/../schemas/hosts.json"
|
|
129
|
+
|
|
130
|
+
# Which host this router is installed under, and therefore which rungs it can
|
|
131
|
+
# dispatch at all. Reading this from the registry rather than assuming one
|
|
132
|
+
# ladder is what keeps a rung another host does not offer from being handed
|
|
133
|
+
# back: a preference file is shared across hosts, so a rule naming a rung that
|
|
134
|
+
# exists on one of them is a normal thing to find here.
|
|
135
|
+
if [ -f "$HOSTS_JSON" ]; then
|
|
136
|
+
# shellcheck source=./host.sh
|
|
137
|
+
[ -f "$HERE/host.sh" ] && . "$HERE/host.sh"
|
|
138
|
+
# Deliberately NOT defaulted to the first host. "I cannot tell which host I
|
|
139
|
+
# am" and "I am the host the paths are authored against" are different
|
|
140
|
+
# answers, and guessing the second hands back the one rung this gate exists
|
|
141
|
+
# to refuse. An empty id takes the single-ladder rule below instead.
|
|
142
|
+
HOST_ID=$(command -v ma_host_id >/dev/null 2>&1 && ma_host_id || echo "")
|
|
143
|
+
else
|
|
144
|
+
HOST_ID=""
|
|
145
|
+
fi
|
|
128
146
|
|
|
129
147
|
STRATEGY=$(jq -r '.global.modelRouting.strategy // "manual"' "$PREFS" 2>/dev/null)
|
|
130
148
|
CHEAPEST_FIRST=false
|
|
@@ -212,10 +230,29 @@ for rung in $CANDIDATES; do
|
|
|
212
230
|
echo "model-dispatch: rung 'free' is reachable only at bulk-read and delegate; a $CALL_SITE is dispatched by the host, skipping it" >&2
|
|
213
231
|
continue
|
|
214
232
|
fi
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
233
|
+
# A rung is dispatchable here when THIS host offers it and the model behind it
|
|
234
|
+
# is one this host speaks. The cost table prices a rung by name; what that
|
|
235
|
+
# name runs differs per host, so the name alone cannot answer either question.
|
|
236
|
+
if [ -n "$HOST_ID" ]; then
|
|
237
|
+
RUNG_MODEL=$(jq -r --arg h "$HOST_ID" --arg r "$rung" \
|
|
238
|
+
'.hosts[$h].models.rungs[$r].model // ""' "$HOSTS_JSON" 2>/dev/null)
|
|
239
|
+
if [ -z "$RUNG_MODEL" ]; then
|
|
240
|
+
echo "model-dispatch: rung '$rung' is not offered on $HOST_ID; skipping it" >&2
|
|
241
|
+
continue
|
|
242
|
+
fi
|
|
243
|
+
RUNG_PROVIDER=$(jq -r --arg m "$RUNG_MODEL" \
|
|
244
|
+
'first(.prices[] | select(.modelId == $m or .copilotModelId == $m) | .provider) // ""' \
|
|
245
|
+
"$COST_TABLE" 2>/dev/null)
|
|
246
|
+
if ! jq -e --arg h "$HOST_ID" --arg p "$RUNG_PROVIDER" \
|
|
247
|
+
'(.hosts[$h].models.providers // []) | index($p) != null' "$HOSTS_JSON" >/dev/null 2>&1; then
|
|
248
|
+
# The call site hands the rung to something that speaks one of this host's
|
|
249
|
+
# own providers, so returning this one would produce a failed call rather
|
|
250
|
+
# than a cheaper one.
|
|
251
|
+
echo "model-dispatch: rung '$rung' runs $RUNG_MODEL ($RUNG_PROVIDER), which $HOST_ID does not dispatch; skipping it" >&2
|
|
252
|
+
continue
|
|
253
|
+
fi
|
|
254
|
+
elif [ "$PROVIDER" != "anthropic" ]; then
|
|
255
|
+
# No registry on this install: keep the single-ladder rule it shipped with.
|
|
219
256
|
echo "model-dispatch: rung '$rung' is $PROVIDER and no call site dispatches to it; skipping it" >&2
|
|
220
257
|
continue
|
|
221
258
|
fi
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* model-resolve.mjs - rung names in, model ids out, and back again.
|
|
3
|
+
*
|
|
4
|
+
* Rung names (`fable`, `opus`, `sonnet`, `haiku`) are the contract: every
|
|
5
|
+
* preference, every routing rule and every escalation ladder is written in
|
|
6
|
+
* them. What a rung IS differs per host, and the registry holds that mapping,
|
|
7
|
+
* so this module is the only place that crosses between the two.
|
|
8
|
+
*
|
|
9
|
+
* Binding time differs too and is not something this module can flatten: one
|
|
10
|
+
* host takes the model from the environment at dispatch, another from a flag,
|
|
11
|
+
* a third from a file written at install. What they share is the question
|
|
12
|
+
* answered here - which model id and effort does this rung mean on this host.
|
|
13
|
+
*
|
|
14
|
+
* @module pipeline/lib/model-resolve
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { HOST_IDS, REGISTRY, currentHostId } from "./host.mjs";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* What a rung means on a host.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} rung
|
|
23
|
+
* @param {string} [hostId]
|
|
24
|
+
* @returns {{model: string, effort?: string}|null} null when the host does not
|
|
25
|
+
* offer that rung - which is a real answer, not a failure: one host carries
|
|
26
|
+
* no top rung at all.
|
|
27
|
+
*/
|
|
28
|
+
export function modelFor(rung, hostId = currentHostId() ?? HOST_IDS[0]) {
|
|
29
|
+
return REGISTRY.hosts[hostId]?.models?.rungs?.[rung] ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The rung a model id sits on, for reading back what a run recorded.
|
|
34
|
+
*
|
|
35
|
+
* A tracker records the model it ran, not the rung it was asked for. Comparing
|
|
36
|
+
* that string against the rung ladder answered "not on the ladder" for every
|
|
37
|
+
* host whose rungs are not named after their models, which silently disabled
|
|
38
|
+
* rework escalation there.
|
|
39
|
+
*
|
|
40
|
+
* Where one model fills several rungs at different efforts, the LEAST capable
|
|
41
|
+
* of them answers unless an effort is given. Naming the most capable one reads
|
|
42
|
+
* as "already at the top" and stops an escalation that had somewhere to go;
|
|
43
|
+
* naming the least can at worst propose a step the run is already taking, and
|
|
44
|
+
* `modelFor` makes that a no-op the caller can see.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} model - a model id, or a rung name, which answers itself
|
|
47
|
+
* @param {string} [hostId]
|
|
48
|
+
* @param {string} [effort] - narrows a model that fills several rungs
|
|
49
|
+
* @returns {string|null}
|
|
50
|
+
*/
|
|
51
|
+
export function rungOf(model, hostId = currentHostId() ?? HOST_IDS[0], effort = undefined) {
|
|
52
|
+
const rungs = REGISTRY.hosts[hostId]?.models?.rungs ?? {};
|
|
53
|
+
if (Object.hasOwn(rungs, model)) return model;
|
|
54
|
+
const matches = Object.entries(rungs).filter(([, slot]) => slot.model === model);
|
|
55
|
+
if (!matches.length) return null;
|
|
56
|
+
const exact = effort ? matches.filter(([, slot]) => slot.effort === effort) : [];
|
|
57
|
+
return (exact.length ? exact : matches).at(-1)[0];
|
|
58
|
+
}
|