chompyy 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/coldstart.js CHANGED
@@ -6,6 +6,7 @@ import { addCard, updateBoard } from './board.js';
6
6
  import { appendJsonl, homePath, readJson, writeJson } from './home.js';
7
7
  import { buildDigest, pickPrompts } from './history.js';
8
8
  import { insertUnderHeading, readTaste } from './taste.js';
9
+ import { branchOf } from './workspace.js';
9
10
  /** A preference must show up in this many separate sessions (spec §5.8: 3 confirmations). */
10
11
  export const MIN_TASTE_SESSIONS = 3;
11
12
  export function coldStartPath() {
@@ -153,7 +154,7 @@ export function acceptColdStart(choice, now) {
153
154
  writeFileSync(path, addTasteLines(text, tasteNow));
154
155
  }
155
156
  const made = updateBoard((b) => cardsNow.map((p) => {
156
- const card = addCard(b, p.idea, p.project, now, 'suggested');
157
+ const card = addCard(b, p.idea, p.project, now, 'suggested', branchOf(p.project));
157
158
  card.title = p.title;
158
159
  card.why = p.why;
159
160
  card.source = 'history';
package/dist/config.js CHANGED
@@ -15,17 +15,10 @@ export const DEFAULT_CONFIG = {
15
15
  permissionMode: 'acceptEdits',
16
16
  permissionPrompts: 'none',
17
17
  allowedTools: [
18
- 'Read',
19
- 'Glob',
20
- 'Grep',
21
- 'WebSearch',
22
- 'WebFetch',
23
18
  'Bash(ls *)',
24
19
  'Bash(git status *)',
25
20
  'Bash(git diff *)',
26
21
  'Bash(git log *)',
27
- 'Bash(git add *)',
28
- 'Bash(git commit *)',
29
22
  'Bash(npm test *)',
30
23
  'Bash(npm run *)',
31
24
  'Bash(npx vitest *)',
@@ -44,6 +37,7 @@ export const DEFAULT_CONFIG = {
44
37
  'Bash(curl *)',
45
38
  'Bash(rm -rf *)',
46
39
  ],
40
+ awayWeb: false,
47
41
  sandbox: true,
48
42
  sandboxAllowedDomains: [],
49
43
  denyReadPaths: [
@@ -67,15 +61,21 @@ export const DEFAULT_CONFIG = {
67
61
  checkCommands: {},
68
62
  loopRepeat: 5,
69
63
  idleTimeoutMin: 15,
64
+ maxDenied: 300,
70
65
  suggestedExpiryDays: 14,
71
66
  quotaSource: 'api',
67
+ allowKeychain: null,
72
68
  extraArgs: [],
73
69
  distillModel: 'sonnet',
74
70
  distillAfterAway: true,
71
+ dream: true,
72
+ dreamModel: 'opus',
73
+ planPriceUsd: null,
75
74
  lastHourTrigger: true,
76
75
  lastHourMinLeftPct: 25,
77
76
  bedtime: null,
78
77
  bedtimeWindowMin: 60,
78
+ missedReset: false,
79
79
  };
80
80
  export function configPath() {
81
81
  return homePath('config.json');
package/dist/deps.js ADDED
@@ -0,0 +1,124 @@
1
+ // Setup stage (research/away-readiness.md, step 2): a card's copy gets its dependencies before the box closes,
2
+ // without ever reinstalling per card. For each package folder in the copy, by its lockfile's contents:
3
+ // your checkout has the same lockfile installed → clone your node_modules (instant, no download)
4
+ // a snapshot for this lockfile exists → clone the snapshot
5
+ // neither → install once into a snapshot (with network, outside the box),
6
+ // then clone it; every later card with this lockfile reuses it
7
+ // Clones are APFS copy-on-write (`cp -c`): near-zero disk, and nothing a card does reaches the source.
8
+ import { spawnSync } from 'node:child_process';
9
+ import { createHash } from 'node:crypto';
10
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs';
11
+ import { join, relative } from 'node:path';
12
+ import { homePath } from './home.js';
13
+ // The snapshot only has package.json and the lockfile, so the repo's own scripts (e.g. "prepare": "npm run build")
14
+ // can't run there: install with --ignore-scripts, then rebuild, which runs the dependencies' install steps only.
15
+ const LOCKFILES = [
16
+ ['package-lock.json', [['npm', 'ci', '--no-audit', '--no-fund', '--ignore-scripts'], ['npm', 'rebuild']]],
17
+ ['npm-shrinkwrap.json', [['npm', 'ci', '--no-audit', '--no-fund', '--ignore-scripts'], ['npm', 'rebuild']]],
18
+ ['pnpm-lock.yaml', [['pnpm', 'install', '--frozen-lockfile', '--ignore-scripts'], ['pnpm', 'rebuild']]],
19
+ ['yarn.lock', [['yarn', 'install', '--frozen-lockfile', '--ignore-scripts']]],
20
+ ];
21
+ const SKIP = new Set(['node_modules', '.git', '.build', 'dist', 'build', 'vendor', 'Pods', 'DerivedData', '.venv', 'venv', 'target']);
22
+ /** Package folders in a tree (relative paths; '' = the top), up to `maxDepth` levels down. */
23
+ export function packageDirs(root, maxDepth = 3) {
24
+ const found = [];
25
+ const walk = (dir, depth) => {
26
+ if (existsSync(join(dir, 'package.json')))
27
+ found.push(relative(root, dir));
28
+ if (depth >= maxDepth)
29
+ return;
30
+ let subdirs = [];
31
+ try {
32
+ subdirs = readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory() && !d.name.startsWith('.') && !SKIP.has(d.name)).map((d) => d.name);
33
+ }
34
+ catch { }
35
+ for (const name of subdirs)
36
+ walk(join(dir, name), depth + 1);
37
+ };
38
+ walk(root, 0);
39
+ return found;
40
+ }
41
+ /** The folder's lockfile and a hash of its contents (null when it has none). */
42
+ export function lockOf(dir) {
43
+ for (const [file, install] of LOCKFILES) {
44
+ const p = join(dir, file);
45
+ if (existsSync(p))
46
+ return { file, hash: createHash('sha256').update(readFileSync(p)).digest('hex').slice(0, 16), install };
47
+ }
48
+ return null;
49
+ }
50
+ function hasModules(dir) {
51
+ try {
52
+ return readdirSync(join(dir, 'node_modules')).length > 0;
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
58
+ /** Copy-on-write clone of a node_modules folder (replaces an empty or missing one). */
59
+ function cloneModules(from, to) {
60
+ const dst = join(to, 'node_modules');
61
+ if (existsSync(dst))
62
+ rmSync(dst, { recursive: true, force: true });
63
+ return spawnSync('cp', ['-cR', join(from, 'node_modules'), dst], { stdio: 'ignore', timeout: 180_000 }).status === 0;
64
+ }
65
+ /**
66
+ * Give every package folder in `worktree` its dependencies, preferring what's already installed. `checkout` is your
67
+ * own copy of the repo (its node_modules are the first choice when its lockfile matches). Never throws.
68
+ */
69
+ export function setupDependencies(checkout, worktree, repoKey, opts = {}) {
70
+ const steps = [];
71
+ const snapshots = opts.snapshotsDir ?? homePath('deps', 'x').replace(/[/\\]x$/, '');
72
+ for (const rel of packageDirs(worktree)) {
73
+ const dir = join(worktree, rel);
74
+ const label = rel || '.';
75
+ if (hasModules(dir)) {
76
+ steps.push({ dir: label, source: 'kept' });
77
+ continue;
78
+ }
79
+ const mine = join(checkout, rel);
80
+ const lock = lockOf(dir);
81
+ if (!lock) {
82
+ // Nothing to compare against: your installed packages are the best guess.
83
+ if (hasModules(mine) && cloneModules(mine, dir))
84
+ steps.push({ dir: label, source: 'your checkout', note: 'no lockfile to compare' });
85
+ else
86
+ steps.push({ dir: label, source: 'none', note: 'no lockfile and nothing installed in your checkout' });
87
+ continue;
88
+ }
89
+ const myLock = lockOf(mine);
90
+ if (myLock?.hash === lock.hash && hasModules(mine) && cloneModules(mine, dir)) {
91
+ steps.push({ dir: label, source: 'your checkout' });
92
+ continue;
93
+ }
94
+ const snap = join(snapshots, repoKey, `${(rel || 'root').replace(/[/\\]/g, '_')}-${lock.hash}`);
95
+ if (!hasModules(snap)) {
96
+ // Install once, with network, outside the box: only package.json and the lockfile are needed.
97
+ mkdirSync(snap, { recursive: true });
98
+ copyFileSync(join(dir, 'package.json'), join(snap, 'package.json'));
99
+ copyFileSync(join(dir, lock.file), join(snap, lock.file));
100
+ const ok = opts.install
101
+ ? opts.install(lock.install, snap)
102
+ : lock.install.every((argv) => spawnSync(argv[0], argv.slice(1), { cwd: snap, stdio: 'ignore', timeout: opts.timeoutMs ?? 300_000, env: { ...process.env, ...opts.env } }).status === 0);
103
+ if (!ok || !hasModules(snap)) {
104
+ rmSync(join(snap, 'node_modules'), { recursive: true, force: true });
105
+ // Better something than nothing: your checkout's packages, flagged as a mismatch.
106
+ if (hasModules(mine) && cloneModules(mine, dir))
107
+ steps.push({ dir: label, source: 'your checkout', note: `${lock.install[0].join(' ')} failed; using your installed packages, which may not match the lockfile` });
108
+ else
109
+ steps.push({ dir: label, source: 'none', note: `${lock.install[0].join(' ')} failed and nothing is installed in your checkout` });
110
+ continue;
111
+ }
112
+ if (cloneModules(snap, dir))
113
+ steps.push({ dir: label, source: 'installed', note: `${lock.install[0].join(' ')}, once for this lockfile` });
114
+ else
115
+ steps.push({ dir: label, source: 'none', note: "couldn't copy the installed packages" });
116
+ continue;
117
+ }
118
+ if (cloneModules(snap, dir))
119
+ steps.push({ dir: label, source: 'snapshot' });
120
+ else
121
+ steps.push({ dir: label, source: 'none', note: "couldn't copy the snapshot" });
122
+ }
123
+ return steps;
124
+ }