@runcanary/cli 0.1.27 → 0.1.28
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/canary.js +53 -33
- package/package.json +1 -1
package/dist/canary.js
CHANGED
|
@@ -15,7 +15,7 @@ var f6=Object.create;var _r=Object.defineProperty;var v6=Object.getOwnPropertyDe
|
|
|
15
15
|
}
|
|
16
16
|
`,"canary/.claude-plugin/plugin.json":`{
|
|
17
17
|
"name": "canary",
|
|
18
|
-
"version": "0.1.
|
|
18
|
+
"version": "0.1.28",
|
|
19
19
|
"description": "Runs Canary's checks that need your machine: a skill for your coding agent and a verifier that works in its own copy of the code.",
|
|
20
20
|
"author": {
|
|
21
21
|
"name": "Canary",
|
|
@@ -207,7 +207,8 @@ export function finalOf(report: Report): Final {
|
|
|
207
207
|
headline: report.verdict.startsWith('on ') ? \`Canary report \${report.verdict}\` : \`Canary report: \${report.verdict}\`,
|
|
208
208
|
pips: report.score?.pips ?? [],
|
|
209
209
|
score: report.score?.value ?? '',
|
|
210
|
-
|
|
210
|
+
// Why the score is what it is: the line under it; on a report from before that line, the caption beside it.
|
|
211
|
+
caption: report.score?.reading ?? report.score?.caption ?? null,
|
|
211
212
|
tally: tally?.kind === 'tally' ? tally.items.map(item => ({ mark: item.mark, text: item.text })) : [],
|
|
212
213
|
next: next?.kind === 'next' ? \`Next\${next.gain === null ? '' : \` \${next.gain}\`}: \${next.action}\` : null,
|
|
213
214
|
}
|
|
@@ -1323,12 +1324,15 @@ export function cardOf(report: Report, width: number): Card {
|
|
|
1323
1324
|
y += 18
|
|
1324
1325
|
const x = left + 15
|
|
1325
1326
|
const head = y + 13
|
|
1326
|
-
|
|
1327
|
+
// The steps to a 5 are numbered under their own label; Next alone is the one step.
|
|
1328
|
+
const numbered = next.label !== 'Next'
|
|
1329
|
+
const parts = [textAt(\`status \${five ? 'g' : 'y'}\`, T.status, x, head, next.label, LABEL)]
|
|
1327
1330
|
if (next.gain !== null) parts.push(textAt(\`ngain\${five ? ' win' : ''}\`, T.count, left + inner - 15, head, next.gain, { end: true, bold: true, base: baseline(T.status, head) }))
|
|
1328
|
-
const pieces: [Token[], Style, string][] = [[tokens(runs(next.action), T.next), T.next, 'nact']]
|
|
1331
|
+
const pieces: [Token[], Style, string][] = [[tokens(numbered ? [{ text: '1. ' }, ...runs(next.action)] : runs(next.action), T.next), T.next, 'nact']]
|
|
1329
1332
|
if (next.agent !== null) pieces.push([tokens([{ text: '\u21B3 ' }, ...runs(next.agent)], T.agent), T.agent, 'nagent'])
|
|
1330
1333
|
if (next.cost !== null) pieces.push([tokens(runs(next.cost), T.how), T.how, 'ncost'])
|
|
1331
|
-
if (then !== null) pieces.push([tokens([{ text:
|
|
1334
|
+
if (then !== null && numbered) then.steps.forEach((step, index) => pieces.push([tokens([{ text: \`\${index + 2}. \` }, ...runs(step)], T.how), T.how, 'nthen']))
|
|
1335
|
+
else if (then !== null) pieces.push([tokens([{ text: 'then: ' }, ...joined(then.steps.map(step => runs(step)))], T.how), T.how, 'nthen'])
|
|
1332
1336
|
let at = head + T.status.line + 6
|
|
1333
1337
|
pieces.forEach(([line, style, cls], index) => {
|
|
1334
1338
|
if (index > 0) at += 4
|
|
@@ -1672,10 +1676,9 @@ function capOf(score: Score, state: State, reach: number | null, inner: number,
|
|
|
1672
1676
|
const scored = score.pips.filter(pip => pip !== '\u26AA').length
|
|
1673
1677
|
const unscored = scored === 0 && !/\\d/.test(value ?? '')
|
|
1674
1678
|
const gainTo = reach === null ? scored : Math.max(scored, Math.min(count, reach))
|
|
1675
|
-
// Only a red score was held down by something, so only a red one leaves its stop behind on a re-check.
|
|
1676
|
-
const before = score.before === null || !score.before.includes('\u{1F534}') ? null : score.before.filter(pip => pip !== '\u26AA').length
|
|
1677
1679
|
const labeled = score.caption === null ? null : /^([^:*\`]{1,24}):\\s+(.+)$/.exec(score.caption)
|
|
1678
|
-
|
|
1680
|
+
// What holds the score down is hung from where it stops: what is left to fix ("capped by" on a report from before).
|
|
1681
|
+
const capped = (labeled?.[1] === 'capped by' || /^\\d+ things? left to fix\\b/.test(score.reading ?? '')) && scored < count
|
|
1679
1682
|
const width = inner - NUMBER - 14
|
|
1680
1683
|
const cell = (width - (count - 1) * BAR.gap) / count
|
|
1681
1684
|
const at = (index: number) => index * (cell + BAR.gap)
|
|
@@ -1706,14 +1709,6 @@ function capOf(score: Score, state: State, reach: number | null, inner: number,
|
|
|
1706
1709
|
const stop = stopAt(scored)
|
|
1707
1710
|
parts.push(line(\`M\${px(stop + 2)} -4C\${px(stop + 3)} 14 \${px(stop - 2)} 32 \${px(stop - 0.5)} \${BAR.row + 3}\`, ' draw', fillEnd.toFixed(2)))
|
|
1708
1711
|
}
|
|
1709
|
-
if (before !== null && before < scored) {
|
|
1710
|
-
const stop = stopAt(before)
|
|
1711
|
-
parts.push(
|
|
1712
|
-
line(\`M\${px(stop + 3)} -2C\${px(stop + 3.5)} 5 \${px(stop + 1)} 11 \${px(stop + 1.6)} 17\`, ' old'),
|
|
1713
|
-
line(\`M\${px(stop - 0.5)} 32C\${px(stop - 1)} 38 \${px(stop - 3)} 43 \${px(stop - 4)} \${BAR.row + 1}\`, ' old'),
|
|
1714
|
-
)
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
1712
|
const bar = x + NUMBER + 14
|
|
1718
1713
|
// 40 is the baseline that centers the 44px digits on the cells.
|
|
1719
1714
|
const svg = [
|
|
@@ -1722,7 +1717,8 @@ function capOf(score: Score, state: State, reach: number | null, inner: number,
|
|
|
1722
1717
|
]
|
|
1723
1718
|
let below = top + BAR.row
|
|
1724
1719
|
if (score.caption !== null) {
|
|
1725
|
-
|
|
1720
|
+
// Only what capped the score hangs from its stop; what else the score's line says ("1 skipped by you") starts under the bar.
|
|
1721
|
+
const hung = capped && labeled?.[1] === 'capped by' ? Math.max(0, Math.min(stopAt(scored) - 2, width - HANG_ROOM)) : 0
|
|
1726
1722
|
// Hung from its line while it reads in two lines there; a longer one starts under the bar's start instead.
|
|
1727
1723
|
const hang = labeled !== null && hung > 0 && lay(tokens(runs(labeled[2]!), T.whyBold), width - hung).length > 2 ? 0 : hung
|
|
1728
1724
|
below += 3
|
|
@@ -1747,10 +1743,9 @@ function capOf(score: Score, state: State, reach: number | null, inner: number,
|
|
|
1747
1743
|
below += T.note.line
|
|
1748
1744
|
}
|
|
1749
1745
|
if (score.reading !== null) {
|
|
1750
|
-
//
|
|
1751
|
-
const end = gainTo > scored ? width - (at(gainTo - 1) + cell) : null
|
|
1746
|
+
// Why the score is what it is, from the card's left edge under the score, the whole width to read in.
|
|
1752
1747
|
below += 4
|
|
1753
|
-
const reading = para(tokens(runs(score.reading), T.reading), T.reading, 'pen reading write',
|
|
1748
|
+
const reading = para(tokens(runs(score.reading), T.reading), T.reading, 'pen reading write', x, below, inner)
|
|
1754
1749
|
svg.push(reading.svg)
|
|
1755
1750
|
below += reading.lines * T.reading.line
|
|
1756
1751
|
}
|
|
@@ -1786,8 +1781,9 @@ function altOf(report: Report, groups: Group[], recheckDetails: (string | undefi
|
|
|
1786
1781
|
for (const block of report.blocks) if (block.kind === 'list') lines.push(\`\${block.label}: \${block.items.map(wordsOf).join(' \xB7 ')}\`)
|
|
1787
1782
|
for (const block of report.blocks) if (block.kind === 'text') lines.push(...block.lines.filter(line => !/^\\s*\\|?\\s*:?-{3,}/.test(line)).map(line => wordsOf(line.replace(/\\|/g, ' ').replace(/^\\s*[-*]\\s+/, '').trim())).filter(line => line !== ''))
|
|
1788
1783
|
for (const block of report.blocks) {
|
|
1789
|
-
if (block.kind === 'next') lines.push(
|
|
1790
|
-
if (block.kind === '
|
|
1784
|
+
if (block.kind === 'next' && block.label !== 'Next') lines.push(\`\${block.label}: 1. \${wordsOf(block.action)}\${block.gain === null ? '' : \` \${block.gain}\`}\`)
|
|
1785
|
+
else if (block.kind === 'next') lines.push([\`Next\${block.gain === null ? '' : \` \${block.gain}\`}: \${wordsOf(block.action)}\`, block.agent, block.cost].filter(piece => piece !== null).map(piece => wordsOf(piece!)).join(' \xB7 '))
|
|
1786
|
+
if (block.kind === 'then') lines.push(report.blocks.some(other => other.kind === 'next' && other.label !== 'Next') ? block.steps.map((step, index) => \`\${index + 2}. \${wordsOf(step)}\`).join(' \xB7 ') : \`then: \${block.steps.map(wordsOf).join(' \xB7 ')}\`)
|
|
1791
1787
|
}
|
|
1792
1788
|
for (const block of report.blocks) {
|
|
1793
1789
|
if (block.kind === 'note') {
|
|
@@ -2343,9 +2339,9 @@ export interface Score {
|
|
|
2343
2339
|
pips: Pip[]
|
|
2344
2340
|
/** "2/5", "\u2013/5". */
|
|
2345
2341
|
value: string
|
|
2346
|
-
/** What
|
|
2342
|
+
/** What the score's own line says beside it: an area's health, how many must-fixes the person skipped ("capped by: \u2026" on a report from before the line under it). */
|
|
2347
2343
|
caption: string | null
|
|
2348
|
-
/**
|
|
2344
|
+
/** The line under the score that says why it is what it is ("1 thing left to fix: \u2026"). */
|
|
2349
2345
|
reading: string | null
|
|
2350
2346
|
}
|
|
2351
2347
|
|
|
@@ -2368,8 +2364,8 @@ export type Block =
|
|
|
2368
2364
|
| { kind: 'shown'; items: { title: string; text: string }[] }
|
|
2369
2365
|
| { kind: 'open'; text: string }
|
|
2370
2366
|
| { kind: 'list'; mark: Pip | null; label: string; items: string[] }
|
|
2371
|
-
/** Next (D6): the step, where it lands, what the agent does, and what the other way costs. */
|
|
2372
|
-
| { kind: 'next'; mark: Pip | null; gain: string | null; action: string; agent: string | null; cost: string | null }
|
|
2367
|
+
/** Next (D6): the step, where it lands, what the agent does, and what the other way costs. Under "To reach a 5/5" it is the first of the numbered steps. */
|
|
2368
|
+
| { kind: 'next'; mark: Pip | null; gain: string | null; action: string; agent: string | null; cost: string | null; label: string }
|
|
2373
2369
|
/** The steps after Next (D9). */
|
|
2374
2370
|
| { kind: 'then'; steps: string[] }
|
|
2375
2371
|
| { kind: 'note'; pieces: string[] }
|
|
@@ -2391,8 +2387,9 @@ export interface Split {
|
|
|
2391
2387
|
|
|
2392
2388
|
// A change's report; an area's, which names the area; and an area's section after a change's report (AREAS.md, D28).
|
|
2393
2389
|
const HEADING = /^## (?:Canary report(?: on (.+?))?|In (.+?)):\\s*(.+?)\\s*$/
|
|
2394
|
-
// The caption after " \xB7 " may still be arriving: it is read as far as it has come.
|
|
2395
|
-
|
|
2390
|
+
// The caption after " \xB7 " may still be arriving: it is read as far as it has come. It is in italics on a report from
|
|
2391
|
+
// before the score's own line said why, and plain since ("1 skipped by you").
|
|
2392
|
+
const SCORE = /^###\\s+([\u{1F534}\u{1F7E2}\u{1F7E1}\u26AA\uFE0F]+)(?:\\s+\u2192\\s+([\u{1F534}\u{1F7E2}\u{1F7E1}\u26AA\uFE0F]+))?\\s+\\*\\*\\*(.+?)\\*\\*\\*(?:\\s+([^\xB7*\\s][^\xB7*]*?))?(?:\\s+\xB7(?:\\s+\\*?(.*?)\\*?)?)?\\s*$/u
|
|
2396
2393
|
const ITALIC_LINE = /^\\*(?!\\*)(.+)(?<!\\*)\\*$/
|
|
2397
2394
|
const LABELED = /^(?:([\u{1F534}\u{1F7E2}\u{1F7E1}\u26AA\u{1F535}])\\s+)?\\*\\*([^*]+?):\\*\\*\\s+(.+)$/u
|
|
2398
2395
|
const SHARE = /^\`(Canary \xB7 [^\`]+)\`$/
|
|
@@ -2412,16 +2409,20 @@ const REVIEWED = /^\\*\\*(Reviewed(?: [\\d,]+ files?| the change| the area)?)(?:
|
|
|
2412
2409
|
*/
|
|
2413
2410
|
const NEXT = /^([\u{1F7E1}\u{1F7E2}])\\s+\\*\\*Next(?:\\s+(\u2192 [^:*]+?))?:\\*\\*\\s+(.+)$/u
|
|
2414
2411
|
const THEN = /^then:\\s+(.+)$/
|
|
2412
|
+
/** The steps to a 5, each with the score it gets to: "**To reach a 5/5:**", then "1. Fix both must-fixes \u2192 4/5". */
|
|
2413
|
+
export const TO_FIVE_LABEL = 'To reach a 5/5'
|
|
2414
|
+
const TO_FIVE = /^\\*\\*To reach a 5\\/5:\\*\\*$/
|
|
2415
|
+
const STEP = /^\\d+\\.\\s+(.+?)\\s+(\u2192 \\d\\/5)$/
|
|
2415
2416
|
/** A table's last row past its first three: "| **+2 more** | | In \`canary show 4d3c2b1a\` |". */
|
|
2416
2417
|
const MORE = /^\\*\\*\\+\\d+ more\\*\\*$/
|
|
2417
2418
|
/** One line under the findings (D31, D51): "- *<title>* \xB7 It failed when Canary ran it with \u2026". */
|
|
2418
2419
|
const SHOWN = /^- \\*(.+?)\\* \xB7 (.+)$/
|
|
2419
2420
|
|
|
2420
2421
|
/** Where each block sits in the report, in the order the server writes them. */
|
|
2421
|
-
const PLACE = { score: 1, reading: 2, reviewed: 3, tally: 4, read: 5, recheck: 6, findings: 7, shown: 8, open: 9, outside: 10, skipped: 10.5, next: 11, then: 12, footer: 13, share: 14 }
|
|
2422
|
+
const PLACE = { score: 1, reading: 2, reviewed: 3, tally: 4, read: 5, recheck: 6, findings: 7, shown: 8, open: 9, outside: 10, skipped: 10.5, next: 11, then: 12, climb: 12.5, footer: 13, share: 14 }
|
|
2422
2423
|
|
|
2423
2424
|
/** The server's own lists, by their labels, and where each sits: what a 5 proved sits where the findings would, and what the person skipped under what checks did outside them. */
|
|
2424
|
-
const LISTS: Record<string, number> = { Read: PLACE.read, 'Proven by running': PLACE.findings, 'Outside the checks': PLACE.outside, 'Skipped by you': PLACE.skipped }
|
|
2425
|
+
const LISTS: Record<string, number> = { Read: PLACE.read, 'Proven by running': PLACE.findings, 'Outside the checks': PLACE.outside, 'Skipped by you': PLACE.skipped, 'So far': PLACE.climb }
|
|
2425
2426
|
|
|
2426
2427
|
/** The line under a score one proof from 5, naming what is left (D10). */
|
|
2427
2428
|
const READING = /^one proof from \\d\\/5(?:: .+)?$/
|
|
@@ -2458,12 +2459,12 @@ const markedOf = (cell: string): Marked => {
|
|
|
2458
2459
|
}
|
|
2459
2460
|
|
|
2460
2461
|
/** Next's words: the action first, then what the agent does, and the other way's cost when it is set in italics. */
|
|
2461
|
-
function nextOf(mark: string, gain: string | undefined, said: string): Extract<Block, { kind: 'next' }> {
|
|
2462
|
+
function nextOf(mark: string, gain: string | undefined, said: string, label = 'Next'): Extract<Block, { kind: 'next' }> {
|
|
2462
2463
|
const pieces = said.split(' \xB7 ')
|
|
2463
2464
|
const last = pieces[pieces.length - 1]!
|
|
2464
2465
|
const cost = pieces.length > 1 && ITALIC_LINE.test(last) ? ITALIC_LINE.exec(last)![1]! : null
|
|
2465
2466
|
const middle = pieces.slice(1, cost === null ? undefined : -1)
|
|
2466
|
-
return { kind: 'next', mark: mark as Pip, gain: gain ?? null, action: pieces[0]!, agent: middle.length > 0 ? middle.join(' \xB7 ') : null, cost }
|
|
2467
|
+
return { kind: 'next', mark: mark as Pip, gain: gain ?? null, action: pieces[0]!, agent: middle.length > 0 ? middle.join(' \xB7 ') : null, cost, label }
|
|
2467
2468
|
}
|
|
2468
2469
|
|
|
2469
2470
|
/**
|
|
@@ -2540,6 +2541,20 @@ function read(block: string[], report: Report, place: number): number | null {
|
|
|
2540
2541
|
report.blocks.push({ kind: 'shown', items: shown.flatMap(line => (line === null ? [] : [{ title: line[1]!, text: line[2]! }])) })
|
|
2541
2542
|
return PLACE.shown
|
|
2542
2543
|
}
|
|
2544
|
+
if (TO_FIVE.test(first)) {
|
|
2545
|
+
// The first step is the one to take now, drawn as Next with the score it gets to; the rest follow it.
|
|
2546
|
+
// A last step still arriving is read as far as it has come; every one before it has to be whole.
|
|
2547
|
+
const lines = block.slice(1).map(line => line.trim())
|
|
2548
|
+
const read = lines.map((line, index) => STEP.exec(line) ?? (index === lines.length - 1 ? /^\\d+\\.\\s+(.+)$/.exec(line) : null))
|
|
2549
|
+
// Its number alone has nothing to draw yet.
|
|
2550
|
+
const steps = read[read.length - 1] === null ? read.slice(0, -1) : read
|
|
2551
|
+
if (place >= PLACE.next || steps.length === 0 || steps.some(step => step === null)) return null
|
|
2552
|
+
const [now, ...rest] = steps as RegExpExecArray[]
|
|
2553
|
+
report.blocks.push(nextOf('\u{1F7E1}', now![2], now![1]!, TO_FIVE_LABEL))
|
|
2554
|
+
if (rest.length === 0) return PLACE.next
|
|
2555
|
+
report.blocks.push({ kind: 'then', steps: rest.map(step => (step[2] === undefined ? step[1]! : \`\${step[1]!} \${step[2]}\`)) })
|
|
2556
|
+
return PLACE.then
|
|
2557
|
+
}
|
|
2543
2558
|
if (block.length !== 1) return null
|
|
2544
2559
|
const reviewed = REVIEWED.exec(first)
|
|
2545
2560
|
if (reviewed !== null) {
|
|
@@ -2607,6 +2622,11 @@ function read(block: string[], report: Report, place: number): number | null {
|
|
|
2607
2622
|
report.blocks.push({ kind: 'open', text: first })
|
|
2608
2623
|
return PLACE.open
|
|
2609
2624
|
}
|
|
2625
|
+
// The one plain line under the score says why it is what it is.
|
|
2626
|
+
if (place === PLACE.score && block.length === 1) {
|
|
2627
|
+
report.score!.reading = first
|
|
2628
|
+
return PLACE.reading
|
|
2629
|
+
}
|
|
2610
2630
|
return null
|
|
2611
2631
|
}
|
|
2612
2632
|
|
|
@@ -3073,7 +3093,7 @@ Output that begins with \`OFFLINE COPY\` could not be refreshed and may be outda
|
|
|
3073
3093
|
you act on it.
|
|
3074
3094
|
`});var T3={};Ur(T3,{installAgentSkill:()=>tn});import{existsSync as _s,lstatSync as y8,mkdirSync as w8,readFileSync as R3,rmSync as b8,rmdirSync as k8,writeFileSync as z8}from"node:fs";import{homedir as Bs}from"node:os";import{join as wt}from"node:path";function C8(e){let t=wt(e,"skills",S8),n=wt(t,"SKILL.md");if(dq(t)||dq(n)||!_s(n))return;let q;try{q=R3(n,"utf8")}catch{return}if(!(!/^name:\s*canary-setup\s*$/m.test(q)||!/runcanary\.ai|@runcanary\/cli/.test(q))){try{b8(n,{force:!1})}catch{return}try{k8(t)}catch{}}}function dq(e){try{return y8(e).isSymbolicLink()}catch{return!1}}function A8(){return[wt(Bs(),".claude"),wt(Bs(),".agents"),wt(Bs(),".codex")].filter(e=>_s(e))}function tn(){let e={installed:[],refreshed:[],current:[],skipped:[]};if(K().agentSkills===!1)return e;for(let t of A8()){C8(t);let n=wt(t,"skills",x8),q=wt(n,"SKILL.md");try{if(dq(n)||dq(q)){e.skipped.push(q);continue}let r=_s(q)?R3(q,"utf8"):null;if(r===Hs){e.current.push(q);continue}w8(n,{recursive:!0}),z8(q,Hs),(r===null?e.installed:e.refreshed).push(q)}catch{}}return e}var x8,S8,uq=Z(()=>{"use strict";g();e1();I3();x8="canary",S8="canary-setup"});import{createHash as I8,randomUUID as R8}from"node:crypto";import{mkdirSync as T8,readFileSync as O8,renameSync as E8,rmSync as O3,writeFileSync as N8}from"node:fs";import{dirname as Us,join as P8,resolve as E3}from"node:path";function j3(e,t,n=Date.now()){try{let q=P3(e),r=`${q}.${R8()}.tmp`;T8(Us(q),{recursive:!0,mode:448});try{N8(r,JSON.stringify({version:1,chat:t,at:n})+`
|
|
3075
3095
|
`,{flag:"wx",mode:384}),E8(r,q)}catch(s){throw O3(r,{force:!0}),s}}catch{}}function M3(e,t=Date.now()){for(let n=E3(e);;n=Us(n)){let q=P3(n),r=null;try{r=JSON.parse(O8(q,"utf8")),O3(q,{force:!0})}catch{}if(r&&r.version===1&&typeof r.chat=="string"&&r.chat&&typeof r.at=="number"&&t-r.at>=0&&t-r.at<j8)return r.chat;if(Us(n)===n)return null}}var j8,M8,N3,P3,Gs=Z(()=>{"use strict";g();e1();j8=1e4,M8=/(?:^|[;&|(]|\$\()\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:[^\s;&|()]*\/)?canary(?=[\s;&|)]|$)/m,N3=e=>e.some(t=>M8.test(t)),P3=e=>P8(G(),"hold",`chat-${I8("sha256").update(E3(e)).digest("hex").slice(0,32)}.json`)});import{mkdirSync as L8,readFileSync as F8,writeFileSync as $8}from"node:fs";import{homedir as D8}from"node:os";import{dirname as W8,join as L3}from"node:path";function $3(){try{return JSON.parse(F8(Vs(),"utf8"))}catch{return{}}}function B8(e,t){let n=e.split(".").map(Number),q=t.split(".").map(Number);for(let r=0;r<3;r+=1){let s=(n[r]||0)-(q[r]||0);if(s!==0)return s>0}return!1}function D3(){if(ke==="0.0.0-dev")return;let{latest:e}=$3();e&&B8(e,ke)&&console.error(`A newer Canary CLI is available (${ke} -> ${e}): npm install -g ${F3}`)}function Zt(){if(ke==="0.0.0-dev")return;let e=$3();e.checkedAt&&Date.now()-e.checkedAt<H8||(async()=>{let t=n=>{try{L8(W8(Vs()),{recursive:!0}),$8(Vs(),JSON.stringify({checkedAt:Date.now(),latest:n??e.latest})+`
|
|
3076
|
-
`)}catch{}};try{let n=await fetch(`https://registry.npmjs.org/${F3}/latest`,{signal:AbortSignal.timeout(1500)});if(!n.ok)return t();let{version:q}=await n.json();t(q||void 0)}catch{t()}})()}var ke,F3,H8,Vs,bt=Z(()=>{"use strict";g();ke="0.1.
|
|
3096
|
+
`)}catch{}};try{let n=await fetch(`https://registry.npmjs.org/${F3}/latest`,{signal:AbortSignal.timeout(1500)});if(!n.ok)return t();let{version:q}=await n.json();t(q||void 0)}catch{t()}})()}var ke,F3,H8,Vs,bt=Z(()=>{"use strict";g();ke="0.1.28",F3="@runcanary/cli",H8=1440*60*1e3,Vs=()=>L3(process.env.CANARY_HOME||L3(D8(),".canary"),"update-check.json")});import{createHash as _8}from"node:crypto";import{execFileSync as U8,spawn as G8}from"node:child_process";function Q1(e){Ve={...Ve,...e},nn=null}function Ys(e=process.env){if(e.CLAUDECODE==="1"||e.CLAUDE_CODE_SESSION_ID){let t=e.CLAUDE_CODE_SESSION_ID??e.CLAUDE_CODE_HOST_SESSION_ID;return{harness:"claude-code",...t?{chatId:t}:{}}}return e.CODEX_SANDBOX||e.CODEX_SANDBOX_NETWORK_DISABLED==="1"?{harness:"codex"}:e.CURSOR_AGENT==="1"?{harness:"cursor"}:{harness:"unknown"}}function kt(e=process.env,t=process.cwd()){let n=e.CLAUDE_CODE_SESSION_ID?.trim(),q=e.CODEX_THREAD_ID?.trim();return n&&!q?n:(Js===void 0&&(Js=M3(t)),Js??q??n??null)}function V8(e,t){return _8("sha256").update(`${t}\0${e}`).digest("hex").slice(0,24)}function mq(){return{...Object.fromEntries(Object.entries(process.env).filter(([e])=>!e.startsWith("GIT_")||["GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM","GIT_CONFIG_NOSYSTEM"].includes(e))),GIT_OPTIONAL_LOCKS:"0",GIT_NO_LAZY_FETCH:"1",GIT_NO_REPLACE_OBJECTS:"1",GIT_TERMINAL_PROMPT:"0",GIT_TRACE2:"0",GIT_TRACE2_EVENT:"0",GIT_TRACE2_PERF:"0"}}function W3(e,t){try{let n=mq();return U8("git",e,{cwd:t,env:n,stdio:["ignore","pipe","ignore"],timeout:5e3}).toString("utf8").trim()}catch{return null}}function J8(e,t){let[n,q,r]=(W3(["rev-parse","--show-toplevel","--abbrev-ref","HEAD","--is-shallow-repository"],e)??"").split(`
|
|
3077
3097
|
`);if(!n)return{};let s={worktreeId:V8(n,t)};if(r!=="true"){let o=Fi(s.worktreeId);o&&W3(["cat-file","-e",`${o}^{commit}`],n)!==null?s.repoFingerprint=o:Y8(n,s.worktreeId)}return s.branch=q&&q!=="HEAD"?q:"HEAD",s}function Y8(e,t){H3.has(t)||H3.set(t,new Promise(n=>{try{let q=mq(),r=G8("git",["rev-list","--max-parents=0","HEAD"],{cwd:e,env:q,stdio:["ignore","pipe","ignore"],timeout:6e4}),s="";r.stdout.on("data",o=>{s+=o.toString("utf8")}),r.on("error",()=>n()),r.on("close",o=>{let i=o===0?s.trim().split(`
|
|
3078
3098
|
`).filter(Boolean).sort()[0]:void 0;i&&$i(t,i),n()}),r.unref(),r.stdout.unref?.()}catch{n()}}))}function K8(){if(nn)return nn;let e=/^[a-z][a-z-]*$/.test(process.argv[2]??"")?process.argv[2]:"",t=Ys(),n=Ve.harness??t.harness,q=t.harness===n?t.chatId:void 0,r="",s={};try{r=Li(),s=J8(Ve.cwd??process.cwd(),r)}catch{}return nn={cliVersion:ke,command:e,installId:r,...s,harness:n,...q?{chatId:q}:{},...Ve.agent!==void 0?{agent:Ve.agent}:{},...Ve.mode?{mode:Ve.mode}:{}},nn}function Je(){let e=K8(),t=q=>q.replace(/[^\x20-\x7e]/g,"?").slice(0,200),n={[g1.cli]:e.cliVersion,[g1.harness]:e.harness};return e.installId&&(n[g1.install]=e.installId),e.command&&(n[g1.command]=t(e.command)),e.worktreeId&&(n[g1.worktree]=e.worktreeId),e.repoFingerprint&&(n[g1.repo]=e.repoFingerprint),e.branch&&(n[g1.branch]=t(e.branch)),e.chatId&&(n[g1.chat]=t(e.chatId)),e.agent!==void 0&&(n[g1.agent]=e.agent?"1":"0"),e.mode&&(n[g1.mode]=e.mode),n}var g1,Ve,nn,Js,H3,ie=Z(()=>{"use strict";g();e1();Gs();bt();g1={cli:"x-canary-cli",command:"x-canary-command",install:"x-canary-install",worktree:"x-canary-worktree",repo:"x-canary-repo",branch:"x-canary-branch",harness:"x-canary-harness",chat:"x-canary-chat",agent:"x-canary-agent",mode:"x-canary-mode"},Ve={},nn=null;H3=new Map});async function W(e,t={}){let n=(t.baseUrl||a1()).replace(/\/+$/,""),q={...Je(),...t.headers};t.token&&(q.authorization=`Bearer ${t.token}`),t.body!==void 0&&(q["content-type"]="application/json");let r;try{r=await fetch(n+e,{method:t.method??"GET",headers:q,body:t.body!==void 0?JSON.stringify(t.body):void 0,signal:t.signal})}catch(s){throw new L(0,`could not reach ${n} (${s instanceof Error?s.message:String(s)})`)}if(!r.ok){let s=r.statusText,o,i,a;try{let l=await r.json();s=l.error||l.message||s,typeof l.fix=="string"&&l.fix&&(o=l.fix),typeof l.runId=="string"&&l.runId&&(i=l.runId),typeof l.code=="string"&&l.code&&(a=l.code)}catch{}throw new L(r.status,s,o,i,a)}return r.status===204?null:await r.json()}var L,z1,p1=Z(()=>{"use strict";g();e1();ie();L=class extends Error{constructor(n,q,r,s,o){super(q);this.status=n;this.fix=r;this.runId=s;this.code=o;this.name="ApiError"}},z1=e=>e instanceof L&&(e.status===0||e.status===408||e.status===429||e.status===502||e.status===503||e.status===504)});function B3(e){return P1(t=>({...t,gate:{...t.gate,mode:e}}))}var zt,pq=Z(()=>{"use strict";g();e1();zt=()=>K().gate?.mode==="off"?"off":"on"});var Ik,fq,X8,Rk,_3=Z(()=>{"use strict";g();Ik=Object.freeze({name:"Canary Verify",email:"verify@runcanary.ai",date:"@0 +0000",message:e=>`canary verify: tree ${e}`}),fq=e=>`tree:${e.slice(0,12)}`,X8=[["core.fsmonitor","false"],["core.splitIndex","false"],["gc.auto","0"],["commit.gpgsign","false"],["i18n.commitEncoding","utf-8"],["log.showSignature","false"],["diff.noprefix","false"],["diff.mnemonicPrefix","false"],["diff.relative","false"],["diff.context","3"],["diff.interHunkContext","0"],["diff.submodule","short"],["apply.ignoreWhitespace","no"],["apply.whitespace","nowarn"]],Rk=X8.flatMap(([e,t])=>["-c",`${e}=${t}`])});import{createHash as Q8}from"node:crypto";import{existsSync as Z8,mkdirSync as Ks,readFileSync as e2,writeFileSync as vq}from"node:fs";import{join as Ne}from"node:path";function t2(e){return Ne(e,".canary")}function V3(e){let t=e.trim();if(!t)return null;if(!t.includes("://")){let n=t.match(/^[^@]+@([^:]+):(.+)$/);if(n){let q=n[2].replace(/\/+$/,"").replace(/\.git$/,"").split("/").filter(Boolean);return q.length>=2?{host:n[1],owner:q[0],name:q.slice(1).join("/")}:null}}try{let n=new URL(t),q=n.pathname.replace(/^\/+/,"").replace(/\/+$/,"").replace(/\.git$/,"").split("/").filter(Boolean);if(q.length>=2)return{host:n.host,owner:q[0],name:q.slice(1).join("/")}}catch{}return null}function qn(e){let t=t2(e),n=Ne(t,".gitignore");try{let q=e2(n,"utf8").split(`
|
|
3079
3099
|
`).map(r=>r.trim()).filter(r=>r.length>0);if(q[q.length-1]==="*")return}catch{}try{Ks(t,{recursive:!0});let q="";try{q=e2(n,"utf8"),q&&!q.endsWith(`
|