even-keel 0.3.0 → 0.3.2
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 +54 -0
- package/README.md +3 -3
- package/dist/src/agent/scripted.js +32 -3
- package/dist/src/badge/collect.js +26 -4
- package/dist/src/badge/render.js +2 -1
- package/dist/src/chain/conflict.js +41 -0
- package/dist/src/chain/forward.js +22 -5
- package/dist/src/chain/handover.js +1 -2
- package/dist/src/chain/maincheck.js +13 -9
- package/dist/src/changelog/drafts.js +4 -3
- package/dist/src/changelog/file.js +4 -0
- package/dist/src/changelog/limit.js +30 -0
- package/dist/src/ci/protection.js +8 -1
- package/dist/src/claude/adapter.js +4 -4
- package/dist/src/claude/sdk/host.js +10 -3
- package/dist/src/copilot/adapter.js +1 -1
- package/dist/src/copilot/errors.js +11 -6
- package/dist/src/gitlab/adapter.js +1 -0
- package/dist/src/limits/chatgpt-seat.js +49 -0
- package/dist/src/limits/chatgpt.js +37 -7
- package/dist/src/limits/copilot.js +12 -3
- package/dist/src/limits/model.js +3 -0
- package/dist/src/limits/overage.js +6 -2
- package/dist/src/limits/usage.js +42 -4
- package/dist/src/limits/watcher.js +1 -1
- package/dist/src/notice/en-advice.js +2 -1
- package/dist/src/notice/en-values.js +2 -0
- package/dist/src/notice/en.js +5 -1
- package/dist/src/opencode/adapter.js +1 -1
- package/dist/src/opencode/cli.js +10 -2
- package/dist/src/packages/service.js +37 -0
- package/dist/src/profiles/model.js +1 -0
- package/dist/src/profiles/service.js +1 -1
- package/dist/src/server.js +1 -0
- package/dist/src/service/chain-prompts.js +13 -1
- package/dist/src/service/chain.js +17 -12
- package/dist/src/service/trackers.js +3 -2
- package/dist/src/service.js +1 -1
- package/dist/src/sessions/ask.js +6 -0
- package/dist/src/sessions/monitor.js +1 -0
- package/dist/src/sessions/permission.js +3 -2
- package/dist/src/sessions/transcript.js +29 -2
- package/dist/src/storage/migrations.js +2 -0
- package/dist/src/storage/schema.js +1 -1
- package/dist/src/tools/panel.js +7 -9
- package/dist/src/tools/projectSettings.js +60 -0
- package/dist/src/tools/sessionSettings.js +11 -4
- package/dist/src/tracker/questions.js +35 -3
- package/dist/web/assets/{BadgeDialog-B8RUL_Ow.js → BadgeDialog-DTnQXw9H.js} +1 -1
- package/dist/web/assets/{DescriptionEditor-DUSwRGCZ.js → DescriptionEditor-CpRmzCRQ.js} +1 -1
- package/dist/web/assets/{ProjectPackages-BJEPijBV.js → ProjectPackages-BILdF91o.js} +1 -1
- package/dist/web/assets/{Select-NXi_Bsw-.js → Select-BkfVMQn9.js} +1 -1
- package/dist/web/assets/{TaskCard-DeP8bF9-.js → TaskCard-BdMTPm5U.js} +2 -2
- package/dist/web/assets/TranscriptWindow-BNF7AkTM.css +1 -0
- package/dist/web/assets/TranscriptWindow-DWmiEsux.js +4 -0
- package/dist/web/assets/{accountParts-CNUeXPYn.js → accountParts-BgNHNRlI.js} +1 -1
- package/dist/web/assets/blocks-CrABcaPz.js +12 -0
- package/dist/web/assets/{cardDrafts-CyzO-ro7.js → cardDrafts-BfmbAV1M.js} +1 -1
- package/dist/web/assets/{cardSide-CSmytank.js → cardSide-D2KI5tvT.js} +1 -1
- package/dist/web/assets/feedLine-Ba2zSS8M.js +1 -0
- package/dist/web/assets/{hooks-CgKVeUg8.js → hooks-JRdbz0x_.js} +1 -1
- package/dist/web/assets/index-CLtOpp9i.js +25 -0
- package/dist/web/assets/index-gsaRwWJo.css +1 -0
- package/dist/web/assets/{lib-DnFFmOv9.js → lib-BWXVCBDM.js} +1 -1
- package/dist/web/assets/overview-D3YlvCUL.js +7 -0
- package/dist/web/assets/packageGroups-Bp5E3IBW.js +1 -0
- package/dist/web/assets/{react-dom-DiYkIXNS.js → react-dom-BrsVbrva.js} +1 -1
- package/dist/web/assets/{rules-DLe7kZM5.js → rules-LK65q0Fp.js} +1 -1
- package/dist/web/assets/{useFileDrop-CEn6qZnh.js → useFileDrop-uBrD_n1G.js} +1 -1
- package/dist/web/assets/{useHeightGlide-BPjzH9PL.js → useHeightGlide-DUlst5w-.js} +1 -1
- package/dist/web/assets/useRowFocus-B25YUpUj.js +1 -0
- package/dist/web/index.html +15 -15
- package/even-keel.config.example.json +1 -1
- package/package.json +2 -2
- package/tally/tally.config.json +8 -0
- package/dist/web/assets/TranscriptWindow-BN6jSpev.css +0 -1
- package/dist/web/assets/TranscriptWindow-DVoHtE_o.js +0 -4
- package/dist/web/assets/blocks-CiOz7u_W.js +0 -12
- package/dist/web/assets/feedLine-txivfLQO.js +0 -1
- package/dist/web/assets/index-BT7ooY-T.js +0 -25
- package/dist/web/assets/index-hTYDOTAZ.css +0 -1
- package/dist/web/assets/overview-0NAogPYB.js +0 -7
- package/dist/web/assets/packageGroups-6mYiV3fk.js +0 -1
- package/dist/web/assets/useRowFocus-COI8llTH.js +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { wireChangelogs, wireBriefed, wireWithProject } from './chain-prompts.js';
|
|
2
2
|
import { deferLeftFolder, midTurn } from './cleanup.js';
|
|
3
3
|
export { deferLeftFolder, STOP_RETRY_MS, stopLingering, stopTaskSessions } from './cleanup.js';
|
|
4
|
-
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
5
6
|
import { accountAt } from '../account/ledger.js';
|
|
6
7
|
import { accountId, launchBlock } from '../account/model.js';
|
|
7
8
|
import { sessionBase } from '../agent/env.js';
|
|
@@ -130,7 +131,7 @@ export function wireKeepWarm(ctx) {
|
|
|
130
131
|
if (view === undefined || session === undefined)
|
|
131
132
|
throw new Error(`the session ${sessionId} is not live`);
|
|
132
133
|
const home = ctx.homeOf(session.account);
|
|
133
|
-
const start = { name: task, cwd: session.cwd, prompt: KEEP_WARM_PROMPT, model: view.model, settings: ctx.settingsFor(task), ...ctx.agentExtras(home, ctx.projectOf(task), task) };
|
|
134
|
+
const start = { name: task, cwd: session.cwd, prompt: KEEP_WARM_PROMPT, model: view.model, settings: await ctx.settingsFor(task), ...ctx.agentExtras(home, ctx.projectOf(task), task) };
|
|
134
135
|
return ctx.agentOf(home).warm(home, session, start);
|
|
135
136
|
},
|
|
136
137
|
now: () => new Date(),
|
|
@@ -152,7 +153,7 @@ export async function wireDispatcher(ctx) {
|
|
|
152
153
|
const started = ctx.withProject(await ctx.briefed(task, startPrompt(task, place, ctx.promptLanguage(project), ctx.branchOf(project), ctx.pullRequestsOn(project), !isPlain(ctx.configStore.current, project)), project), project);
|
|
153
154
|
const { prompt, model, provider, fallback } = ctx.planFor(task, extra === undefined ? started : `${started}\n${extra}\n`, project);
|
|
154
155
|
const extras = ctx.agentExtras(home, project, task);
|
|
155
|
-
const sessionId = await ctx.launchIn(home, { name: task, cwd: place.path, prompt, model, settings: ctx.settingsFor(task, project), ...extras }, project);
|
|
156
|
+
const sessionId = await ctx.launchIn(home, { name: task, cwd: place.path, prompt, model, settings: await ctx.settingsFor(task, project), ...extras }, project);
|
|
156
157
|
if (fallback === null)
|
|
157
158
|
return { sessionId };
|
|
158
159
|
console.warn(englishOf(ctx.noAccountFor(task, fallback, provider)));
|
|
@@ -282,7 +283,7 @@ export async function wireDispatcher(ctx) {
|
|
|
282
283
|
const note = await readNote(notePath);
|
|
283
284
|
const at = new Date().toISOString();
|
|
284
285
|
const extras = ctx.agentExtras(home, project, task);
|
|
285
|
-
const sessionId = await ctx.launchIn(home, { name: task, cwd: session.workdir, prompt, model, settings: ctx.settingsFor(task, project), ...extras }, project);
|
|
286
|
+
const sessionId = await ctx.launchIn(home, { name: task, cwd: session.workdir, prompt, model, settings: await ctx.settingsFor(task, project), ...extras }, project);
|
|
286
287
|
const snapshot = { at, task, sessionId, previous: session.sessionId, reason: snapshotReason(reason), prompt, notePath, note };
|
|
287
288
|
ctx.writes.add(`the handoff snapshot of ${task}`, saveSnapshot(ctx.db, snapshot));
|
|
288
289
|
return sessionId;
|
|
@@ -294,7 +295,7 @@ export async function wireDispatcher(ctx) {
|
|
|
294
295
|
const text = fixPrompt(report, place, ctx.promptLanguage(project), ctx.branchOf(project), reran === true);
|
|
295
296
|
const { prompt, model } = ctx.planFor(name, ctx.withProject(text, project), project);
|
|
296
297
|
const extras = ctx.agentExtras(home, project, name);
|
|
297
|
-
return ctx.launchIn(home, { name, cwd: place.path, prompt, model, settings: ctx.settingsFor(name, project), ...extras }, project);
|
|
298
|
+
return ctx.launchIn(home, { name, cwd: place.path, prompt, model, settings: await ctx.settingsFor(name, project), ...extras }, project);
|
|
298
299
|
},
|
|
299
300
|
launchCarry: async (project, name, report) => {
|
|
300
301
|
const home = ctx.homeOf(ctx.choiceFor(project).account);
|
|
@@ -302,7 +303,7 @@ export async function wireDispatcher(ctx) {
|
|
|
302
303
|
const place = await ctx.places.ready(project, name);
|
|
303
304
|
const { prompt, model } = ctx.planFor(name, ctx.withProject(carryPrompt(report, place, ctx.promptLanguage(project), ctx.branchOf(project)), project), project);
|
|
304
305
|
const extras = ctx.agentExtras(home, project, name);
|
|
305
|
-
return ctx.launchIn(home, { name, cwd: place.path, prompt, model, settings: ctx.settingsFor(name, project), ...extras }, project);
|
|
306
|
+
return ctx.launchIn(home, { name, cwd: place.path, prompt, model, settings: await ctx.settingsFor(name, project), ...extras }, project);
|
|
306
307
|
},
|
|
307
308
|
carried: async (project, commit) => (await runGit(ctx.configStore.current.projects[project], ['merge-base', '--is-ancestor', commit, `refs/heads/${ctx.branchOf(project)}`])).code === 0,
|
|
308
309
|
stop: async (session) => {
|
|
@@ -442,11 +443,12 @@ export function wireForwards(ctx) {
|
|
|
442
443
|
return chainQuiet(ctx.dispatcher.state.active.find((chain) => chain.project === project), (task) => status(task) === 'busy' || status(task) === 'waiting');
|
|
443
444
|
},
|
|
444
445
|
git: runGit,
|
|
446
|
+
read: (repo, path) => readFile(join(repo, path), 'utf8').catch(() => null),
|
|
445
447
|
sync: ctx.syncProject,
|
|
446
448
|
now: () => new Date(),
|
|
447
449
|
changed: () => ctx.hub.broadcastSoon('state', ctx.getState),
|
|
448
450
|
log: (message) => console.log(message),
|
|
449
|
-
carrying: (from) => ctx.dispatcher.carrying(from)
|
|
451
|
+
carrying: (from) => ctx.dispatcher.carrying(from) ?? null,
|
|
450
452
|
auto: (from) => ctx.configStore.current.settings[from]?.carryAgent === true || ctx.configStore.current.unattended,
|
|
451
453
|
resolve: async (from, ask) => {
|
|
452
454
|
const config = ctx.configStore.current;
|
|
@@ -462,7 +464,10 @@ export function wireForwards(ctx) {
|
|
|
462
464
|
output: ask.output,
|
|
463
465
|
});
|
|
464
466
|
const at = new Date().toISOString();
|
|
465
|
-
|
|
467
|
+
const carry = { task: carryNameOf(config.keys, from), into: ask.into, at, commit: ask.commit, commits: ask.commits, report };
|
|
468
|
+
if (ask.conflict !== undefined)
|
|
469
|
+
carry.conflict = ask.conflict;
|
|
470
|
+
ctx.dispatcher.carry(from, carry);
|
|
466
471
|
},
|
|
467
472
|
});
|
|
468
473
|
}
|
|
@@ -471,7 +476,7 @@ export function resumeWith(ctx, task, session, prompt) {
|
|
|
471
476
|
if (ctx.approved(task, session, prompt))
|
|
472
477
|
return session.sessionId;
|
|
473
478
|
const home = ctx.homeOf(session.account);
|
|
474
|
-
const start = ctx.goOnWith(home, task, session, prompt);
|
|
479
|
+
const start = await ctx.goOnWith(home, task, session, prompt);
|
|
475
480
|
const went = session.stopped || ctx.liveView(task)?.hungSince != null ? undefined : await ctx.agentOf(home).reply?.(home, session, start);
|
|
476
481
|
if (went != null)
|
|
477
482
|
return went;
|
|
@@ -498,14 +503,14 @@ export function approved(ctx, task, session, prompt) {
|
|
|
498
503
|
console.log(`sessions: ${task}: the user ${move.kind === 'allow' ? 'allowed' : 'denied'} the call the session ${session.sessionId} waited to have approved`);
|
|
499
504
|
return true;
|
|
500
505
|
}
|
|
501
|
-
export function goOnWith(ctx, home, task, session, prompt) {
|
|
506
|
+
export async function goOnWith(ctx, home, task, session, prompt) {
|
|
502
507
|
const { model } = ctx.planFor(task, prompt);
|
|
503
508
|
const extras = ctx.agentExtras(home, ctx.projectOf(task), task);
|
|
504
|
-
return { name: task, cwd: session.cwd, prompt, model, settings: ctx.settingsFor(task), ...extras };
|
|
509
|
+
return { name: task, cwd: session.cwd, prompt, model, settings: await ctx.settingsFor(task), ...extras };
|
|
505
510
|
}
|
|
506
511
|
export async function steer(ctx, task, session, prompt) {
|
|
507
512
|
const home = ctx.homeOf(session.account);
|
|
508
|
-
return (await ctx.agentOf(home).reply?.(home, session, ctx.goOnWith(home, task, session, prompt))) != null;
|
|
513
|
+
return (await ctx.agentOf(home).reply?.(home, session, await ctx.goOnWith(home, task, session, prompt))) != null;
|
|
509
514
|
}
|
|
510
515
|
export function occupantsOf(ctx, slot, task) {
|
|
511
516
|
const owners = new Map(ctx.launches.map((entry) => [entry.sessionId, entry.task]));
|
|
@@ -123,6 +123,7 @@ export function wireTrackers(ctx) {
|
|
|
123
123
|
log: (line) => console.log(line),
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
const expiredOf = (view) => (view.expiredApprovals === undefined ? {} : { expired: view.expiredApprovals });
|
|
126
127
|
export function wireQuestions(ctx) {
|
|
127
128
|
return new TrackerQuestions({
|
|
128
129
|
sessions: () => {
|
|
@@ -131,13 +132,13 @@ export function wireQuestions(ctx) {
|
|
|
131
132
|
const view = sessionId == null ? undefined : ctx.liveView(chain.current.task);
|
|
132
133
|
if (view === undefined || view.sessionId !== sessionId || isOwnName(view.task))
|
|
133
134
|
return [];
|
|
134
|
-
return [{ project: chain.project, task: view.task, sessionId, ask: view.ask, current: true }];
|
|
135
|
+
return [{ project: chain.project, task: view.task, sessionId, ask: view.ask, current: true, ...expiredOf(view) }];
|
|
135
136
|
});
|
|
136
137
|
const aside = ctx.sessions.flatMap((view) => {
|
|
137
138
|
const project = ctx.configuredProject(view.task);
|
|
138
139
|
if (view.lamp === 'finished' || project === undefined || current.some((each) => each.sessionId === view.sessionId))
|
|
139
140
|
return [];
|
|
140
|
-
return [{ project, task: view.task, sessionId: view.sessionId, ask: view.ask, current: false }];
|
|
141
|
+
return [{ project, task: view.task, sessionId: view.sessionId, ask: view.ask, current: false, ...expiredOf(view) }];
|
|
141
142
|
});
|
|
142
143
|
return [...current, ...aside];
|
|
143
144
|
},
|
package/dist/src/service.js
CHANGED
|
@@ -735,7 +735,7 @@ const trackerPlace = (reader) => {
|
|
|
735
735
|
const briefed = chainService.wireBriefed(context);
|
|
736
736
|
/** Even Keel's prompt and the project's own, for a new session only: a resumed one already has them. */
|
|
737
737
|
const withProject = chainService.wireWithProject(context);
|
|
738
|
-
const settingsFor = createSessionSettings({ config: () => configStore.current, packages, globalDir: homes.global.dir, trim: () => dispatcher.state.trimTools, projectOf });
|
|
738
|
+
const settingsFor = createSessionSettings({ config: () => configStore.current, packages, globalDir: homes.global.dir, trim: () => dispatcher.state.trimTools, projectOf, git: runGit, branchOf });
|
|
739
739
|
function projectOf(task) { return chainService.projectOf(context, task); }
|
|
740
740
|
const slotsSeen = new Map();
|
|
741
741
|
/** How many slots the project's tasks may be in: the most it had since the start, so a pool shrunk on the fly still finds its busy slots. */
|
package/dist/src/sessions/ask.js
CHANGED
|
@@ -11,6 +11,7 @@ const TEXTS = {
|
|
|
11
11
|
: 'Ответьте комментарием: номер варианта (`2`), несколько через запятую (`1, 3`) или свой текст.',
|
|
12
12
|
chat: 'Ответ — в чате сессии на странице: заметка здесь сессии не дойдёт.',
|
|
13
13
|
answer: '**Ответ сессии**',
|
|
14
|
+
expired: '**Вопрос истёк**: CLI перестал ждать ответа и сам отказал, вызов не выполнен. Сессия продолжает без него; ответ на вопрос выше ей уже не дойдёт.',
|
|
14
15
|
},
|
|
15
16
|
en: {
|
|
16
17
|
lost: 'The question you asked through AskUserQuestion was lost when the session restarted:',
|
|
@@ -21,6 +22,7 @@ const TEXTS = {
|
|
|
21
22
|
: 'Reply with a comment: the option number (`2`), several separated by commas (`1, 3`), or your own text.',
|
|
22
23
|
chat: 'Answer in the session’s chat on the page: a note here does not reach the session.',
|
|
23
24
|
answer: '**Answer to the session**',
|
|
25
|
+
expired: '**The question expired**: the CLI stopped waiting for an answer and refused the call itself, it did not run. The session goes on without it; an answer to the question above no longer reaches it.',
|
|
24
26
|
},
|
|
25
27
|
};
|
|
26
28
|
/** The questions of an `AskUserQuestion` input; malformed questions and options are left out. */
|
|
@@ -227,6 +229,10 @@ export function questionComment(ask, language, journal = false) {
|
|
|
227
229
|
blocks.push(journal ? text.chat : text.how(several));
|
|
228
230
|
return blocks.join('\n\n');
|
|
229
231
|
}
|
|
232
|
+
/** The tracker comment after a question the CLI stopped waiting on (EKR-140): it is closed, no reply reaches the session. */
|
|
233
|
+
export function expiredComment(language) {
|
|
234
|
+
return TEXTS[language].expired;
|
|
235
|
+
}
|
|
230
236
|
/** `text` as a Markdown code block whose fence is longer than any backtick run inside it. */
|
|
231
237
|
function fenced(text) {
|
|
232
238
|
const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map((run) => run[0].length));
|
|
@@ -239,6 +239,7 @@ function toView(task, { agent, runsOn, present, transcript, bridge }, remoteOf,
|
|
|
239
239
|
silentSince: present && agent.silentSince !== undefined ? new Date(agent.silentSince).toISOString() : null,
|
|
240
240
|
asking: ask !== null,
|
|
241
241
|
ask,
|
|
242
|
+
...((summary.expiredApprovals?.length ?? 0) > 0 && { expiredApprovals: summary.expiredApprovals }),
|
|
242
243
|
apiError: summary.apiError?.text ?? null,
|
|
243
244
|
apiErrorKind: summary.apiError?.kind ?? null,
|
|
244
245
|
...(summary.apiError?.notice === undefined ? {} : { apiErrorNotice: summary.apiError.notice }),
|
|
@@ -40,7 +40,8 @@ function cut(shown, text) {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* A tool call the CLI wants approved, put to the user as a question with two options (BTN-303): the first allows it,
|
|
43
|
-
* the second refuses it. The call itself is the preview of
|
|
43
|
+
* the second refuses it. The call itself is the preview of both — a command, or the input as JSON — so pointing at
|
|
44
|
+
* either keeps it in view (EKR-139). The input's
|
|
44
45
|
* `description` is the agent's own word on its call, so it follows the call in the preview, marked as the agent's,
|
|
45
46
|
* and never stands under the allowing option (BTN-1128).
|
|
46
47
|
*/
|
|
@@ -60,7 +61,7 @@ export function permissionAsk(id, tool, input, language) {
|
|
|
60
61
|
multiSelect: false,
|
|
61
62
|
options: [
|
|
62
63
|
{ label: text.allow, description: text.allowHint, preview },
|
|
63
|
-
{ label: text.deny, description: text.denyHint },
|
|
64
|
+
{ label: text.deny, description: text.denyHint, preview },
|
|
64
65
|
],
|
|
65
66
|
},
|
|
66
67
|
],
|
|
@@ -2,6 +2,7 @@ import { cloudErrorNotice } from '../account/cloud-errors.js';
|
|
|
2
2
|
import { badgeActionOf } from '../badge/action.js';
|
|
3
3
|
import { statusAsked, statusLineIn, statusTextOf, withoutStatusLine } from '../badge/status.js';
|
|
4
4
|
import { isSpendingLimit } from '../limits/spending.js';
|
|
5
|
+
import { notice } from '../notice/notice.js';
|
|
5
6
|
import { isTransientError } from './transient.js';
|
|
6
7
|
import { questionsOf, replyParts, toolAnswers } from './ask.js';
|
|
7
8
|
import { typedText } from './commandPrompt.js';
|
|
@@ -29,6 +30,9 @@ const NO_CHANGES_LINE = /^([`*_]*)NO CHANGES:([`*_]*)(.*)$/;
|
|
|
29
30
|
const TASK_DONE_LINE = /^([`*_]*)TASK DONE(?::|(?=[`*_]*$))([`*_]*)(.*)$/;
|
|
30
31
|
const CONTEXT_BLOCK = /^<([a-z][\w-]*)\b[^>]*>[\s\S]*<\/\1>$/;
|
|
31
32
|
const ASK_TOOL = 'AskUserQuestion';
|
|
33
|
+
/** CLI 2.1.3xx: "…and no person did (the permission prompt timed out, or none was shown)" — or "…this session cannot prompt". */
|
|
34
|
+
const EXPIRED_APPROVAL = /\bthe permission prompt timed out\b/;
|
|
35
|
+
const EXPIRED_KEPT = 10;
|
|
32
36
|
const SHELLS = new Set(['Bash', 'PowerShell']);
|
|
33
37
|
export const TTL_MS = { '5m': 5 * 60_000, '30m': 30 * 60_000, '1h': 60 * 60_000 };
|
|
34
38
|
const STAGE_RANK = { task: 0, recon: 1, edit: 2, test: 3, commit: 4, merge: 5 };
|
|
@@ -73,6 +77,10 @@ export class TranscriptFold {
|
|
|
73
77
|
backgroundCommand = null;
|
|
74
78
|
/** The tool lines of the turn's calls that have no result yet, by call id. */
|
|
75
79
|
runningTools = new Map();
|
|
80
|
+
/** The tool of each call that has no result yet, by call id: an expired approval names it. */
|
|
81
|
+
callTools = new Map();
|
|
82
|
+
/** The calls whose approval the CLI stopped waiting for, the latest last (EKR-140). */
|
|
83
|
+
expiredApprovals = [];
|
|
76
84
|
/** The CLI's queue of messages for the session, in order; `line` — `null` for one that is not the user's. */
|
|
77
85
|
queue = [];
|
|
78
86
|
/** `whole` keeps texts and prompts as written and adds shell commands to tool lines. */
|
|
@@ -177,6 +185,7 @@ export class TranscriptFold {
|
|
|
177
185
|
effort: this.effort,
|
|
178
186
|
badgeStatus: this.badgeStatus,
|
|
179
187
|
backgroundCommand: this.backgroundCommand,
|
|
188
|
+
expiredApprovals: [...this.expiredApprovals],
|
|
180
189
|
};
|
|
181
190
|
}
|
|
182
191
|
pushAssistant(entry) {
|
|
@@ -252,8 +261,10 @@ export class TranscriptFold {
|
|
|
252
261
|
const background = backgroundCommandOf(block.name, input);
|
|
253
262
|
if (background !== null)
|
|
254
263
|
this.backgroundCommand = background;
|
|
255
|
-
if (typeof block.id === 'string')
|
|
264
|
+
if (typeof block.id === 'string') {
|
|
256
265
|
this.runningTools.set(block.id, line.text);
|
|
266
|
+
this.callTools.set(block.id, block.name);
|
|
267
|
+
}
|
|
257
268
|
this.addAction(line);
|
|
258
269
|
this.advanceStage(stageOf(block.name, input));
|
|
259
270
|
}
|
|
@@ -266,9 +277,17 @@ export class TranscriptFold {
|
|
|
266
277
|
if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string')
|
|
267
278
|
continue;
|
|
268
279
|
this.runningTools.delete(block.tool_use_id);
|
|
280
|
+
const name = this.callTools.get(block.tool_use_id);
|
|
281
|
+
this.callTools.delete(block.tool_use_id);
|
|
282
|
+
const expired = block.is_error === true && isExpiredApproval(block.content);
|
|
283
|
+
if (expired)
|
|
284
|
+
this.expiredApprovals = [...this.expiredApprovals, block.tool_use_id].slice(-EXPIRED_KEPT);
|
|
269
285
|
// A question's error result is how a stop or a resume delivers its answer (BTN-220): the answer line tells the rest.
|
|
270
286
|
if (this.whole && block.is_error === true && block.tool_use_id !== this.openAsk?.id) {
|
|
271
|
-
|
|
287
|
+
const at = entry.timestamp ?? '';
|
|
288
|
+
this.addFeed({ at, kind: 'failed', text: failureText(block.content), tool: block.tool_use_id, ...(expired && { expired: true }) });
|
|
289
|
+
if (expired)
|
|
290
|
+
this.addFeed({ at, kind: 'error', text: '', notice: notice('session.approvalExpired', { tool: name ?? '?' }) });
|
|
272
291
|
}
|
|
273
292
|
}
|
|
274
293
|
const ask = this.openAsk;
|
|
@@ -298,6 +317,7 @@ export class TranscriptFold {
|
|
|
298
317
|
this.turnStartedAt = entry.timestamp ?? '';
|
|
299
318
|
this.statusAsked = false;
|
|
300
319
|
this.runningTools.clear();
|
|
320
|
+
this.callTools.clear();
|
|
301
321
|
if (entry.origin?.kind !== undefined && entry.origin.kind !== 'human')
|
|
302
322
|
return;
|
|
303
323
|
const answered = this.openAsk ?? this.strayAsk;
|
|
@@ -429,6 +449,13 @@ export function callFacts(name, input, size) {
|
|
|
429
449
|
const subject = subjectOf(name, input);
|
|
430
450
|
return { name, ...(subject === undefined ? {} : { subject }), ...size };
|
|
431
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* The CLI's own refusal of a call it held for a person's approval and gave up on (its removal check waits two minutes):
|
|
454
|
+
* the page's question closes with it, no answer from anywhere (EKR-140).
|
|
455
|
+
*/
|
|
456
|
+
export function isExpiredApproval(content) {
|
|
457
|
+
return EXPIRED_APPROVAL.test(failureText(content, Infinity));
|
|
458
|
+
}
|
|
432
459
|
/** The start of a failed call's output; the rest stays in the transcript. */
|
|
433
460
|
export function failureText(content, limit = ERROR_LIMIT) {
|
|
434
461
|
const text = typeof content === 'string' ? content : blocksOf(content).map((block) => block.text ?? '').join('\n');
|
|
@@ -152,6 +152,8 @@ export function currentConfig(raw, active = GLOBAL_ACCOUNT) {
|
|
|
152
152
|
// seen yet, so only the version changes.
|
|
153
153
|
// v33 → v34: a project's optional `milestoneOrder` (BTN-792); omitted keeps the automatic order, so only the version changes.
|
|
154
154
|
// v34 → v35: a project's optional `badge` (BTN-915); omitted means no badge is pushed, so only the version changes.
|
|
155
|
+
// v39 → v40: the optional `conflict` of a carry session in `state/chain.json` (`ci[<project>].carry`, EKR-135); omitted
|
|
156
|
+
// means the page shows dashes for the conflict, so only the version changes.
|
|
155
157
|
const feeds = version < 23 ? feedsRuled(sdk) : sdk;
|
|
156
158
|
const trusted = version < 26 ? automaticTrust(feeds) : feeds;
|
|
157
159
|
const kept = version < 28 ? manualKept(trusted) : trusted;
|
|
@@ -4,7 +4,7 @@ import { fail } from '../notice/notice.js';
|
|
|
4
4
|
* file's format is a new version, a step in `migrations.ts` and a new frozen sample in `test/fixtures/schema-v<N>/`.
|
|
5
5
|
* A future import into a database reads it to know what it imports.
|
|
6
6
|
*/
|
|
7
|
-
export const SCHEMA_VERSION =
|
|
7
|
+
export const SCHEMA_VERSION = 40;
|
|
8
8
|
/** A file without a version is from before versions: 1. */
|
|
9
9
|
export function versionOf(raw) {
|
|
10
10
|
const version = typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? raw.version : undefined;
|
package/dist/src/tools/panel.js
CHANGED
|
@@ -9,6 +9,7 @@ import { parseCodexRules } from '../codex/rules.js';
|
|
|
9
9
|
import { samePath } from '../paths.js';
|
|
10
10
|
import { protectionRules } from '../sessions/protection.js';
|
|
11
11
|
import { projectDirName } from '../sessions/paths.js';
|
|
12
|
+
import { readProjectSettings } from './projectSettings.js';
|
|
12
13
|
import { latestStarted, readReceived, skillSource } from './received.js';
|
|
13
14
|
import { accountDrift, forPackageOff, settingRows, trimSettings } from './settings.js';
|
|
14
15
|
/** Tool attachments come in the first lines; MCP servers connect a little after the first answer. */
|
|
@@ -23,7 +24,7 @@ const RECENT = 8;
|
|
|
23
24
|
* blanked in `env`, the ban on git of a project without it (`noGit`) with the CLI's worktree guard off and, with trimming on, the trimming. The flag's `env` outranks the user's and the project's settings,
|
|
24
25
|
* and an empty value hides a key one of them sets (checked on CLI 2.1.310, BTN-436).
|
|
25
26
|
*/
|
|
26
|
-
export function chainSettings(repo, plugins, trim, hidden, globalDir, cacheTtl, secrets = [], protection, autoCompactWindow = null, noGit = false) {
|
|
27
|
+
export function chainSettings(repo, plugins, trim, hidden, globalDir, cacheTtl, secrets = [], protection, autoCompactWindow = null, noGit = false, files = { project: undefined, local: undefined }) {
|
|
27
28
|
const always = {
|
|
28
29
|
permissions: { deny: protectionRules(protection, [], undefined, undefined, noGit).claude },
|
|
29
30
|
autoMemoryDirectory: sharedMemory(globalDir, repo),
|
|
@@ -37,14 +38,11 @@ export function chainSettings(repo, plugins, trim, hidden, globalDir, cacheTtl,
|
|
|
37
38
|
};
|
|
38
39
|
if (!trim)
|
|
39
40
|
return JSON.stringify(always);
|
|
40
|
-
|
|
41
|
-
return JSON.stringify({ ...trimSettings(hidden, project, local), ...always });
|
|
41
|
+
return JSON.stringify({ ...trimSettings(hidden, files.project, files.local), ...always });
|
|
42
42
|
}
|
|
43
43
|
export async function readToolsView(project, places) {
|
|
44
44
|
const { repo } = places;
|
|
45
45
|
const user = readJson(join(places.globalDir, 'settings.json'));
|
|
46
|
-
const { project: shared, local } = projectSettings(repo);
|
|
47
|
-
const chain = places.trim ? trimSettings(places.hidden, shared, local) : undefined;
|
|
48
46
|
const configs = places.configs.map(readJson).filter((config) => config !== undefined);
|
|
49
47
|
const localAllowed = configs.flatMap((config) => {
|
|
50
48
|
const entries = Object.entries(objectOf(config.projects)).filter(([path]) => samePath(path, repo));
|
|
@@ -56,12 +54,14 @@ export async function readToolsView(project, places) {
|
|
|
56
54
|
.filter((drift) => drift.keys.length > 0);
|
|
57
55
|
const plain = places.plain === true;
|
|
58
56
|
const files = plain ? folderFiles(repo) : [];
|
|
59
|
-
const [received, rules, docs, codexProject] = await Promise.all([
|
|
57
|
+
const [{ project: shared, local, drift }, received, rules, docs, codexProject] = await Promise.all([
|
|
58
|
+
readProjectSettings(places.git, repo, places.branch, plain),
|
|
60
59
|
readNewest(places.homes, repo),
|
|
61
60
|
plain ? repoRulesOf(files) : readRepoRules(places.git, repo, places.branch),
|
|
62
61
|
plain ? files.filter(isDoc).sort() : readBranchDocs(places.git, repo, places.branch),
|
|
63
62
|
plain ? readFolderCodexRules(join(repo, CODEX_RULES)) : readBranchCodexRules(places.git, repo, places.branch),
|
|
64
63
|
]);
|
|
64
|
+
const chain = places.trim ? trimSettings(places.hidden, shared, local) : undefined;
|
|
65
65
|
const codexUser = places.codexHome === undefined ? [] : readFolderCodexRules(join(places.codexHome, 'rules'));
|
|
66
66
|
const known = { user: new Set(dirNames(join(places.globalDir, 'skills'))), project: new Set(dirNames(join(repo, '.claude', 'skills'))) };
|
|
67
67
|
return {
|
|
@@ -73,6 +73,7 @@ export async function readToolsView(project, places) {
|
|
|
73
73
|
received: received === undefined ? null : { ...received, skills: received.skills.map((name) => ({ name, source: skillSource(name, known) })) },
|
|
74
74
|
rules,
|
|
75
75
|
docs,
|
|
76
|
+
...(drift !== undefined && { settingsDrift: drift }),
|
|
76
77
|
...(plain ? { plain: true } : {}),
|
|
77
78
|
};
|
|
78
79
|
}
|
|
@@ -144,9 +145,6 @@ function readFolderCodexRules(dir) {
|
|
|
144
145
|
function isOwnRulesFile(file) {
|
|
145
146
|
return file.endsWith('.rules') && !file.endsWith(PROTECTION_FILE);
|
|
146
147
|
}
|
|
147
|
-
function projectSettings(repo) {
|
|
148
|
-
return { project: readJson(join(repo, '.claude', 'settings.json')), local: readJson(join(repo, '.claude', 'settings.local.json')) };
|
|
149
|
-
}
|
|
150
148
|
/** The project's session that started last among the last touched transcripts, worktree ones first: chain sessions run there. */
|
|
151
149
|
async function readNewest(homes, repo) {
|
|
152
150
|
const base = projectDirName(repo).toLowerCase();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const SHARED = '.claude/settings.json';
|
|
4
|
+
/**
|
|
5
|
+
* The project's Claude settings files as its chain sessions get them (EKR-128): a task worktree starts from the branch,
|
|
6
|
+
* so an ignored or uncommitted `settings.json` never reaches it. A project without git runs its sessions in the folder.
|
|
7
|
+
*/
|
|
8
|
+
export async function readProjectSettings(git, repo, branch, plain) {
|
|
9
|
+
const disk = readText(join(repo, '.claude', 'settings.json'));
|
|
10
|
+
const local = parseObject(readText(join(repo, '.claude', 'settings.local.json')));
|
|
11
|
+
if (plain)
|
|
12
|
+
return { project: parseObject(disk), local };
|
|
13
|
+
const listed = await git(repo, ['ls-tree', '--name-only', branch, '--', SHARED]);
|
|
14
|
+
if (listed.code !== 0)
|
|
15
|
+
return { project: undefined, local };
|
|
16
|
+
const committed = listed.out.trim() === '' ? undefined : await git(repo, ['show', `${branch}:${SHARED}`]);
|
|
17
|
+
const text = committed?.code === 0 ? committed.out : undefined;
|
|
18
|
+
const drift = await driftOf(git, repo, disk, text);
|
|
19
|
+
return { project: parseObject(text), local, ...(drift !== undefined && { drift }) };
|
|
20
|
+
}
|
|
21
|
+
async function driftOf(git, repo, disk, branch) {
|
|
22
|
+
if (disk === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (branch !== undefined)
|
|
25
|
+
return sameSettings(disk, branch) ? undefined : 'edited';
|
|
26
|
+
// `check-ignore` exits 0 for an ignored path, 1 for one nothing ignores.
|
|
27
|
+
return (await git(repo, ['check-ignore', '-q', '--', SHARED])).code === 0 ? 'ignored' : 'uncommitted';
|
|
28
|
+
}
|
|
29
|
+
/** Line endings and formatting are no edit: Git for Windows may check the file out with CRLF. */
|
|
30
|
+
function sameSettings(a, b) {
|
|
31
|
+
const canonical = (text) => {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.stringify(JSON.parse(text));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return text.replace(/\r\n/g, '\n').trim();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return canonical(a) === canonical(b);
|
|
40
|
+
}
|
|
41
|
+
function readText(file) {
|
|
42
|
+
try {
|
|
43
|
+
const text = readFileSync(file, 'utf8');
|
|
44
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function parseObject(text) {
|
|
51
|
+
if (text === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
try {
|
|
54
|
+
const value = JSON.parse(text);
|
|
55
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -3,14 +3,21 @@ import { sessionSecrets } from '../agent/env.js';
|
|
|
3
3
|
import { isPlain } from '../config.js';
|
|
4
4
|
import { readJson } from '../packages/plugins.js';
|
|
5
5
|
import { chainSettings } from './panel.js';
|
|
6
|
-
|
|
6
|
+
import { readProjectSettings } from './projectSettings.js';
|
|
7
|
+
/**
|
|
8
|
+
* Settings are assembled at launch from the current configuration, including the account-independent overrides. The
|
|
9
|
+
* project's `settings.json` is the branch's, as the session's worktree has it and "What sessions get" shows it.
|
|
10
|
+
*/
|
|
7
11
|
export function createSessionSettings(deps) {
|
|
8
|
-
return (task, project = deps.projectOf(task)) => {
|
|
12
|
+
return async (task, project = deps.projectOf(task)) => {
|
|
9
13
|
if (project === undefined)
|
|
10
14
|
return undefined;
|
|
11
15
|
const config = deps.config();
|
|
12
16
|
const repo = config.projects[project];
|
|
13
|
-
const
|
|
14
|
-
|
|
17
|
+
const plain = isPlain(config, project);
|
|
18
|
+
const files = await readProjectSettings(deps.git, repo, deps.branchOf(project), plain);
|
|
19
|
+
const plugins = deps.packages.otherPlugins(project, task, [readJson(join(deps.globalDir, 'settings.json')), files.project, files.local]);
|
|
20
|
+
const own = config.settings[project];
|
|
21
|
+
return chainSettings(repo, plugins, deps.trim(), config.hiddenSkills, deps.globalDir, own?.cacheTtl ?? null, sessionSecrets(deps.packages.keyNames()), own?.protection ?? config.protection, own?.autoCompactWindow ?? null, plain, files);
|
|
15
22
|
};
|
|
16
23
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { isCopy } from '../intake/model.js';
|
|
2
2
|
import { englishOf, noticeOf } from '../notice/notice.js';
|
|
3
|
-
import { questionComment, trackerAnswers } from '../sessions/ask.js';
|
|
3
|
+
import { expiredComment, questionComment, trackerAnswers } from '../sessions/ask.js';
|
|
4
|
+
/** How long a question the session left is watched for the CLI's expiry: the transcript gets the call's result a moment later. */
|
|
5
|
+
const LEFT_WATCH_MS = 60_000;
|
|
4
6
|
const RETRIED = new Set(['answer.busy', 'chain.launching', 'chain.limitSpent', 'chain.notCurrent']);
|
|
5
7
|
const waitsOn = (session, question) => session.task === question.task && session.sessionId === question.sessionId && session.ask?.id === question.ask;
|
|
6
8
|
/**
|
|
7
9
|
* What to do on a tick: post the new questions of current tasks, read the replies to the open ones, forget those the
|
|
8
10
|
* session left. A question stays while its session waits on it, current or not, so a reply written meanwhile is read
|
|
9
|
-
* once the chain takes the task again.
|
|
11
|
+
* once the chain takes the task again. `left` — the questions the session no longer waits on.
|
|
10
12
|
*/
|
|
11
13
|
export function questionPlan(sessions, posted) {
|
|
12
14
|
const keep = posted.filter((each) => sessions.some((session) => waitsOn(session, each)));
|
|
15
|
+
const left = posted.filter((each) => !keep.includes(each));
|
|
13
16
|
const post = sessions.filter((session) => session.current && session.ask !== null && !keep.some((each) => each.task === session.task && each.ask === session.ask.id));
|
|
14
17
|
const read = keep.filter((each) => each.done !== true && sessions.some((session) => session.current && waitsOn(session, each)));
|
|
15
|
-
return { post, read, keep };
|
|
18
|
+
return { post, read, keep, left };
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* The reply that comments after the question make: the first one answers the question, the rest go along as text.
|
|
@@ -43,6 +46,11 @@ export class TrackerQuestions {
|
|
|
43
46
|
* files (BTN-1020).
|
|
44
47
|
*/
|
|
45
48
|
seen = new Map();
|
|
49
|
+
/**
|
|
50
|
+
* The questions the session left, by comment, since when: the CLI aborts an expired approval as it does one Remote
|
|
51
|
+
* Control answered, and only the call's result in the transcript, which comes a moment later, tells them apart (EKR-140).
|
|
52
|
+
*/
|
|
53
|
+
leaving = new Map();
|
|
46
54
|
constructor(deps) {
|
|
47
55
|
this.deps = deps;
|
|
48
56
|
this.posted = deps.load();
|
|
@@ -59,6 +67,7 @@ export class TrackerQuestions {
|
|
|
59
67
|
for (const comment of this.seen.keys())
|
|
60
68
|
if (!plan.read.some((each) => each.comment === comment))
|
|
61
69
|
this.seen.delete(comment);
|
|
70
|
+
await this.watchLeft(plan.left, sessions);
|
|
62
71
|
for (const session of plan.post)
|
|
63
72
|
await this.post(session);
|
|
64
73
|
for (const question of plan.read)
|
|
@@ -68,6 +77,29 @@ export class TrackerQuestions {
|
|
|
68
77
|
this.running = false;
|
|
69
78
|
}
|
|
70
79
|
}
|
|
80
|
+
async watchLeft(left, sessions) {
|
|
81
|
+
const now = (this.deps.now ?? Date.now)();
|
|
82
|
+
for (const question of left)
|
|
83
|
+
this.leaving.set(question.comment, { question, since: now });
|
|
84
|
+
for (const [comment, { question, since }] of this.leaving) {
|
|
85
|
+
const session = sessions.find((each) => each.task === question.task && each.sessionId === question.sessionId);
|
|
86
|
+
if (session?.expired?.includes(question.ask) === true) {
|
|
87
|
+
this.leaving.delete(comment);
|
|
88
|
+
await this.postExpired(session, question);
|
|
89
|
+
}
|
|
90
|
+
else if (session === undefined || now - since > LEFT_WATCH_MS)
|
|
91
|
+
this.leaving.delete(comment);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async postExpired(session, question) {
|
|
95
|
+
try {
|
|
96
|
+
await this.deps.tracker(session.project, question.task, async (tracker) => tracker.comment?.(question.task, expiredComment(this.deps.language(session.project))));
|
|
97
|
+
this.deps.log(`tracker: ${question.task}: the CLI stopped waiting on the question ${question.comment}; the tracker is told it expired`);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.deps.log(`tracker: ${question.task}: the expiry of the question was not posted: ${englishOf(noticeOf(error))}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
71
103
|
async post(session) {
|
|
72
104
|
const ask = session.ask;
|
|
73
105
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,D as n,Ei as r,Lr as i,M as a,Nn as o,Pr as s,Rr as c,Xt as l,i as u,ki as d,pi as f,t as p,ut as m,v as h,xi as g,y as _}from"./blocks-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,D as n,Ei as r,Lr as i,M as a,Nn as o,Pr as s,Rr as c,Xt as l,i as u,ki as d,pi as f,t as p,ut as m,v as h,xi as g,y as _}from"./blocks-CrABcaPz.js";import{t as v}from"./react-dom-BrsVbrva.js";import{t as y}from"./secret-CmK85pY6.js";/* empty css */var b=e(d(),1),x=e(v(),1),S=[`title`,`agent`,`model`,`time`,`action`,`context`,`chain`,`milestone`,`sessions`,`medianCost`,`medianMinutes`],C=`EVEN_KEEL_BADGE_SECRET`,w=[{id:`tasks`,fields:[`agent`,`model`,`time`,`action`]},{id:`context`,fields:[`context`]},{id:`chain`,fields:[`chain`]},{id:`milestone`,fields:[`milestone`]},{id:`sessions`,fields:[`sessions`]},{id:`medianCost`,fields:[`medianCost`]},{id:`medianMinutes`,fields:[`medianMinutes`]},{id:`title`,fields:[`title`]}],T=(e,t)=>t.fields.every(t=>e.includes(t));function E(e,t,n){return S.filter(r=>t.fields.includes(r)?n:e.includes(r))}function D(e){let t=e.toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,64);return t===``?`project`:t}function O(e,t){return e??{on:!1,url:``,slug:D(t),fields:[...S]}}var k=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?::\d+)?\//;function A(e){let t=e.filter(e=>k.test(e.id)),n=t.find(e=>e.id.startsWith(`github.com/`))??t.find(e=>e.id.startsWith(`gitlab.`))??t[0];return n===void 0?null:`https://${n.id}${n.id.startsWith(`gitlab.`)?`/-/releases`:`/releases`}`}var j=e=>e.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`);function M(e){let t=`${e.url.trim().replace(/\/+$/,``)}/${e.slug}.svg`,n=`<picture><source media="(prefers-color-scheme: light)" srcset="${j(`${t}?theme=light`)}"><img alt="${j(`${e.name}: what the chain is building now`)}" src="${j(`${t}?theme=dark`)}"></picture>`,r=e.releases.trim();return r===``?n:`<a href="${j(r)}">${n}</a>`}function N(e,t,n){let r=e=>String(e).padStart(2,`0`);return`${e}-badge-${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}-${r(n.getHours())}${r(n.getMinutes())}-${t}.png`}var P=2;async function F(e){let t=await fetch(e);if(!t.ok)throw Error(`badge: the picture answered ${t.status}`);let n=URL.createObjectURL(new Blob([await t.text()],{type:`image/svg+xml`}));try{let e=new Image;e.src=n,await e.decode();let t=document.createElement(`canvas`);t.width=e.naturalWidth*P,t.height=e.naturalHeight*P;let r=t.getContext(`2d`);if(r===null)throw Error(`badge: no 2D canvas`);return r.drawImage(e,0,0,t.width,t.height),await new Promise((e,n)=>t.toBlob(t=>t===null?n(Error(`badge: the canvas gave no PNG`)):e(t),`image/png`))}finally{URL.revokeObjectURL(n)}}function I(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),0)}var L=c(),R=`https://github.com/NamerekT/even-keel/blob/main/deploy/badge/README.md`,z=5e3;function B({state:e,project:n,onClose:r}){let i=(0,b.useRef)(null),c=h(i,r),l=(0,b.useId)();(0,b.useEffect)(()=>{i.current?.open===!1&&i.current.showModal()},[]);let u=e.projectKeys[n]??n,d=e.config.projects[n],m=O(d?.badge,u),_=o(e,n),v=s(),y=e=>v.send(`project/badge`,{project:n,badge:e});return(0,x.createPortal)((0,L.jsx)(`dialog`,{ref:i,className:`add-package add-package--wide badge-dialog`,"aria-labelledby":l,onCancel:e=>{e.preventDefault(),r()},...c,children:(0,L.jsxs)(`div`,{className:`add-package__frame`,children:[(0,L.jsxs)(`header`,{className:`add-package__head`,children:[(0,L.jsx)(`h2`,{id:l,className:`add-package__title`,children:g.badge.title(_)}),(0,L.jsx)(`button`,{type:`button`,className:`panel__close`,"aria-label":g.badge.close,onClick:r,children:`×`})]}),(0,L.jsxs)(`div`,{className:`add-package__body badge-dialog__body`,children:[v.failure!==null&&(0,L.jsx)(p,{tone:`error`,children:f(v.failure)}),(0,L.jsx)(V,{project:n,badge:m,state:e,disabled:v.sending,onSave:y}),(0,L.jsx)(t,{title:g.badge.show,hint:g.badge.showHint,children:w.map(e=>(0,L.jsx)(a,{className:`badge-dialog__field`,label:g.badge.groups[e.id],hint:g.badge.groupHints[e.id],checked:T(m.fields,e),disabled:v.sending,onChange:t=>void y({...m,fields:E(m.fields,e,t)})},e.id))}),(0,L.jsx)(G,{project:n,label:_,fields:m.fields.join(),slug:m.slug===``?D(u):m.slug}),(0,L.jsx)(K,{state:e,project:n,badge:m,name:d?.name??u})]}),(0,L.jsxs)(`footer`,{className:`add-package__foot`,children:[(0,L.jsx)(`span`,{className:`add-package__spacer`}),(0,L.jsx)(`button`,{type:`button`,className:`button button--primary`,onClick:r,children:g.badge.done})]})]})}),document.body)}function V({project:e,badge:n,state:o,disabled:s,onSave:c}){let{query:u}=i(),[d,h]=(0,b.useState)(!1),[_,v]=(0,b.useState)(null),y=H(n.url,e=>({...n,url:e}),e),x=H(n.slug,e=>({...n,slug:e}),e),S=y.value.trim()!==``&&x.value.trim()!==``,C=async()=>{h(!0),v(null);try{v(await u(`project/badge/check`,{project:e,url:y.value,slug:x.value}))}catch(e){v({ok:!1,notice:r(e)})}finally{h(!1)}},w=(0,L.jsxs)(`a`,{className:`badge-dialog__deploy`,href:R,target:`_blank`,rel:`noreferrer`,children:[g.badge.deploy,(0,L.jsx)(m,{})]});return(0,L.jsxs)(t,{title:g.badge.where,hint:g.badge.whereHint,aside:w,children:[(0,L.jsx)(a,{className:`badge-dialog__field`,label:g.badge.on,hint:g.badge.onHint,checked:n.on,disabled:s,onChange:e=>void c({...n,on:e})}),(0,L.jsx)(U,{wide:!0,label:g.badge.url,hint:g.badge.urlHint,field:y,placeholder:`https://even-keel-badge.example.workers.dev`}),(0,L.jsx)(U,{label:g.badge.slug,hint:g.badge.slugHint,field:x,placeholder:`project`}),(0,L.jsx)(W,{state:o}),(0,L.jsxs)(`div`,{className:`badge-dialog__check`,children:[(0,L.jsx)(l,{tip:S?g.badge.checkTip:g.badge.checkNeeds,inline:!0,children:(0,L.jsx)(`button`,{type:`button`,className:`button`,"aria-disabled":!S||d,onClick:()=>S&&!d&&void C(),children:g.badge.check})}),_!==null&&(0,L.jsx)(p,{tone:_.ok?`note`:`error`,className:`badge-dialog__result`,children:f(_.notice)})]})]})}function H(e,t,n){let r=(0,b.useId)(),[i,a]=(0,b.useState)(e),[o,c]=(0,b.useState)(!1),{send:l,failure:u}=s();return(0,b.useEffect)(()=>{o||a(e)},[e,o]),{id:r,value:i,error:u,edit:e=>{c(!0),a(e)},commit:()=>{c(!1),i.trim()!==e&&l(`project/badge`,{project:n,badge:t(i.trim())})}}}function U({label:e,hint:t,field:r,placeholder:i,wide:a=!1}){return(0,L.jsx)(n,{className:`badge-dialog__field badge-dialog__field--${a?`wide`:`text`}`,label:e,hint:t,htmlFor:r.id,error:r.error,control:(0,L.jsx)(`input`,{id:r.id,className:`settings__text settings__text--mono`,autoComplete:`off`,spellCheck:!1,value:r.value,placeholder:i,"aria-invalid":r.error!==null,onChange:e=>r.edit(e.target.value),onBlur:r.commit,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),r.commit())}})})}function W({state:e}){let t=(0,b.useId)(),{send:r,sending:i,failure:a}=s(),[o,c]=(0,b.useState)(``),l=e.secrets.variables.find(e=>e.name===C),u=l?.set===!0,d=l?.outer===!0,f=async e=>{e.preventDefault(),o!==``&&await r(`secrets/set`,{name:`EVEN_KEEL_BADGE_SECRET`,value:o})&&c(``)};return(0,L.jsx)(n,{className:`badge-dialog__field badge-dialog__field--text`,label:g.badge.secret,hint:d?`${g.badge.secretHint}. ${g.badge.secretOuter}`:g.badge.secretHint,htmlFor:t,mark:!u&&(0,L.jsx)(`span`,{className:`chip packages__unset`,children:g.badge.secretUnset}),control:(0,L.jsx)(_,{error:a,children:(0,L.jsxs)(`form`,{className:`badge-dialog__secret`,onSubmit:e=>void f(e),children:[(0,L.jsx)(`input`,{id:t,className:`settings__text`,...y(),value:o,disabled:d,placeholder:u?g.badge.secretSaved:void 0,"aria-label":g.badge.secretValue,onChange:e=>c(e.target.value)}),(0,L.jsx)(`button`,{type:`submit`,className:`button button--small`,disabled:i||o===``||d,children:g.badge.save})]})})})}function G({project:e,label:n,fields:r,slug:a}){let{badgeUrl:o,state:s}=i(),[c,u]=(0,b.useState)(`dark`),[d,f]=(0,b.useState)(!1),[m,h]=(0,b.useState)(!1),_=async()=>{f(!0),h(!1);try{I(await F(o(e,c,!0)),N(a,c,new Date))}catch{h(!0)}finally{f(!1)}},[v,y]=(0,b.useState)(()=>Date.now()),x=(0,b.useRef)(v);(0,b.useEffect)(()=>{let e=Date.now();e-x.current<z||(x.current=e,y(e))},[s]),(0,b.useEffect)(()=>{x.current=Date.now(),y(x.current)},[r]);let S=o(e,c),C=S.startsWith(`data:`)?S:`${S}&at=${v}`,w=(0,L.jsx)(`div`,{className:`segmented`,role:`group`,"aria-label":g.badge.preview,children:[`dark`,`light`].map(e=>(0,L.jsx)(`button`,{type:`button`,className:c===e?`segmented__item segmented__item--on`:`segmented__item`,"aria-pressed":c===e,onClick:()=>u(e),children:g.badge[e]},e))});return(0,L.jsxs)(t,{title:g.badge.preview,hint:g.badge.previewHint,aside:w,children:[(0,L.jsx)(`div`,{className:`badge-dialog__preview badge-dialog__preview--${c}`,children:(0,L.jsx)(`img`,{src:C,alt:g.badge.previewAlt(n)})}),(0,L.jsxs)(`div`,{className:`badge-dialog__check`,children:[(0,L.jsx)(l,{tip:g.badge.pngTip,inline:!0,children:(0,L.jsx)(`button`,{type:`button`,className:`button`,"aria-disabled":d,onClick:()=>!d&&void _(),children:g.badge.png})}),m&&(0,L.jsx)(p,{tone:`error`,className:`badge-dialog__result`,children:g.badge.pngFailed})]})]})}function K({state:e,project:r,badge:i,name:a}){let o=(0,b.useId)(),s=A(e.remotes[r]??[]),[c,l]=(0,b.useState)(null),d=c??s??``,f=i.url!==``&&i.slug!==``;return(0,L.jsxs)(t,{title:g.badge.markdown,hint:g.badge.markdownHint,children:[(0,L.jsx)(n,{className:`badge-dialog__field badge-dialog__field--wide`,label:g.badge.releases,hint:g.badge.releasesHint,htmlFor:o,control:(0,L.jsx)(`input`,{id:o,className:`settings__text settings__text--mono`,autoComplete:`off`,spellCheck:!1,value:d,placeholder:`https://github.com/owner/repo/releases`,onChange:e=>l(e.target.value)})}),f?(0,L.jsx)(u,{className:`badge-dialog__markdown`,command:M({url:i.url,slug:i.slug,name:a,releases:d})}):(0,L.jsx)(`p`,{className:`badge-dialog__needs`,children:g.badge.markdownNeeds})]})}export{B as BadgeDialog};
|