even-keel 0.2.1 → 0.2.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +77 -88
  3. package/dist/src/account/current.js +4 -4
  4. package/dist/src/account/model.js +1 -1
  5. package/dist/src/account/watcher.js +4 -1
  6. package/dist/src/agent/providers.js +2 -1
  7. package/dist/src/autostart.js +32 -2
  8. package/dist/src/chain/dispatcher.js +8 -2
  9. package/dist/src/chain/launches.js +1 -1
  10. package/dist/src/chain/log.js +2 -0
  11. package/dist/src/chain/maincheck.js +19 -0
  12. package/dist/src/chain/mainci.js +4 -0
  13. package/dist/src/chain/mainfix.js +30 -0
  14. package/dist/src/chain/prompts.js +2 -0
  15. package/dist/src/chain/unchanged.js +47 -19
  16. package/dist/src/ci/watcher.js +12 -1
  17. package/dist/src/claude/adapter.js +8 -2
  18. package/dist/src/claude/cli.js +11 -3
  19. package/dist/src/claude/sdk/release.js +1 -1
  20. package/dist/src/claude/trust.js +77 -4
  21. package/dist/src/codex/adapter.js +2 -2
  22. package/dist/src/codex/plugins.js +20 -5
  23. package/dist/src/codex/version.js +1 -1
  24. package/dist/src/copilot/adapter.js +2 -1
  25. package/dist/src/copilot/cli.js +10 -5
  26. package/dist/src/copilot/home.js +19 -5
  27. package/dist/src/copilot/machine.js +20 -3
  28. package/dist/src/git/setup.js +2 -2
  29. package/dist/src/gitlab/adapter.js +1 -0
  30. package/dist/src/gitlab/source.js +13 -1
  31. package/dist/src/jira/adapter.js +1 -0
  32. package/dist/src/jira/api.js +13 -5
  33. package/dist/src/jira/source.js +20 -2
  34. package/dist/src/notice/en.js +7 -2
  35. package/dist/src/opencode/adapter.js +1 -1
  36. package/dist/src/packages/service.js +2 -0
  37. package/dist/src/packages/store.js +2 -1
  38. package/dist/src/paths.js +35 -0
  39. package/dist/src/projects/check.js +15 -6
  40. package/dist/src/projects/folder.js +8 -0
  41. package/dist/src/projects/state.js +1 -0
  42. package/dist/src/service/accounts.js +19 -4
  43. package/dist/src/service/chain.js +2 -2
  44. package/dist/src/service/stats.js +3 -0
  45. package/dist/src/sessions/protection.js +9 -6
  46. package/dist/src/stats/tally.js +2 -2
  47. package/dist/src/storage/atomic.js +19 -3
  48. package/dist/src/storage/database.js +5 -0
  49. package/dist/src/storage/migrations.js +17 -1
  50. package/dist/src/storage/schema.js +1 -1
  51. package/dist/src/tracker/model.js +4 -0
  52. package/dist/src/tracker/trackers.js +7 -0
  53. package/dist/tally/src/collect-worker.js +2 -2
  54. package/dist/tally/src/collect.js +3 -2
  55. package/dist/tally/src/db.js +3 -0
  56. package/dist/tally/src/steps.js +7 -2
  57. package/dist/tally/src/tracker-times.js +47 -0
  58. package/dist/web/assets/Loader-CRe-GCoI.js +31 -0
  59. package/dist/web/assets/{TaskCard-CjyQeVqL.js → TaskCard-C2xeaHWD.js} +2 -2
  60. package/dist/web/assets/TranscriptWindow-B9zsSmIg.css +1 -0
  61. package/dist/web/assets/TranscriptWindow-COL_WTrF.js +4 -0
  62. package/dist/web/assets/{feedLine-CDr3S8u-.js → feedLine-D0lnFyBZ.js} +1 -1
  63. package/dist/web/assets/index-DQje9Nfo.js +25 -0
  64. package/dist/web/assets/index-mDBlgk2Y.css +1 -0
  65. package/dist/web/assets/{media-CZ0HLFuK.js → media-BlW-XXN0.js} +1 -1
  66. package/dist/web/assets/useModels-DRW63oka.js +15 -0
  67. package/dist/web/index.html +5 -5
  68. package/even-keel.config.example.json +1 -1
  69. package/package.json +3 -2
  70. package/dist/web/assets/Loader-CG5xzofh.js +0 -31
  71. package/dist/web/assets/TranscriptWindow-2afYjYo9.css +0 -1
  72. package/dist/web/assets/TranscriptWindow-z3VnB6bE.js +0 -4
  73. package/dist/web/assets/index-AeOeU4Dr.js +0 -25
  74. package/dist/web/assets/index-DMDSaLu7.css +0 -1
  75. package/dist/web/assets/useModels-DfXVnluv.js +0 -15
@@ -1,15 +1,19 @@
1
1
  import { notice, noticeOf } from '../notice/notice.js';
2
+ import { isFixName } from './fix.js';
2
3
  import { PROMPTS } from './prompts.js';
3
4
  // Out of PR mode a session merges its branch, and the merge closes the task. A task with nothing to merge — done in
4
5
  // main already, research, an answer — never closes that way: its session ends the turn with `NO CHANGES: <why>`
5
6
  // instead (EKR-10). With nothing beyond main and a clean worktree the task is moved to Done with the reason as a
6
7
  // comment, and the chain's own Done cleans up after it (invariant 1, exception 4); otherwise the session is told.
8
+ // A fix session of a red main marks it too when the code is not broken (EKR-88): `MainFix.unneeded` takes it from there.
7
9
  export class Unchanged {
8
10
  deps;
9
11
  handovers;
10
12
  hold;
11
13
  /** The `lastReplyAt` of each task's mark acted on: only a new turn of the session marks again. A service restart forgets it. */
12
14
  tried = new Map();
15
+ /** The `lastReplyAt` of each task's mark found clean and not acted on yet: a fix of main waits on it for a verdict. */
16
+ clean = new Map();
13
17
  constructor(deps, handovers,
14
18
  /** Pauses the chain on its current task, which stays current. */
15
19
  hold) {
@@ -19,20 +23,53 @@ export class Unchanged {
19
23
  }
20
24
  /** The current task's mark on each step: `true` — the chain acted on it. */
21
25
  async follow(chain, current) {
26
+ const mark = await this.check(chain, current);
27
+ if (mark === null)
28
+ return false;
29
+ if (mark === 'acted')
30
+ return true;
31
+ const { project } = chain;
32
+ const { task } = current;
33
+ this.clean.delete(task);
34
+ const main = this.deps.mainBranch(task);
35
+ const texts = PROMPTS[this.deps.promptLanguage(task)].unchanged;
36
+ this.deps.log(`chain: ${task} needs no change and its branch has nothing beyond ${main}; the task is done`);
37
+ try {
38
+ await this.deps.unchanged.complete(project, task, texts.comment(mark.reason));
39
+ }
40
+ catch (error) {
41
+ this.hold(chain, notice('chain.unchangedNotCompleted', { task }, { cause: noticeOf(error) }));
42
+ return true;
43
+ }
44
+ this.deps.log(`chain: ${task} is moved to done in the tracker`);
45
+ await this.deps.refresh(project).catch(() => undefined);
46
+ return true;
47
+ }
48
+ /**
49
+ * The current session's `NO CHANGES:` mark: `null` — none to act on; `acted` — the chain halted or the session was told
50
+ * its branch is not clean; a reason — the branch has nothing beyond main, asked again on each step until the session
51
+ * takes another turn (a fix of main waits on it for the verdict, EKR-88).
52
+ */
53
+ async check(chain, current) {
22
54
  const unchanged = this.deps.unchanged;
23
55
  const { project } = chain;
24
56
  const { task } = current;
25
57
  // A turn that ended on a background command is over, as for Done (BTN-202): only a clean branch goes on without it.
26
58
  const busy = this.deps.busy(task);
27
59
  const shell = busy && this.deps.shell(task);
28
- if (unchanged === undefined || (busy && !shell) || this.deps.pullRequests?.(task) === true)
29
- return false;
60
+ // A fix of main merges by itself even in PR mode, so it marks no pull request either.
61
+ if (unchanged === undefined || (busy && !shell) || (!isFixName(task) && this.deps.pullRequests?.(task) === true))
62
+ return null;
30
63
  const session = this.deps.handoff(task);
31
64
  if (session === undefined || session.sessionId !== current.sessionId)
32
- return false;
65
+ return null;
33
66
  const reason = session.noChanges ?? null;
34
- if (reason === null || (this.tried.has(task) && this.tried.get(task) === session.lastReplyAt))
35
- return false;
67
+ if (reason === null)
68
+ return null;
69
+ if (this.clean.has(task) && this.clean.get(task) === session.lastReplyAt)
70
+ return { reason };
71
+ if (this.tried.has(task) && this.tried.get(task) === session.lastReplyAt)
72
+ return null;
36
73
  this.tried.set(task, session.lastReplyAt);
37
74
  const main = this.deps.mainBranch(task);
38
75
  const texts = PROMPTS[this.deps.promptLanguage(task)].unchanged;
@@ -42,30 +79,21 @@ export class Unchanged {
42
79
  }
43
80
  catch (error) {
44
81
  this.hold(chain, notice('chain.unchangedNotChecked', { task }, { cause: noticeOf(error) }));
45
- return true;
82
+ return 'acted';
46
83
  }
47
84
  if (changes.ahead > 0 || changes.files > 0) {
48
85
  if (shell) {
49
86
  // The work is not over: the session is told once its command ends or counts as hung.
50
87
  this.tried.delete(task);
51
- return false;
88
+ return null;
52
89
  }
53
90
  // Told as a chat answer is, by `--resume` whatever its cache: the reply belongs to the session's own turn.
54
91
  const what = changes.ahead > 0 ? `${changes.ahead} commit(s) beyond ${main}` : 'uncommitted changes';
55
92
  this.deps.log(`chain: ${task} is marked as needing no change, but its branch has ${what}; the session is told`);
56
93
  await this.handovers.deliver(chain, current, session, changes.ahead > 0 ? texts.ahead(main) : texts.dirty(main), null);
57
- return true;
58
- }
59
- this.deps.log(`chain: ${task} needs no change and its branch has nothing beyond ${main}; the task is done`);
60
- try {
61
- await unchanged.complete(project, task, texts.comment(reason));
62
- }
63
- catch (error) {
64
- this.hold(chain, notice('chain.unchangedNotCompleted', { task }, { cause: noticeOf(error) }));
65
- return true;
94
+ return 'acted';
66
95
  }
67
- this.deps.log(`chain: ${task} is moved to done in the tracker`);
68
- await this.deps.refresh(project).catch(() => undefined);
69
- return true;
96
+ this.clean.set(task, session.lastReplyAt);
97
+ return { reason };
70
98
  }
71
99
  }
@@ -6,6 +6,8 @@ export const POLL_MS = 15_000;
6
6
  /** How long after a push the CI is polled for a run to take it. */
7
7
  export const PUSH_WINDOW_MS = 10 * 60_000;
8
8
  export const ERROR_RETRY_MS = 60_000;
9
+ /** How long one `want` keeps a finished history polled: the chain asks again on each of its steps while it waits. */
10
+ export const WANT_MS = 2 * 60_000;
9
11
  export const HISTORY = 10;
10
12
  /** A run's tasks come from at most this many commits since the previous run. */
11
13
  const TASK_COMMITS = 50;
@@ -19,6 +21,7 @@ export class CiWatch {
19
21
  push = null;
20
22
  branch;
21
23
  polledAt = -Infinity;
24
+ wantedAt = -Infinity;
22
25
  jobsOf = null;
23
26
  tasksOf = null;
24
27
  busy = false;
@@ -63,6 +66,13 @@ export class CiWatch {
63
66
  this.view.error = source === null ? notice('ci.noToken', { kind: this.deps.target.kind }) : null;
64
67
  this.deps.onChange();
65
68
  }
69
+ /**
70
+ * The chain waits for a fresh verdict on a commit whose runs are over — a red one the fix session reran (EKR-88):
71
+ * no push and no run under way would poll for it, so the history is polled for `WANT_MS` after the last call.
72
+ */
73
+ want() {
74
+ this.wantedAt = this.now().getTime();
75
+ }
66
76
  async tick() {
67
77
  const source = this.source;
68
78
  if (source === null || this.busy)
@@ -138,7 +148,8 @@ export class CiWatch {
138
148
  return since >= ERROR_RETRY_MS;
139
149
  const running = this.view.current !== null && !isFinished(this.view.current.run.status);
140
150
  const waiting = this.push !== null && now.getTime() - Date.parse(this.push.at) < PUSH_WINDOW_MS;
141
- return (running || waiting) && since >= POLL_MS;
151
+ const wanted = now.getTime() - this.wantedAt < WANT_MS;
152
+ return (running || waiting || wanted) && since >= POLL_MS;
142
153
  }
143
154
  async poll(source, now, branch) {
144
155
  try {
@@ -1,4 +1,5 @@
1
1
  import { readFile, stat } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
2
3
  import { join } from 'node:path';
3
4
  import { cliCopy } from '../agent/copy.js';
4
5
  import { PinnedCli } from '../agent/pinned.js';
@@ -19,8 +20,9 @@ import { claudeBinaryIn, claudeLatest, fetchClaude } from './release.js';
19
20
  import { SdkSessions } from './sdk/host.js';
20
21
  import { SDK_KIND } from './sdk/registry.js';
21
22
  import { fetchSdk, sdkModuleIn, sdkVersionOf } from './sdk/release.js';
23
+ import { trustFolder } from './trust.js';
22
24
  /** The version the README's "Before you run it" names; raised after the live run of each release (`docs/releases.md`). */
23
- const CHECKED = '2.1.317';
25
+ const CHECKED = '2.1.319';
24
26
  /** Even Keel's folder of SDK sessions in `state/` and of the SDK's copies in `state/cli/`. */
25
27
  const CLAUDE_SDK = 'claude-sdk';
26
28
  const SDK_TRANSPORT = 'sdk';
@@ -86,18 +88,22 @@ export const claude = {
86
88
  return {
87
89
  updateMarketplace: (home, marketplace, timeout) => updateMarketplace(envOf(home), marketplace, timeout, bin()),
88
90
  addMarketplace: (home, dir, timeout) => addMarketplace(envOf(home), dir, timeout, bin()),
89
- cli: cliCopy(copy, { checkedCli }, version, onMachine, () => !!env().EVEN_KEEL_CLAUDE_BIN, 280 * 1_000_000, sdkCopy),
91
+ cli: cliCopy(copy, { checkedCli }, version, onMachine, () => !!env().EVEN_KEEL_CLAUDE_BIN, 340 * 1_000_000, sdkCopy),
90
92
  mode: SESSION_MODE,
91
93
  env: envOf,
92
94
  launch: async (home, start) => {
93
95
  if (viaSdk(home))
94
96
  return sdk.launch(home, start);
97
+ if (start.trustedRepo !== undefined)
98
+ trustFolder(envOf(home).CLAUDE_CONFIG_DIR === undefined ? join(homedir(), '.claude.json') : join(home.dir, '.claude.json'), start.trustedRepo);
95
99
  const { name, cwd, prompt, model, settings, mcp, plugins } = start;
96
100
  return (await cli.launch(home, name, cwd, prompt, model, { settings, mcp, plugins, instructions: agentsFallback(cwd) })).sessionId;
97
101
  },
98
102
  resume: async (home, { agentId, sessionId }, start) => {
99
103
  if (await sdk.knows(sessionId))
100
104
  return sdk.resume(home, sessionId, start);
105
+ if (start.trustedRepo !== undefined)
106
+ trustFolder(envOf(home).CLAUDE_CONFIG_DIR === undefined ? join(homedir(), '.claude.json') : join(home.dir, '.claude.json'), start.trustedRepo);
101
107
  const { name, cwd, prompt, model, settings, mcp, plugins } = start;
102
108
  return (await cli.resume(home, agentId, sessionId, name, cwd, prompt, model, { settings, mcp, plugins, instructions: agentsFallback(cwd) })).sessionId;
103
109
  },
@@ -2,14 +2,14 @@ import { execFile, spawn } from 'node:child_process';
2
2
  import { existsSync, readdirSync } from 'node:fs';
3
3
  import { readdir, readFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
- import { join } from 'node:path';
5
+ import { isAbsolute, join, resolve } from 'node:path';
6
6
  import { setTimeout as delay } from 'node:timers/promises';
7
7
  import { promisify } from 'node:util';
8
8
  import { parseAuthStatus } from '../account/model.js';
9
9
  import { gatewayName } from '../agent/contract.js';
10
10
  import { runWithInput } from '../agent/oneturn.js';
11
11
  import { fail, notice, NoticeError } from '../notice/notice.js';
12
- import { samePath } from '../paths.js';
12
+ import { binaryPath, samePath } from '../paths.js';
13
13
  import { blockedAsk, blockedOn, launchedModel, launchedSettings, parseAgents, parseSessionRecord, withLiveRecords } from '../sessions/agents.js';
14
14
  import { newestExtensionBinary } from '../sessions/paths.js';
15
15
  import { CallTimeout, FolderCalls } from './calls.js';
@@ -193,10 +193,18 @@ export class ClaudeCli {
193
193
  }
194
194
  }
195
195
  async start(home, args, cwd, failure) {
196
+ const env = { ...this.envOf(home) };
197
+ const selected = this.bin();
198
+ const binary = binaryPath(selected, env, cwd) ?? selected;
199
+ const override = env.CLAUDE_CONFIG_DIR;
200
+ const recovery = { binary, configDir: override ? (isAbsolute(override) ? override : resolve(cwd, override)) : null };
196
201
  try {
197
- await run(this.bin(), args, { cwd, env: this.envOf(home), timeout: this.timeoutMs, windowsHide: true });
202
+ await run(binary, args, { cwd, env, timeout: this.timeoutMs, windowsHide: true });
198
203
  }
199
204
  catch (error) {
205
+ if (failure.code === 'claude.startFailed' || failure.code === 'claude.resumeFailed') {
206
+ failure = { ...failure, params: { ...failure.params, recovery } };
207
+ }
200
208
  throw new NoticeError({ ...failure, detail: outputOf(error) }, { cause: error });
201
209
  }
202
210
  }
@@ -17,7 +17,7 @@ export function sdkModuleIn(folder) {
17
17
  }
18
18
  /**
19
19
  * Downloads the SDK's npm package of `version` into `into`, checked against the registry's sha512. Only the package
20
- * itself: its optional platform packages carry a CLI of their own (~280 MB), and the session runs on Even Keel's copy.
20
+ * itself: its optional platform packages carry a CLI of their own (~340 MB), and the session runs on Even Keel's copy.
21
21
  */
22
22
  export async function fetchSdk(version, into, progress) {
23
23
  await fetchNpmPackage(PACKAGE, version, into, progress);
@@ -1,12 +1,85 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { isPlainObject } from '../settings/file.js';
4
+ import { samePath, workingFolder } from '../paths.js';
5
+ import { isTrusted, readsKey } from '../projects/check.js';
6
+ import { writeAtomic } from '../storage/atomic.js';
1
7
  import { NoticeError, fail } from '../notice/notice.js';
8
+ /**
9
+ * Add checkout trust without replacing any of the CLI's other settings, under the key the CLI reads (`readsKey`): the
10
+ * folder's real path (`workingFolder`), with forward slashes on Windows, carrying what an entry under another spelling
11
+ * of it already holds.
12
+ */
13
+ export function trustFolder(file, folder, platform = process.platform) {
14
+ try {
15
+ let text;
16
+ try {
17
+ text = readFileSync(file, 'utf8');
18
+ }
19
+ catch (error) {
20
+ if (error.code !== 'ENOENT')
21
+ throw error;
22
+ }
23
+ const config = text === undefined ? {} : JSON.parse(text.replace(/^\uFEFF/, ''));
24
+ if (!isPlainObject(config) || (config.projects !== undefined && !isPlainObject(config.projects)))
25
+ throw new Error('Invalid Claude configuration');
26
+ if (isTrusted(config, folder, platform))
27
+ return;
28
+ const projects = config.projects === undefined ? {} : config.projects;
29
+ const keys = Object.keys(projects).filter((key) => samePath(key, folder, platform));
30
+ const real = workingFolder(folder, platform);
31
+ const key = keys.find((key) => readsKey(key, folder, platform)) ?? (platform === 'win32' ? real.replaceAll('\\', '/') : real);
32
+ const entry = projects[keys.includes(key) ? key : keys[0] ?? key];
33
+ if (entry !== undefined && !isPlainObject(entry))
34
+ throw new Error('Invalid Claude project configuration');
35
+ // A new file is private, as the CLI creates it; an existing one keeps its own mode (EKR-95).
36
+ writeAtomic(file, `${JSON.stringify({ ...config, projects: { ...projects, [key]: { ...entry, hasTrustDialogAccepted: true } } }, null, 2)}\n`, text === undefined ? 0o600 : undefined);
37
+ }
38
+ catch (error) {
39
+ // A file system error has a code; a parse error or a wrong shape has none.
40
+ const reason = typeof error.code === 'string' ? 'access' : 'invalid';
41
+ throw fail('claude.trustWriteFailed', { folder, file, reason }, { detail: error instanceof Error ? error.message : String(error) }, { cause: error });
42
+ }
43
+ }
44
+ const psQuoted = (text) => `'${text.replace(/'/g, "''")}'`;
45
+ /**
46
+ * The refused invocation as a `.ps1` the service user runs through `runas` (EKR-87): a short command naming a file the
47
+ * user can open and read, instead of a PowerShell line quoted twice over. UTF-8 with a BOM, so Windows PowerShell 5
48
+ * reads non-ASCII paths right. Returns the path, or `undefined` when the file cannot be written.
49
+ */
50
+ function writeTrustScript(dir, task, folder, recovery) {
51
+ const file = join(dir, 'trust', `${task.replace(/[^\w.-]/g, '_')}.ps1`);
52
+ const lines = [
53
+ "$ErrorActionPreference = 'Stop'",
54
+ `Set-Location -LiteralPath ${psQuoted(folder)}`,
55
+ recovery.configDir === null ? 'Remove-Item Env:CLAUDE_CONFIG_DIR -ErrorAction SilentlyContinue' : `$env:CLAUDE_CONFIG_DIR = ${psQuoted(recovery.configDir)}`,
56
+ `& ${psQuoted(recovery.binary)}`,
57
+ ];
58
+ try {
59
+ writeAtomic(file, `${lines.join('\r\n')}\r\n`);
60
+ return file;
61
+ }
62
+ catch (error) {
63
+ console.warn(`trust: could not write ${file}: ${error instanceof Error ? error.message : String(error)}`);
64
+ return undefined;
65
+ }
66
+ }
2
67
  /** What `claude --bg` prints when the folder's trust dialog was never accepted: it refuses to start, no session is made. */
3
68
  const UNTRUSTED = /workspace not trusted/i;
4
69
  /**
5
70
  * The CLI's refusal of a folder Claude Code does not trust, as a notice that says what to do (BTN-429), or `null` for
6
- * any other failure. `folder` is the project's checkout: its trust covers the task worktrees inside it.
71
+ * any other failure. `folder` is the project's checkout: its trust covers the task worktrees inside it. With
72
+ * `scriptDir` (the state folder), a Windows service's refusal also gets the script its `runas` command opens.
7
73
  */
8
- export function untrustedStart(error, place) {
9
- if (!(error instanceof NoticeError) || error.notice.code !== 'claude.startFailed' || !UNTRUSTED.test(error.notice.detail ?? ''))
74
+ export function untrustedStart(error, place, scriptDir) {
75
+ if (!(error instanceof NoticeError))
76
+ return null;
77
+ const { notice } = error;
78
+ if ((notice.code !== 'claude.startFailed' && notice.code !== 'claude.resumeFailed') || !UNTRUSTED.test(notice.detail ?? ''))
10
79
  return null;
11
- return fail('claude.untrusted', place, {}, { cause: error });
80
+ const { recovery } = notice.params;
81
+ const script = recovery !== undefined && scriptDir !== undefined && place.platform === 'win32' && place.service
82
+ ? writeTrustScript(scriptDir, place.task, place.folder, recovery)
83
+ : undefined;
84
+ return fail('claude.untrusted', { ...place, ...(recovery === undefined ? {} : { recovery }), ...(script === undefined ? {} : { script }) }, {}, { cause: error });
12
85
  }
@@ -43,14 +43,14 @@ export const codex = {
43
43
  const bin = () => resolveCodexBinary(env(), env().EVEN_KEEL_CODEX_BIN || !checkedCli() ? undefined : copy?.path());
44
44
  const system = () => resolveCodexBinary(env());
45
45
  const onMachine = () => findBinary(system(), env());
46
- const cli = new CodexCli(bin, timeoutMs, envOf, new TurnRegistry(join(workDir, 'codex')), new CodexPlugins(bin, envOf));
46
+ const cli = new CodexCli(bin, timeoutMs, envOf, new TurnRegistry(join(workDir, 'codex')), new CodexPlugins(bin, envOf, log));
47
47
  const usage = new CodexUsage({
48
48
  timeoutMs,
49
49
  sessions: (home) => cli.sessions(home),
50
50
  refresh: (home) => appServer(bin(), [], workDir, envOf(home), [['account/read', { refreshToken: true }]]),
51
51
  });
52
52
  return {
53
- cli: cliCopy(copy, { checkedCli }, version, onMachine, () => !!env().EVEN_KEEL_CODEX_BIN, 175 * 1_000_000),
53
+ cli: cliCopy(copy, { checkedCli }, version, onMachine, () => !!env().EVEN_KEEL_CODEX_BIN, 180 * 1_000_000),
54
54
  mode: SESSION_MODE,
55
55
  // GPT-5.6 and later keep a cache 30 minutes at least; the rollout does not say.
56
56
  warmMs: () => warmCacheMs(CODEX_TTL),
@@ -1,3 +1,4 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { existsSync } from 'node:fs';
2
3
  import { readFile } from 'node:fs/promises';
3
4
  import { dirname, join } from 'node:path';
@@ -74,20 +75,29 @@ export function untrustedHooks(answer, id, keys) {
74
75
  return each === 'trusted' ? [] : [{ key, status: each }];
75
76
  });
76
77
  }
78
+ /** A folder in the log: its path holds the user's home and its name an account, so only a short hash of the path. */
79
+ function folderTag(home) {
80
+ return createHash('sha256').update(home.dir).digest('hex').slice(0, 8);
81
+ }
77
82
  /**
78
83
  * The project's plugins in the Codex folders: a plugin goes into a folder on the first turn there, the hashes of its
79
- * hooks are asked once per folder and kept while the service runs — an install never changes. Before they are kept,
84
+ * hooks are asked once per folder and kept while the service runs — an install never changes. The log gets one line
85
+ * per folder and plugin in a service run, `installed into` or `found in the cache of`; later turns add none. Before they are kept,
80
86
  * `hooks/list` is asked again with the turn's flags: a hook Codex does not trust there fails the launch, so a change of
81
87
  * the hash format cannot turn the hooks off without a word.
82
88
  */
83
89
  export class CodexPlugins {
84
90
  bin;
85
91
  envOf;
92
+ log;
93
+ call;
86
94
  hooks = new Map();
87
95
  queues = new Map();
88
- constructor(bin, envOf) {
96
+ constructor(bin, envOf, log = () => { }, call = appServer) {
89
97
  this.bin = bin;
90
98
  this.envOf = envOf;
99
+ this.log = log;
100
+ this.call = call;
91
101
  }
92
102
  /** The `-c` flags of a turn; one folder is prepared by one call at a time, since installs write its `config.toml`. */
93
103
  async args(home, cwd, plugins) {
@@ -116,19 +126,24 @@ export class CodexPlugins {
116
126
  async install(home, cwd, plugin) {
117
127
  const id = pluginId(plugin);
118
128
  const env = this.envOf(home);
129
+ const folder = folderTag(home);
119
130
  if (!existsSync(join(home.dir, 'plugins', 'cache', plugin.marketplace, plugin.name))) {
120
- await appServer(this.bin(), [], cwd, env, [
131
+ const started = Date.now();
132
+ await this.call(this.bin(), [], cwd, env, [
121
133
  ['plugin/install', { pluginName: plugin.name, marketplacePath: plugin.marketplaceFile }],
122
134
  ['config/value/write', { keyPath: `plugins.${id}.enabled`, value: false, mergeStrategy: 'replace' }],
123
135
  ]);
136
+ this.log(`codex plugins: ${id} installed into folder ${folder} in ${Math.round((Date.now() - started) / 100) / 10} s`);
124
137
  }
125
- const [list] = await appServer(this.bin(), ['-c', `plugins.${id}.enabled=true`], cwd, env, [['hooks/list', {}]]);
138
+ else
139
+ this.log(`codex plugins: ${id} found in the cache of folder ${folder}`);
140
+ const [list] = await this.call(this.bin(), ['-c', `plugins.${id}.enabled=true`], cwd, env, [['hooks/list', {}]]);
126
141
  const hooks = pluginHooks(list, id);
127
142
  const keys = Object.keys(hooks);
128
143
  if (keys.length === 0)
129
144
  return hooks;
130
145
  const configured = configPlugins(await readFile(join(home.dir, 'config.toml'), 'utf8').catch(() => ''));
131
- const [check] = await appServer(this.bin(), pluginArgs([plugin], hooks, configured), cwd, env, [['hooks/list', {}]]);
146
+ const [check] = await this.call(this.bin(), pluginArgs([plugin], hooks, configured), cwd, env, [['hooks/list', {}]]);
132
147
  const untrusted = untrustedHooks(check, id, keys);
133
148
  if (untrusted.length > 0)
134
149
  throw new UntrustedHooks(plugin, untrusted);
@@ -1,2 +1,2 @@
1
1
  /** Raised after the live run of each release (`docs/releases.md`). */
2
- export const CODEX_CHECKED = '0.166.0';
2
+ export const CODEX_CHECKED = '0.167.0';
@@ -18,7 +18,7 @@ import { foldEvents } from './transcript.js';
18
18
  import { withTurnError } from './errors.js';
19
19
  const HISTORY_FEED = 5_000;
20
20
  /** The version the README's "Before you run it" names; raised after the live run of each release (`docs/releases.md`). */
21
- const CHECKED = '1.0.105';
21
+ const CHECKED = '1.0.106';
22
22
  /**
23
23
  * GitHub Copilot CLI through `copilot -p … --output-format json`: a turn is a detached process, as Codex's is; a session
24
24
  * lives between turns in Even Keel's registry and the account folder's `session-state/<id>/events.jsonl`
@@ -92,6 +92,7 @@ export const copilot = {
92
92
  feedFile: async (home, sessionId) => eventsFile(home.dir, sessionId),
93
93
  transcripts: async (home) => [...new Set([...(await sessionIds(home.dir)), ...(await registry.list(home.key)).map((entry) => entry.sessionId)])],
94
94
  authStatus: (home) => cli.authStatus(home),
95
+ terminalLogin: (home) => cli.terminalLogin(home),
95
96
  login: (home) => cli.login(home),
96
97
  logout: (home) => cli.logout(home),
97
98
  installed: () => findBinary(bin(), env()),
@@ -10,7 +10,8 @@ import { isAlive, killTree } from '../agent/process.js';
10
10
  import { polledProcessStartedAt, processBelongsToTurn, processStartedAt, turnStartedAt } from '../codex/process.js';
11
11
  import { entryOf, lastEvent, outputTail } from '../codex/turns.js';
12
12
  import { fail, notice, NoticeError } from '../notice/notice.js';
13
- import { eventsFile, parseAuth, tokenFile, tokenOf, trustFolder } from './home.js';
13
+ import { eventsFile, loginCommand, parseAuth, tokenFile, tokenOf, trustFolder } from './home.js';
14
+ import { machineSignedIn } from './machine.js';
14
15
  import { COPILOT } from './name.js';
15
16
  import { pathFolders } from '../paths.js';
16
17
  import { protectionRules } from '../sessions/protection.js';
@@ -86,7 +87,7 @@ export function turnArgs(start, prompt, place, session) {
86
87
  '--no-auto-update',
87
88
  '--no-ask-user',
88
89
  `--${SESSION_MODE}`,
89
- ...(start.protection === undefined ? [] : protectionRules(start.protection, place.remotes).copilot.flatMap(rule => ['--deny-tool', rule])),
90
+ ...(start.protection === undefined ? [] : protectionRules(start.protection, place.remotes, start.mainBranch).copilot.flatMap(rule => ['--deny-tool', rule])),
90
91
  ...(session.resume ? [`--resume=${session.id}`] : ['--session-id', session.id, '--name', name]),
91
92
  ...(model === null ? [] : ['--model', model]),
92
93
  ...place.dirs.flatMap((dir) => ['--add-dir', dir]),
@@ -213,11 +214,15 @@ export class CopilotCli {
213
214
  return (await run(binary, ['--version'], { env, timeout: this.timeoutMs, windowsHide: true })).stdout;
214
215
  }
215
216
  async authStatus(home) {
216
- return parseAuth(tokenOf(home.dir));
217
+ const token = tokenOf(home.dir);
218
+ return parseAuth(token, token === null ? await machineSignedIn(this.bin(), this.envOf(home), home.dir, this.timeoutMs) : null);
219
+ }
220
+ terminalLogin(home) {
221
+ return tokenOf(home.dir) === null ? loginCommand(this.bin(), home.dir) : undefined;
217
222
  }
218
223
  /**
219
- * The CLI's own device sign-in. Its token goes to the OS credential store, shared by every folder, so the page adds
220
- * Copilot accounts by token instead; this is only for the CLI's contract.
224
+ * The CLI's own device sign-in. Without a credential store its plaintext fallback needs a terminal, so the page
225
+ * gives a signed-out folder `terminalLogin`; this piped login is only for the CLI's contract.
221
226
  */
222
227
  login(home) {
223
228
  return spawn(this.bin(), ['login'], { env: this.envOf(home), windowsHide: true, stdio: 'pipe' });
@@ -7,7 +7,7 @@ import { pathsOf, samePath } from '../paths.js';
7
7
  * `mcp-config.json` and the transcripts `session-state/<id>/events.jsonl` there. The sign-in is a GitHub token Even
8
8
  * Keel keeps in the folder's `even-keel.json` and hands to the CLI as `COPILOT_GITHUB_TOKEN`; the CLI's own sign-in
9
9
  * (`copilot login`) goes to the OS credential store, shared by every folder, so it is the account of a folder without
10
- * a token.
10
+ * a token. Without a store it is plaintext in the `config.json` of the `COPILOT_HOME` it ran with, that folder's only.
11
11
  */
12
12
  const TOKEN_FILE = 'even-keel.json';
13
13
  const CONFIG_FILE = 'config.json';
@@ -46,11 +46,25 @@ export function tokenFile(dir) {
46
46
  }
47
47
  /**
48
48
  * A folder with a token is signed in by it, an account of a key like an API one (its token is checked and refused the
49
- * same way); one without runs on the CLI's own sign-in. Its source is probed separately for usage, while its status
50
- * counts as signed in with the method `none` and no identity.
49
+ * same way); one without runs on the CLI's own sign-in, with the method `none` and no identity. `machine` is what the
50
+ * CLI said of that sign-in in the folder (`machineSignedIn`): an unknown answer stays unknown and does not block a launch.
51
51
  */
52
- export function parseAuth(token) {
53
- return { loggedIn: true, authMethod: token === null ? 'none' : 'api_key', email: null, orgName: null, subscriptionType: null };
52
+ export function parseAuth(token, machine) {
53
+ const loggedIn = token !== null ? true : machine;
54
+ return { loggedIn, authMethod: token === null ? 'none' : 'api_key', email: null, orgName: null, subscriptionType: null };
55
+ }
56
+ /**
57
+ * The CLI's own sign-in into the folder, to run in a terminal of this machine: without a keyring (Linux) the CLI keeps
58
+ * the token as plaintext in `COPILOT_HOME`'s `config.json` and asks about it only in a terminal, so the page cannot run
59
+ * it (EKR-73). `bin` is the binary the sessions run on; a child cmd or sh subshell removes inherited tokens and keeps
60
+ * the original terminal's environment intact even when login fails.
61
+ */
62
+ export function loginCommand(bin, dir, platform = process.platform) {
63
+ if (platform === 'win32') {
64
+ return `cmd /d /v:off /c ${TOKEN_KEYS.map((key) => `set "${key}="`).join(' ^& ')} ^& set "COPILOT_HOME=${dir}" ^& "${bin}" login`;
65
+ }
66
+ const quote = (text) => `'${text.replaceAll("'", "'\\''")}'`;
67
+ return `(unset ${TOKEN_KEYS.join(' ')}; COPILOT_HOME=${quote(dir)} ${quote(bin)} login)`;
54
68
  }
55
69
  /**
56
70
  * Adds `folder` to `trustedFolders` of the account folder's `config.json`, the rest of the file kept (BTN-645).
@@ -1,11 +1,23 @@
1
1
  import { runWithInput } from '../agent/oneturn.js';
2
+ /**
3
+ * Whether the CLI, run with a folder's environment, sees a sign-in by any source; `null` — it could not be asked or its
4
+ * answer was unreadable. A plaintext sign-in in another folder's `config.json` is not seen (EKR-73).
5
+ */
6
+ export async function machineSignedIn(bin, env, cwd, timeoutMs) {
7
+ try {
8
+ const status = await authStatus(bin, { cwd, env, timeoutMs });
9
+ return typeof status?.isAuthenticated === 'boolean' ? status.isAuthenticated : null;
10
+ }
11
+ catch {
12
+ // CLI failures may contain credentials; neither the output nor the exception leaves this call.
13
+ return null;
14
+ }
15
+ }
2
16
  /** Only a source confirmed by the CLI may supply a machine allowance; never substitute another account's token. */
3
17
  export async function machineToken(bin, env, cwd, timeoutMs) {
4
18
  const options = { cwd, env, timeoutMs };
5
- const request = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'auth.getStatus', params: {} });
6
19
  try {
7
- const output = await runWithInput(bin, ['--headless', '--stdio', '--no-auto-update'], `Content-Length: ${Buffer.byteLength(request)}\r\n\r\n${request}`, options);
8
- const status = statusOf(output);
20
+ const status = await authStatus(bin, options);
9
21
  if (status?.isAuthenticated !== true || status.authType !== 'gh-cli' ||
10
22
  !['github.com', 'https://github.com'].includes(String(status.host)) ||
11
23
  typeof status.login !== 'string' || !/^[a-z\d][a-z\d-]{0,38}$/i.test(status.login))
@@ -18,6 +30,11 @@ export async function machineToken(bin, env, cwd, timeoutMs) {
18
30
  return null;
19
31
  }
20
32
  }
33
+ async function authStatus(bin, options) {
34
+ const request = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'auth.getStatus', params: {} });
35
+ const output = await runWithInput(bin, ['--headless', '--stdio', '--no-auto-update'], `Content-Length: ${Buffer.byteLength(request)}\r\n\r\n${request}`, options);
36
+ return statusOf(output);
37
+ }
21
38
  function statusOf(output) {
22
39
  let frames = Buffer.from(output);
23
40
  while (frames.length > 0) {
@@ -2,7 +2,7 @@ import { lstatSync, statSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { fail } from '../notice/notice.js';
4
4
  import { findBinary } from '../paths.js';
5
- import { expandHome } from '../projects/folder.js';
5
+ import { expandFolder } from '../projects/folder.js';
6
6
  import { windowsStart } from '../updates/control.js';
7
7
  import { runGit } from './run.js';
8
8
  const FIRST_COMMIT = 'Initial commit';
@@ -138,7 +138,7 @@ export class GitSetup {
138
138
  await this.check();
139
139
  }
140
140
  async init(path, branch) {
141
- await initRepository(this.git, expandHome(path, this.home), branch);
141
+ await initRepository(this.git, expandFolder(path, this.home), branch);
142
142
  }
143
143
  }
144
144
  export const gitSetup = new GitSetup();
@@ -9,6 +9,7 @@ export const gitlab = {
9
9
  help: 'https://docs.gitlab.com/user/profile/personal_access_tokens/',
10
10
  mcpServer: 'gitlab',
11
11
  mcpKeys: { GITLAB_PERSONAL_ACCESS_TOKEN: GITLAB_TOKEN },
12
+ logsTime: true,
12
13
  profileName: (_values, account) => account?.name ?? 'GitLab',
13
14
  account: async (values, timeoutMs) => (await import('./profile.js')).gitlabAccount(values, timeoutMs),
14
15
  projects: async (values, query, timeoutMs) => (await import('./profile.js')).gitlabProjects(values, query, timeoutMs),
@@ -1,6 +1,6 @@
1
1
  import { Skipped } from '../github/trust.js';
2
2
  import { resolveLabels } from '../tracker/labels.js';
3
- import { parseTaskId } from '../tracker/model.js';
3
+ import { entryMinutes, parseTaskId } from '../tracker/model.js';
4
4
  import { TrackerNotFound } from '../tracker/source.js';
5
5
  import { GitlabApi, GitlabHttpError } from './api.js';
6
6
  import { GitlabBatch, limitedMap } from './batch.js';
@@ -241,6 +241,18 @@ export async function connectGitlab(settings, timeoutMs, fetchImpl = fetch, log
241
241
  async isPublic(project) {
242
242
  return (await api.rest(projectBase(pathOf(project)))).visibility === 'public';
243
243
  },
244
+ // A 403: the token's user may not log time in the project (below Reporter, or time tracking off by its features).
245
+ async logTime(id, entry) {
246
+ try {
247
+ await api.rest(`${addressOf(id).base}/add_spent_time`, 'POST', { duration: `${entryMinutes(entry.hours)}m`, summary: entry.summary });
248
+ return true;
249
+ }
250
+ catch (error) {
251
+ if (error instanceof GitlabHttpError && error.status === 403)
252
+ return false;
253
+ throw error;
254
+ }
255
+ },
244
256
  close: async () => { },
245
257
  };
246
258
  }
@@ -8,6 +8,7 @@ export const jira = {
8
8
  help: 'https://id.atlassian.com/manage-profile/security/api-tokens',
9
9
  mcpServer: 'jira',
10
10
  moves: true,
11
+ logsTime: true,
11
12
  // Atlassian's MCP server takes an API token only as a Basic header of the e-mail and the token.
12
13
  mcpValues: {
13
14
  JIRA_BASIC_AUTH: {