sideby 0.38.1 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +6 -0
- package/dist/src/cli/commands.js +88 -0
- package/dist/src/cli/json-schemas.js +35 -0
- package/dist/src/cli/main.js +29 -0
- package/dist/src/core/cli-commands.js +14 -2
- package/dist/src/core/config.d.ts +13 -0
- package/dist/src/core/config.js +18 -0
- package/dist/src/core/launch.d.ts +5 -0
- package/dist/src/core/launch.js +11 -1
- package/dist/src/core/progress-state.d.ts +80 -0
- package/dist/src/core/progress-state.js +216 -0
- package/dist/src/core/progress.d.ts +36 -0
- package/dist/src/core/progress.js +77 -0
- package/dist/src/core/prompt-origin.d.ts +40 -0
- package/dist/src/core/prompt-origin.js +98 -0
- package/dist/src/core/search-catalog.js +25 -0
- package/dist/src/core/unattended-attended.d.ts +109 -0
- package/dist/src/core/unattended-attended.js +337 -0
- package/dist/src/core/unattended.d.ts +10 -2
- package/dist/src/core/unattended.js +11 -2
- package/dist/src/handoff/hook.js +19 -4
- package/dist/src/network/hook.js +4 -8
- package/dist/src/panel/handler.d.ts +3 -0
- package/dist/src/panel/handler.js +15 -0
- package/dist/src/panel/i18n.d.ts +18 -0
- package/dist/src/panel/i18n.js +36 -0
- package/dist/src/panel/page-script.js +67 -2
- package/dist/src/panel/page-styles.js +14 -0
- package/dist/src/progress/hook.d.ts +50 -0
- package/dist/src/progress/hook.js +251 -0
- package/dist/src/runtime.d.ts +9 -0
- package/dist/src/runtime.js +45 -2
- package/dist/src/unattended/hook.d.ts +5 -0
- package/dist/src/unattended/hook.js +103 -9
- package/package.json +1 -1
- package/schemas/config.json +13 -0
- package/schemas/progress.json +137 -0
- package/schemas/unattended.json +38 -0
- package/skills/sideby/SKILL.md +3 -1
- package/skills/sideby/references/progress.md +25 -0
- package/skills/sideby/references/unattended.md +9 -1
package/dist/src/panel/i18n.js
CHANGED
|
@@ -1716,6 +1716,10 @@ const en = {
|
|
|
1716
1716
|
'ua.overnight': 'next day',
|
|
1717
1717
|
'ua.allDay': 'all day',
|
|
1718
1718
|
'ua.remove': 'Remove {slot}',
|
|
1719
|
+
'ua.here': 'Asking you as usual',
|
|
1720
|
+
'ua.hereNote': 'You typed in these sessions in the last 30 minutes, so they ask you as usual. Each message you send gives that session another 30 minutes. Every other session stays unattended.',
|
|
1721
|
+
'ua.hereHint': 'Back early? Type in a session and it asks you as usual for 30 minutes. The others stay unattended.',
|
|
1722
|
+
'ua.hereSession': 'Session {id}',
|
|
1719
1723
|
'ua.pending': 'Waiting for you',
|
|
1720
1724
|
'ua.pendingNote': 'Questions sessions did not ask you, steps that needed your OK, and steps they skipped. Nothing here was done.',
|
|
1721
1725
|
'ua.pendingEmpty': 'Nothing is waiting for you.',
|
|
@@ -1749,6 +1753,20 @@ const en = {
|
|
|
1749
1753
|
'ua.problem': 'sideby cannot keep its state: {msg}',
|
|
1750
1754
|
'ua.unreadable': 'sideby could not read Unattended Mode. Refresh to try again.',
|
|
1751
1755
|
'ai.ask.unattended': 'Run unattended tonight, until 8 tomorrow morning.',
|
|
1756
|
+
'ai.ask.progress': 'While background tasks run, tell me every 10 minutes what my sessions are waiting for.',
|
|
1757
|
+
'pr.title': 'Progress updates',
|
|
1758
|
+
'pr.hint': 'When a Claude session waits on background work (subagents, long commands), it tells you every few minutes what it is waiting for and for how long.',
|
|
1759
|
+
'pr.switch': 'Report progress while waiting',
|
|
1760
|
+
'pr.every': 'How often',
|
|
1761
|
+
'pr.minutes': '{n} min',
|
|
1762
|
+
'pr.everyLong': 'Every {n} minutes',
|
|
1763
|
+
'pr.cost': 'Each update is one model turn, which reads the whole conversation, so it uses quota.',
|
|
1764
|
+
'pr.scope': 'Claude sessions you start after turning it on get it. Turning it off stops it in open sessions too. No updates while you are away (Unattended Mode).',
|
|
1765
|
+
'pr.codex': 'Codex is not covered: it has no way to wake a waiting session.',
|
|
1766
|
+
'pr.onToast': 'Progress updates on, every {n} minutes. Claude sessions you start from now on get them.',
|
|
1767
|
+
'pr.everyToast': 'Progress updates now every {n} minutes.',
|
|
1768
|
+
'pr.offToast': 'Progress updates off.',
|
|
1769
|
+
'pr.failed': 'Could not change progress updates: {msg}. It is back as it was; try again, or run sideby progress in a terminal.',
|
|
1752
1770
|
};
|
|
1753
1771
|
const zh = {
|
|
1754
1772
|
'top.tagline': '所有 AI 编程账号,并排运行。',
|
|
@@ -3465,6 +3483,10 @@ const zh = {
|
|
|
3465
3483
|
'ua.overnight': '次日',
|
|
3466
3484
|
'ua.allDay': '全天',
|
|
3467
3485
|
'ua.remove': '删除{slot}',
|
|
3486
|
+
'ua.here': '照常问你的会话',
|
|
3487
|
+
'ua.hereNote': '你 30 分钟内在这些会话里打过字,它们照常问你;每发一条消息,那个会话再算 30 分钟。其他会话仍然无人值守。',
|
|
3488
|
+
'ua.hereHint': '提前回来了?在哪个会话里打字,那个会话 30 分钟内照常问你,其他会话不受影响。',
|
|
3489
|
+
'ua.hereSession': '会话 {id}',
|
|
3468
3490
|
'ua.pending': '待你决定',
|
|
3469
3491
|
'ua.pendingNote': '会话没问你的问题、要你确认的操作和跳过的操作。这里的事都还没做。',
|
|
3470
3492
|
'ua.pendingEmpty': '没有待你决定的事',
|
|
@@ -3498,5 +3520,19 @@ const zh = {
|
|
|
3498
3520
|
'ua.problem': 'sideby 没法保存状态:{msg}',
|
|
3499
3521
|
'ua.unreadable': 'sideby 读不到无人值守的状态。刷新再试一次。',
|
|
3500
3522
|
'ai.ask.unattended': '今晚无人值守,到明早 8 点',
|
|
3523
|
+
'ai.ask.progress': '后台任务跑着时,每 10 分钟告诉我会话在等什么。',
|
|
3524
|
+
'pr.title': '进度提醒',
|
|
3525
|
+
'pr.hint': 'Claude 会话等后台任务(子任务、长命令)时,每隔几分钟告诉你在等什么、等了多久。',
|
|
3526
|
+
'pr.switch': '等待时报进度',
|
|
3527
|
+
'pr.every': '多久一次',
|
|
3528
|
+
'pr.minutes': '{n} 分钟',
|
|
3529
|
+
'pr.everyLong': '每 {n} 分钟',
|
|
3530
|
+
'pr.cost': '每次提醒是一轮模型调用,会读一遍整个对话,会用额度。',
|
|
3531
|
+
'pr.scope': '打开后启动的 Claude 会话才有;关掉对已经开着的会话也生效。无人值守时不提醒。',
|
|
3532
|
+
'pr.codex': 'Codex 不支持:它没有办法叫醒等待中的会话。',
|
|
3533
|
+
'pr.onToast': '已打开进度提醒,每 {n} 分钟一次。之后启动的 Claude 会话会有。',
|
|
3534
|
+
'pr.everyToast': '进度提醒改为每 {n} 分钟一次。',
|
|
3535
|
+
'pr.offToast': '已关闭进度提醒。',
|
|
3536
|
+
'pr.failed': '没能改进度提醒:{msg}。已恢复原样;可以再试一次,或在终端运行 sideby progress。',
|
|
3501
3537
|
};
|
|
3502
3538
|
export const MESSAGES = { en, zh };
|
|
@@ -6754,6 +6754,28 @@ const MAIN = String.raw `
|
|
|
6754
6754
|
h('p', { class: 'muted small' }, t('ua.pendingNote'))), box]
|
|
6755
6755
|
}
|
|
6756
6756
|
|
|
6757
|
+
// ---------- Attended Sessions (ADR-0075) ----------
|
|
6758
|
+
// While it is on: the sessions someone typed into within the last 30 minutes, which ask as usual, each with until
|
|
6759
|
+
// when; with none, one line that says typing in a session is all it takes. Only shown: nothing here sets it.
|
|
6760
|
+
function uaHereBlock(st, p) {
|
|
6761
|
+
if (p.state !== 'on' || st.problem) return []
|
|
6762
|
+
const now = Date.now()
|
|
6763
|
+
const list = (st.attended || []).filter((x) => Date.parse(x.until) > now)
|
|
6764
|
+
if (!list.length) return [h('p', { class: 'note ua-here-hint', 'data-key': 'ua-here-hint', 'data-ua': 'here-hint' }, icon('messages'), t('ua.hereHint'))]
|
|
6765
|
+
return [h('div', { class: 'ua-here', 'data-key': 'ua-here', 'data-ua': 'here', 'data-patch': '' },
|
|
6766
|
+
h('div', { class: 'page-sec-head' },
|
|
6767
|
+
h('h3', { class: 'page-sec' }, t('ua.here'), ' ', h('span', { class: 'tab-count' }, String(list.length))),
|
|
6768
|
+
h('p', { class: 'muted small' }, t('ua.hereNote'))),
|
|
6769
|
+
h('ul', { class: 'ua-here-list', 'data-patch': '' }, list.map((x) => {
|
|
6770
|
+
const folder = x.cwd ? x.cwd.split(/[\\/]/).filter(Boolean).pop() : null
|
|
6771
|
+
return h('li', { class: 'ua-here-row', 'data-key': 'ua-here-' + x.sessionId, 'data-ua': 'here-' + x.sessionId, 'data-patch': '', 'data-tip': t('ua.hereSession', { id: x.sessionId.slice(0, 8) }) },
|
|
6772
|
+
badge(x.family, 'sm'),
|
|
6773
|
+
h('b', null, x.account ? accountLabel(x.account) : family(x.family).title),
|
|
6774
|
+
folder ? h('code', { class: 'ua-cwd' }, folder) : null,
|
|
6775
|
+
h('span', { class: 'ua-when muted' }, uaAt('until', Date.parse(x.until))))
|
|
6776
|
+
})))]
|
|
6777
|
+
}
|
|
6778
|
+
|
|
6757
6779
|
// ---------- the page ----------
|
|
6758
6780
|
function uaCoverage(st) {
|
|
6759
6781
|
const have = new Set(S.state.accounts.map((a) => a.family))
|
|
@@ -6836,6 +6858,7 @@ const MAIN = String.raw `
|
|
|
6836
6858
|
main))
|
|
6837
6859
|
if (ua.choosing && p.state !== 'on') kids.push(uaChooser(st))
|
|
6838
6860
|
if (!st.configured || ua.firstUse) kids.push(h('p', { class: 'note ua-first', 'data-key': 'ua-first', 'data-ua': 'first' }, icon('clock'), t('ua.firstUse')))
|
|
6861
|
+
kids.push(...uaHereBlock(st, p))
|
|
6839
6862
|
kids.push(...uaScheduleBlock())
|
|
6840
6863
|
kids.push(...uaPendingBlock(st))
|
|
6841
6864
|
kids.push(...uaCoverage(st))
|
|
@@ -6949,6 +6972,45 @@ const MAIN = String.raw `
|
|
|
6949
6972
|
} catch (e) { toast(t('quota.checkFailed', { msg: e.message }), { kind: 'fail' }) }
|
|
6950
6973
|
load({ silent: true })
|
|
6951
6974
|
}
|
|
6975
|
+
// Progress Reminders (spec §3.42): on with every minutes, or off with null. The switch moves at once (the state
|
|
6976
|
+
// here first), so the interval row grows in or folds away without waiting for the server; a failure puts it back.
|
|
6977
|
+
async function setProgressEvery(every) {
|
|
6978
|
+
const p = S.state && S.state.progress
|
|
6979
|
+
if (!p) return
|
|
6980
|
+
const was = { on: p.on, every: p.every }
|
|
6981
|
+
S.state.progress = Object.assign({}, p, every === null ? { on: false, every: undefined } : { on: true, every })
|
|
6982
|
+
refreshSettings()
|
|
6983
|
+
try {
|
|
6984
|
+
await api('/api/progress', { every })
|
|
6985
|
+
toast(every === null ? t('pr.offToast') : was.on ? t('pr.everyToast', { n: every }) : t('pr.onToast', { n: every }))
|
|
6986
|
+
} catch (e) {
|
|
6987
|
+
S.state.progress = Object.assign({}, S.state.progress, was)
|
|
6988
|
+
refreshSettings()
|
|
6989
|
+
toast(t('pr.failed', { msg: e.message }), { kind: 'fail' })
|
|
6990
|
+
}
|
|
6991
|
+
load({ silent: true })
|
|
6992
|
+
}
|
|
6993
|
+
// The section's rows: the switch, the interval (it grows in under the switch while on), and three short notes.
|
|
6994
|
+
function progressItems() {
|
|
6995
|
+
const p = S.state.progress
|
|
6996
|
+
const every = p.every || p.defaultEvery
|
|
6997
|
+
const label = t('pr.switch')
|
|
6998
|
+
const seg = (name, opts, cur, pick) => h('div', { class: 'seg', role: 'group', 'aria-label': name, 'data-patch': '' }, opts.map(([v, text]) =>
|
|
6999
|
+
h('button', { class: 'seg-btn', type: 'button', 'aria-pressed': String(v === cur), onclick: () => { if (v !== cur) pick(v) } }, text)))
|
|
7000
|
+
const out = [fm('progress', h('div', { class: 'set-row', 'data-patch': '' },
|
|
7001
|
+
h('span', { class: 'set-label' }, label),
|
|
7002
|
+
BOOT.readOnly ? h('span', { class: 'chip chip-sm' + (p.on ? ' chip-ok' : '') }, p.on ? t('pr.everyLong', { n: every }) : t('ah.off'))
|
|
7003
|
+
: seg(label, [[true, t('ah.on')], [false, t('ah.off')]], p.on, (v) => setProgressEvery(v ? every : null))))]
|
|
7004
|
+
if (!BOOT.readOnly)
|
|
7005
|
+
out.push(h('div', { class: 'reveal' + (p.on ? ' is-open' : ''), 'data-patch': '', 'data-key': 'pr-every', inert: p.on ? undefined : true },
|
|
7006
|
+
h('div', { class: 'reveal-in', 'data-patch': '' }, h('div', { class: 'set-row pr-every', 'data-patch': '' },
|
|
7007
|
+
h('span', { class: 'set-label' }, t('pr.every')),
|
|
7008
|
+
seg(t('pr.every'), p.choices.map((n) => [n, t('pr.minutes', { n })]), p.on ? every : null, (n) => setProgressEvery(n))))))
|
|
7009
|
+
out.push(h('ul', { class: 'pr-notes' }, h('li', null, t('pr.cost')), h('li', null, t('pr.scope')), h('li', null, t('pr.codex'))))
|
|
7010
|
+
if (!BOOT.readOnly && !askBridged(BOOT, window))
|
|
7011
|
+
out.push(h('p', { class: 'small' }, h('button', { class: 'link-btn small', type: 'button', 'data-key': 'pr-ask', onclick: () => openAsk({ text: t('ai.ask.progress') }) }, t('adv.ask'))))
|
|
7012
|
+
return out
|
|
7013
|
+
}
|
|
6952
7014
|
function famTitleOf(fam) { const f = S.state && S.state.families.find((x) => x.id === fam); return f ? f.title : fam }
|
|
6953
7015
|
// ---------- settings ----------
|
|
6954
7016
|
// One header button holds what is set once and rarely changed: language, theme, Remote Control and Auto Handoff.
|
|
@@ -6965,6 +7027,7 @@ const MAIN = String.raw `
|
|
|
6965
7027
|
if (S.state && ahState()) out.push('ah')
|
|
6966
7028
|
if (S.state && (S.state.quotaChecks || []).length) out.push('checks')
|
|
6967
7029
|
if (S.state && S.state.network) out.push('net')
|
|
7030
|
+
if (S.state && S.state.progress) out.push('progress')
|
|
6968
7031
|
return out
|
|
6969
7032
|
}
|
|
6970
7033
|
function renderSettingsButton() {
|
|
@@ -7012,7 +7075,8 @@ const MAIN = String.raw `
|
|
|
7012
7075
|
function aiLink(leave) {
|
|
7013
7076
|
return setLink(leave, t('ai.title'), t(skillInstalled() ? 'ai.installed' : 'ai.notInstalled'), skillInstalled() ? 'chip-ok' : '', () => openAsk(), true)
|
|
7014
7077
|
}
|
|
7015
|
-
// The dialog's sections, in order: General, Menu bar, Accounts, Quota checks, Auto Handoff,
|
|
7078
|
+
// The dialog's sections, in order: General, Menu bar, Accounts, Quota checks, Auto Handoff, Progress updates,
|
|
7079
|
+
// Network check, Let AI help. Each is
|
|
7016
7080
|
// { id, title, items, foot }: foot is the one line that explains the whole section.
|
|
7017
7081
|
function settingsGroups(leave) {
|
|
7018
7082
|
const secs = settingsSections()
|
|
@@ -7077,6 +7141,7 @@ const MAIN = String.raw `
|
|
|
7077
7141
|
{ id: 'accounts', title: t('set.g.accounts'), items: acct },
|
|
7078
7142
|
{ id: 'quota', title: t('set.g.quota'), items: checks, foot: t('set.quotaChecksHint', { n: every }) },
|
|
7079
7143
|
{ id: 'handoff', title: t('ah.button'), items: [ahLink(leave)].filter(Boolean), foot: t('set.ahHint') },
|
|
7144
|
+
{ id: 'progress', title: t('pr.title'), items: secs.includes('progress') ? progressItems() : [], foot: t('pr.hint') },
|
|
7080
7145
|
{ id: 'network', title: t('net.title'), items: netItems, foot: t('net.hint') },
|
|
7081
7146
|
{ id: 'ai', title: t('set.g.ai'), items: ai, foot: t('set.aiHint') },
|
|
7082
7147
|
].filter((g) => g.items.length)
|
|
@@ -7777,7 +7842,7 @@ const MAIN = String.raw `
|
|
|
7777
7842
|
return Boolean(u && u.skillUpdate && u.skillUpdate.installed && u.skillUpdate.installed.length)
|
|
7778
7843
|
}
|
|
7779
7844
|
// Example phrases: a click puts one in the Let AI do it box (spec §3.28).
|
|
7780
|
-
const AI_ASKS = ['ai.ask.quota', 'ai.ask.reset', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.expired', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.advisor', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
|
|
7845
|
+
const AI_ASKS = ['ai.ask.quota', 'ai.ask.reset', 'ai.ask.pick', 'ai.ask.new', 'ai.ask.api', 'ai.ask.pin', 'ai.ask.hide', 'ai.ask.relogin', 'ai.ask.expired', 'ai.ask.fix', 'ai.ask.handoff', 'ai.ask.handoffRules', 'ai.ask.session', 'ai.ask.history', 'ai.ask.send', 'ai.ask.inbound', 'ai.ask.menubar', 'ai.ask.rc', 'ai.ask.advisor', 'ai.ask.network', 'ai.ask.unattended', 'ai.ask.progress', 'ai.ask.theme', 'ai.ask.find', 'ai.ask.commands', 'ai.ask.tool']
|
|
7781
7846
|
// Network Guard (spec §3.35): one dialog with the switch, the allowed countries and the newest result per address.
|
|
7782
7847
|
// Countries are never ticked for the user, the current one included: a wrong network would allow itself.
|
|
7783
7848
|
const NET_COMMON = ['US', 'JP', 'SG', 'GB', 'DE', 'FR', 'NL', 'CA', 'AU', 'KR', 'TW', 'HK']
|
|
@@ -977,6 +977,15 @@ ${UI_CSS}
|
|
|
977
977
|
.set-foot { margin: -8px 0 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
|
|
978
978
|
.set-dialog .set-hint { max-width: none; }
|
|
979
979
|
.set-dialog .set-link { margin: 0 -12px; width: calc(100% + 20px); }
|
|
980
|
+
/* Progress updates (spec §3.42): the interval grows in under the switch while it is on. Folded, it takes no room: the
|
|
981
|
+
group's gap above it is taken back and given inside instead. */
|
|
982
|
+
.set-group > .reveal[data-key=pr-every] { margin-top: -8px; }
|
|
983
|
+
.reveal[data-key=pr-every] > .reveal-in > .pr-every { padding-top: 8px; }
|
|
984
|
+
.pr-notes { margin: 4px 0 0; padding-left: 16px; display: grid; gap: 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
|
|
985
|
+
.pr-every .seg-btn { white-space: nowrap; }
|
|
986
|
+
:where(:root[data-width=phone]) .pr-every { flex-direction: column; align-items: flex-start; gap: 8px; }
|
|
987
|
+
:where(:root[data-width=phone]) .pr-every .seg { max-width: 100%; }
|
|
988
|
+
:where(:root[data-width=phone]) .pr-every .seg-btn { padding: 0 8px; }
|
|
980
989
|
:where(:root[data-width=narrow], :root[data-width=phone]) {
|
|
981
990
|
.set-dialog { grid-template-columns: minmax(0, 1fr); gap: 16px; min-height: 0; }
|
|
982
991
|
.set-nav { flex-direction: row; overflow-x: auto; padding: 0 0 8px; border-right: 0; border-bottom: 1px solid var(--border); }
|
|
@@ -1454,6 +1463,11 @@ input.ua-time::placeholder { color: var(--faint); }
|
|
|
1454
1463
|
.ua-item-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: flex-start; gap: 12px; }
|
|
1455
1464
|
.ua-cover { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
|
|
1456
1465
|
.ua-cover li::before { content: "·"; margin-right: 8px; color: var(--faint); }
|
|
1466
|
+
.ua-here-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
|
|
1467
|
+
.ua-here-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
|
|
1468
|
+
.ua-here-row:first-child { border-top: 0; }
|
|
1469
|
+
.ua-here-hint { gap: 8px; margin-top: 12px; }
|
|
1470
|
+
.ua-here-hint .ic { width: 15px; height: 15px; flex: none; }
|
|
1457
1471
|
:where(:root[data-width=narrow], :root[data-width=phone]) .ua-item { grid-template-columns: minmax(0, 1fr); }
|
|
1458
1472
|
:where(:root[data-width=narrow], :root[data-width=phone]) .ua-item-actions { grid-column: 1; grid-row: auto; }
|
|
1459
1473
|
:where(:root[data-width=phone]) .ua-del { margin-left: 0; }
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type Env = Record<string, string | undefined>;
|
|
2
|
+
/** How often a watch looks whether it is still wanted. */
|
|
3
|
+
export declare const CHECK_EVERY_MS = 60000;
|
|
4
|
+
/** A watch ends by itself after this long, under the five-hour `timeout` Claude Code gives the hook. */
|
|
5
|
+
export declare const WATCH_FOR_MS: number;
|
|
6
|
+
export interface ProgressHookDeps {
|
|
7
|
+
now?: () => Date;
|
|
8
|
+
sleep?: (ms: number) => Promise<void>;
|
|
9
|
+
/** Whether the Host that started the hook is gone; by default, whether this process's parent changed. */
|
|
10
|
+
parentGone?: () => boolean;
|
|
11
|
+
/** This watch's id; random by default. */
|
|
12
|
+
id?: string;
|
|
13
|
+
checkEveryMs?: number;
|
|
14
|
+
/** How long a write waits for the session's lock (for tests). */
|
|
15
|
+
lockWait?: {
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
pollMs: number;
|
|
18
|
+
};
|
|
19
|
+
/** Runs between the last check of the watch record and marking it woken, inside the lock (for tests). */
|
|
20
|
+
beforeWake?: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
type Input = AsyncIterable<string | Uint8Array> | string;
|
|
23
|
+
/** The background tasks as the reminder names them: kind and description, never the command. */
|
|
24
|
+
export declare function taskList(tasks: readonly unknown[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* What the model is woken with. It starts with `PROGRESS_MARK`, names the clock time the wait began (so a reminder
|
|
27
|
+
* Network Guard held and delivered late still makes sense), and asks for one or two sentences and the end of the turn.
|
|
28
|
+
*/
|
|
29
|
+
export declare function reminderMessage(o: {
|
|
30
|
+
tasks: readonly unknown[];
|
|
31
|
+
since: string;
|
|
32
|
+
now: Date;
|
|
33
|
+
every: number;
|
|
34
|
+
}): string;
|
|
35
|
+
/**
|
|
36
|
+
* The `Stop` watch (spec §3.42). Replaces the session's earlier watch first, then, while background work runs and the
|
|
37
|
+
* setting is on, wakes the session every `progress.every` minutes with a reminder (exit 2). Ends with exit 0 when a
|
|
38
|
+
* later `Stop` took over, the session's latest prompt is not the one this `Stop` ended, the parent is gone, the
|
|
39
|
+
* setting is off, Auto Handoff is handing over, or time runs out. While the session is unattended a reminder is skipped and the wait starts again.
|
|
40
|
+
*/
|
|
41
|
+
export declare function watchWhileWaiting(input: Record<string, unknown>, env: Env, deps?: ProgressHookDeps): Promise<{
|
|
42
|
+
exit: 0 | 2;
|
|
43
|
+
message?: string;
|
|
44
|
+
}>;
|
|
45
|
+
export declare function runProgressHook(argv: readonly string[], env: Env, input: Input, io: {
|
|
46
|
+
err: {
|
|
47
|
+
write(s: string): unknown;
|
|
48
|
+
};
|
|
49
|
+
}, deps?: ProgressHookDeps): Promise<number>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// Entry for `sideby progress-hook claude <event>` (spec §3.42, ADR-0076): Progress Reminders. Claude Code runs it in
|
|
2
|
+
// the background after every turn (`Stop`, `asyncRewake`) and on every prompt (`UserPromptSubmit`, `async`) in a
|
|
3
|
+
// session sideby started while config `progress.every` is set. It imports only Node built-ins and leaf modules: never
|
|
4
|
+
// the Runtime, a Family index or core/accounts.ts. It never fails the Host: any problem means no output and exit 0.
|
|
5
|
+
//
|
|
6
|
+
// `UserPromptSubmit` keeps when the session's latest prompt came, a hash of its id, and whether it was a reminder's
|
|
7
|
+
// wake-up. `Stop` watches while the session waits on background work: every `every` minutes it wakes the session with
|
|
8
|
+
// exit 2 and asks the model to tell the user what it waits for, then end its turn. It ends without a word when a later
|
|
9
|
+
// `Stop` took over, a new turn began (told by the prompt's id), the Host is gone, the setting was turned off or Auto
|
|
10
|
+
// Handoff is handing over, and it stays quiet while the session is unattended (ADR-0075). A reminder Network Guard
|
|
11
|
+
// held and delivered later still counts as a reminder.
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { FILES, HANDOFF_ENV, readJsonFile } from '../core/handoff-chain.js';
|
|
15
|
+
import { resolvePaths } from '../core/paths.js';
|
|
16
|
+
import { hashOf, markWatchWoken, progressReminderTurn, readProgressEvery, readPromptRecord, readWatch, writePromptRecord, writeWatch, } from '../core/progress-state.js';
|
|
17
|
+
import { PROGRESS_MARK, progressWakeUp } from '../core/prompt-origin.js';
|
|
18
|
+
import { sessionUnattended } from '../core/unattended-attended.js';
|
|
19
|
+
import { UNATTENDED_ENV } from '../core/unattended-state.js';
|
|
20
|
+
/** How often a watch looks whether it is still wanted. */
|
|
21
|
+
export const CHECK_EVERY_MS = 60_000;
|
|
22
|
+
/** A watch ends by itself after this long, under the five-hour `timeout` Claude Code gives the hook. */
|
|
23
|
+
export const WATCH_FOR_MS = (4 * 60 + 55) * 60_000;
|
|
24
|
+
const STDIN_MAX = 8 * 1024 * 1024;
|
|
25
|
+
/** Input that has not ended after this long is not waited for: the hook then does nothing. */
|
|
26
|
+
const STDIN_WAIT_MS = 5000;
|
|
27
|
+
/** Background tasks named in a reminder, and the most of each description. */
|
|
28
|
+
const TASKS_NAMED = 5;
|
|
29
|
+
const DESCRIPTION_MAX = 80;
|
|
30
|
+
async function readInput(input) {
|
|
31
|
+
if (typeof input === 'string')
|
|
32
|
+
return input;
|
|
33
|
+
const read = (async () => {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
let size = 0;
|
|
36
|
+
for await (const chunk of input) {
|
|
37
|
+
const b = Buffer.from(chunk);
|
|
38
|
+
size += b.length;
|
|
39
|
+
if (size > STDIN_MAX)
|
|
40
|
+
return '';
|
|
41
|
+
chunks.push(b);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
44
|
+
})();
|
|
45
|
+
read.catch(() => { });
|
|
46
|
+
// A Host that never ends the input must not keep the hook waiting.
|
|
47
|
+
let timer;
|
|
48
|
+
const late = new Promise((resolve) => {
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
;
|
|
51
|
+
input.destroy?.();
|
|
52
|
+
resolve('');
|
|
53
|
+
}, STDIN_WAIT_MS);
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
return await Promise.race([read, late]);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function parseInput(input) {
|
|
63
|
+
try {
|
|
64
|
+
const v = JSON.parse(await readInput(input));
|
|
65
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : undefined;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const str = (v) => (typeof v === 'string' && v ? v : undefined);
|
|
72
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
73
|
+
/** Notes the session's latest prompt: when, a hash of its id, and whether it is a reminder's wake-up. */
|
|
74
|
+
async function notePrompt(env, input, now) {
|
|
75
|
+
const v = await parseInput(input);
|
|
76
|
+
if (!v || v.agent_id !== undefined)
|
|
77
|
+
return;
|
|
78
|
+
const sessionId = str(v.session_id);
|
|
79
|
+
const promptId = str(v.prompt_id);
|
|
80
|
+
if (!sessionId || !promptId)
|
|
81
|
+
return;
|
|
82
|
+
const paths = resolvePaths(env);
|
|
83
|
+
if ((await readProgressEvery(paths.configFile, env)) === undefined)
|
|
84
|
+
return;
|
|
85
|
+
const prompt = typeof v.prompt === 'string' ? v.prompt : '';
|
|
86
|
+
await writePromptRecord(paths.stateDir, sessionId, { at: now.toISOString(), prompt: hashOf(promptId), reminder: progressWakeUp(prompt) }, now);
|
|
87
|
+
}
|
|
88
|
+
/** One line of text from the Host: no control characters or quotes, runs of space as one, at most `max` characters. */
|
|
89
|
+
function clean(s, max) {
|
|
90
|
+
const one = [...s]
|
|
91
|
+
.map((ch) => (ch < ' ' || ch === '\u007f' || ch === '"' || ch === '`' ? ' ' : ch))
|
|
92
|
+
.join('')
|
|
93
|
+
.replace(/\s+/g, ' ')
|
|
94
|
+
.trim();
|
|
95
|
+
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
96
|
+
}
|
|
97
|
+
/** The background tasks as the reminder names them: kind and description, never the command. */
|
|
98
|
+
export function taskList(tasks) {
|
|
99
|
+
const named = tasks.slice(0, TASKS_NAMED).map((t) => {
|
|
100
|
+
const r = (t && typeof t === 'object' ? t : {});
|
|
101
|
+
const kind = r.type === 'shell'
|
|
102
|
+
? 'command'
|
|
103
|
+
: r.type === 'subagent'
|
|
104
|
+
? 'subagent'
|
|
105
|
+
: typeof r.type === 'string' && r.type
|
|
106
|
+
? clean(r.type, 20)
|
|
107
|
+
: 'task';
|
|
108
|
+
const what = typeof r.description === 'string' ? clean(r.description, DESCRIPTION_MAX) : '';
|
|
109
|
+
return what ? `${kind} "${what}"` : kind;
|
|
110
|
+
});
|
|
111
|
+
const more = tasks.length > TASKS_NAMED ? `; and ${tasks.length - TASKS_NAMED} more` : '';
|
|
112
|
+
return `${tasks.length} ${tasks.length === 1 ? 'task' : 'tasks'}: ${named.join('; ')}${more}`;
|
|
113
|
+
}
|
|
114
|
+
const hhmm = (ms) => {
|
|
115
|
+
const d = new Date(ms);
|
|
116
|
+
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* What the model is woken with. It starts with `PROGRESS_MARK`, names the clock time the wait began (so a reminder
|
|
120
|
+
* Network Guard held and delivered late still makes sense), and asks for one or two sentences and the end of the turn.
|
|
121
|
+
*/
|
|
122
|
+
export function reminderMessage(o) {
|
|
123
|
+
const since = Date.parse(o.since);
|
|
124
|
+
const minutes = Math.max(1, Math.round((o.now.getTime() - since) / 60_000));
|
|
125
|
+
return [
|
|
126
|
+
`${PROGRESS_MARK} you are waiting on background work (${taskList(o.tasks)}), since ${hhmm(since)}, ${minutes} ${minutes === 1 ? 'minute' : 'minutes'} as of this reminder.`,
|
|
127
|
+
'Tell the user in one or two sentences what you are waiting for, how long it has been, and whether there is new output (look only if that is quick), then end your turn.',
|
|
128
|
+
'Do not start new work or stop the tasks.',
|
|
129
|
+
`sideby sends this every ${o.every} ${o.every === 1 ? 'minute' : 'minutes'} while background work runs; if the user asks how to stop it, the command is \`sideby progress off\`.`,
|
|
130
|
+
].join(' ');
|
|
131
|
+
}
|
|
132
|
+
/** Whether Auto Handoff of this session's run is handing over: the threshold was sent or the run is ready. */
|
|
133
|
+
async function handingOver(env) {
|
|
134
|
+
const runId = env[HANDOFF_ENV.run];
|
|
135
|
+
const dir = env[HANDOFF_ENV.dir];
|
|
136
|
+
if (!runId || !dir)
|
|
137
|
+
return false;
|
|
138
|
+
if (await readJsonFile(join(dir, FILES.ready)))
|
|
139
|
+
return true;
|
|
140
|
+
return Boolean((await readJsonFile(join(dir, FILES.run(runId))))?.thresholdSentAt);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The `Stop` watch (spec §3.42). Replaces the session's earlier watch first, then, while background work runs and the
|
|
144
|
+
* setting is on, wakes the session every `progress.every` minutes with a reminder (exit 2). Ends with exit 0 when a
|
|
145
|
+
* later `Stop` took over, the session's latest prompt is not the one this `Stop` ended, the parent is gone, the
|
|
146
|
+
* setting is off, Auto Handoff is handing over, or time runs out. While the session is unattended a reminder is skipped and the wait starts again.
|
|
147
|
+
*/
|
|
148
|
+
export async function watchWhileWaiting(input, env, deps = {}) {
|
|
149
|
+
const clock = deps.now ?? (() => new Date());
|
|
150
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
151
|
+
const startPpid = process.ppid;
|
|
152
|
+
const parentGone = deps.parentGone ?? (() => process.ppid !== startPpid || process.ppid === 1);
|
|
153
|
+
const checkEvery = deps.checkEveryMs ?? CHECK_EVERY_MS;
|
|
154
|
+
const sessionId = str(input.session_id);
|
|
155
|
+
if (!sessionId)
|
|
156
|
+
return { exit: 0 };
|
|
157
|
+
const promptId = str(input.prompt_id);
|
|
158
|
+
const paths = resolvePaths(env);
|
|
159
|
+
const start = clock().getTime();
|
|
160
|
+
// The wait goes on across the turns reminders start; any other turn starts a new one.
|
|
161
|
+
const prev = await readWatch(paths.stateDir, sessionId);
|
|
162
|
+
const afterReminder = await progressReminderTurn(paths.stateDir, sessionId, promptId);
|
|
163
|
+
const since = afterReminder && prev ? prev.since : iso(start);
|
|
164
|
+
const id = deps.id ?? randomBytes(8).toString('hex');
|
|
165
|
+
// Written first, so a watch left by an earlier Stop ends even when this one has nothing to watch. When the session's
|
|
166
|
+
// lock stays held nothing is written, and this Stop does not watch: an earlier watch may still hold the record.
|
|
167
|
+
if (!(await writeWatch(paths.stateDir, sessionId, { id, since, at: iso(start) }, deps)))
|
|
168
|
+
return { exit: 0 };
|
|
169
|
+
const tasks = input.background_tasks;
|
|
170
|
+
if (!Array.isArray(tasks) || tasks.length === 0)
|
|
171
|
+
return { exit: 0 };
|
|
172
|
+
let every = await readProgressEvery(paths.configFile, env);
|
|
173
|
+
if (every === undefined)
|
|
174
|
+
return { exit: 0 };
|
|
175
|
+
const ownPrompt = promptId ? hashOf(promptId) : undefined;
|
|
176
|
+
let base = start;
|
|
177
|
+
for (;;) {
|
|
178
|
+
const wait = Math.min(checkEvery, Math.max(1000, base + every * 60_000 - clock().getTime()));
|
|
179
|
+
await sleep(wait);
|
|
180
|
+
const now = clock();
|
|
181
|
+
const t = now.getTime();
|
|
182
|
+
if (t - start >= WATCH_FOR_MS || parentGone())
|
|
183
|
+
return { exit: 0 };
|
|
184
|
+
if ((await readWatch(paths.stateDir, sessionId))?.id !== id)
|
|
185
|
+
return { exit: 0 };
|
|
186
|
+
// The latest prompt is another one: a turn began after this Stop's, and its own Stop decides again. Compared by
|
|
187
|
+
// the prompt's id, never by time: the next prompt's record can be written before this watch even starts. Only a
|
|
188
|
+
// Stop without an id falls back to whether the record came after it.
|
|
189
|
+
const p = await readPromptRecord(paths.stateDir, sessionId);
|
|
190
|
+
if (p && (ownPrompt ? p.prompt !== ownPrompt : Date.parse(p.at) > start))
|
|
191
|
+
return { exit: 0 };
|
|
192
|
+
// Read every time: turning it off, or another interval, reaches a running session.
|
|
193
|
+
every = await readProgressEvery(paths.configFile, env);
|
|
194
|
+
if (every === undefined)
|
|
195
|
+
return { exit: 0 };
|
|
196
|
+
if (await handingOver(env))
|
|
197
|
+
return { exit: 0 };
|
|
198
|
+
if (t - base < every * 60_000)
|
|
199
|
+
continue;
|
|
200
|
+
let quiet = true;
|
|
201
|
+
try {
|
|
202
|
+
quiet = (await sessionUnattended({
|
|
203
|
+
stateDir: paths.stateDir,
|
|
204
|
+
configFile: paths.configFile,
|
|
205
|
+
session: env[UNATTENDED_ENV] === '1',
|
|
206
|
+
sessionId,
|
|
207
|
+
now,
|
|
208
|
+
})).on;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// cannot tell: no reminder
|
|
212
|
+
}
|
|
213
|
+
if (quiet) {
|
|
214
|
+
base = t;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
// Checked and marked under the session's lock just before waking, so a Stop that came meanwhile is never
|
|
218
|
+
// answered by this watch, and never has its record put back to this one.
|
|
219
|
+
const hook = deps.beforeWake ? { beforeWrite: deps.beforeWake } : {};
|
|
220
|
+
if (!(await markWatchWoken(paths.stateDir, sessionId, id, now, hook)))
|
|
221
|
+
return { exit: 0 };
|
|
222
|
+
return { exit: 2, message: reminderMessage({ tasks, since, now, every }) };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
export async function runProgressHook(argv, env, input, io, deps = {}) {
|
|
226
|
+
const [family, event] = argv;
|
|
227
|
+
if (family !== 'claude')
|
|
228
|
+
return 0;
|
|
229
|
+
try {
|
|
230
|
+
if (event === 'UserPromptSubmit') {
|
|
231
|
+
// In the background: its output and exit code change nothing, and it never holds a prompt back.
|
|
232
|
+
await notePrompt(env, input, deps.now ? deps.now() : new Date());
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
if (event !== 'Stop')
|
|
236
|
+
return 0;
|
|
237
|
+
const v = await parseInput(input);
|
|
238
|
+
if (!v)
|
|
239
|
+
return 0;
|
|
240
|
+
const w = await watchWhileWaiting(v, env, deps);
|
|
241
|
+
// Exit 2 wakes the session (asyncRewake), which hands stderr to the model.
|
|
242
|
+
if (w.exit === 2 && w.message) {
|
|
243
|
+
io.err.write(`${w.message}\n`);
|
|
244
|
+
return 2;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// never fail the Host
|
|
249
|
+
}
|
|
250
|
+
return 0;
|
|
251
|
+
}
|
package/dist/src/runtime.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { type LimitResetPlan, type LimitResetResult } from './core/limit-reset.t
|
|
|
14
14
|
import { type NetworkOverview } from './core/network.ts';
|
|
15
15
|
import { type Paths } from './core/paths.ts';
|
|
16
16
|
import { type PickChoice } from './core/pick-commands.ts';
|
|
17
|
+
import { type ProgressView } from './core/progress.ts';
|
|
17
18
|
import { type ProjectCategories } from './core/project-categories.ts';
|
|
18
19
|
import { type QuotaFetchMode } from './core/quota-fetch.ts';
|
|
19
20
|
import { type RemoteControlChange, type RemoteControlGroup } from './core/remote-control.ts';
|
|
@@ -376,6 +377,14 @@ export interface Runtime {
|
|
|
376
377
|
setQuotaCheck(family: string, on: boolean): Promise<{
|
|
377
378
|
changed: boolean;
|
|
378
379
|
}>;
|
|
380
|
+
/** Progress Reminders (spec §3.42): whether they are on, how often, and for which Families. */
|
|
381
|
+
progressView(): ProgressView;
|
|
382
|
+
/** Turns Progress Reminders on with `every` minutes, or off (undefined); writes only config `progress`. */
|
|
383
|
+
setProgress(every: number | undefined): Promise<{
|
|
384
|
+
changed: boolean;
|
|
385
|
+
before?: number;
|
|
386
|
+
after?: number;
|
|
387
|
+
}>;
|
|
379
388
|
/** The config `display` (spec §3.25), or an empty object. */
|
|
380
389
|
displayOrder(): DisplayConfig;
|
|
381
390
|
/** Replaces the config `display`; undefined or empty removes it. Returns what the file now holds. */
|
package/dist/src/runtime.js
CHANGED
|
@@ -20,7 +20,10 @@ import { memoStore } from './core/memo-store.js';
|
|
|
20
20
|
import { codexNetworkTrustLine, guardLaunch, guardOn, ipChangedLine, networkHookPart, networkOverview, networkSettingsLine, } from './core/network.js';
|
|
21
21
|
import { resolvePaths } from './core/paths.js';
|
|
22
22
|
import { choosePick, suggestPickName } from './core/pick-commands.js';
|
|
23
|
+
import { PROGRESS_FAMILIES, progressHookPart, progressSettingsLine, progressView, setProgress, } from './core/progress.js';
|
|
24
|
+
import { PROGRESS_ENV, validEvery } from './core/progress-state.js';
|
|
23
25
|
import { categoryReader } from './core/project-categories.js';
|
|
26
|
+
import { LAUNCH_PROMPTS_ENV, LAUNCH_PROMPTS_UNSET } from './core/prompt-origin.js';
|
|
24
27
|
import { FETCH_TIMEOUT_MS, fetchedQuota, loginProblemOf, quotaCheckOff, shownQuota, } from './core/quota-fetch.js';
|
|
25
28
|
import { takeoverLimits } from './core/quota-levels.js';
|
|
26
29
|
import { quotaStoreFile, readQuotaStore } from './core/quota-store.js';
|
|
@@ -150,8 +153,27 @@ export async function createRuntime(opts = {}) {
|
|
|
150
153
|
}
|
|
151
154
|
if (p.family.id === 'codex')
|
|
152
155
|
addNotice(p, [await codexUnattendedTrustLine(paths.stateDir, p.account.ref, p.env)]);
|
|
156
|
+
// Which prompts sideby put on the command line, so the hook never takes one for typed (ADR-0075): filled in from
|
|
157
|
+
// the final arguments where the Host starts (`spawnHost`); left as it is, the session counts no prompt as typed.
|
|
158
|
+
if (p.family.id === 'claude')
|
|
159
|
+
p.env[LAUNCH_PROMPTS_ENV] = LAUNCH_PROMPTS_UNSET;
|
|
153
160
|
return unattendedHookPart();
|
|
154
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* Progress Reminders on a Claude session sideby starts (spec §3.42): their hooks while config `progress.every` is
|
|
164
|
+
* set, and the interval at launch in the environment (used only when the config cannot be read).
|
|
165
|
+
*/
|
|
166
|
+
const progressPrepared = (p) => {
|
|
167
|
+
const every = config.progress?.every;
|
|
168
|
+
if (!validEvery(every) || !PROGRESS_FAMILIES.includes(p.family.id))
|
|
169
|
+
return null;
|
|
170
|
+
if (hasOption(p.args, ['--settings'])) {
|
|
171
|
+
addNotice(p, [progressSettingsLine(p.env)]);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
p.env[PROGRESS_ENV] = String(every);
|
|
175
|
+
return progressHookPart();
|
|
176
|
+
};
|
|
155
177
|
/** Puts every session hook into the Launch's arguments: one `--settings` for Claude, `-c hooks.*` for Codex. */
|
|
156
178
|
const addSessionHooks = async (p, list) => {
|
|
157
179
|
const parts = list.filter((x) => x !== null);
|
|
@@ -163,13 +185,18 @@ export async function createRuntime(opts = {}) {
|
|
|
163
185
|
p.networkArgs = args;
|
|
164
186
|
p.args = beforeDashes(p.args, args);
|
|
165
187
|
};
|
|
166
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* Network Guard, Unattended Mode and Progress Reminders on a prepared Launch, in that order; hooks only for a session
|
|
190
|
+
* (`run`).
|
|
191
|
+
*/
|
|
167
192
|
const sessionReady = async (p, session, o) => {
|
|
168
193
|
const parts = [];
|
|
169
194
|
if (!o.ignoreNetwork)
|
|
170
195
|
parts.push(await guardPrepared(p, session));
|
|
171
196
|
if (session)
|
|
172
197
|
parts.push(await unattendedPrepared(p, Boolean(o.unattended)));
|
|
198
|
+
if (session)
|
|
199
|
+
parts.push(progressPrepared(p));
|
|
173
200
|
await addSessionHooks(p, parts);
|
|
174
201
|
};
|
|
175
202
|
const familyOf = (id) => {
|
|
@@ -1003,6 +1030,8 @@ export async function createRuntime(opts = {}) {
|
|
|
1003
1030
|
config.ask = fresh.ask;
|
|
1004
1031
|
config.advisor = fresh.advisor;
|
|
1005
1032
|
config.claude = fresh.claude;
|
|
1033
|
+
// Progress Reminders turned on, off or to another interval reach the next session a chain starts too.
|
|
1034
|
+
config.progress = fresh.progress;
|
|
1006
1035
|
}
|
|
1007
1036
|
const all = await accounts();
|
|
1008
1037
|
const inputs = launchInputs(ref, all, userArgs, command);
|
|
@@ -1065,7 +1094,8 @@ export async function createRuntime(opts = {}) {
|
|
|
1065
1094
|
const guarded = async (h) => {
|
|
1066
1095
|
const net = !ro.ignoreNetwork && guardOn(config, h.env);
|
|
1067
1096
|
const unattended = Boolean(ro.unattended) || config.unattended !== undefined;
|
|
1068
|
-
|
|
1097
|
+
const progress = validEvery(config.progress?.every) && PROGRESS_FAMILIES.includes(family.id);
|
|
1098
|
+
if (!net && !unattended && !progress)
|
|
1069
1099
|
return h;
|
|
1070
1100
|
const main = (await accounts()).find((a) => a.family === family.id && a.isMain);
|
|
1071
1101
|
if (!main)
|
|
@@ -1387,6 +1417,19 @@ export async function createRuntime(opts = {}) {
|
|
|
1387
1417
|
config.quota = r.after;
|
|
1388
1418
|
return { changed: r.changed };
|
|
1389
1419
|
},
|
|
1420
|
+
progressView: () => progressView(config),
|
|
1421
|
+
async setProgress(every) {
|
|
1422
|
+
const r = await setProgress(paths.configFile, every);
|
|
1423
|
+
if (r.config === undefined)
|
|
1424
|
+
delete config.progress;
|
|
1425
|
+
else
|
|
1426
|
+
config.progress = r.config;
|
|
1427
|
+
return {
|
|
1428
|
+
changed: r.changed,
|
|
1429
|
+
...(r.before === undefined ? {} : { before: r.before }),
|
|
1430
|
+
...(r.after === undefined ? {} : { after: r.after }),
|
|
1431
|
+
};
|
|
1432
|
+
},
|
|
1390
1433
|
displayOrder: () => config.display ?? {},
|
|
1391
1434
|
async setDisplayOrder(display) {
|
|
1392
1435
|
const r = await editConfigDisplay(paths.configFile, display);
|
|
@@ -54,6 +54,11 @@ export declare function commandProgram(command: string): string | undefined;
|
|
|
54
54
|
export declare function permissionText(tool: string, input: Record<string, unknown>): string;
|
|
55
55
|
/** What the model reads instead of the permission prompt Claude Code would have shown. */
|
|
56
56
|
export declare function permissionReason(state: UnattendedState, now: Date, kept: boolean): string;
|
|
57
|
+
/**
|
|
58
|
+
* What the user reads once in an Attended Session while Unattended Mode is on (ADR-0075), as a `systemMessage`: shown
|
|
59
|
+
* in the session, never to the model.
|
|
60
|
+
*/
|
|
61
|
+
export declare function attendedNotice(state: UnattendedState, zh: boolean): string;
|
|
57
62
|
/**
|
|
58
63
|
* Returns the exit code: 0 lets the Host go on, 2 refuses the tool call (the reason is written to `err`). A permission
|
|
59
64
|
* request, a stop on a question and an MCP form are answered with exit 0 and the decision written to `out`. Errors
|