From 23f2387f1d34c2e70f9f932d36aca34f52e5097a Mon Sep 17 00:00:00 2001 From: Louis Tissot Date: Wed, 4 Nov 2026 10:50:58 +0100 Subject: [PATCH] 0.2.1: an icon and a privacy link for the Claude directory, and a pause after a credit refusal - The plugin has an icon (.claude-plugin/icon.png) and a privacy policy link (privacyPolicyUrl). - The manifest no longer names hooks/hooks.json, which Claude Code always loads. - After 402 out-of-credits, the plugin pauses the refused operation and keeps unsent data on the machine. It checks the balance at most once every five minutes, and resumes when the balance covers the call. /past:status --refresh checks the balance now. What the plugin sends does not change. Co-Authored-By: Claude Opus 5.5 --- .claude-plugin/marketplace.json | 2 +- CLAUDE.md | 6 ++ plugins/past/.claude-plugin/icon.png | Bin 0 -> 4670 bytes plugins/past/.claude-plugin/plugin.json | 5 +- plugins/past/README.md | 9 +++ plugins/past/bin/past-hook.mjs | 74 +++++++++++++++++++++++- plugins/past/commands/status.md | 3 + 7 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 plugins/past/.claude-plugin/icon.png diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index b5b0265..7742924 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -10,7 +10,7 @@ "name": "past", "source": "./plugins/past", "description": "Your Claude Code sessions become memory, and every session starts briefed.", - "version": "0.2.0", + "version": "0.2.1", "author": { "name": "past.dev", "url": "https://past.dev" diff --git a/CLAUDE.md b/CLAUDE.md index dd363d4..d9f9290 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -34,6 +34,7 @@ Claude Code .claude-plugin/marketplace.json the catalog — this repository is the marketplace plugins/past/ .claude-plugin/plugin.json the manifest, including the settings form (userConfig) + .claude-plugin/icon.png the directory listing's icon, taken once at the first save hooks/hooks.json SessionStart, UserPromptSubmit, Stop, PreCompact, SessionEnd .mcp.json past_recall: the script's mcp mode, started by Claude Code bin/past-hook.mjs the whole connector, one file, no dependencies @@ -43,6 +44,11 @@ plugins/past/ .github/workflows/check.yml every pull request: the script parses and runs, the manifests validate ``` +Credit refusals persist per operation in this host's state book, under `creditPauses`. +Each pause stores a connection fingerprint, required credits, and the next balance check time. +Use `updateState` for every change. Keep transcript hashes and pending sessions intact on a refusal. +`status --refresh` reads `/api/v1/usage` before it clears a pause. A write pause leaves recall available. + ## The rules this code keeps 1. **A hook never breaks the session.** Every mode exits 0, prints valid JSON or nothing, and diff --git a/plugins/past/.claude-plugin/icon.png b/plugins/past/.claude-plugin/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7db7f9a4514033a7d4bc816991e90eb3e6aaea78 GIT binary patch literal 4670 zcmeI0`BzhC8pq#+1}uoEt)i^9PKQ>Oph&|~NGw+BSOH~;3LzjW7-R4t@Qo^PFXH*nDPAOoQt2_m;OVnK$Ap9Jgip<`k9WMDKih z*f#slALF{`FrIg>N4~VbIi{bs<7?C`$3C(v!O6t%<}HEDzvInXQWBajwCB~<1ieb@ zMKXMAmr9HC&OK?L=a!?wK0LeFo{1Wb4{Epatqr#X%GRC&7j*)maf57nXimgl@WmGf!Y5BuXKLV*hp8QQ%YQ zw;^Ftl(lSSn5(NREI?gW4(As2q@qU8gl*4o9;k&4J`QZvMGY@k(UlcdRaKzJNg|Qp zrO)-l8~8=19v#bY?!&@DLPHxDYlh0cP@l~Ceiuj#mo86mPmj-+Gb_1-LOtcjLWue}c* zOB66zaUVx@%&9bdQUc@`imZ>W4agBQ9a(54-(62#{Bj!#nEOVvd8 zg2Kn8&fvwghw*vPEFTdj&3n=bp`qr$=o{|#%41QsciO+QzYm5ABn1oq>dx-<>xv`lC;%yv@R+L7BIf&;Q6+D?#}j6 zAKNsHV(wVxwS<@g@rE$&>RpqMqc+eJfdY6!1l%DpdwV` zTIjiZ&M?i&sL7X%GfzI^go!+7{D@F{JjF2FS_#v9RvpS4jh{@F6XV9rsjo~aB$=3R zY;266Uau%9n1E`SKp-T_PssgY!?ArQi_n~X9=akyWn(xUxfq04Zu`RhFbXAq7EEm^ zsH|Li=W5E(l>2uJ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JIMA&hk3bN%0%gv|@L<|0gwm@1G}Slcs9BOC1lEj7ZCt`Bp;Wn0$$~ zJ_S<#eO4SjY$g&3#T_R&+)Z}k)^J#u8zKyV#*ACcH8lhiQx^w zQll`>@!C?RrLQ({9e}VfX}xg_7ukZC_TU=NFicI!;&+?a`AL`VpO#LhvuE>&**Q7w zfp){f*-|S9B(C9EF)a^fcOf`0VP=2&57Du`@$CS>W;f3Q9zcPE_H33L+uN##R%9?q zg`kI4cA}Z*PYknF62(fDTsgEYMkmCb8{SWA78gRhsRlhm$I^`6_x2u&nd#^~k!S-h z@c4v)xhU!87eHq4hn zlnBSTcRV;ac@wP&^z`)P+mPi?!l45I+|vthH1vM3Cax{OF{qAgTY*Y0WTphu-PFB2 zbE*@=uRdC(*kH@J%$l$v9}r*u^5x3}(F`u8)7FemiiQZ?4>W8td%bdPh^F8#oBd!jh(P{Pdezba{8#-=qL!-b21N-QyLYlvijV8I6wz_;3TjeJbKBzL{uQqbJ2 zaxsNvG1I+(< hashOf(`${config.apiUrl}\n${config.apiKey}`); +function creditPause(config, operation) { + const pauses = book(loadState()).creditPauses; + const pause = pauses && pauses[operation]; + return pause && pause.account === creditAccount(config) ? pause : null; +} + +async function checkCredits(config, operation, timeoutMs, force = false) { + const pause = creditPause(config, operation); + if (!pause) return true; + const now = Date.now(); + let claimed = false; + updateState((fresh) => { + const own = book(fresh); + const current = own.creditPauses && own.creditPauses[operation]; + if (current && current.account === pause.account && (force || current.nextCheck <= now)) { + current.nextCheck = now + CREDIT_CHECK_MS; + claimed = true; + } + }); + if (!claimed) return false; + const usage = await api(config, '/api/v1/usage', null, timeoutMs, 'GET'); + if (!usage || usage.error) return false; + const available = usage.metered === false || (usage.balance && + typeof usage.balance.left === 'number' && usage.balance.left >= pause.needed); + if (!available) return false; + updateState((fresh) => { + const own = book(fresh); + const current = own.creditPauses && own.creditPauses[operation]; + if (current && current.account === pause.account && current.at === pause.at) + delete own.creditPauses[operation]; + }); + return !creditPause(config, operation); +} + async function api(config, path, body, timeoutMs, method = 'POST') { if (!config.apiKey) return null; + const operation = method === 'POST' && ['/api/v1/ingest', '/api/v1/ingest/batch'].includes(path) ? 'ingest' + : method === 'POST' && path === '/api/v1/recall' ? 'recall' : null; + const started = Date.now(); + if (operation && !await checkCredits(config, operation, Math.min(timeoutMs, 2000))) + return { error: 402, body: JSON.stringify({ code: 'out-of-credits' }), paused: true }; + timeoutMs = Math.max(1, timeoutMs - (Date.now() - started)); const control = new AbortController(); const timer = setTimeout(() => control.abort(), timeoutMs); try { @@ -473,7 +516,23 @@ async function api(config, path, body, timeoutMs, method = 'POST') { body: body === null ? undefined : JSON.stringify(body), signal: control.signal, }); - if (!response.ok) return { error: response.status, body: await response.text().catch(() => '') }; + if (!response.ok) { + const text = await response.text().catch(() => ''); + let refusal; + try { refusal = JSON.parse(text); } catch { /* Keep the HTTP error. */ } + if (operation && response.status === 402 && refusal && refusal.code === 'out-of-credits') { + const needed = refusal.data && refusal.data.creditsNeeded; + updateState((fresh) => { + const own = book(fresh); + if (!own.creditPauses) own.creditPauses = {}; + own.creditPauses[operation] = { + account: creditAccount(config), at: Date.now(), nextCheck: Date.now() + CREDIT_CHECK_MS, + needed: typeof needed === 'number' && needed > 0 ? needed : 1, + }; + }); + } + return { error: response.status, body: text }; + } return await response.json().catch(() => ({})); } catch { return null; @@ -1255,13 +1314,18 @@ async function modeSearch(config, argv) { if (!config.apiKey) { console.log(`Not connected. Run ${commandOf('connect')} first.`); return; } if (!config.identity) { console.log(`No identity set. Run ${commandOf('connect')} to set one.`); return; } const memories = await recall(config, query, 8, 15000); + if (creditPause(config, 'recall')) { console.log(`Recall paused: insufficient credits. Run ${commandOf('status')} --refresh after you add credits.`); return; } if (!memories.length) { console.log('Nothing in past.dev matches that yet.'); return; } for (const [index, memory] of memories.entries()) { console.log(`[${index + 1}] ${(memory.at || '').slice(0, 10)} — ${memory.content.replace(/\s+/g, ' ').trim()}`); } } -function modeStatus(config) { +async function modeStatus(config, argv) { + if (argv.includes('--refresh')) { + for (const operation of ['ingest', 'recall']) + await checkCredits(config, operation, 2000, true); + } // Heals before it reports: a session left overdue by a dead or outdated waiter is sent now. try { ensureWaiters(); } catch { /* status still reports */ } const state = updateState((fresh) => tidyPending(fresh, config, '')); @@ -1299,6 +1363,10 @@ function modeStatus(config) { } lines.push(`Idle timer ${parts.join('; ')}`); } + for (const operation of ['ingest', 'recall']) { + if (creditPause(config, operation)) + lines.push(`Credits ${operation} paused. Unsent data stays local. Run ${commandOf('status')} --refresh after you add credits.`); + } const { lastError } = book(state); if (lastError) { const at = new Date(lastError.at); @@ -1410,7 +1478,7 @@ try { else if (mode === 'idle') await modeIdle(config, argv); else if (mode === 'flush') await modeFlush(config, argv); else if (mode === 'precompact') await modePreCompact(config); - else if (mode === 'status') modeStatus(config); + else if (mode === 'status') await modeStatus(config, argv); else if (mode === 'cut') modeCut(config, argv); else if (mode === 'search') await modeSearch(config, argv); else if (mode === 'backfill') await modeBackfill(config, argv); diff --git a/plugins/past/commands/status.md b/plugins/past/commands/status.md index 6fdaa1d..b6f67b6 100644 --- a/plugins/past/commands/status.md +++ b/plugins/past/commands/status.md @@ -6,3 +6,6 @@ Run `node "${CLAUDE_PLUGIN_ROOT}/bin/past-hook.mjs" status` and show the output If the key or the identity is missing, say which one and point at `/past:connect`. Do not print the key itself beyond the prefix the command already shows. + +If the user asks to check credits now, add `--refresh` to the status command. +This option reads the balance from the API and clears a credit pause only when the balance is sufficient.