@giamme/forge 0.12.1 → 0.13.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 +66 -0
- package/README.md +1 -1
- package/SKILL.md +29 -12
- package/VERSION +1 -1
- package/docs/add-ons.md +11 -6
- package/docs/artifacts.md +12 -6
- package/docs/commands.md +179 -17
- package/docs/decomposed-runs.md +13 -5
- package/docs/forge-ui.md +14 -4
- package/docs/memory.md +2 -1
- package/docs/models.md +4 -2
- package/docs/reviews.md +49 -20
- package/docs/troubleshooting.md +3 -1
- package/forge +17 -1
- package/package.json +1 -1
- package/references/dataset.md +39 -13
- package/references/decision-models.md +763 -0
- package/references/decompose.md +166 -29
- package/references/harnesses.md +10 -3
- package/references/planning.md +8 -0
- package/references/solo.md +13 -3
- package/scripts/forge-artifact.sh +30 -4
- package/scripts/forge-config.py +238 -29
- package/scripts/forge-contract.py +95 -56
- package/scripts/forge-control.py +40 -9
- package/scripts/forge-decide.py +6 -0
- package/scripts/forge-dispatch.sh +38 -16
- package/scripts/forge-fail-first.py +2 -2
- package/scripts/forge-gate-addressed.sh +40 -0
- package/scripts/forge-gate-message.sh +64 -0
- package/scripts/forge-issues.py +321 -33
- package/scripts/forge-jev-options.sh +269 -42
- package/scripts/forge-lib-attribute.sh +447 -0
- package/scripts/forge-lib-gates.sh +32 -0
- package/scripts/forge-lib-plans.sh +22 -6
- package/scripts/forge-lib-review.sh +22 -17
- package/scripts/forge-lib-task.sh +217 -38
- package/scripts/forge-lib-verify.sh +45 -8
- package/scripts/forge-memory.sh +3 -3
- package/scripts/forge-parallel-options.sh +18 -5
- package/scripts/forge-parallel.sh +457 -303
- package/scripts/forge-plan-check.py +35 -1
- package/scripts/forge-pre-review.py +437 -0
- package/scripts/forge-prompt.py +25 -5
- package/scripts/forge-route.py +2 -2
- package/scripts/forge-runtime.py +10 -4
- package/scripts/forge-schedule.py +21 -5
- package/scripts/forge-shadow.py +2 -2
- package/scripts/forge-solo.sh +39 -9
- package/scripts/forge-submodules.py +389 -0
- package/scripts/forge-ui-options.sh +25 -0
- package/scripts/forge_dataset/cli.py +12 -6
- package/scripts/forge_dataset/export.py +140 -84
- package/scripts/forge_dataset/harvest.py +33 -5
- package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
- package/scripts/forge_decide/__init__.py +141 -0
- package/scripts/forge_decide/budget.py +180 -0
- package/scripts/forge_decide/cache.py +66 -0
- package/scripts/forge_decide/cli.py +953 -0
- package/scripts/forge_decide/doctor.py +270 -0
- package/scripts/forge_decide/label_addressed.py +75 -0
- package/scripts/forge_decide/label_attribution.py +62 -0
- package/scripts/forge_decide/label_coverage.py +81 -0
- package/scripts/forge_decide/label_message.py +38 -0
- package/scripts/forge_decide/label_prompt.py +139 -0
- package/scripts/forge_decide/labels.py +328 -0
- package/scripts/forge_decide/metrics.py +125 -0
- package/scripts/forge_decide/migrate.py +226 -0
- package/scripts/forge_decide/providers.py +292 -0
- package/scripts/forge_decide/replay.py +350 -0
- package/scripts/forge_decide/report.py +382 -0
- package/scripts/forge_decide/resolve.py +397 -0
- package/scripts/forge_decide/sites.py +377 -0
- package/scripts/forge_jev/__init__.py +202 -104
- package/scripts/forge_jev/addressed.py +171 -0
- package/scripts/forge_jev/attribution.py +198 -0
- package/scripts/forge_jev/cli.py +460 -382
- package/scripts/forge_jev/client.py +155 -77
- package/scripts/forge_jev/coupling.py +19 -87
- package/scripts/forge_jev/coverage.py +303 -0
- package/scripts/forge_jev/findings.py +219 -0
- package/scripts/forge_jev/gates.py +225 -27
- package/scripts/forge_jev/memory.py +65 -4
- package/scripts/forge_jev/message.py +134 -0
- package/scripts/forge_jev/plan_gates.py +294 -0
- package/scripts/forge_jev/questions.py +173 -313
- package/scripts/forge_jev/verify.py +130 -104
- package/ui/README.md +2 -2
- package/ui/docs/api.md +92 -39
- package/ui/forge_ui/control.py +71 -14
- package/ui/forge_ui/export.py +2 -1
- package/ui/forge_ui/models.py +17 -16
- package/ui/forge_ui/reader.py +132 -21
- package/ui/forge_ui/repos.py +428 -0
- package/ui/forge_ui/static/app.js +24 -5
- package/ui/forge_ui/static/cloudmodel.js +8 -5
- package/ui/forge_ui/static/controls.js +20 -13
- package/ui/forge_ui/static/modelstats.js +12 -8
- package/ui/forge_ui/static/panel.js +63 -17
- package/ui/forge_ui/static/runmodel.js +48 -7
- package/ui/forge_ui/static/scene3d.js +2 -15
- package/ui/forge_ui/static/settings.js +481 -68
- package/ui/forge_ui/static/style.css +56 -9
- package/references/jev.md +0 -865
- package/scripts/forge_jev/backtest.py +0 -322
- package/scripts/forge_jev/corpus.py +0 -156
- package/scripts/forge_jev/features.py +0 -24
- package/scripts/forge_jev/predict.py +0 -204
- package/scripts/forge_jev/review.py +0 -73
- package/scripts/forge_jev/routing.py +0 -271
- package/scripts/forge_jev/subset.py +0 -123
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
/* forge-ui settings view (window.ForgeSettings, and a CommonJS module under node:test). Route #/settings: the model
|
|
2
|
-
registry (read-only),
|
|
3
|
-
The pure helpers (request bodies, value checks, the
|
|
4
|
-
ui/tests/js/settings.test.js; render(host, ctx) is thin DOM
|
|
2
|
+
registry (read-only), the decision-model gates, the three per-repo .forge files of one repository, the dataset and
|
|
3
|
+
the FORGE_* environment. The pure helpers (request bodies, value checks, the decision-model view, the repository
|
|
4
|
+
picker, the editors' unsaved-text state) are tested in ui/tests/js/settings.test.js; render(host, ctx) is thin DOM
|
|
5
|
+
over them. Every value from the server enters the page as text.
|
|
5
6
|
ctx = { key (the run whose repo to show, or null), runs() (the run list), onPick?(key) }. render returns { poll() }:
|
|
6
7
|
the page calls it on each refresh, and unsaved editor text survives it.
|
|
7
8
|
The calls are GET /api/config?run=<key> and POST /api/config, see ui/docs/api.md, "Controls (write endpoints)". A write
|
|
8
|
-
changes a file in the repository's working tree
|
|
9
|
+
changes a file in the repository's working tree, or a decision-model gate in forge's user config, and is only offered
|
|
10
|
+
with controls on. */
|
|
9
11
|
(function (root, factory) {
|
|
10
12
|
'use strict';
|
|
11
|
-
const
|
|
13
|
+
const RM = typeof module === 'object' && module.exports ? require('./runmodel.js') : root.ForgeRunModel;
|
|
14
|
+
const api = factory(root, RM);
|
|
12
15
|
if (typeof module === 'object' && module.exports) module.exports = api;
|
|
13
16
|
else root.ForgeSettings = api;
|
|
14
|
-
})(typeof self !== 'undefined' ? self : this, function (root) {
|
|
17
|
+
})(typeof self !== 'undefined' ? self : this, function (root, RM) {
|
|
15
18
|
'use strict';
|
|
16
19
|
|
|
17
20
|
const FILES = ['verify', 'setup', 'verify-subset'];
|
|
18
21
|
const VALUE_MAX = 4096;
|
|
22
|
+
const DECIDE_VALUE_MAX = 256;
|
|
23
|
+
// The same names as forge_decide.GATES. The section renders this list, not whatever keys a payload happens to carry.
|
|
24
|
+
const GATES = ['drift', 'forward', 'prompt', 'memory-curate', 'memory-slice', 'memory-stale', 'verify-discover',
|
|
25
|
+
'coverage', 'retry-addressed', 'dwarf-message', 'attribution', 'findings'];
|
|
26
|
+
const MODES = ['off', 'shadow', 'on'];
|
|
27
|
+
const ADD_COMMAND = 'forge decide provider add …';
|
|
19
28
|
const POLL_MS = 20000; // the config rarely changes, and each read starts a CLI process
|
|
20
29
|
const list = v => Array.isArray(v) ? v : [];
|
|
21
30
|
const object = v => v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
@@ -23,13 +32,14 @@
|
|
|
23
32
|
const basename = p => String(p || '').replace(/\/+$/, '').split('/').pop() || String(p || '');
|
|
24
33
|
|
|
25
34
|
/* ---------- pure ---------- */
|
|
26
|
-
// The POST body: a set carries `value`, an unset carries `unset: true`, never both.
|
|
27
|
-
// 'true' or 'false', as the CLI takes it.
|
|
35
|
+
// The POST body: a set carries `value`, an unset carries `unset: true`, never both.
|
|
28
36
|
function configBody(run, key, value, unset) {
|
|
29
37
|
if (unset) return { run: String(run), key: String(key), unset: true };
|
|
30
38
|
return { run: String(run), key: String(key), value: String(value) };
|
|
31
39
|
}
|
|
32
40
|
const repoKey = name => 'repo.' + name;
|
|
41
|
+
// decide.gate.<gate>, or the same with .provider or .model.
|
|
42
|
+
const gateKey = (name, field) => 'decide.gate.' + name + (field ? '.' + field : '');
|
|
33
43
|
// The file a save or remove touches, as the confirm names it.
|
|
34
44
|
const targetPath = (repo, name) => String(repo || '').replace(/\/+$/, '') + '/.forge/' + name;
|
|
35
45
|
|
|
@@ -48,8 +58,122 @@
|
|
|
48
58
|
return null;
|
|
49
59
|
}
|
|
50
60
|
|
|
61
|
+
// Why a provider or model would be refused: empty, too long, a control character (newline and tab included),
|
|
62
|
+
// leading or trailing whitespace, or a leading '-'. The same rules as the server, so a bad value is never posted.
|
|
63
|
+
function decideTextProblem(value) {
|
|
64
|
+
const v = text(value);
|
|
65
|
+
if (!v.trim()) return 'Empty.';
|
|
66
|
+
if (v !== v.trim()) return 'The text cannot start or end with a space.';
|
|
67
|
+
const chars = Array.from(v).length;
|
|
68
|
+
if (chars > DECIDE_VALUE_MAX) return `Too long: ${chars} of ${DECIDE_VALUE_MAX} characters.`;
|
|
69
|
+
if (/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/.test(v)) return 'The text has an unpaired surrogate, which cannot be saved.';
|
|
70
|
+
if (/[\u0000-\u001f\u007f]/.test(v)) return 'Control characters are not allowed.';
|
|
71
|
+
if (v.startsWith('-')) return 'The text cannot start with "-".';
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const finite = n => typeof n === 'number' && Number.isFinite(n);
|
|
76
|
+
const capTokens = n => finite(n) ? String(n) : 'none';
|
|
77
|
+
const capMoney = n => finite(n) ? n.toFixed(4) : 'none';
|
|
78
|
+
const money = n => finite(n) ? n.toFixed(4) : '0.0000';
|
|
79
|
+
const count = n => finite(n) ? String(n) : '0';
|
|
80
|
+
// How a shadowed value is named in the note. Strings keep their JSON quotes so a mode is not a bare word.
|
|
81
|
+
function literal(value) {
|
|
82
|
+
if (value == null) return 'nothing';
|
|
83
|
+
if (typeof value === 'string') return JSON.stringify(value);
|
|
84
|
+
if (typeof value === 'number' && Number.isFinite(value)) return String(value);
|
|
85
|
+
if (typeof value === 'boolean') return String(value);
|
|
86
|
+
return 'a value';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The replay a gate carries, or null: `forge decide replay`'s recorded result for the gate's provider and model. An older
|
|
90
|
+
// forge sends none, which reads as no replay, never as an error.
|
|
91
|
+
function describeReplay(replay) {
|
|
92
|
+
if (!replay || typeof replay !== 'object' || Array.isArray(replay)) return null;
|
|
93
|
+
return { provider: text(replay.provider), model: text(replay.model), passes: replay.passes === true, at: finite(replay.at) ? replay.at : null };
|
|
94
|
+
}
|
|
95
|
+
// The day a replay was recorded, in local time like the CLI's `replayed <date>`; '?' when the time is unusable.
|
|
96
|
+
function replayDate(at) {
|
|
97
|
+
const d = finite(at) ? new Date(at * 1000) : null;
|
|
98
|
+
if (!d || Number.isNaN(d.getTime())) return '?';
|
|
99
|
+
const two = n => String(n).padStart(2, '0');
|
|
100
|
+
return d.getFullYear() + '-' + two(d.getMonth() + 1) + '-' + two(d.getDate());
|
|
101
|
+
}
|
|
102
|
+
// The tags a gate row shows beside its source tag: [{suffix, text, title, bad}], the element id being
|
|
103
|
+
// set-gate-<name>-<suffix>. A forced gate acts on without a passing replay; a replay shows when it was recorded and
|
|
104
|
+
// whether it passed. A gate with neither has none.
|
|
105
|
+
function gateTags(gate) {
|
|
106
|
+
const tags = [];
|
|
107
|
+
const replay = gate.replay;
|
|
108
|
+
const on = replay ? replay.provider + '/' + replay.model : '';
|
|
109
|
+
if (gate.forced && gate.mode === 'on') {
|
|
110
|
+
tags.push({ suffix: 'forced', text: 'forced', bad: true,
|
|
111
|
+
title: 'This gate acts without a recorded replay for its provider and model that passes.' });
|
|
112
|
+
}
|
|
113
|
+
if (replay) {
|
|
114
|
+
tags.push(replay.passes
|
|
115
|
+
? { suffix: 'replay', text: 'replayed ' + replayDate(replay.at), title: 'Replay on ' + on + ' passed.', bad: false }
|
|
116
|
+
: { suffix: 'replay', text: 'replay failed', title: 'Replay on ' + on + ' did not pass (' + replayDate(replay.at) + ').', bad: true });
|
|
117
|
+
}
|
|
118
|
+
return tags;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// The Decision models section, as data. render() draws only this, so the page and the test share one reading of the
|
|
122
|
+
// status object. Provider key fields are dropped here and never reach a string the page shows.
|
|
123
|
+
function describeDecide(decide) {
|
|
124
|
+
const d = object(decide);
|
|
125
|
+
const gatesIn = object(d.gates);
|
|
126
|
+
const floor = object(d.privacy).floor === true;
|
|
127
|
+
const providers = Object.keys(object(d.providers)).sort().map(name => {
|
|
128
|
+
const row = object(object(d.providers)[name]);
|
|
129
|
+
return { name, type: text(row.type), local: row.local === true };
|
|
130
|
+
});
|
|
131
|
+
const gates = GATES.map(name => {
|
|
132
|
+
const g = object(gatesIn[name]);
|
|
133
|
+
const skip = floor ? 'privacy' : (typeof g.skip === 'string' ? g.skip : '');
|
|
134
|
+
const mode = MODES.includes(g.mode) ? g.mode : 'off';
|
|
135
|
+
const source = text(g.source) || 'default';
|
|
136
|
+
return {
|
|
137
|
+
name,
|
|
138
|
+
mode,
|
|
139
|
+
source,
|
|
140
|
+
// The mode the user level holds, where the status shows it: the user file set it and no override applies.
|
|
141
|
+
userMode: source === 'user' && !skip ? mode : null,
|
|
142
|
+
provider: typeof g.provider === 'string' ? g.provider : '',
|
|
143
|
+
model: typeof g.model === 'string' ? g.model : '',
|
|
144
|
+
skip,
|
|
145
|
+
ready: g.ready === true,
|
|
146
|
+
forced: g.forced === true,
|
|
147
|
+
replay: describeReplay(g.replay),
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
const caps = object(object(d.budget).caps);
|
|
151
|
+
const spend = object(object(d.budget).spend);
|
|
152
|
+
const today = object(spend.today);
|
|
153
|
+
const date = text(spend.date) || '—';
|
|
154
|
+
const line = 'run cap ' + capTokens(caps.run_tokens) + ' tokens, $' + capMoney(caps.run_usd)
|
|
155
|
+
+ '; daily cap ' + capTokens(caps.daily_tokens) + ' tokens, $' + capMoney(caps.daily_usd)
|
|
156
|
+
+ '; today (' + date + '): ' + count(today.tokens) + ' tokens of ' + capTokens(caps.daily_tokens)
|
|
157
|
+
+ ', $' + money(today.usd) + ' of $' + capMoney(caps.daily_usd);
|
|
158
|
+
const shadowed = list(d.shadowed).filter(e => e && typeof e === 'object').map(e => ({
|
|
159
|
+
key: text(e.key),
|
|
160
|
+
note: text(e.key) + ': the repo sets ' + literal(e.repo) + ', the user file\'s ' + literal(e.user) + ' wins',
|
|
161
|
+
}));
|
|
162
|
+
return {
|
|
163
|
+
gates, privacyFloor: floor,
|
|
164
|
+
banner: floor ? 'Nothing is sent. This repository is under a privacy floor.' : '',
|
|
165
|
+
budget: {
|
|
166
|
+
run: { tokens: caps.run_tokens == null ? null : caps.run_tokens, usd: caps.run_usd == null ? null : caps.run_usd },
|
|
167
|
+
daily: { tokens: caps.daily_tokens == null ? null : caps.daily_tokens, usd: caps.daily_usd == null ? null : caps.daily_usd },
|
|
168
|
+
today: { tokens: today.tokens == null ? 0 : today.tokens, usd: today.usd == null ? 0 : today.usd, date },
|
|
169
|
+
line,
|
|
170
|
+
},
|
|
171
|
+
shadowed, providers, noProviders: providers.length === 0, addCommand: ADD_COMMAND,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
51
175
|
// The runs a repository can be taken from (those that name one), newest first.
|
|
52
|
-
const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof r
|
|
176
|
+
const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof RM.repoKey(r) === 'string');
|
|
53
177
|
const newestFirst = (a, b) => (Number(b.updated) || 0) - (Number(a.updated) || 0);
|
|
54
178
|
// The run whose repository the page opens on: the current run when it is in the list, else the most recent one.
|
|
55
179
|
function pickDefault(runs, current) {
|
|
@@ -58,19 +182,37 @@
|
|
|
58
182
|
const latest = usable.slice().sort(newestFirst)[0];
|
|
59
183
|
return latest ? latest.key : null;
|
|
60
184
|
}
|
|
61
|
-
// The choices grouped by repository: [{repo, name, runs}], the repository of the newest run first.
|
|
185
|
+
// The choices grouped by repository root: [{repo, name, runs}], the repository of the newest run first.
|
|
62
186
|
function groupRuns(runs) {
|
|
63
187
|
const groups = new Map();
|
|
64
188
|
for (const r of withRepo(runs).sort(newestFirst)) {
|
|
65
|
-
|
|
66
|
-
groups.
|
|
189
|
+
const repo = RM.repoKey(r);
|
|
190
|
+
if (!groups.has(repo)) groups.set(repo, { repo, name: basename(repo), runs: [] });
|
|
191
|
+
groups.get(repo).runs.push(r);
|
|
67
192
|
}
|
|
68
193
|
return [...groups.values()];
|
|
69
194
|
}
|
|
195
|
+
// The run inside its repository's group. The worktree it started in belongs to the run too, and the picker shows it
|
|
196
|
+
// beside this label as secondary text; the group names the repository.
|
|
70
197
|
const optionLabel = r => {
|
|
71
198
|
const goal = text(r.goal).split('\n')[0].trim();
|
|
72
|
-
|
|
199
|
+
const short = goal.length > 60 ? goal.slice(0, 59) + '…' : goal;
|
|
200
|
+
return [r.run_id || r.key, short].filter(Boolean).join(' · ');
|
|
73
201
|
};
|
|
202
|
+
// The option the picker's type-ahead lands on: the first label that starts with `query`, ignoring case, searching on from
|
|
203
|
+
// the active one `from` and wrapping round; -1 when none does. One letter typed again and again steps through the labels
|
|
204
|
+
// that start with it, so the search starts after the active label; a longer query starts at it, which stays put.
|
|
205
|
+
function typeAhead(labels, from, query) {
|
|
206
|
+
const all = list(labels), q = text(query).toLowerCase();
|
|
207
|
+
if (!q || !all.length) return -1;
|
|
208
|
+
const repeat = [...q].every(ch => ch === q[0]);
|
|
209
|
+
const want = repeat ? q[0] : q, start = repeat ? from + 1 : Math.max(from, 0);
|
|
210
|
+
for (let i = 0; i < all.length; i++) {
|
|
211
|
+
const at = (start + i) % all.length;
|
|
212
|
+
if (text(all[at]).toLowerCase().startsWith(want)) return at;
|
|
213
|
+
}
|
|
214
|
+
return -1;
|
|
215
|
+
}
|
|
74
216
|
|
|
75
217
|
// An editor's unsaved text. `base` is the file as last read, `draft` the textarea (null: untouched). The CLI ends a saved
|
|
76
218
|
// file with a newline, so trailing newlines do not count as an edit.
|
|
@@ -103,12 +245,12 @@
|
|
|
103
245
|
function render(host, ctx) {
|
|
104
246
|
const UI = root.ForgeUI, c = ctx || {};
|
|
105
247
|
const el = (tag, t, cls) => UI.el(tag, t, cls);
|
|
106
|
-
const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false };
|
|
248
|
+
const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, models: {}, modelMoved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false, listOpen: false };
|
|
107
249
|
const key_ = (label, cls, onclick) => { const b = el('button', label, cls); b.type = 'button'; if (onclick) b.addEventListener('click', onclick); return b; };
|
|
108
250
|
|
|
109
251
|
const head = el('header', undefined, 'set-head');
|
|
110
252
|
head.append(el('h1', 'Settings', 'module-title'),
|
|
111
|
-
el('p', 'What forge reads when it runs: its model registry
|
|
253
|
+
el('p', 'What forge reads when it runs: its model registry, the decision-model gates, and the three files a repository can keep in .forge.', 'muted set-lede'));
|
|
112
254
|
const picker = el('div', undefined, 'set-picker');
|
|
113
255
|
const body = el('div', undefined, 'set-body');
|
|
114
256
|
const note = el('p', 'This page is read-only: this server has no write token, or has controls off.', 'muted set-readonly');
|
|
@@ -120,10 +262,26 @@
|
|
|
120
262
|
host.replaceChildren(head, picker, note, stale, body);
|
|
121
263
|
const staleNote = msg => { stale.hidden = !msg; stale.textContent = msg ? `The last read of the configuration failed: ${msg}. This shows the read before it; the next refresh tries again.` : ''; };
|
|
122
264
|
|
|
123
|
-
/* the repository picker
|
|
265
|
+
/* the repository picker: a button and a listbox rather than a native select, whose options hold plain text only, so
|
|
266
|
+
that each run can show the worktree it started in as secondary text. */
|
|
267
|
+
// The repository the configuration was read from, as the server answered; until then the run's root.
|
|
268
|
+
const repoPath = () => text(object(object(s.data).repo).path) || s.repo || '';
|
|
269
|
+
// A run as the picker shows it: its label, then its worktree as secondary text, with the full path and branch in its title.
|
|
270
|
+
function runFace(r) {
|
|
271
|
+
const face = [el('span', optionLabel(r), 'set-run-label')];
|
|
272
|
+
const worktree = RM.repoLabel(r).worktree;
|
|
273
|
+
if (worktree) {
|
|
274
|
+
const wt = el('span', worktree, 'muted repo-wt');
|
|
275
|
+
const branch = typeof r.repo_branch === 'string' ? r.repo_branch.trim() : '';
|
|
276
|
+
wt.title = r.repo_worktree + (branch ? `\nbranch ${branch}` : '');
|
|
277
|
+
face.push(wt);
|
|
278
|
+
}
|
|
279
|
+
return face;
|
|
280
|
+
}
|
|
124
281
|
function drawPicker() {
|
|
125
|
-
// The switch confirm lives in the picker: while
|
|
126
|
-
|
|
282
|
+
// The switch confirm lives in the picker, and the open list is part of it: while either is open the rebuild waits,
|
|
283
|
+
// and runs when the confirm is answered or the list closes.
|
|
284
|
+
if (s.asking || s.listOpen) { s.pickerLate = true; return; }
|
|
127
285
|
const runs = c.runs ? c.runs() : [];
|
|
128
286
|
const groups = groupRuns(runs);
|
|
129
287
|
const before = s.run, usable = withRepo(runs);
|
|
@@ -132,53 +290,135 @@
|
|
|
132
290
|
if (s.run != null && !usable.some(r => r.key === s.run)) {
|
|
133
291
|
// The run left the list. Another run of the same repository carries on with the editors as they are; with unsaved
|
|
134
292
|
// text and no such run the page stays on it, flagged, rather than throwing the text away.
|
|
135
|
-
const sibling = usable.slice().sort(newestFirst).find(r => r
|
|
293
|
+
const sibling = usable.slice().sort(newestFirst).find(r => RM.repoKey(r) === s.repo);
|
|
136
294
|
if (sibling) { s.run = sibling.key; kept = true; }
|
|
137
295
|
else if (FILES.some(n => isDirty(s.editors[n]))) s.gone = true;
|
|
138
296
|
else s.run = null;
|
|
139
297
|
}
|
|
140
298
|
if (s.run == null) s.run = pickDefault(runs, c.key);
|
|
141
299
|
const now = usable.find(r => r.key === s.run);
|
|
142
|
-
if (now) s.repo = now
|
|
300
|
+
if (now) s.repo = RM.repoKey(now);
|
|
143
301
|
if (s.run !== before) {
|
|
144
302
|
if (!kept) resetRun();
|
|
145
303
|
if (s.ready) { if (!kept) drawBody(); load(); } // the default arrived, or the run went away
|
|
146
304
|
}
|
|
147
|
-
const sig = JSON.stringify([s.run, s.gone, groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r)])])]);
|
|
305
|
+
const sig = JSON.stringify([s.run, s.gone, repoPath(), groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r), r.repo_worktree || null, r.repo_branch || null])])]);
|
|
148
306
|
if (sig === s.runsSig) return;
|
|
149
307
|
s.runsSig = sig;
|
|
150
308
|
if (!groups.length) { picker.replaceChildren(el('p', 'No run names a repository yet, so there is nothing to configure.', 'muted')); return; }
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
309
|
+
const refocus = document.activeElement && document.activeElement.id === 'set-run';
|
|
310
|
+
const current = s.gone ? null : usable.find(r => r.key === s.run);
|
|
311
|
+
|
|
312
|
+
const btn = el('button', undefined, 'set-run'); btn.type = 'button'; btn.id = 'set-run';
|
|
313
|
+
btn.dataset.run = current ? current.key : '';
|
|
314
|
+
btn.setAttribute('aria-haspopup', 'listbox'); btn.setAttribute('aria-expanded', 'false');
|
|
315
|
+
btn.setAttribute('aria-controls', 'set-run-list'); btn.setAttribute('aria-labelledby', 'set-run-cap set-run');
|
|
316
|
+
if (current) btn.append(...runFace(current));
|
|
317
|
+
else btn.append(el('span', 'This run is no longer listed', 'set-run-label'));
|
|
318
|
+
const pop = el('div', undefined, 'set-run-pop popover'); pop.popover = 'auto'; pop.id = 'set-run-pop';
|
|
319
|
+
const box = el('div', undefined, 'set-run-list'); box.id = 'set-run-list'; box.tabIndex = -1;
|
|
320
|
+
box.setAttribute('role', 'listbox'); box.setAttribute('aria-labelledby', 'set-run-cap');
|
|
321
|
+
const options = [];
|
|
322
|
+
groups.forEach((g, i) => {
|
|
323
|
+
const group = el('div', undefined, 'set-run-group'); group.setAttribute('role', 'group');
|
|
324
|
+
const name = el('div', undefined, 'set-run-group-name'); name.id = 'set-run-g' + i;
|
|
325
|
+
name.append(el('span', g.name, 'plate'), el('span', g.repo, 'muted mono'));
|
|
326
|
+
group.setAttribute('aria-labelledby', name.id); group.append(name);
|
|
327
|
+
for (const r of g.runs) {
|
|
328
|
+
const o = el('div', undefined, 'set-run-opt'); o.id = 'set-run-o-' + r.key; o.dataset.run = r.key;
|
|
329
|
+
o.setAttribute('role', 'option'); o.setAttribute('aria-selected', String(r.key === btn.dataset.run));
|
|
330
|
+
o.append(...runFace(r)); group.append(o); options.push(o);
|
|
331
|
+
}
|
|
332
|
+
box.append(group);
|
|
333
|
+
});
|
|
334
|
+
pop.append(box);
|
|
335
|
+
|
|
336
|
+
let active = -1, query = '', queryAt = 0; // the type-ahead's letters, and when the last came
|
|
337
|
+
const typing = () => query !== '' && Date.now() - queryAt < 700;
|
|
338
|
+
function activate(i) {
|
|
339
|
+
active = i;
|
|
340
|
+
options.forEach((o, j) => o.classList.toggle('is-active', j === i));
|
|
341
|
+
if (i < 0) { box.removeAttribute('aria-activedescendant'); return; }
|
|
342
|
+
box.setAttribute('aria-activedescendant', options[i].id);
|
|
343
|
+
options[i].scrollIntoView({ block: 'nearest' });
|
|
157
344
|
}
|
|
158
|
-
|
|
345
|
+
const isOpen = () => pop.matches(':popover-open');
|
|
346
|
+
const close = () => { s.listOpen = false; btn.setAttribute('aria-expanded', 'false'); if (isOpen()) pop.hidePopover(); };
|
|
347
|
+
btn.popoverTargetElement = pop; // a click toggles the list; Escape or a click elsewhere closes it
|
|
348
|
+
btn.addEventListener('keydown', e => {
|
|
349
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
|
|
350
|
+
e.preventDefault();
|
|
351
|
+
if (!isOpen()) pop.showPopover();
|
|
352
|
+
});
|
|
353
|
+
// The open state as the list starts to open or close (beforetoggle runs at once); where it sits and the focus once it has
|
|
354
|
+
// (toggle runs after).
|
|
355
|
+
pop.addEventListener('beforetoggle', e => {
|
|
356
|
+
s.listOpen = e.newState === 'open'; btn.setAttribute('aria-expanded', String(s.listOpen));
|
|
357
|
+
});
|
|
358
|
+
pop.addEventListener('toggle', e => {
|
|
359
|
+
if (e.newState === 'open') {
|
|
360
|
+
// under the button, or above it when the button sits low on the screen
|
|
361
|
+
const r = btn.getBoundingClientRect();
|
|
362
|
+
pop.style.minWidth = Math.round(r.width) + 'px';
|
|
363
|
+
const h = pop.offsetHeight, below = window.innerHeight - r.bottom > h + 16;
|
|
364
|
+
pop.style.left = Math.round(Math.max(8, Math.min(window.innerWidth - pop.offsetWidth - 8, r.left))) + 'px';
|
|
365
|
+
pop.style.top = Math.round(below ? r.bottom + 4 : Math.max(8, r.top - h - 4)) + 'px';
|
|
366
|
+
query = '';
|
|
367
|
+
activate(Math.max(0, options.findIndex(o => o.dataset.run === btn.dataset.run)));
|
|
368
|
+
box.focus({ preventScroll: true });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
// Focus left with the list goes back to the button, the one on the page now (a choice may have rebuilt it).
|
|
372
|
+
const at = document.activeElement;
|
|
373
|
+
if (!at || at === document.body || pop.contains(at)) { const b = document.getElementById('set-run'); if (b) b.focus({ preventScroll: true }); }
|
|
374
|
+
if (s.pickerLate && !s.asking) { s.pickerLate = false; drawPicker(); }
|
|
375
|
+
});
|
|
376
|
+
box.addEventListener('keydown', e => {
|
|
377
|
+
const k = e.key, last = options.length - 1;
|
|
378
|
+
if (k === 'ArrowDown') activate(Math.min(last, active + 1));
|
|
379
|
+
else if (k === 'ArrowUp') activate(Math.max(0, active - 1));
|
|
380
|
+
else if (k === 'Home') activate(0);
|
|
381
|
+
else if (k === 'End') activate(last);
|
|
382
|
+
else if (k === 'Enter' || (k === ' ' && !typing())) { if (active >= 0) choose(options[active].dataset.run); }
|
|
383
|
+
else if (k === 'Tab') { close(); return; }
|
|
384
|
+
else if (k.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
385
|
+
query = (typing() ? query : '') + k; queryAt = Date.now();
|
|
386
|
+
const at = typeAhead(options.map(o => o.firstChild.textContent), active, query);
|
|
387
|
+
if (at >= 0) activate(at);
|
|
388
|
+
} else return;
|
|
389
|
+
e.preventDefault();
|
|
390
|
+
});
|
|
391
|
+
box.addEventListener('mousemove', e => { const o = e.target.closest('[role=option]'); if (o && options.indexOf(o) !== active) activate(options.indexOf(o)); });
|
|
392
|
+
box.addEventListener('click', e => { const o = e.target.closest('[role=option]'); if (o) choose(o.dataset.run); });
|
|
393
|
+
async function choose(key) {
|
|
394
|
+
close();
|
|
395
|
+
if (key === btn.dataset.run) return; // the run already shown
|
|
159
396
|
const unsaved = FILES.filter(n => s.editors[n] && isDirty(s.editors[n]));
|
|
160
397
|
if (unsaved.length) {
|
|
161
398
|
const ask = s.asking = ++s.asks;
|
|
162
399
|
const yes = await UI.confirmInline(picker, `Switch repository and discard the unsaved edits to ${unsaved.map(n => '.forge/' + n).join(', ')}?`, { danger: true });
|
|
163
|
-
if (s.asking !== ask) return; // a later
|
|
400
|
+
if (s.asking !== ask) return; // a later choice asked again, and that confirm decides
|
|
164
401
|
const late = s.pickerLate;
|
|
165
402
|
s.asking = 0; s.pickerLate = false;
|
|
166
|
-
if (!yes) {
|
|
403
|
+
if (!yes) { if (late) drawPicker(); return; }
|
|
167
404
|
}
|
|
168
|
-
pick(
|
|
169
|
-
}
|
|
405
|
+
pick(key);
|
|
406
|
+
}
|
|
407
|
+
|
|
170
408
|
const lab = el('label', undefined, 'set-field'); lab.htmlFor = 'set-run';
|
|
171
|
-
|
|
409
|
+
const cap = el('span', 'Repository of run', 'plate'); cap.id = 'set-run-cap';
|
|
410
|
+
lab.append(cap);
|
|
172
411
|
const path = el('p', undefined, 'set-repo-path');
|
|
173
|
-
path.append(el('i', undefined, 'lamp lamp-route'), el('span',
|
|
174
|
-
const row = el('div', undefined, 'set-picker-row'); row.append(lab,
|
|
412
|
+
path.append(el('i', undefined, 'lamp lamp-route'), el('span', repoPath(), 'mono'));
|
|
413
|
+
const row = el('div', undefined, 'set-picker-row'); row.append(lab, btn, pop);
|
|
175
414
|
picker.replaceChildren(row, path);
|
|
176
415
|
if (s.gone) picker.append(el('p', 'The run is gone from the list. Your unsaved edits are kept; pick another run to continue, which discards them.', 'warn set-problem'));
|
|
416
|
+
if (refocus) btn.focus({ preventScroll: true });
|
|
177
417
|
}
|
|
178
418
|
// A new run: nothing of the old one stays, and confirms of the old body (now detached) no longer hold a redraw.
|
|
179
419
|
function resetRun() {
|
|
180
420
|
staleNote(null);
|
|
181
|
-
s.data = null; s.dataText = null; s.error = null; s.editors = {}; s.moved = {}; s.loading = s.run != null;
|
|
421
|
+
s.data = null; s.dataText = null; s.error = null; s.editors = {}; s.moved = {}; s.models = {}; s.modelMoved = {}; s.loading = s.run != null;
|
|
182
422
|
s.gen++; s.hold = 0; s.redraw = false;
|
|
183
423
|
}
|
|
184
424
|
function pick(key) {
|
|
@@ -210,9 +450,14 @@
|
|
|
210
450
|
const next = dirtyState(s.editors[name], object(files[name]).content);
|
|
211
451
|
s.editors[name] = next.editor; s.moved[name] = next.moved || (next.dirty && !!s.moved[name]);
|
|
212
452
|
}
|
|
453
|
+
for (const g of describeDecide(res.data.decide).gates) {
|
|
454
|
+
const next = dirtyState(s.models[g.name], g.model);
|
|
455
|
+
s.models[g.name] = next.editor; s.modelMoved[g.name] = next.moved || (next.dirty && !!s.modelMoved[g.name]);
|
|
456
|
+
}
|
|
213
457
|
const t = JSON.stringify(res.data);
|
|
214
458
|
if (t === s.dataText && !s.redraw) return;
|
|
215
459
|
s.data = res.data; s.dataText = t;
|
|
460
|
+
drawPicker(); // its path line names the repository this read came from
|
|
216
461
|
if (s.hold > 0) { s.redraw = true; return; } // a confirm or a write is open: draw after it
|
|
217
462
|
drawBody();
|
|
218
463
|
}
|
|
@@ -224,13 +469,14 @@
|
|
|
224
469
|
|
|
225
470
|
function drawBody() {
|
|
226
471
|
const focus = document.activeElement && body.contains(document.activeElement) ? document.activeElement : null;
|
|
227
|
-
const at = focus && focus.dataset.editor ? { name: focus.dataset.editor, a: focus.selectionStart, b: focus.selectionEnd }
|
|
472
|
+
const at = focus && focus.dataset.editor ? { kind: 'editor', name: focus.dataset.editor, a: focus.selectionStart, b: focus.selectionEnd }
|
|
473
|
+
: focus && focus.dataset.model ? { kind: 'model', name: focus.dataset.model, a: focus.selectionStart, b: focus.selectionEnd } : null;
|
|
228
474
|
if (s.loading) { body.replaceChildren(el('p', 'Reading the configuration…', 'muted')); return; }
|
|
229
475
|
if (s.error) { body.replaceChildren(el('p', 'Could not read the configuration: ' + s.error, 'warn')); return; }
|
|
230
476
|
if (!s.data) { body.replaceChildren(); return; }
|
|
231
|
-
body.replaceChildren(registrySection(),
|
|
477
|
+
body.replaceChildren(registrySection(), decideSection(), repoSection(), datasetSection(), envSection());
|
|
232
478
|
if (at) {
|
|
233
|
-
const t = body.querySelector(`textarea[data-editor="${at.name}"]`);
|
|
479
|
+
const t = at.kind === 'model' ? body.querySelector(`input[data-model="${at.name}"]`) : body.querySelector(`textarea[data-editor="${at.name}"]`);
|
|
234
480
|
if (t) { t.focus({ preventScroll: true }); try { t.setSelectionRange(at.a, at.b); } catch (_) { /* not selectable */ } }
|
|
235
481
|
}
|
|
236
482
|
}
|
|
@@ -274,37 +520,203 @@
|
|
|
274
520
|
return sec;
|
|
275
521
|
}
|
|
276
522
|
|
|
277
|
-
function
|
|
278
|
-
const
|
|
279
|
-
const sec = section('
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (s.writes) {
|
|
287
|
-
const sw = el('button', undefined, 'set-switch'); sw.type = 'button';
|
|
288
|
-
sw.setAttribute('role', 'switch'); sw.setAttribute('aria-checked', String(on));
|
|
289
|
-
sw.append(el('span', undefined, 'set-switch-knob'), el('span', on ? 'On' : 'Off', 'set-switch-label'));
|
|
290
|
-
sw.setAttribute('aria-label', 'Jev enabled');
|
|
291
|
-
sw.addEventListener('click', async () => {
|
|
292
|
-
const next = !on;
|
|
293
|
-
const gen = s.gen, release = grab();
|
|
294
|
-
sw.disabled = true;
|
|
295
|
-
const yes = await UI.confirmInline(result, `Turn Jev ${next ? 'on' : 'off'}? This changes forge's own config (${text(jev.path)}) for every repository.`);
|
|
296
|
-
if (!yes) { sw.disabled = false; release(); sw.focus({ preventScroll: true }); return; }
|
|
297
|
-
const res = await UI.post('/api/config', configBody(s.run, 'jev.enabled', next));
|
|
298
|
-
UI.outcome(result, res, `Jev is now ${next ? 'enabled' : 'disabled'}.`);
|
|
299
|
-
sw.disabled = false; release();
|
|
300
|
-
if (res.ok && gen === s.gen) await reload();
|
|
301
|
-
});
|
|
302
|
-
row.append(sw);
|
|
523
|
+
function decideSection() {
|
|
524
|
+
const view = describeDecide(s.data.decide);
|
|
525
|
+
const sec = section('decide', 'Decision models', 'Each gate is off, shadow or on, with a provider and a model. A change writes your forge config (the user level), so it applies to every repository. The mode shown is the one in effect for this repository, and where it came from.');
|
|
526
|
+
const where = text(object(s.data.decide).user_path);
|
|
527
|
+
if (where) sec.append(pathLine('config', where));
|
|
528
|
+
if (view.privacyFloor) {
|
|
529
|
+
const banner = el('p', view.banner, 'set-banner');
|
|
530
|
+
banner.id = 'set-decide-privacy';
|
|
531
|
+
sec.append(banner);
|
|
303
532
|
}
|
|
304
|
-
|
|
533
|
+
const budget = el('p', view.budget.line, 'muted set-budget');
|
|
534
|
+
budget.id = 'set-decide-budget';
|
|
535
|
+
sec.append(budget);
|
|
536
|
+
if (view.noProviders) {
|
|
537
|
+
const note = el('p', undefined, 'muted');
|
|
538
|
+
note.append(el('span', 'No provider is configured. Add one with '), el('span', view.addCommand, 'mono'), el('span', '.'));
|
|
539
|
+
sec.append(note);
|
|
540
|
+
}
|
|
541
|
+
for (const item of view.shadowed) sec.append(el('p', item.note, 'muted'));
|
|
542
|
+
const gates = el('div', undefined, 'set-gates');
|
|
543
|
+
for (const gate of view.gates) gates.append(gateRow(gate, view.providers));
|
|
544
|
+
sec.append(gates);
|
|
305
545
|
return sec;
|
|
306
546
|
}
|
|
307
547
|
|
|
548
|
+
const providerLabel = p => [p.name, p.type, p.local ? 'local' : ''].filter(Boolean).join(' · ');
|
|
549
|
+
|
|
550
|
+
function gateRow(gate, providers) {
|
|
551
|
+
const art = el('article', undefined, 'set-file set-gate');
|
|
552
|
+
art.id = 'set-gate-' + gate.name;
|
|
553
|
+
const h = el('h3', gate.name, 'set-file-name');
|
|
554
|
+
const status = el('p', undefined, 'set-file-status');
|
|
555
|
+
const source = el('span', gate.source, 'tag');
|
|
556
|
+
source.id = 'set-gate-' + gate.name + '-source';
|
|
557
|
+
status.append(source);
|
|
558
|
+
for (const t of gateTags(gate)) {
|
|
559
|
+
const tag = el('span', t.text, t.bad ? 'tag tag-bad' : 'tag');
|
|
560
|
+
tag.id = 'set-gate-' + gate.name + '-' + t.suffix;
|
|
561
|
+
tag.title = t.title;
|
|
562
|
+
status.append(tag);
|
|
563
|
+
}
|
|
564
|
+
if (gate.skip) status.append(el('span', 'skip: ' + gate.skip, 'set-gate-skip'));
|
|
565
|
+
const top = el('div', undefined, 'set-file-head');
|
|
566
|
+
top.append(h, status);
|
|
567
|
+
art.append(top);
|
|
568
|
+
if (!s.writes) {
|
|
569
|
+
const bits = ['mode ' + gate.mode, gate.provider ? 'provider ' + gate.provider : 'no provider', gate.model ? 'model ' + gate.model : 'no model'];
|
|
570
|
+
art.append(el('p', bits.join(', '), 'muted'));
|
|
571
|
+
return art;
|
|
572
|
+
}
|
|
573
|
+
const result = el('div', undefined, 'set-result');
|
|
574
|
+
const row = el('div', undefined, 'filters');
|
|
575
|
+
row.append(modeField(gate, result), providerField(gate, providers, result), modelField(gate, result));
|
|
576
|
+
art.append(row, result);
|
|
577
|
+
return art;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function modeField(gate, result) {
|
|
581
|
+
const lab = el('label', undefined, 'filter');
|
|
582
|
+
const sel = el('select');
|
|
583
|
+
sel.id = 'set-gate-' + gate.name + '-mode';
|
|
584
|
+
sel.setAttribute('aria-label', 'Mode for ' + gate.name);
|
|
585
|
+
// The select shows the user level's mode when the status has it. Otherwise the mode in effect is a label that no
|
|
586
|
+
// choice matches, so every mode is a choice that writes the user level, the one in effect included.
|
|
587
|
+
const rest = gate.userMode || ''; // the value the select goes back to
|
|
588
|
+
if (!gate.userMode) {
|
|
589
|
+
const effect = el('option', 'in effect: ' + gate.mode);
|
|
590
|
+
effect.value = ''; effect.disabled = true; effect.selected = true;
|
|
591
|
+
sel.append(effect);
|
|
592
|
+
}
|
|
593
|
+
for (const mode of MODES) {
|
|
594
|
+
const o = el('option', mode);
|
|
595
|
+
o.value = mode;
|
|
596
|
+
o.selected = mode === gate.userMode;
|
|
597
|
+
sel.append(o);
|
|
598
|
+
}
|
|
599
|
+
sel.addEventListener('change', async () => {
|
|
600
|
+
const next = sel.value;
|
|
601
|
+
if (!MODES.includes(next) || next === gate.userMode) { sel.value = rest; return; }
|
|
602
|
+
const gen = s.gen, release = grab();
|
|
603
|
+
sel.disabled = true;
|
|
604
|
+
const yes = await UI.confirmInline(result, `Set ${gate.name} to ${next}? This writes your forge config (the user level) for every repository.`);
|
|
605
|
+
if (!yes || gen !== s.gen) {
|
|
606
|
+
sel.value = rest; sel.disabled = false; release();
|
|
607
|
+
if (!yes && gen === s.gen) sel.focus({ preventScroll: true });
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const res = await UI.post('/api/config', configBody(s.run, gateKey(gate.name), next));
|
|
611
|
+
UI.outcome(result, res, `${gate.name} is set to ${next}.`);
|
|
612
|
+
if (!res.ok) sel.value = rest;
|
|
613
|
+
sel.disabled = false; release();
|
|
614
|
+
if (res.ok && gen === s.gen) await reload();
|
|
615
|
+
});
|
|
616
|
+
lab.append(el('span', 'Mode'), sel);
|
|
617
|
+
return lab;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function providerField(gate, providers, result) {
|
|
621
|
+
const lab = el('label', undefined, 'filter');
|
|
622
|
+
const sel = el('select');
|
|
623
|
+
sel.id = 'set-gate-' + gate.name + '-provider';
|
|
624
|
+
sel.setAttribute('aria-label', 'Provider for ' + gate.name);
|
|
625
|
+
const blank = el('option', providers.length ? 'Default' : 'No provider');
|
|
626
|
+
blank.value = '';
|
|
627
|
+
if (gate.provider) blank.disabled = true;
|
|
628
|
+
sel.append(blank);
|
|
629
|
+
const known = new Set(providers.map(p => p.name));
|
|
630
|
+
for (const p of providers) {
|
|
631
|
+
const o = el('option', providerLabel(p));
|
|
632
|
+
o.value = p.name;
|
|
633
|
+
o.selected = p.name === gate.provider;
|
|
634
|
+
sel.append(o);
|
|
635
|
+
}
|
|
636
|
+
if (gate.provider && !known.has(gate.provider)) {
|
|
637
|
+
const o = el('option', gate.provider + ' · not configured');
|
|
638
|
+
o.value = gate.provider;
|
|
639
|
+
o.selected = true;
|
|
640
|
+
sel.append(o);
|
|
641
|
+
}
|
|
642
|
+
if (!providers.length) sel.disabled = true;
|
|
643
|
+
sel.addEventListener('change', async () => {
|
|
644
|
+
const next = sel.value;
|
|
645
|
+
if (!next || next === gate.provider) { sel.value = gate.provider; return; }
|
|
646
|
+
if (decideTextProblem(next)) { sel.value = gate.provider; return; }
|
|
647
|
+
const gen = s.gen, release = grab();
|
|
648
|
+
sel.disabled = true;
|
|
649
|
+
const yes = await UI.confirmInline(result, `Set the provider for ${gate.name} to ${next}? This writes your forge config (the user level) for every repository.`);
|
|
650
|
+
if (!yes || gen !== s.gen) {
|
|
651
|
+
sel.value = gate.provider;
|
|
652
|
+
sel.disabled = providers.length === 0;
|
|
653
|
+
release();
|
|
654
|
+
if (!yes && gen === s.gen) sel.focus({ preventScroll: true });
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const res = await UI.post('/api/config', configBody(s.run, gateKey(gate.name, 'provider'), next));
|
|
658
|
+
UI.outcome(result, res, `The provider for ${gate.name} is set to ${next}.`);
|
|
659
|
+
if (!res.ok) sel.value = gate.provider;
|
|
660
|
+
sel.disabled = false; release();
|
|
661
|
+
if (res.ok && gen === s.gen) await reload();
|
|
662
|
+
});
|
|
663
|
+
lab.append(el('span', 'Provider'), sel);
|
|
664
|
+
return lab;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function modelField(gate, result) {
|
|
668
|
+
const id = 'set-gate-' + gate.name + '-model';
|
|
669
|
+
const ed = s.models[gate.name] || (s.models[gate.name] = editorOf(gate.model));
|
|
670
|
+
const wrap = el('div', undefined, 'filter');
|
|
671
|
+
const input = el('input', undefined, 'mono');
|
|
672
|
+
input.type = 'text'; input.id = id; input.dataset.model = gate.name;
|
|
673
|
+
input.spellcheck = false; input.setAttribute('autocomplete', 'off'); input.setAttribute('autocapitalize', 'off');
|
|
674
|
+
input.setAttribute('aria-label', 'Model for ' + gate.name);
|
|
675
|
+
input.value = shown(ed);
|
|
676
|
+
let from = ed.base;
|
|
677
|
+
const movedNote = el('p', 'The model changed on disk after you began editing; saving replaces it with your text.', 'warn set-file-note');
|
|
678
|
+
movedNote.hidden = !(isDirty(ed) && s.modelMoved[gate.name]);
|
|
679
|
+
const problem = el('p', undefined, 'warn set-problem');
|
|
680
|
+
problem.hidden = true; problem.id = id + '-problem';
|
|
681
|
+
const set = key_('Set', 'primary');
|
|
682
|
+
set.setAttribute('aria-label', 'Set model for ' + gate.name);
|
|
683
|
+
const sync = () => {
|
|
684
|
+
const cur = s.models[gate.name], dirtyNow = isDirty(cur), bad = dirtyNow ? decideTextProblem(cur.draft) : null;
|
|
685
|
+
problem.hidden = !bad; problem.textContent = bad || '';
|
|
686
|
+
if (bad) { input.setAttribute('aria-invalid', 'true'); input.setAttribute('aria-describedby', problem.id); }
|
|
687
|
+
else { input.removeAttribute('aria-invalid'); input.removeAttribute('aria-describedby'); }
|
|
688
|
+
set.disabled = !dirtyNow || !!bad;
|
|
689
|
+
movedNote.hidden = !(dirtyNow && s.modelMoved[gate.name]);
|
|
690
|
+
};
|
|
691
|
+
input.addEventListener('input', () => {
|
|
692
|
+
const next = typed(s.models[gate.name], input.value, from);
|
|
693
|
+
s.models[gate.name] = next.editor;
|
|
694
|
+
s.modelMoved[gate.name] = next.moved || (next.dirty && !!s.modelMoved[gate.name]);
|
|
695
|
+
sync();
|
|
696
|
+
});
|
|
697
|
+
set.addEventListener('click', async () => {
|
|
698
|
+
const cur = s.models[gate.name], bad = decideTextProblem(shown(cur));
|
|
699
|
+
if (!isDirty(cur) || bad) { sync(); return; }
|
|
700
|
+
const draft = cur.draft;
|
|
701
|
+
const gen = s.gen, release = grab();
|
|
702
|
+
set.disabled = true; input.readOnly = true;
|
|
703
|
+
const yes = await UI.confirmInline(result, `Set the model for ${gate.name} to ${draft}? This writes your forge config (the user level) for every repository.`);
|
|
704
|
+
if (!yes || gen !== s.gen) {
|
|
705
|
+
input.readOnly = false; release(); sync();
|
|
706
|
+
if (!yes && gen === s.gen) set.focus({ preventScroll: true });
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const res = await UI.post('/api/config', configBody(s.run, gateKey(gate.name, 'model'), draft));
|
|
710
|
+
UI.outcome(result, res, `The model for ${gate.name} is set.`);
|
|
711
|
+
if (res.ok && gen === s.gen) { s.models[gate.name] = editorOf(draft); s.modelMoved[gate.name] = false; from = draft; }
|
|
712
|
+
input.readOnly = false; release(); sync();
|
|
713
|
+
if (res.ok && gen === s.gen) await reload();
|
|
714
|
+
});
|
|
715
|
+
wrap.append(el('span', 'Model'), input, problem, movedNote, set);
|
|
716
|
+
sync();
|
|
717
|
+
return wrap;
|
|
718
|
+
}
|
|
719
|
+
|
|
308
720
|
function repoSection() {
|
|
309
721
|
const repo = object(s.data.repo), files = object(repo.files);
|
|
310
722
|
const sec = section('repo', 'This repository');
|
|
@@ -430,6 +842,7 @@
|
|
|
430
842
|
return { poll, pick };
|
|
431
843
|
}
|
|
432
844
|
|
|
433
|
-
return { render, configBody, repoKey, targetPath, subsetOk, valueProblem,
|
|
434
|
-
editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
|
|
845
|
+
return { render, configBody, repoKey, gateKey, targetPath, subsetOk, valueProblem, decideTextProblem, describeDecide, gateTags, replayDate,
|
|
846
|
+
pickDefault, groupRuns, optionLabel, typeAhead, editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
|
|
847
|
+
FILES, GATES, MODES, VALUE_MAX, DECIDE_VALUE_MAX, ADD_COMMAND };
|
|
435
848
|
});
|