chompyy 0.4.7 → 0.5.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/README.md +29 -6
- package/dist/advice.js +2 -1
- package/dist/appstate.js +9 -2
- package/dist/board.js +3 -0
- package/dist/cli.js +67 -12
- package/dist/daytime.js +68 -0
- package/dist/didwork.js +46 -0
- package/dist/learning.js +35 -0
- package/dist/send.js +46 -20
- package/dist/taste.js +67 -7
- package/dist/unkeep.js +220 -0
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# chompyy (CLI)
|
|
2
2
|
|
|
3
|
-
Uses the capacity in Claude Code's 5-hour window that would otherwise reset unused. You park ideas as cards, each card gets a short **blueprint** (the scope agreed before it runs), approved cards run headless while you're away, and a report shows what ran so you can rate it.
|
|
3
|
+
Uses the capacity in Claude Code's 5-hour window that would otherwise reset unused. You park ideas as cards, each card gets a short **blueprint** (the scope agreed before it runs), approved cards run headless while you're away, and a report shows what ran so you can rate it, keep it and send it to GitHub.
|
|
4
4
|
|
|
5
|
-
This is the
|
|
5
|
+
This is the engine behind the [Mac app](../mac/README.md): everything the app does is a `chompyy` command, so it all works from Terminal too. Node 20+, no runtime dependencies. Design: [the spec](../research/spec-token-utilization.md).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -116,28 +116,51 @@ Each card in a git repo runs in its own worktree at `~/.chompyy/worktrees/<id>`
|
|
|
116
116
|
| `chompyy blueprint <id> [--model m]` | Draft (or redraft) the blueprint with a cheap model |
|
|
117
117
|
| `chompyy picture <id> [--model m]` | Draw (or redraw) the card's picture: a diagram of what it will do, made with the diagram-design skill. Happens on its own after each blueprint while a window is active (`"pictures": false` in config.json turns it off) |
|
|
118
118
|
| `chompyy edit-idea <id>` | Replace a *later* card's idea (and its title) with text from stdin, e.g. `echo "new idea" \| chompyy edit-idea 3`. The blueprint stays; redraft it with `blueprint <id>` |
|
|
119
|
-
| `chompyy
|
|
119
|
+
| `chompyy edit-blueprint <id>` | Replace a card's blueprint with text from stdin |
|
|
120
|
+
| `chompyy approve <id>` / `chompyy drop <id>` | Queue a card for away runs / remove it (kept in `archive.jsonl`) |
|
|
121
|
+
| `chompyy answer <id> ["answers"]` | Answer a card's questions (as words, or on stdin); it goes back to *approved* and the next away run continues it |
|
|
122
|
+
| `chompyy suggest [repo] [--force]` | A few tasks for a repo, from its goals and its code, added as suggested cards (one model call, only inside an active window) |
|
|
120
123
|
| `chompyy away <1h\|30m\|1h30m> [--dry-run] [--force]` | Run approved cards until the time is up or the gate closes |
|
|
121
124
|
| `chompyy report [--all]` | Cards that ran since the last report: one action each, cards needing you first. No paths or raw agent text; ask for those with `show` |
|
|
122
125
|
| `chompyy diff <id>` | The change the card made on its branch |
|
|
123
126
|
| `chompyy keep <id>` | Merge the card's branch into your current branch and remove its worktree. Refuses when you have unsaved changes in a file the card also changed, or anything staged; other unsaved work is left alone |
|
|
124
|
-
| `chompyy undo <id
|
|
127
|
+
| `chompyy undo <id> [--plan] [--json]` | Throw the run away: remove its worktree and branch (or draft folder). Your own branches are never touched. On a kept card it takes the card back: off your branch when it's only on this Mac (closing its PR if one is open), or with a revert PR on GitHub once its PR merged. `--plan` says which and changes nothing |
|
|
128
|
+
| `chompyy redo <id>` | Throw a ran card's result away and put it back in *approved*; it runs again from your latest code |
|
|
129
|
+
| `chompyy continue <id> ["what is still missing"]` | Put a ran card back in *approved* as its next cycle; the next run gets what the last one did, plus your note |
|
|
130
|
+
| `chompyy refresh [<id>]` | Bring a card that clashes with your newer main up to date and check it again (no id: every clashing card). Waits for quota when there is none |
|
|
131
|
+
| `chompyy send [--json]` | Open one pull request on GitHub per kept card your main has and GitHub's doesn't, from `chompyy/card-<id>` with just that card's commits (needs `gh`). Main itself is never pushed. Run it again after merging: once every card is on GitHub, your main moves to match GitHub's (only when that loses nothing; unsaved work is kept) |
|
|
125
132
|
| `chompyy rate <id> <1-5> ["why"]` | Rate a result against its blueprint; moves it to *done* and logs a signal |
|
|
133
|
+
| `chompyy signals [--json]` | Every signal so far (ratings, edits, cold start picks), oldest first |
|
|
126
134
|
| `chompyy taste` | Show `taste.md` |
|
|
127
135
|
| `chompyy taste list` / `why <id>` | Every learned preference and its status / the cards, edits and quotes behind one |
|
|
128
136
|
| `chompyy taste yes\|not-now\|never <id>` | Answer the report's question. Only *yes* writes it to `taste.md`; *never* stops Chompyy proposing it again |
|
|
129
137
|
| `chompyy taste retire <id>` | Stop using a preference; it stays in `taste list` with the reason |
|
|
138
|
+
| `chompyy taste daytime [on\|off]` | Your rules in every Claude Code session too: one import line in `~/.claude/CLAUDE.md` loads `~/.chompyy/taste-for-claude.md`, which Chompyy keeps up to date. Off takes the line out |
|
|
139
|
+
| `chompyy dream [--dry-run] [--force] [--since 7d]` | The nightly read: learn taste from your recent Claude Code sessions in ticked folders now. Runs on its own at bedtime when on |
|
|
140
|
+
| `chompyy dream workspaces` / `tick <folder>` / `untick <folder>` / `on\|off` | Which folders the nightly read may learn from; turn it on or off |
|
|
130
141
|
| `chompyy distill [--force]` | Read new signals and update preferences now (also runs after every away run) |
|
|
131
|
-
| `chompyy trends` | Last 7 days vs the 7 before: cost per card, keep rate, rating, blueprint edits |
|
|
142
|
+
| `chompyy trends` | Last 7 days vs the 7 before: cost per card, keep rate, rating, blueprint edits; then what Chompyy learned: rules this week, waiting, corrections per conversation |
|
|
132
143
|
| `chompyy premise [--json]` | How often a 5-hour window reset with 20%+ left in a week that still had 10%+ spare: the capacity away runs can use. From your quota readings; every ended window is kept in `windows.jsonl` (numbers only), so it grows past the 8 days of `quota-history.json`. `--json` to share it |
|
|
133
144
|
| `chompyy detect [--days 30] [--all] [--json]` | The detective: what wastes tokens in your setup and habits, from your own files. One screen: the findings ranked by tokens and the fix to start with; `--all` adds each finding's count, measured or estimated, what it doesn't prove, and every fix. A mid-session cache rebuild names its cause (e.g. Tool Search loading an MCP server's tools). Works cold with `npx chompyy detect`, nothing else installed. This version checks startup tax (long CLAUDE.md, unused skills and MCP servers, cut-off MEMORY.md) and cache (cold returns, mid-session rebuilds). Reads only; changes nothing |
|
|
134
145
|
| `chompyy advise [--json]` | The detective, step 3: turns detect's findings into suggested cards on the board (the app's "Find savings"). Each card's plan shows what Chompyy saw, what it doesn't prove, the exact change and how it will check it worked. Approve a settings card (e.g. turn off a plugin you never use) and Chompyy applies it once no Claude Code session has been active for 10 minutes, backed up first; `chompyy undo <id>` puts it back if nothing changed it since. Habit cards are tracked from the day you approve; some things only you can do (claude.ai-synced skills). Dropped advice never comes back. Advice never runs on an away run |
|
|
135
146
|
| `chompyy advise apply` | Apply approved settings advice now if no session has been active for 10 minutes (the app and the 5-minute tick do this on their own) |
|
|
147
|
+
| `chompyy worked [--all] [--json] [--share]` | Did the advice work: each applied card against the check it set up, plus the nudge's measured result, and one "Saved so far" total (also in the menu panel) that adds only what was counted. `--share` prints a summary with no project, skill or file names |
|
|
136
148
|
| `chompyy nudge on\|off` | Live suggestions while you work. Adds a UserPromptSubmit hook to `~/.claude/settings.json` (backed up first; your other hooks stay). When you come back to a conversation of 40k+ tokens after more than an hour, its cache has expired: the hook stops that first message once and says what sending it rebuilds, what a fresh start costs, and the cheaper ways (/clear with a note, or /compact). Send it again and it goes through. A conversation compacted since its last reply (your /compact, or Claude Code's own while you were away) sends a summary, so it isn't stopped. Needs a global install (`npm install -g chompyy`); away runs turn hooks off, so it never touches them |
|
|
137
149
|
| `chompyy nudge [--json]` | On or off, what the stops and warnings led to (compacted, left, sent anyway), the tokens not written again, and the measured trend: cold returns this week against last week. The menu panel shows the same line |
|
|
138
150
|
| `chompyy nudge due [--json]` | Conversations 45-60 minutes into a pause, about to go cold, each reported once (only while nudge is on). The menu bar app asks every minute and sends a notification, while /compact is still cheap. Skips conversations already compacted |
|
|
139
151
|
| `chompyy triggers on\|off` | Install or remove the macOS LaunchAgent that runs `chompyy tick` every 5 minutes |
|
|
140
|
-
| `chompyy bedtime <23:30\|off>` / `last-hour <on\|off>` / `missed-reset <on\|off>` | Turn the bedtime, last-hour-before-reset and missed-reset (first tick after an unused reset, default off) triggers on or off |
|
|
152
|
+
| `chompyy bedtime <23:30\|off>` / `chompyy last-hour <on\|off>` / `chompyy missed-reset <on\|off>` | Turn the bedtime, last-hour-before-reset and missed-reset (first tick after an unused reset, default off) triggers on or off |
|
|
153
|
+
| `chompyy quota [--refresh] [--allow-keychain\|--no-keychain]` | Read the live quota now and show `status`. The keychain flags allow or stop reading your Claude sign-in from the macOS keychain |
|
|
154
|
+
| `chompyy usage [--period today\|7d\|30d\|month] [--days 7] [--json]` | Tokens and cost by day, project and kind of work, pull request costs, and how your plan compares with API prices |
|
|
155
|
+
| `chompyy trace <conversation id> [--json]` | Where one conversation's tokens went (ids: `chompyy usage --json`) |
|
|
156
|
+
| `chompyy tokens [--json]` | Exact tokens and API-price cost of each away run (last 20) |
|
|
157
|
+
| `chompyy plan-price <dollars\|auto>` | Your plan's monthly price, for the plan-vs-API comparison in `usage` |
|
|
158
|
+
| `chompyy history [--digest] [--json]` | What cold start would read: sessions, projects, dates. Local; sends nothing |
|
|
159
|
+
| `chompyy coldstart [show\|accept\|forget] [--force]` | One model call that proposes taste lines and suggested cards from your history; `accept --taste t1 --cards c1` keeps the ones you pick |
|
|
160
|
+
| `chompyy keep-history <days>` | How long Claude Code keeps transcripts (default 30 days) |
|
|
161
|
+
| `chompyy projects [--json]` | Recent project folders, for picking where a card runs |
|
|
162
|
+
| `chompyy app` | macOS: download and open the menu bar app |
|
|
163
|
+
| `chompyy version` / `chompyy help` | The CLI's version / the command list |
|
|
141
164
|
|
|
142
165
|
## Taste
|
|
143
166
|
|
package/dist/advice.js
CHANGED
|
@@ -214,10 +214,11 @@ export function approveAdvice(c, now) {
|
|
|
214
214
|
a.note = 'Applies once no Claude Code session has run for 10 minutes.';
|
|
215
215
|
return `✅ #${c.id} approved. Applies once no Claude Code session has run for 10 minutes.`;
|
|
216
216
|
}
|
|
217
|
+
// Nothing for Chompyy to apply or run: the card closes at once, so it leaves the board.
|
|
217
218
|
c.column = 'done';
|
|
218
219
|
a.since = at;
|
|
219
220
|
a.state = a.lane === 'habit' ? 'trying' : 'done';
|
|
220
|
-
return a.lane === 'habit' ? `✅ #${c.id}: trying it from today. ${a.check}` : `✅ #${c.id}
|
|
221
|
+
return a.lane === 'habit' ? `✅ #${c.id} closed: trying it from today. ${a.check}` : `✅ #${c.id} closed. ${a.check}`;
|
|
221
222
|
}
|
|
222
223
|
/** When a Claude Code session last wrote its transcript (ms), so settings never change under an open conversation. */
|
|
223
224
|
export function lastSessionActivity(root = projectsDir()) {
|
package/dist/appstate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// What the Mac app reads (`chompyy state --json`) and the card actions it needs beyond the CLI's.
|
|
2
2
|
// The app holds no logic of its own: it shows this JSON and calls chompyy commands.
|
|
3
|
+
import { daytimeState } from './daytime.js';
|
|
3
4
|
import { execFileSync } from 'node:child_process';
|
|
4
5
|
import { readFileSync, existsSync } from 'node:fs';
|
|
5
6
|
import { clashOf } from './refresh.js';
|
|
@@ -15,6 +16,7 @@ import { loadColdStart } from './coldstart.js';
|
|
|
15
16
|
import { blueprintHash } from './picture.js';
|
|
16
17
|
import { costRange, readRuns } from './costs.js';
|
|
17
18
|
import { cachedWorkspaces, loadDream } from './dream.js';
|
|
19
|
+
import { learning } from './learning.js';
|
|
18
20
|
import { describeSignal, loadStore, nextQuestion, readSignals, receipts } from './taste.js';
|
|
19
21
|
import { agentInstalled, loadTriggerState } from './triggers.js';
|
|
20
22
|
import { planFor } from './permissions.js';
|
|
@@ -106,7 +108,7 @@ export function tasteQuestion() {
|
|
|
106
108
|
* For "What Chompyy heard from you": the rules waiting for your yes (strongest evidence first) and the ones in
|
|
107
109
|
* force. The app shows the waiting count as a badge on the button.
|
|
108
110
|
*/
|
|
109
|
-
export function tasteState() {
|
|
111
|
+
export function tasteState(now = new Date()) {
|
|
110
112
|
const signals = readSignals();
|
|
111
113
|
const byId = new Map(signals.map((s) => [s.id, s]));
|
|
112
114
|
const store = loadStore();
|
|
@@ -123,7 +125,12 @@ export function tasteState() {
|
|
|
123
125
|
waiting.push(q);
|
|
124
126
|
rest.prefs = rest.prefs.filter((p) => p.id !== q.id);
|
|
125
127
|
}
|
|
126
|
-
return {
|
|
128
|
+
return {
|
|
129
|
+
waiting: waiting.map(item),
|
|
130
|
+
learned: store.prefs.filter((p) => p.status === 'active').map(item),
|
|
131
|
+
daytime: daytimeState().on,
|
|
132
|
+
learning: learning(store, signals, loadDream().readThrough ?? {}, waiting.length, now),
|
|
133
|
+
};
|
|
127
134
|
}
|
|
128
135
|
/** Whether the app should offer the cold start: never run, proposals waiting, or done. */
|
|
129
136
|
export function coldStartState() {
|
package/dist/board.js
CHANGED
|
@@ -143,6 +143,7 @@ export function continueCard(board, id, note, now, prior = {}) {
|
|
|
143
143
|
// The new cycle starts clean: these belonged to the run that just ended (and are kept in the Cycle).
|
|
144
144
|
delete card.run;
|
|
145
145
|
delete card.outcome;
|
|
146
|
+
delete card.unkept;
|
|
146
147
|
delete card.rating;
|
|
147
148
|
delete card.answers;
|
|
148
149
|
delete card.fiveStarOptions;
|
|
@@ -341,6 +342,8 @@ export function formatCard(c) {
|
|
|
341
342
|
lines.push(`log: ${c.logPath}`);
|
|
342
343
|
if (c.outcome)
|
|
343
344
|
lines.push(`outcome: ${c.outcome}`);
|
|
345
|
+
if (c.unkept)
|
|
346
|
+
lines.push(`undone after keep: ${c.unkept.how === 'revert-pr' ? `revert PR #${c.unkept.pr?.number ?? '?'}` : c.unkept.how === 'dropped' ? 'branch moved back' : 'Undo commit'}${c.unkept.closed ? `, PR #${c.unkept.closed} closed` : ''}`);
|
|
344
347
|
if (c.rating)
|
|
345
348
|
lines.push(`rating: ${c.rating.score}/5${c.rating.reason ? ` · ${c.rating.reason}` : ''}`);
|
|
346
349
|
return lines.join('\n');
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { execFileSync, spawn } from 'node:child_process';
|
|
4
4
|
import { backfillTokens, median } from './tokenstore.js';
|
|
5
5
|
import { compact, formatTokens, totalTokens } from './tokens.js';
|
|
6
|
-
import { closeSync, existsSync, openSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { closeSync, existsSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { resolve } from 'node:path';
|
|
8
8
|
import { parseArgs } from 'node:util';
|
|
9
9
|
import { away, runCard } from './away.js';
|
|
@@ -22,7 +22,7 @@ import { cardsSince, formatReport, lastReportAt, markReported, morningLine, rate
|
|
|
22
22
|
import { approvedText, changedFiles, diffCard, keepCard, overlaps, questionsOf, undoCard } from './review.js';
|
|
23
23
|
import { CappedText, ClaudeRunner, claudeAvailable } from './runner.js';
|
|
24
24
|
import { branchOf, commitLeftovers, gitRoot, planWorkspace, prepareWorkspace } from './workspace.js';
|
|
25
|
-
import { answerCard, appState, cardView, currentBranch, editBlueprint, editIdea, recordCliLocation } from './appstate.js';
|
|
25
|
+
import { answerCard, appState, cardView, currentBranch, editBlueprint, editIdea, recordCliLocation, tasteState } from './appstate.js';
|
|
26
26
|
import { detect, detectText } from './detect.js';
|
|
27
27
|
import { allWindowEnds, archiveWindowEnds, premise, premiseText } from './premise.js';
|
|
28
28
|
import { keychainAllowed, loadLiveState, refreshLiveQuota } from './livequota.js';
|
|
@@ -33,18 +33,20 @@ import { acceptColdStart, forgetColdStart, formatColdStart, loadColdStart, runCo
|
|
|
33
33
|
import { keepHistory } from './claudesettings.js';
|
|
34
34
|
import { blueprintHash, drawPicture } from './picture.js';
|
|
35
35
|
import { costRange, formatCostRange, readRuns, tasteEffect, tasteEffectLine, trendLines } from './costs.js';
|
|
36
|
-
import { answerPreference, distill, distillDue, formatPrefs, formatQuestion, formatWhy, getPref, learnedCount, loadStore, nextQuestion, readSignals, recordOutcome, retirePreference, syncTasteFile, tasteChangesSince, } from './taste.js';
|
|
36
|
+
import { answerPreference, distill, distillDue, formatPrefs, formatQuestion, formatWhy, getPref, learnedCount, loadStore, nextQuestion, readSignals, recordOutcome, renderAgentsBlock, retirePreference, syncTasteFile, tasteChangesSince, tasteRulesForProject, } from './taste.js';
|
|
37
37
|
import { cachedWorkspaces, dream, dreamDue, formatDream, formatWorkspaces, projectsDir, readLogPath, setTicked } from './dream.js';
|
|
38
38
|
import { byKind, compare, formatExtras, formatUsage, loadLedger, periodDays, PERIODS, prCosts, usageView } from './usage.js';
|
|
39
39
|
import { formatTrace, traceSession } from './trace.js';
|
|
40
40
|
import { homedir } from 'node:os';
|
|
41
41
|
import { clashOf, refreshCard, refreshGate, refreshClashing, withRefreshLock } from './refresh.js';
|
|
42
42
|
import { adviseText, applyDue, approveAdvice, runAdvise, undoAdvice } from './advice.js';
|
|
43
|
-
import {
|
|
43
|
+
import { daytimeFile, daytimeState, setDaytime } from './daytime.js';
|
|
44
|
+
import { checkWorked, nudgeProofText, savedSoFar, shareText, workedText } from './didwork.js';
|
|
44
45
|
import { addSuggested, suggestTasks, suggestText } from './suggest.js';
|
|
45
46
|
import { coldWarningText, hookCommand, impact, loadNudges, nudgeInstalled, nudgeText, runHook, setNudge, setProjectMode, takeGoingCold } from './nudge.js';
|
|
46
47
|
import { withKeepLock } from './keeplock.js';
|
|
47
48
|
import { sendKept } from './send.js';
|
|
49
|
+
import { planUnkeep, unkeep } from './unkeep.js';
|
|
48
50
|
import { cacheText, composeLine, setStatusline, statuslineInstalled, statusLineOutput, wrappedCommand } from './statusline.js';
|
|
49
51
|
import { formatLive, keepAffectsLive, liveOff, liveSet, liveUpdateLocked, loadLive, startLiveUpdate } from './live.js';
|
|
50
52
|
import { agentInstalled, awayRunning, bedtimeKey, decideTrigger, installAgent, loadTriggerState, markFired, noteTick, parseClock, takeAwayLock, uninstallAgent } from './triggers.js';
|
|
@@ -99,6 +101,8 @@ Back
|
|
|
99
101
|
chompyy send [--json] open one PR on GitHub per kept card GitHub's main doesn't have yet
|
|
100
102
|
chompyy refresh [<id>] bring cards in review up to date with main (Chompyy does this by itself after each Keep)
|
|
101
103
|
chompyy undo <id> throw it away (removes its branch; yours are untouched)
|
|
104
|
+
a kept card: takes it back off your branch, or opens a revert PR on GitHub
|
|
105
|
+
(--plan says which, changing nothing; --json for the app)
|
|
102
106
|
chompyy answer <id> answer the run's questions (stdin); the card goes back to approved
|
|
103
107
|
chompyy redo <id> throw this attempt away and run it again from your latest code
|
|
104
108
|
chompyy continue <id> ["note"] a done card did only part of the job: run another cycle that builds on it
|
|
@@ -122,6 +126,8 @@ Taste (learned from what you keep, undo, edit and rate)
|
|
|
122
126
|
chompyy taste why <id> the cards, edits and quotes behind a preference
|
|
123
127
|
chompyy taste yes|not-now|never <id> answer a question (yes writes it to taste.md)
|
|
124
128
|
chompyy taste retire <id> stop using a preference (kept, with the reason)
|
|
129
|
+
chompyy taste agents <project> <file> copy Everywhere + <project> rules into a marked block in an AGENTS.md
|
|
130
|
+
chompyy taste daytime on|off your rules in every Claude Code session too (one import line in ~/.claude/CLAUDE.md)
|
|
125
131
|
chompyy distill [--force] read new signals and update preferences now (one model call; runs after away too)
|
|
126
132
|
|
|
127
133
|
Triggers (start away runs on their own; the budget gate still decides every card)
|
|
@@ -489,6 +495,7 @@ async function main(argv) {
|
|
|
489
495
|
column: { type: 'string', multiple: true },
|
|
490
496
|
help: { type: 'boolean', short: 'h' },
|
|
491
497
|
json: { type: 'boolean' },
|
|
498
|
+
plan: { type: 'boolean' },
|
|
492
499
|
refresh: { type: 'boolean' },
|
|
493
500
|
'allow-keychain': { type: 'boolean' },
|
|
494
501
|
'no-keychain': { type: 'boolean' },
|
|
@@ -1184,7 +1191,7 @@ async function main(argv) {
|
|
|
1184
1191
|
case 'worked': {
|
|
1185
1192
|
// The detective, step 5: each applied/tried advice card against the check it registered (didwork.ts).
|
|
1186
1193
|
const cards = updateBoard((b) => checkWorked(b, now));
|
|
1187
|
-
const proof = nudgeInstalled() || loadNudges().length
|
|
1194
|
+
const { proof, total } = savedSoFar(cards, now, { on: nudgeInstalled() || loadNudges().length > 0 });
|
|
1188
1195
|
if (values.share) {
|
|
1189
1196
|
// A summary to paste on the tester issue: counts, tokens and dates; no project, skill or file names.
|
|
1190
1197
|
const text = shareText(cards, proof, { version: cliVersion(), now });
|
|
@@ -1193,10 +1200,11 @@ async function main(argv) {
|
|
|
1193
1200
|
return console.log(`${text}\n\nNo project, skill or file names in it. Copy it: chompyy worked --share | pbcopy`);
|
|
1194
1201
|
}
|
|
1195
1202
|
if (values.json)
|
|
1196
|
-
return json({ cards: cards.map((c) => ({ id: c.id, title: c.title, rule: c.advice.rule, lane: c.advice.lane, ...c.advice.result })), nudge: proof });
|
|
1203
|
+
return json({ cards: cards.map((c) => ({ id: c.id, title: c.title, rule: c.advice.rule, lane: c.advice.lane, ...c.advice.result })), nudge: proof, total });
|
|
1204
|
+
const sum = total ? ['', total.line] : [];
|
|
1197
1205
|
if (!cards.length && proof)
|
|
1198
|
-
return console.log(nudgeProofText(proof).join('\n'));
|
|
1199
|
-
return console.log([workedText(cards, { all: Boolean(values.all) }), ...(proof ? ['', ...nudgeProofText(proof)] : [])].join('\n'));
|
|
1206
|
+
return console.log([...nudgeProofText(proof), ...sum].join('\n'));
|
|
1207
|
+
return console.log([workedText(cards, { all: Boolean(values.all) }), ...(proof ? ['', ...nudgeProofText(proof)] : []), ...sum].join('\n'));
|
|
1200
1208
|
}
|
|
1201
1209
|
case 'suggest': {
|
|
1202
1210
|
// A few tasks for a repo, from what it wants to become and what its code shows: suggested cards to approve.
|
|
@@ -1245,9 +1253,10 @@ async function main(argv) {
|
|
|
1245
1253
|
}
|
|
1246
1254
|
if (values.json) {
|
|
1247
1255
|
// The menu panel: the trend line, plus did the nudge work (its verdict, from the day it was turned on).
|
|
1256
|
+
// Plus the running total: what was counted (stops, re-counted fixes), from the results `worked` last wrote.
|
|
1248
1257
|
const i = impact();
|
|
1249
|
-
const p
|
|
1250
|
-
return json({ ...i, ...(p ? { verdict: { verdict: p.result.verdict, line: p.result.line, dueAt: p.result.dueAt } } : {}) });
|
|
1258
|
+
const { proof: p, total } = savedSoFar(loadBoard().cards, now, { on: i.on });
|
|
1259
|
+
return json({ ...i, ...(p ? { verdict: { verdict: p.result.verdict, line: p.result.line, dueAt: p.result.dueAt } } : {}), ...(total ? { total: { tokens: total.tokens, line: total.line } } : {}) });
|
|
1251
1260
|
}
|
|
1252
1261
|
return console.log([nudgeText(nudgeInstalled()), impact().line].join('\n'));
|
|
1253
1262
|
}
|
|
@@ -1266,6 +1275,7 @@ async function main(argv) {
|
|
|
1266
1275
|
const lines = trendLines(runs, signals, now);
|
|
1267
1276
|
console.log(lines.length ? lines.join('\n') : 'Not enough runs yet for trends (needs 3).');
|
|
1268
1277
|
console.log(tasteEffectLine(tasteEffect(runs, signals)));
|
|
1278
|
+
console.log(tasteState(now).learning.line);
|
|
1269
1279
|
return;
|
|
1270
1280
|
}
|
|
1271
1281
|
case 'report': {
|
|
@@ -1311,7 +1321,7 @@ async function main(argv) {
|
|
|
1311
1321
|
case 'send': {
|
|
1312
1322
|
// Kept cards live on your local main only; this opens (or updates) one PR per card. Main itself is never pushed.
|
|
1313
1323
|
const sent = sendKept(loadBoard().cards);
|
|
1314
|
-
console.log(
|
|
1324
|
+
console.log(values.json ? JSON.stringify(sent) : sent.message);
|
|
1315
1325
|
return;
|
|
1316
1326
|
}
|
|
1317
1327
|
case 'refresh': {
|
|
@@ -1333,6 +1343,23 @@ async function main(argv) {
|
|
|
1333
1343
|
const undone = getCard(loadBoard(), id);
|
|
1334
1344
|
if (undone.advice && undone.advice.lane !== 'work')
|
|
1335
1345
|
return console.log(updateBoard((b) => undoAdvice(getCard(b, id), now)));
|
|
1346
|
+
if (undone.outcome === 'kept') {
|
|
1347
|
+
// Undo after Keep: off your branch, or a revert PR on GitHub once it's there (unkeep.ts). It moves the
|
|
1348
|
+
// branch Keep lands on, so it waits in line with Keeps.
|
|
1349
|
+
if (values.plan)
|
|
1350
|
+
return console.log(planUnkeep(undone).line);
|
|
1351
|
+
const r = withKeepLock(() => unkeep(undone));
|
|
1352
|
+
console.log(values.json ? JSON.stringify({ message: r.message, url: r.url }) : r.message);
|
|
1353
|
+
updateBoard((b) => {
|
|
1354
|
+
const card = getCard(b, id);
|
|
1355
|
+
card.outcome = 'undone';
|
|
1356
|
+
card.unkept = { at: now.toISOString(), ...r.unkept };
|
|
1357
|
+
card.updatedAt = now.toISOString();
|
|
1358
|
+
recordOutcome(card, 'undone', now);
|
|
1359
|
+
return card;
|
|
1360
|
+
});
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1336
1363
|
const files = changedFiles(undone); // read before Undo removes the branch
|
|
1337
1364
|
console.log(undoCard(undone));
|
|
1338
1365
|
updateBoard((b) => {
|
|
@@ -1361,6 +1388,7 @@ async function main(argv) {
|
|
|
1361
1388
|
c.updatedAt = c.approvedAt;
|
|
1362
1389
|
delete c.run;
|
|
1363
1390
|
delete c.outcome;
|
|
1391
|
+
delete c.unkept;
|
|
1364
1392
|
return c;
|
|
1365
1393
|
});
|
|
1366
1394
|
console.log(`🔁 #${card.id} back in approved; it runs again from your latest code on the next away run.`);
|
|
@@ -1406,8 +1434,35 @@ async function main(argv) {
|
|
|
1406
1434
|
const p = retirePreference(need(args[1], 'chompyy taste retire <id>'), now);
|
|
1407
1435
|
return console.log(`Retired ${p.id}: "${p.text}". It's kept in \`chompyy taste list\` with the reason.`);
|
|
1408
1436
|
}
|
|
1437
|
+
if (sub === 'agents') {
|
|
1438
|
+
const usage = 'chompyy taste agents <project> <file>';
|
|
1439
|
+
const project = need(args[1], usage);
|
|
1440
|
+
const file = resolve(need(args[2], usage));
|
|
1441
|
+
const rules = tasteRulesForProject(project);
|
|
1442
|
+
if (!rules)
|
|
1443
|
+
throw new Error(`Add a rule under "## Everywhere" or "## ${project}" in taste.md first: no rules to copy. Nothing changed.`);
|
|
1444
|
+
const before = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
1445
|
+
const after = renderAgentsBlock(before, rules);
|
|
1446
|
+
if (after === before)
|
|
1447
|
+
return console.log(`Nothing to do: ${file} already has these rules.`);
|
|
1448
|
+
writeFileSync(file, after);
|
|
1449
|
+
const n = rules.split('\n').filter((l) => !l.startsWith('## ') && l.trim()).length;
|
|
1450
|
+
return console.log(`Wrote ${n} rule${n === 1 ? '' : 's'} for ${project} to ${file}. Text outside the chompyy:taste block is unchanged.`);
|
|
1451
|
+
}
|
|
1452
|
+
if (sub === 'daytime') {
|
|
1453
|
+
const how = args[1];
|
|
1454
|
+
if (how === 'on' || how === 'off') {
|
|
1455
|
+
if (how === 'on')
|
|
1456
|
+
syncTasteFile(now);
|
|
1457
|
+
return console.log(setDaytime(how === 'on'));
|
|
1458
|
+
}
|
|
1459
|
+
if (how)
|
|
1460
|
+
throw new Error('Usage: chompyy taste daytime [on|off]');
|
|
1461
|
+
const st = daytimeState();
|
|
1462
|
+
return console.log(st.on ? `On: Claude Code loads your rules from ${daytimeFile()} at every session start. Turn off: chompyy taste daytime off` : 'Off: only away runs use your taste. Turn on: chompyy taste daytime on');
|
|
1463
|
+
}
|
|
1409
1464
|
if (sub)
|
|
1410
|
-
throw new Error('Usage: chompyy taste [list | why <id> | yes|not-now|never <id> | retire <id>]');
|
|
1465
|
+
throw new Error('Usage: chompyy taste [list | why <id> | yes|not-now|never <id> | retire <id> | agents <project> <file> | daytime [on|off]]');
|
|
1411
1466
|
const { path, text, created } = readTaste();
|
|
1412
1467
|
if (created)
|
|
1413
1468
|
console.log(`(created ${path})\n`);
|
package/dist/daytime.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Taste in daytime sessions: the rules you said yes to, in a file Claude Code loads at every session start.
|
|
2
|
+
//
|
|
3
|
+
// Chompyy writes its own file (~/.chompyy/taste-for-claude.md) and adds one import line to your user CLAUDE.md,
|
|
4
|
+
// inside the chompyy:taste markers. After that it only ever rewrites its own file: a yes, a retire or an edit to
|
|
5
|
+
// taste.md shows up in the next session without touching CLAUDE.md again. Off takes the line out and leaves
|
|
6
|
+
// everything else in CLAUDE.md as it was.
|
|
7
|
+
import { existsSync, readFileSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { dirname, join } from 'node:path';
|
|
10
|
+
import { homePath, readJson, writeJson } from './home.js';
|
|
11
|
+
import { AGENTS_END, AGENTS_START, renderAgentsBlock, tasteForPrompt } from './taste.js';
|
|
12
|
+
export const claudeMdPath = () => join(homedir(), '.claude', 'CLAUDE.md');
|
|
13
|
+
const statePath = () => homePath('daytime.json');
|
|
14
|
+
export const daytimeFile = () => homePath('taste-for-claude.md');
|
|
15
|
+
export const daytimeState = () => readJson(statePath(), { on: false });
|
|
16
|
+
/** `~/…` when under your home folder: the import line reads the same on any Mac. */
|
|
17
|
+
const tilde = (p) => (p.startsWith(`${homedir()}/`) ? `~${p.slice(homedir().length)}` : p);
|
|
18
|
+
const HEADER = '# How I like work done (learned by Chompyy)\n\nFollow these. A section named after a project applies only in that project.';
|
|
19
|
+
/** The text Claude Code loads: your taste.md rules through the same filter as away runs (retired ones left out). */
|
|
20
|
+
export function daytimeText(rules = tasteForPrompt()) {
|
|
21
|
+
return rules ? `${HEADER}\n\n${rules}\n` : `${HEADER}\n\n(No rules yet: say yes to one in Chompyy.)\n`;
|
|
22
|
+
}
|
|
23
|
+
/** Rough size, so turning it on says what it costs at each session start (about 4 characters a token). */
|
|
24
|
+
export const daytimeTokens = (text) => Math.ceil(text.length / 4);
|
|
25
|
+
/** Rewrite Chompyy's own file when it's on. Called after every taste change. */
|
|
26
|
+
export function refreshDaytime() {
|
|
27
|
+
if (!daytimeState().on)
|
|
28
|
+
return;
|
|
29
|
+
const path = daytimeFile();
|
|
30
|
+
const text = daytimeText();
|
|
31
|
+
if (!existsSync(path) || readFileSync(path, 'utf8') !== text)
|
|
32
|
+
writeFileSync(path, text);
|
|
33
|
+
}
|
|
34
|
+
/** CLAUDE.md text with the chompyy:taste block taken out, and the blank line before it. */
|
|
35
|
+
export function removeBlock(text) {
|
|
36
|
+
const start = text.indexOf(AGENTS_START);
|
|
37
|
+
const end = text.indexOf(AGENTS_END);
|
|
38
|
+
if (start < 0 || end < start)
|
|
39
|
+
return text;
|
|
40
|
+
const before = text.slice(0, start).replace(/\n+$/, text.slice(0, start).trim() ? '\n' : '');
|
|
41
|
+
const after = text.slice(end + AGENTS_END.length).replace(/^\n/, '');
|
|
42
|
+
return before + (before && after ? '\n' : '') + after;
|
|
43
|
+
}
|
|
44
|
+
export function setDaytime(on, claudeMd = claudeMdPath()) {
|
|
45
|
+
const before = existsSync(claudeMd) ? readFileSync(claudeMd, 'utf8') : null;
|
|
46
|
+
const shown = tilde(claudeMd);
|
|
47
|
+
if (on) {
|
|
48
|
+
writeJson(statePath(), { on: true, claudeMd });
|
|
49
|
+
const text = daytimeText();
|
|
50
|
+
writeFileSync(daytimeFile(), text);
|
|
51
|
+
const after = renderAgentsBlock(before ?? '', `@${tilde(daytimeFile())}`);
|
|
52
|
+
if (after !== before) {
|
|
53
|
+
if (before !== null)
|
|
54
|
+
writeFileSync(`${claudeMd}.chompyy-backup`, before);
|
|
55
|
+
mkdirSync(dirname(claudeMd), { recursive: true });
|
|
56
|
+
writeFileSync(claudeMd, after);
|
|
57
|
+
}
|
|
58
|
+
return `Taste in everyday sessions on: new Claude Code sessions load your rules (~${daytimeTokens(text)} tokens each start).\nOne import line in ${shown}; nothing else there changed.`;
|
|
59
|
+
}
|
|
60
|
+
writeJson(statePath(), { on: false });
|
|
61
|
+
rmSync(daytimeFile(), { force: true });
|
|
62
|
+
if (before !== null) {
|
|
63
|
+
const after = removeBlock(before);
|
|
64
|
+
if (after !== before)
|
|
65
|
+
writeFileSync(claudeMd, after);
|
|
66
|
+
}
|
|
67
|
+
return `Taste in everyday sessions off: Chompyy's line is out of ${shown}. Away runs still use your taste.`;
|
|
68
|
+
}
|
package/dist/didwork.js
CHANGED
|
@@ -411,6 +411,52 @@ function shareLabel(a) {
|
|
|
411
411
|
return 'MEMORY.md compressed';
|
|
412
412
|
return 'Other fix';
|
|
413
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Only what was counted goes in: each stop's next request, and each re-counted fix times the sessions that started
|
|
416
|
+
* after it (every stop since the first, even across an off-and-on, unlike the verdict's clean before). Before-vs-after readings (habits, the cold-return trend) can't separate a fix from the rest of the week,
|
|
417
|
+
* so they stay beside the total, never in it (M1). A settings change altered since isn't claimed (M3).
|
|
418
|
+
*/
|
|
419
|
+
export function savedTotal(cards, stops, s, now) {
|
|
420
|
+
const counted = cards.filter((c) => {
|
|
421
|
+
const r = c.advice?.result;
|
|
422
|
+
return r?.method === 'recount' && r.per === 'session start' && r.saved !== undefined && r.verdict !== 'cant-tell' && r.verdict !== 'too-early' && (r.provenance ?? 'intact') === 'intact';
|
|
423
|
+
});
|
|
424
|
+
if (!counted.length && !stops)
|
|
425
|
+
return null;
|
|
426
|
+
let tokens = 0;
|
|
427
|
+
let starts = 0;
|
|
428
|
+
for (const c of counted) {
|
|
429
|
+
const n = sessionsIn(s, startOf(c), now + 1).length;
|
|
430
|
+
starts += n;
|
|
431
|
+
tokens += c.advice.result.saved * n;
|
|
432
|
+
}
|
|
433
|
+
const nudge = stops?.saved ?? 0;
|
|
434
|
+
const since = Math.min(...counted.map(startOf), stops?.since ?? Infinity);
|
|
435
|
+
const total = nudge + tokens;
|
|
436
|
+
const parts = [
|
|
437
|
+
...(stops ? [`live suggestions ~${k(nudge)}`] : []),
|
|
438
|
+
...(counted.length ? [`${plural(counted.length, 'fix', 'fixes')} ~${k(tokens)} over ${plural(starts, 'session start')}`] : []),
|
|
439
|
+
];
|
|
440
|
+
const head = total >= 0 ? `Saved so far: ~${k(total)} tokens since ${day(since)}` : `Cost so far: ~${k(-total)} tokens since ${day(since)}`;
|
|
441
|
+
return { tokens: total, since: new Date(since).toISOString(), nudge, fixes: { count: counted.length, tokens, starts }, line: `${head} (${parts.join(', ')}).` };
|
|
442
|
+
}
|
|
443
|
+
/** Live suggestions' proof and the running total, from one transcript scan long enough for both. */
|
|
444
|
+
export function savedSoFar(cards, now, opts = {}) {
|
|
445
|
+
const events = loadNudges();
|
|
446
|
+
const since = nudgeOnSince(events);
|
|
447
|
+
// The total counts every stop, the same way as the panel's "saved this week" line; the verdict keeps its own start.
|
|
448
|
+
const counted = [...outcomes(events), ...warnOutcomes(events)];
|
|
449
|
+
const stops = counted.length ? { saved: counted.reduce((a, o) => a + o.saved, 0), since: Math.min(...counted.map((o) => Date.parse(o.event.at))) } : null;
|
|
450
|
+
const starts = cards.filter((c) => c.advice?.result?.method === 'recount').map(startOf);
|
|
451
|
+
const earliest = Math.min(since ?? Infinity, stops?.since ?? Infinity, ...starts);
|
|
452
|
+
if (earliest === Infinity)
|
|
453
|
+
return { proof: null, total: null };
|
|
454
|
+
const t = now.getTime();
|
|
455
|
+
const root = opts.root ?? projectsDir();
|
|
456
|
+
const s = scan({ days: Math.max(30, Math.ceil((t - earliest) / DAY) + 8), now, root });
|
|
457
|
+
const proof = (opts.on ?? true) && since ? nudgeProof(now, { root, events, s }) : null;
|
|
458
|
+
return { proof, total: savedTotal(cards, stops, s, t) };
|
|
459
|
+
}
|
|
414
460
|
const VERDICT_WORD = { 'too-early': 'too early', worked: 'worked', short: 'fell short', 'no-change': 'no change', worse: 'went the wrong way', 'cant-tell': "can't tell" };
|
|
415
461
|
/** The numbers only: before → after, the method, the verdict or the day it comes. */
|
|
416
462
|
function shareNumbers(a, r) {
|
package/dist/learning.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const WEEK = 7 * 86_400_000;
|
|
2
|
+
/** Conversations read in each week before the correction rate is compared. */
|
|
3
|
+
export const MIN_READ = 5;
|
|
4
|
+
export function learning(store, signals, readThrough, waiting, now) {
|
|
5
|
+
const t = now.getTime();
|
|
6
|
+
const inWeek = (at, back) => {
|
|
7
|
+
const x = Date.parse(at);
|
|
8
|
+
return x >= t - (back + 1) * WEEK && x < t - back * WEEK;
|
|
9
|
+
};
|
|
10
|
+
const active = store.prefs.filter((p) => p.status === 'active');
|
|
11
|
+
const learnedThisWeek = active.filter((p) => p.validFrom && inWeek(p.validFrom, 0)).length;
|
|
12
|
+
const chats = signals.filter((s) => s.kind === 'chat');
|
|
13
|
+
const reads = Object.values(readThrough);
|
|
14
|
+
const c = {
|
|
15
|
+
thisWeek: chats.filter((s) => inWeek(s.at, 0)).length,
|
|
16
|
+
lastWeek: chats.filter((s) => inWeek(s.at, 1)).length,
|
|
17
|
+
readThisWeek: reads.filter((at) => inWeek(at, 0)).length,
|
|
18
|
+
readLastWeek: reads.filter((at) => inWeek(at, 1)).length,
|
|
19
|
+
perThis: null,
|
|
20
|
+
perLast: null,
|
|
21
|
+
};
|
|
22
|
+
if (c.readThisWeek >= MIN_READ && c.readLastWeek >= MIN_READ) {
|
|
23
|
+
c.perThis = c.thisWeek / c.readThisWeek;
|
|
24
|
+
c.perLast = c.lastWeek / c.readLastWeek;
|
|
25
|
+
}
|
|
26
|
+
const rules = (n) => `${n} rule${n === 1 ? '' : 's'}`;
|
|
27
|
+
const head = active.length
|
|
28
|
+
? `Chompyy learned ${learnedThisWeek ? `${rules(learnedThisWeek)} this week (${active.length} in all)` : `${rules(active.length)} so far, none new this week`}`
|
|
29
|
+
: 'Chompyy has no rules yet';
|
|
30
|
+
const wait = waiting ? `; ${waiting} wait${waiting === 1 ? 's' : ''} for your yes` : '';
|
|
31
|
+
const rate = c.perThis !== null && c.perLast !== null
|
|
32
|
+
? ` Corrections per conversation: ${c.perLast.toFixed(1)} → ${c.perThis.toFixed(1)}.`
|
|
33
|
+
: ` Corrections per conversation: not enough read yet (${c.readThisWeek} this week, needs ${MIN_READ}).`;
|
|
34
|
+
return { learned: active.length, learnedThisWeek, waiting, corrections: c, line: `${head}${wait}.${rate}` };
|
|
35
|
+
}
|
package/dist/send.js
CHANGED
|
@@ -20,13 +20,15 @@ const tryGit = (dir, args) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
/** The merge commit Keep makes (review.ts keepCard). */
|
|
23
|
-
const KEEP = /^Keep Chompyy card #(\S+): (.*)$/;
|
|
24
|
-
|
|
23
|
+
export const KEEP = /^Keep Chompyy card #(\S+): (.*)$/;
|
|
24
|
+
/** The commit Undo after Keep makes when other commits came after the card (unkeep.ts): it reverses that Keep. */
|
|
25
|
+
export const UNDO = /^Undo Chompyy card #(\S+): (.*)$/;
|
|
26
|
+
export const sentPath = () => homePath('sent.json');
|
|
25
27
|
/** The repo's one .git folder, as a real path: every folder of the repo (and /var vs /private/var) agrees on it. */
|
|
26
28
|
const commonDir = (repo) => realpathSync(resolve(repo, git(repo, ['rev-parse', '--git-common-dir'])));
|
|
27
|
-
const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
29
|
+
export const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
28
30
|
/** The PRs Send opened for this branch, by card id (a record from before per-card PRs has none). */
|
|
29
|
-
const sentCards = (repo, branch) => (readJson(sentPath(), {})[sentKey(repo, branch)]?.cards ?? {});
|
|
31
|
+
export const sentCards = (repo, branch) => (readJson(sentPath(), {})[sentKey(repo, branch)]?.cards ?? {});
|
|
30
32
|
export const cardBranch = (id) => `chompyy/card-${id}`;
|
|
31
33
|
/** The branches kept cards landed on: one per repo and branch, however many folders the repo has. */
|
|
32
34
|
export function landings(cards) {
|
|
@@ -51,7 +53,7 @@ export function landings(cards) {
|
|
|
51
53
|
return [...out.values()];
|
|
52
54
|
}
|
|
53
55
|
/** Where `branch` goes on GitHub: its upstream's remote and branch, or null when it has none. */
|
|
54
|
-
function upstreamOf(repo, branch) {
|
|
56
|
+
export function upstreamOf(repo, branch) {
|
|
55
57
|
const remote = tryGit(repo, ['config', `branch.${branch}.remote`]);
|
|
56
58
|
const merge = tryGit(repo, ['config', `branch.${branch}.merge`]);
|
|
57
59
|
if (!remote || remote === '.' || !merge?.startsWith('refs/heads/'))
|
|
@@ -67,18 +69,41 @@ export function outbox(repo, branch) {
|
|
|
67
69
|
return outboxAt(repo, branch, up.remote, up.base, tip);
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
+
* The branch's own line (first parent) since GitHub's base: Keep's merges still in effect, oldest first, and your own
|
|
73
|
+
* commits. A Keep followed by an Undo of that card is out (a card kept again after its Undo is back in), and the
|
|
74
|
+
* Undo commit isn't counted as yours: together they change nothing.
|
|
72
75
|
*/
|
|
73
|
-
function
|
|
74
|
-
const keeps =
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
function ownLine(repo, tip, upstream) {
|
|
77
|
+
const keeps = [];
|
|
78
|
+
const undone = new Map();
|
|
79
|
+
let own = 0;
|
|
80
|
+
for (const line of git(repo, ['log', '--first-parent', '--format=%P%x09%s', tip, `^${upstream}`]).split('\n')) {
|
|
81
|
+
if (!line)
|
|
82
|
+
continue;
|
|
77
83
|
const tab = line.indexOf('\t');
|
|
78
84
|
const parents = line.slice(0, tab).split(' ');
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
const subject = line.slice(tab + 1);
|
|
86
|
+
const keep = parents.length > 1 ? KEEP.exec(subject) : null;
|
|
87
|
+
const undo = parents.length === 1 ? UNDO.exec(subject) : null;
|
|
88
|
+
if (undo)
|
|
89
|
+
undone.set(undo[1], (undone.get(undo[1]) ?? 0) + 1);
|
|
90
|
+
else if (keep && parents[1]) {
|
|
91
|
+
const left = undone.get(keep[1]) ?? 0;
|
|
92
|
+
if (left)
|
|
93
|
+
undone.set(keep[1], left - 1); // the newest Undo after it took this Keep back
|
|
94
|
+
else
|
|
95
|
+
keeps.unshift({ id: keep[1], title: keep[2], tip: parents[1] });
|
|
96
|
+
}
|
|
97
|
+
else if (parents.length === 1)
|
|
98
|
+
own++;
|
|
99
|
+
}
|
|
100
|
+
return { keeps, own };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Keep's merges still in effect on the branch whose card isn't on GitHub's base yet. A card counts as there once its
|
|
104
|
+
* own commits are, however they got there: its PR, or an older Send that carried all of main.
|
|
105
|
+
*/
|
|
106
|
+
function unsentKeeps(repo, keeps, upstream) {
|
|
82
107
|
if (!keeps.length)
|
|
83
108
|
return [];
|
|
84
109
|
const missing = new Set(git(repo, ['rev-list', ...keeps.map((k) => k.tip), `^${upstream}`]).split('\n'));
|
|
@@ -87,11 +112,12 @@ function unsentKeeps(repo, tip, upstream) {
|
|
|
87
112
|
function outboxAt(repo, branch, remote, base, tip) {
|
|
88
113
|
const upstream = `refs/remotes/${remote}/${base}`;
|
|
89
114
|
const sent = sentCards(repo, branch);
|
|
90
|
-
const
|
|
115
|
+
const line = ownLine(repo, tip, upstream);
|
|
116
|
+
const cards = unsentKeeps(repo, line.keeps, upstream).map((k) => {
|
|
91
117
|
const rec = sent[k.id];
|
|
92
118
|
return { ...k, pr: rec && rec.tip === k.tip ? { number: rec.number, url: rec.url } : null };
|
|
93
119
|
});
|
|
94
|
-
const own =
|
|
120
|
+
const own = line.own;
|
|
95
121
|
return { repo, branch, remote, base, cards, fresh: cards.filter((c) => !c.pr), own };
|
|
96
122
|
}
|
|
97
123
|
/** Every landing branch with kept cards GitHub doesn't have, for the app (`chompyy state`). */
|
|
@@ -152,9 +178,9 @@ export function checksOf(card) {
|
|
|
152
178
|
const result = card?.run?.verified?.result ?? card?.run?.checks?.result;
|
|
153
179
|
return result === 'passed' ? 'checks passed' : result === 'failed' ? 'checks failed' : null;
|
|
154
180
|
}
|
|
155
|
-
const realGh = (repo, args, input) => execFileSync(exe('gh'), args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
181
|
+
export const realGh = (repo, args, input) => execFileSync(exe('gh'), args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
156
182
|
/** The folder that has `branch` checked out, if any. */
|
|
157
|
-
function folderWith(repo, branch) {
|
|
183
|
+
export function folderWith(repo, branch) {
|
|
158
184
|
for (const b of git(repo, ['worktree', 'list', '--porcelain']).split('\n\n')) {
|
|
159
185
|
const dir = b.match(/^worktree (.+)$/m)?.[1];
|
|
160
186
|
if (dir && b.includes(`\nbranch refs/heads/${branch}`))
|
|
@@ -171,10 +197,10 @@ function catchUp(repo, branch, upstream, base, tip) {
|
|
|
171
197
|
const there = git(repo, ['rev-parse', upstream]);
|
|
172
198
|
if (tip === there)
|
|
173
199
|
return { message: `${done}.`, url: null };
|
|
174
|
-
const own =
|
|
200
|
+
const own = ownLine(repo, tip, upstream).own;
|
|
175
201
|
if (own)
|
|
176
202
|
return { message: `${done}. Push your own ${plural(own, 'commit')} on ${branch} yourself: Send only carries kept cards.`, url: null };
|
|
177
|
-
// Your branch may only add Keep's merges: merged into GitHub's base, it would change nothing.
|
|
203
|
+
// Your branch may only add Keep's merges (and Undos of them): merged into GitHub's base, it would change nothing.
|
|
178
204
|
const merged = tryGit(repo, ['merge-tree', '--write-tree', upstream, tip])?.split('\n')[0];
|
|
179
205
|
if (merged !== git(repo, ['rev-parse', `${upstream}^{tree}`]))
|
|
180
206
|
return { message: `${done}. Your ${branch} differs from GitHub's: run git pull there.`, url: null };
|
package/dist/taste.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// - Never silently deleted: contradicted or removed preferences are retired with the reason and evidence.
|
|
9
9
|
// - Your edits win: delete a learned line from taste.md and the preference is retired.
|
|
10
10
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { refreshDaytime } from './daytime.js';
|
|
11
12
|
import { appendJsonl, homePath, readJson, writeJson } from './home.js';
|
|
12
13
|
// ---------- taste.md ----------
|
|
13
14
|
export const TASTE_STUB = `# taste.md
|
|
@@ -51,19 +52,76 @@ export function tasteForPrompt() {
|
|
|
51
52
|
const path = tastePath();
|
|
52
53
|
if (!existsSync(path))
|
|
53
54
|
return '';
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
return promptLines(readFileSync(path, 'utf8'), retiredIds()).join('\n').replace(/(## [^\n]+\n)(?=## |$)/g, '').trim();
|
|
56
|
+
}
|
|
57
|
+
function retiredIds() {
|
|
58
|
+
return new Set(loadStore().prefs.filter((p) => p.status === 'retired').map((p) => p.id));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The line filter agents see: bullets and "## " headings only, retired ids dropped, "(learned …)" tails cut.
|
|
62
|
+
* Empty when there are headings but no preferences.
|
|
63
|
+
*/
|
|
64
|
+
function promptLines(text, retired) {
|
|
65
|
+
const kept = text
|
|
56
66
|
.split('\n')
|
|
57
67
|
.filter((l) => {
|
|
58
68
|
const id = l.match(MARK)?.[1];
|
|
59
69
|
return !id || !retired.has(id);
|
|
60
70
|
})
|
|
61
|
-
.map((l) => l.replace(/\s+\((learned|from your history)[^)]*\)\s*$/, ''))
|
|
62
|
-
|
|
71
|
+
.map((l) => l.replace(/\s+\((learned|from your history)[^)]*\)\s*$/, ''))
|
|
72
|
+
.filter((l) => /^\s*[-*]\s+\S/.test(l) || l.startsWith('## '));
|
|
63
73
|
// Only headings, no preferences: nothing to say.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
return kept.some((l) => !l.startsWith('## ')) ? kept : [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* One project's rules from taste.md text: the "## Everywhere" section plus the "## <project>" section, through
|
|
78
|
+
* the same filter as tasteForPrompt(). Sections with no rules are left out. Empty when neither has a rule.
|
|
79
|
+
*/
|
|
80
|
+
export function tasteRulesFor(text, project, retired = new Set()) {
|
|
81
|
+
const wanted = new Set(['Everywhere', project.trim()]);
|
|
82
|
+
const sections = [];
|
|
83
|
+
let current = null;
|
|
84
|
+
for (const line of promptLines(text, retired)) {
|
|
85
|
+
if (line.startsWith('## ')) {
|
|
86
|
+
current = wanted.has(line.slice(3).trim()) ? [line] : null;
|
|
87
|
+
if (current)
|
|
88
|
+
sections.push(current);
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
current?.push(line);
|
|
92
|
+
}
|
|
93
|
+
return sections
|
|
94
|
+
.filter((s) => s.length > 1)
|
|
95
|
+
.map((s) => s.join('\n'))
|
|
96
|
+
.join('\n\n');
|
|
97
|
+
}
|
|
98
|
+
/** tasteRulesFor() on the real taste.md, with retired preferences left out. */
|
|
99
|
+
export function tasteRulesForProject(project) {
|
|
100
|
+
const path = tastePath();
|
|
101
|
+
return existsSync(path) ? tasteRulesFor(readFileSync(path, 'utf8'), project, retiredIds()) : '';
|
|
102
|
+
}
|
|
103
|
+
export const AGENTS_START = '<!-- chompyy:taste:start -->';
|
|
104
|
+
export const AGENTS_END = '<!-- chompyy:taste:end -->';
|
|
105
|
+
/**
|
|
106
|
+
* AGENTS.md text with `rules` between the chompyy taste markers. Replaces an existing block, or appends one at
|
|
107
|
+
* the end. Everything outside the markers is kept byte for byte, so the same rules give back the same text.
|
|
108
|
+
* Throws when the markers are broken (a start without an end, or doubled), rather than guess.
|
|
109
|
+
*/
|
|
110
|
+
export function renderAgentsBlock(text, rules) {
|
|
111
|
+
const block = `${AGENTS_START}\n${rules.trim()}\n${AGENTS_END}`;
|
|
112
|
+
const start = text.indexOf(AGENTS_START);
|
|
113
|
+
const end = text.indexOf(AGENTS_END);
|
|
114
|
+
const count = (m) => text.split(m).length - 1;
|
|
115
|
+
if (start < 0 && end < 0) {
|
|
116
|
+
if (text === '')
|
|
117
|
+
return `${block}\n`;
|
|
118
|
+
const sep = text.endsWith('\n\n') ? '' : text.endsWith('\n') ? '\n' : '\n\n';
|
|
119
|
+
return `${text}${sep}${block}\n`;
|
|
120
|
+
}
|
|
121
|
+
if (start < 0 || end < start || count(AGENTS_START) > 1 || count(AGENTS_END) > 1) {
|
|
122
|
+
throw new Error(`The chompyy taste markers are broken: keep one ${AGENTS_START} line before one ${AGENTS_END} line. Nothing changed.`);
|
|
123
|
+
}
|
|
124
|
+
return text.slice(0, start) + block + text.slice(end + AGENTS_END.length);
|
|
67
125
|
}
|
|
68
126
|
const DAY_MS = 86_400_000;
|
|
69
127
|
/**
|
|
@@ -494,6 +552,8 @@ export function syncTasteFile(now) {
|
|
|
494
552
|
if (out !== text)
|
|
495
553
|
writeFileSync(path, out);
|
|
496
554
|
saveStore(store);
|
|
555
|
+
// Everyday sessions see the change from their next start (only when you turned that on).
|
|
556
|
+
refreshDaytime();
|
|
497
557
|
return retiredByYou;
|
|
498
558
|
}
|
|
499
559
|
// ---------- views ----------
|
package/dist/unkeep.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Undo after Keep (2026-12-01). Keep merges a card into your local main and Send gives it its own PR, but the only way
|
|
2
|
+
// back was a git command printed by Keep, which only worked right after Keep and never on GitHub. This takes one kept
|
|
3
|
+
// card back wherever it got to, and leaves the cards kept around it alone:
|
|
4
|
+
// - only on this Mac: off your branch (moved back one step when it's the newest, else one Undo commit that reverses
|
|
5
|
+
// it, built off to the side like Keep so your folder never sits in a conflict). Its PR is closed if one is open.
|
|
6
|
+
// - on GitHub's main (its PR merged): a revert PR there (`gh pr revert`); your branch follows when you pull.
|
|
7
|
+
// Send skips a card whose Keep is followed by its Undo (send.ts ownLine), so an undone card is never sent.
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { readJson, writeJson } from './home.js';
|
|
10
|
+
import { gitRoot } from './workspace.js';
|
|
11
|
+
import { exe } from './exe.js';
|
|
12
|
+
import { KEEP, UNDO, folderWith, githubRepo, realGh, sentCards, sentKey, sentPath, upstreamOf } from './send.js';
|
|
13
|
+
const git = (dir, args) => execFileSync(exe('git'), ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
14
|
+
const tryGit = (dir, args) => {
|
|
15
|
+
try {
|
|
16
|
+
return git(dir, args);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const firstLine = (e) => String(e.stderr || e.message).trim().split('\n')[0].replace(/^(error|fatal): /, '');
|
|
23
|
+
const words = (xs) => (xs.length < 3 ? xs.join(' and ') : `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}`);
|
|
24
|
+
function find(card) {
|
|
25
|
+
if (card.outcome !== 'kept')
|
|
26
|
+
throw new Error(`Card #${card.id} isn't kept, so there's nothing to take back.`);
|
|
27
|
+
const repo = gitRoot(card.cwd);
|
|
28
|
+
if (!repo)
|
|
29
|
+
throw new Error(`${card.cwd} is no longer a git repo.`);
|
|
30
|
+
const branch = card.run?.base?.branch ?? tryGit(repo, ['symbolic-ref', '--short', 'HEAD']);
|
|
31
|
+
if (!branch)
|
|
32
|
+
throw new Error(`Can't tell which branch card #${card.id} was kept on. Nothing was changed.`);
|
|
33
|
+
const id = card.id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
34
|
+
// The newest Keep or Undo of this card on the branch's own line.
|
|
35
|
+
const latest = tryGit(repo, ['log', '--first-parent', '-E', `--grep=^(Keep|Undo) Chompyy card #${id}: `, '--format=%H %P%x09%s', '-1', `refs/heads/${branch}`]);
|
|
36
|
+
let merge = null;
|
|
37
|
+
let tip = null;
|
|
38
|
+
if (latest) {
|
|
39
|
+
const tab = latest.indexOf('\t');
|
|
40
|
+
const [sha, , second] = latest.slice(0, tab).split(' ');
|
|
41
|
+
if (UNDO.test(latest.slice(tab + 1)))
|
|
42
|
+
throw new Error(`Card #${card.id} is already undone on ${branch}.`);
|
|
43
|
+
if (KEEP.test(latest.slice(tab + 1)) && second)
|
|
44
|
+
[merge, tip] = [sha, second];
|
|
45
|
+
}
|
|
46
|
+
const up = upstreamOf(repo, branch);
|
|
47
|
+
const slug = up ? githubRepo(tryGit(repo, ['config', `remote.${up.remote}.url`]) ?? '') : null;
|
|
48
|
+
const sent = sentCards(repo, branch)[card.id] ?? null;
|
|
49
|
+
return { repo, branch, merge, tip: tip ?? sent?.tip ?? null, up, slug, sent };
|
|
50
|
+
}
|
|
51
|
+
const upstreamRef = (f) => {
|
|
52
|
+
if (!f.up)
|
|
53
|
+
return null;
|
|
54
|
+
const ref = `refs/remotes/${f.up.remote}/${f.up.base}`;
|
|
55
|
+
return tryGit(f.repo, ['rev-parse', '--verify', '-q', ref]) ? ref : null;
|
|
56
|
+
};
|
|
57
|
+
const onGithub = (f) => {
|
|
58
|
+
const upstream = upstreamRef(f);
|
|
59
|
+
return !!(f.tip && upstream && tryGit(f.repo, ['merge-base', '--is-ancestor', f.tip, upstream]) !== null);
|
|
60
|
+
};
|
|
61
|
+
/** Later kept cards on the branch that started on top of this one: their own work carries this card's commits. */
|
|
62
|
+
function builtOn(f, head) {
|
|
63
|
+
if (!f.merge || !f.tip || head === f.merge)
|
|
64
|
+
return [];
|
|
65
|
+
return git(f.repo, ['log', '--first-parent', '--merges', '--reverse', '--format=%P%x09%s', `${f.merge}..${head}`])
|
|
66
|
+
.split('\n')
|
|
67
|
+
.flatMap((line) => {
|
|
68
|
+
const tab = line.indexOf('\t');
|
|
69
|
+
const second = line.slice(0, tab).split(' ')[1];
|
|
70
|
+
const m = KEEP.exec(line.slice(tab + 1));
|
|
71
|
+
return m && second && tryGit(f.repo, ['merge-base', '--is-ancestor', f.tip, second]) !== null ? [m[1]] : [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const builtOnNote = (ids, id) => ids.length ? `Undo card${ids.length === 1 ? '' : 's'} ${words(ids)} too, or ${ids.length === 1 ? 'its' : 'their'} PR brings this work back: ${ids.length === 1 ? 'it was' : 'they were'} built on card ${id}.` : '';
|
|
75
|
+
function planFrom(card, f) {
|
|
76
|
+
if (onGithub(f)) {
|
|
77
|
+
const base = f.up.base;
|
|
78
|
+
if (!f.sent || !f.slug)
|
|
79
|
+
throw new Error(`Revert card ${card.id} on GitHub by hand: it reached ${base} without its own PR, so Chompyy can't take it back alone. Nothing was changed.`);
|
|
80
|
+
return { how: 'revert-pr', line: `Opens a PR on GitHub that reverts PR #${f.sent.number}, which landed card ${card.id} on ${base}. Your ${f.branch} follows once you merge it and pull.` };
|
|
81
|
+
}
|
|
82
|
+
if (!f.merge)
|
|
83
|
+
throw new Error(`Can't find card ${card.id}'s Keep on ${f.branch}: it was reset away or never landed there. Nothing was changed.`);
|
|
84
|
+
const head = git(f.repo, ['rev-parse', `refs/heads/${f.branch}`]);
|
|
85
|
+
const after = head === f.merge ? 0 : Number(git(f.repo, ['rev-list', '--count', '--first-parent', `${f.merge}..${head}`]));
|
|
86
|
+
const take = after
|
|
87
|
+
? `takes card ${card.id} off your ${f.branch} with one Undo commit (${after === 1 ? 'the commit after it stays' : `the ${after} commits after it stay`})`
|
|
88
|
+
: `takes card ${card.id} off your ${f.branch}: it moves back one step, to before the Keep`;
|
|
89
|
+
const first = f.sent ? `Closes PR #${f.sent.number}, then ${take}.` : `${take[0].toUpperCase()}${take.slice(1)}.`;
|
|
90
|
+
return { how: after ? 'reverted' : 'dropped', line: [first, builtOnNote(builtOn(f, head), card.id)].filter(Boolean).join('\n') };
|
|
91
|
+
}
|
|
92
|
+
/** What Undo Keep would do, from what this Mac last fetched (no network, nothing changed). */
|
|
93
|
+
export function planUnkeep(card) {
|
|
94
|
+
return planFrom(card, find(card));
|
|
95
|
+
}
|
|
96
|
+
/** `git merge-tree` of three commits: the merged tree, or the files that conflict. */
|
|
97
|
+
function mergeTree(repo, base, ours, theirs) {
|
|
98
|
+
try {
|
|
99
|
+
return { tree: git(repo, ['merge-tree', '--write-tree', '--name-only', `--merge-base=${base}`, ours, theirs]).split('\n')[0] };
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
const out = String(e.stdout ?? '');
|
|
103
|
+
if (e.status !== 1 || !out)
|
|
104
|
+
throw e;
|
|
105
|
+
const files = [];
|
|
106
|
+
for (const l of out.split('\n').slice(1)) {
|
|
107
|
+
if (!l)
|
|
108
|
+
break;
|
|
109
|
+
files.push(l);
|
|
110
|
+
}
|
|
111
|
+
return { files: [...new Set(files)] };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** Who changed `files` after the card's Keep: "card 36", or your own commit. */
|
|
115
|
+
function inTheWay(f, head, files) {
|
|
116
|
+
const subjects = git(f.repo, ['log', '--first-parent', '--format=%s', `${f.merge}..${head}`, '--', ...files]).split('\n').filter(Boolean);
|
|
117
|
+
const last = subjects.at(-1) ?? ''; // the first one after the card's Keep
|
|
118
|
+
const keep = KEEP.exec(last) ?? UNDO.exec(last);
|
|
119
|
+
return keep ? { card: keep[1], what: `card ${keep[1]}` } : { card: null, what: `your commit "${last}"` };
|
|
120
|
+
}
|
|
121
|
+
function revertOnGithub(card, f, gh) {
|
|
122
|
+
const n = String(f.sent.number);
|
|
123
|
+
const slug = f.slug;
|
|
124
|
+
const base = f.up.base;
|
|
125
|
+
let state;
|
|
126
|
+
try {
|
|
127
|
+
state = JSON.parse(gh(f.repo, ['pr', 'view', n, '--repo', slug, '--json', 'state'])).state;
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
throw new Error(`Install GitHub's gh and sign in first (brew install gh, then gh auth login): ${firstLine(e)}. Nothing was changed.`);
|
|
131
|
+
}
|
|
132
|
+
if (state !== 'MERGED')
|
|
133
|
+
throw new Error(`Revert card ${card.id} on GitHub by hand: its work is on ${base}, but PR #${n} didn't merge it. Nothing was changed.`);
|
|
134
|
+
const body = `Undoes kept card ${card.id} (${card.title}), which PR #${n} landed on ${base}. Opened by Undo Keep in Chompyy.\n`;
|
|
135
|
+
let url;
|
|
136
|
+
try {
|
|
137
|
+
url = gh(f.repo, ['pr', 'revert', n, '--repo', slug, '--title', `Undo kept card ${card.id}: ${card.title}`, '--body-file', '-'], body).split('\n').pop().trim();
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
throw new Error(`Revert PR #${n} on GitHub by hand: gh couldn't (${firstLine(e)}). Nothing was changed.`);
|
|
141
|
+
}
|
|
142
|
+
const number = Number(/\/pull\/(\d+)/.exec(url)?.[1] ?? 0);
|
|
143
|
+
return {
|
|
144
|
+
message: `Merge ${number ? `PR #${number}` : 'the revert PR'} on GitHub to undo card ${card.id}: it reverts PR #${n}. Your ${f.branch} follows when you pull.\n${url}`,
|
|
145
|
+
unkept: { how: 'revert-pr', ...(number ? { pr: { number, url } } : {}) },
|
|
146
|
+
url,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** Close the card's PR (its work was taken back before it merged) and forget it, so Send never brings it back. */
|
|
150
|
+
function closePr(card, f, gh) {
|
|
151
|
+
const n = f.sent.number;
|
|
152
|
+
const all = readJson(sentPath(), {});
|
|
153
|
+
delete all[sentKey(f.repo, f.branch)]?.cards?.[card.id];
|
|
154
|
+
writeJson(sentPath(), all);
|
|
155
|
+
if (!f.slug)
|
|
156
|
+
return { note: '' };
|
|
157
|
+
try {
|
|
158
|
+
const { state } = JSON.parse(gh(f.repo, ['pr', 'view', String(n), '--repo', f.slug, '--json', 'state']));
|
|
159
|
+
if (state !== 'OPEN')
|
|
160
|
+
return { note: '' };
|
|
161
|
+
gh(f.repo, ['pr', 'close', String(n), '--repo', f.slug, '--delete-branch', '--comment', `Undone in Chompyy: card ${card.id} was taken off ${f.branch} before this merged.`]);
|
|
162
|
+
return { closed: n, note: ` Closed PR #${n}.` };
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
return { note: ` Close PR #${n} on GitHub yourself: ${firstLine(e)}.` };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Undo Keep: take one kept card back, off your branch or with a revert PR on GitHub (see the top of this file). */
|
|
169
|
+
export function unkeep(card, deps = {}) {
|
|
170
|
+
const gh = deps.gh ?? realGh;
|
|
171
|
+
const f = find(card);
|
|
172
|
+
// GitHub's latest first: whether the card's PR merged there decides how it comes back.
|
|
173
|
+
if (f.up) {
|
|
174
|
+
try {
|
|
175
|
+
git(f.repo, ['fetch', '-q', f.up.remote, `+refs/heads/${f.up.base}:refs/remotes/${f.up.remote}/${f.up.base}`]);
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
if (f.sent)
|
|
179
|
+
throw new Error(`Connect to the internet and try again: card ${card.id} was sent to GitHub, and Chompyy has to see whether its PR merged (${firstLine(e)}). Nothing was changed.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const plan = planFrom(card, f);
|
|
183
|
+
if (plan.how === 'revert-pr')
|
|
184
|
+
return revertOnGithub(card, f, gh);
|
|
185
|
+
const merge = f.merge;
|
|
186
|
+
const head = git(f.repo, ['rev-parse', `refs/heads/${f.branch}`]);
|
|
187
|
+
const folder = folderWith(f.repo, f.branch);
|
|
188
|
+
let to;
|
|
189
|
+
if (plan.how === 'dropped') {
|
|
190
|
+
to = git(f.repo, ['rev-parse', `${merge}^1`]);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Reverse just this Keep on top of everything after it, without touching a folder: a conflict changes nothing.
|
|
194
|
+
const r = mergeTree(f.repo, merge, head, `${merge}^1`);
|
|
195
|
+
if ('files' in r) {
|
|
196
|
+
const who = inTheWay(f, head, r.files);
|
|
197
|
+
const shown = r.files.slice(0, 3).join(', ') + (r.files.length > 3 ? ` and ${r.files.length - 3} more` : '');
|
|
198
|
+
throw new Error(`${who.card ? `Undo card ${who.card} first` : `Take card ${card.id} back by hand`}: ${who.what} changed the same lines in ${shown} after card ${card.id}. Nothing was changed.`);
|
|
199
|
+
}
|
|
200
|
+
to = git(f.repo, ['commit-tree', r.tree, '-p', head, '-m', `Undo Chompyy card #${card.id}: ${card.title}`, '-m', `Reverses ${merge.slice(0, 7)}, the Keep of card #${card.id}.`]);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// In the folder that has the branch open, your unsaved changes stay; git refuses if they touch the same files.
|
|
204
|
+
if (folder)
|
|
205
|
+
git(folder, plan.how === 'dropped' ? ['reset', '-q', '--keep', to] : ['merge', '-q', '--ff-only', to]);
|
|
206
|
+
else
|
|
207
|
+
git(f.repo, ['update-ref', `refs/heads/${f.branch}`, to, head]);
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
throw new Error(`Commit or set aside your unsaved changes in ${folder ?? f.repo} first: they touch files card ${card.id} changed (${firstLine(e)}). Nothing was changed.`);
|
|
211
|
+
}
|
|
212
|
+
const pr = f.sent ? closePr(card, f, gh) : { note: '' };
|
|
213
|
+
const did = plan.how === 'dropped' ? `your ${f.branch} moved back one step, to before its Keep` : `one Undo commit on ${f.branch} reverses it, and the commits after it stay`;
|
|
214
|
+
const later = builtOnNote(builtOn(f, head), card.id);
|
|
215
|
+
return {
|
|
216
|
+
message: [`Undone #${card.id} after Keep: ${did}.${pr.note}`, later].filter(Boolean).join('\n'),
|
|
217
|
+
unkept: { how: plan.how, ...(pr.closed ? { closed: pr.closed } : {}) },
|
|
218
|
+
url: null,
|
|
219
|
+
};
|
|
220
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chompyy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Chompyy: runs the tasks you approve with the Claude Code 5-hour window you'd otherwise lose, then lets you review, keep and send them to GitHub. CLI behind the Chompyy Mac menu bar app.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
7
7
|
"claude",
|
|
8
8
|
"tokens",
|
|
9
9
|
"quota",
|
|
10
10
|
"agent",
|
|
11
|
-
"kanban"
|
|
11
|
+
"kanban",
|
|
12
|
+
"chompyy",
|
|
13
|
+
"anthropic",
|
|
14
|
+
"macos",
|
|
15
|
+
"menu-bar",
|
|
16
|
+
"ai-agent",
|
|
17
|
+
"coding-agent",
|
|
18
|
+
"usage-limits",
|
|
19
|
+
"productivity"
|
|
12
20
|
],
|
|
13
21
|
"homepage": "https://github.com/BranchWork-HQ/Chompyy#readme",
|
|
14
22
|
"bugs": {
|