Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ plugins/past/
the plugin's name, the skills (`/past-status`), the tool (`past_recall`), `~/.past`, the key
prefix `past_sk_`, the data point ids and the recall block's header,
`=== past · recalled from memory ===`, which the journal reader drops by that exact text.
13. **A sitting is sent with the connection it was typed under.** The prompt hook writes a
fingerprint of the key and the address beside each prompt (`connection`). A prompt typed under
another connection than its sitting's starts a new sitting, and a sitting is sent only while
its connection is the one in force, whichever way the send starts (the sender, `ingest`); `cut`
does not print the others. So what was typed under one project's key never goes to another
project. A prompt journaled before 0.1.1 names no connection: the journal was only ever written
on a connected machine, so its sitting is sent, and it starts no new sitting, so no chat already
in past.dev moves. A sitting kept back holds its last hash in the chat's record, or `null`. The
folder's path stays in the journal, where the skills find this workspace's chat by it, and is
never sent: `metadata.project` is the folder's name. `SENDER_VERSION` went to 3 with it.

## Beside other past.dev plugins

Expand Down Expand Up @@ -150,7 +160,11 @@ everything else of its own in `~/.past/cursor/` and `~/.past/hosts/cursor.json`.
- `POST /api/v1/ingest/batch`: one item per sitting. `id` gives replacement (`cursor:<chat id>`
for the first sitting, `cursor:<chat id>:<n>` for the others), `timestamp` dates every memory
drawn from the item, `label` names the chat (`Cursor · <project> · <branch>`, or `Cursor · no folder`), `metadata` carries
`conversationId`, `project`, `cwd`, `gitBranch`, `sitting`, `turns` and `cursorVersion`.
`conversationId`, `project`, `gitBranch`, `sitting`, `turns` and `cursorVersion`, and `model` and
`effort` where the sitting's latest prompt names them.
- Cursor names, in every hook's input, the model a turn runs on (`model_id`, or the older `model`)
and that model's options (`model_params`, the item `effort` among them). The prompt hook keeps
them beside the prompt in the journal; neither is rendered, so neither changes a hash (rule 10).
- `POST /api/v1/recall`: **`identity` is required**. Recall stays off until `/past-connect` sets
one.
- `audience` on ingest: a slug; absent means the whole project. `connect --audience` checks it with
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ so nothing already sent is sent again.

## What leaves your machine

Your prompts as you typed them, the agent's reply to each, and the project and branch names.
Nothing else.
Your prompts as you typed them and the agent's reply to each, with the names of the project's
folder and its branch, the chat's id, Cursor's version, the model the agent ran on with its effort
level, and the identity you connected with. The folder's path stays on your machine. Recall sends queries: one with a chat's first prompt, the
first 1,000 characters of each prompt, and the questions the agent asks `past_recall`. Nothing else.

A chat is recorded only once you are connected, and each prompt is sent with the key it was typed
under, and with no other: what was typed under one project's key never goes to another project. A
chat goes on, in a new sitting, from the prompt after you change keys.

Never sent: tool calls and their output, file contents, diffs, command output, attachments, the
model's thinking, what the agent writes between tool calls, and anything injected into the chat
Expand Down
2 changes: 1 addition & 1 deletion plugins/past/.cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "past",
"displayName": "past.dev",
"version": "0.1.0",
"version": "0.1.1",
"description": "Your Cursor chats become memory, and every prompt reaches the model with what past.dev recalls for it.",
"author": { "name": "past.dev" },
"publisher": "past.dev",
Expand Down
84 changes: 69 additions & 15 deletions plugins/past/bin/past-hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DEFAULT_SITTING_MINUTES = 30;
const MIN_SITTING_MINUTES = 5;
const DEFAULT_API_URL = 'https://api.past.dev';
const MARKER = '=== past · recalled from memory ===';
const VERSION = '0.1.0';
const VERSION = '0.1.1';

// ---------------------------------------------------------------------------------------- Cursor

Expand Down Expand Up @@ -221,7 +221,10 @@ function isSynthetic(text) {
// Conservative redaction. It is not a guarantee and the docs say so, but the obvious shapes (keys,
// tokens, and assignments whose name says "secret") never leave the machine by accident.
const SECRET_PATTERNS = [
/\b(?:past_sk|past_mk|sk-ant|sk-|ghp_|gho_|ghu_|ghs_|github_pat|xox[baprs]|AKIA|ASIA|glpat)-?[A-Za-z0-9_\-]{12,}/g,
// past_ct_ is a past.dev claim token. Its underscore is part of the match, so a name that only
// begins with past_ct, such as past_ctx_identifier_value, keeps its bytes: redacting it would
// change a chat already in past.dev, and that chat would be sent again as a paid revision.
/\b(?:past_sk|past_mk|past_ct_|sk-ant|sk-|ghp_|gho_|ghu_|ghs_|github_pat|xox[baprs]|AKIA|ASIA|glpat)-?[A-Za-z0-9_\-]{12,}/g,
/\bBearer\s+[A-Za-z0-9._\-]{20,}/gi,
/\beyJ[A-Za-z0-9._\-]{20,}/g,
/\b([A-Z0-9_]*(?:SECRET|PASSWORD|TOKEN|API_?KEY|PRIVATE_?KEY|CREDENTIAL)[A-Z0-9_]*)\s*[=:]\s*\S+/g,
Expand Down Expand Up @@ -259,16 +262,24 @@ function renderSitting(sitting) {
function sittingsOf(parsed, minutes) {
const sittings = [];
for (const turn of parsed.turns) {
if (!sittings.length || (turn.role === 'user' && turn.quiet >= minutes * 60000)) {
sittings.push({ turns: [], firstAt: turn.at, project: turn.project, branch: turn.branch, cwd: turn.cwd });
const open = sittings[sittings.length - 1];
// A prompt typed under another connection starts a new sitting: a sitting belongs to one. A
// prompt journaled before connections were recorded names none, and starts nothing.
const moved = turn.role === 'user' && Boolean(open) && turn.connection !== undefined && open.connection !== undefined && turn.connection !== open.connection;
if (!open || (turn.role === 'user' && turn.quiet >= minutes * 60000) || moved) {
// A sitting that starts on a reply is in the place of the one before it.
const connection = turn.role === 'user' ? turn.connection : open && open.connection;
sittings.push({ turns: [], firstAt: turn.at, project: turn.project, branch: turn.branch, connection });
}
const sitting = sittings[sittings.length - 1];
sitting.turns.push(turn);
// A sitting is named by the place of its latest prompt: a person can switch branches mid-chat.
if (turn.role === 'user') {
if (turn.project) sitting.project = turn.project;
if (turn.branch) sitting.branch = turn.branch;
if (turn.cwd) sitting.cwd = turn.cwd;
// The model its latest prompt ran on, and that model's effort, where the prompt names them.
if (turn.model) { sitting.model = turn.model; sitting.effort = turn.effort; }
if (sitting.connection === undefined) sitting.connection = turn.connection;
}
}
return sittings;
Expand All @@ -285,6 +296,9 @@ const hashOf = (text) => createHash('sha256').update(text).digest('hex');
* What sending a chat carries now: each sitting rendered, and the ones past.dev does not hold yet.
* A chat keeps the sitting length it was first sent with: a new value in the config applies to the
* chats sent after it, and the boundaries of one already in past.dev never move.
* `changed` holds the sittings to send; `kept` the ones that differ too but were typed under another
* connection, and stay on this machine. A sitting journaled before connections were recorded names
* none: the journal was only ever written on a connected machine, so it is sent.
*/
function planSend(parsed, record, config) {
const minutes = (record && record.sittingMinutes) || config.sittingMinutes;
Expand All @@ -293,7 +307,10 @@ function planSend(parsed, record, config) {
return { index, sitting, content, hash: hashOf(content), bytes: Buffer.byteLength(content) };
});
const known = record && Array.isArray(record.sittings) ? record.sittings : [];
return { minutes, sittings, changed: sittings.filter((part) => known[part.index] !== part.hash) };
const connection = connectionOf(config);
const mine = (part) => part.sitting.connection === undefined || part.sitting.connection === connection;
const differing = sittings.filter((part) => known[part.index] !== part.hash);
return { minutes, sittings, known, changed: differing.filter(mine), kept: differing.filter((part) => !mine(part)) };
}

const credits = (bytes) => Math.ceil(bytes / 350);
Expand All @@ -311,6 +328,24 @@ const kilobytes = (parts) => (parts.reduce((sum, part) => sum + part.bytes, 0) /
const chatFile = (chat) => String(chat).replace(/[^A-Za-z0-9-]/g, '');
const journalPath = (chat) => join(CURSOR_DIR, `${chatFile(chat)}.jsonl`);

// A fingerprint of the key and address a prompt was typed under, kept beside it in the journal. A
// sitting is sent with the connection it was typed under and with no other: what a person typed
// under another project's key stays on this machine.
const connectionOf = (config) => hashOf(`${config.apiUrl}\n${config.apiKey}`).slice(0, 16);

// Cursor names, in every hook's input, the model a turn runs on (`model_id`, or the older `model`)
// and that model's options, the reasoning effort among them. Kept beside the prompt, for the
// sitting's metadata; a prompt that names neither adds nothing to its entry.
function ranOn(input) {
const named = typeof input.model_id === 'string' && input.model_id ? input.model_id : input.model;
const options = Array.isArray(input.model_params) ? input.model_params : [];
const effort = options.find((option) => option && option.id === 'effort' && typeof option.value === 'string' && option.value);
const ran = {};
if (typeof named === 'string' && named) ran.model = named.slice(0, 100);
if (effort) ran.effort = effort.value.slice(0, 40);
return ran;
}

function appendJournal(chat, entry) {
privateDir(CURSOR_DIR);
// Appended in one write, created private: a journal holds what a person typed.
Expand Down Expand Up @@ -347,10 +382,13 @@ function readJournal(path) {
if (entry.kind === 'prompt') {
const quiet = Number.isNaN(last) ? 0 : Math.max(0, at - last);
place = { project: entry.project || place.project, branch: entry.branch || '', cwd: entry.cwd || place.cwd };
const connection = typeof entry.connection === 'string' ? entry.connection : undefined;
const model = typeof entry.model === 'string' ? entry.model : '';
const effort = typeof entry.effort === 'string' ? entry.effort : '';
if (entry.cursor) cursor = entry.cursor;
if (entry.mode) modes.add(entry.mode);
if (entry.generation) prompted.add(entry.generation);
if (text && !isSynthetic(text)) turns.push({ role: 'user', at: entry.at, text, quiet, ...place });
if (text && !isSynthetic(text)) turns.push({ role: 'user', at: entry.at, text, quiet, connection, model, effort, ...place });
open = true;
} else if (entry.kind === 'reply') {
// A reply belongs to the conversation when its prompt does. The answer to a prompt that only
Expand Down Expand Up @@ -554,11 +592,13 @@ async function sendChat(config, chat, parsed, plan) {
client: SOURCE,
conversationId: chat,
project: part.sitting.project || '',
cwd: part.sitting.cwd || '',
gitBranch: part.sitting.branch || '',
sitting: part.index + 1,
turns: part.sitting.turns.length,
cursorVersion: parsed.cursor || '',
// Not part of the rendered content: a sitting whose prompts name no model adds nothing.
model: part.sitting.model || undefined,
effort: part.sitting.effort || undefined,
},
}));
if (parsed.cursor) cursorVersion = parsed.cursor;
Expand All @@ -571,8 +611,12 @@ async function sendChat(config, chat, parsed, plan) {
updateState((fresh) => { book(fresh).lastError = lastError; });
return { error: lastError.status, code };
}
// A sitting kept on this machine keeps the hash it was last sent with, or none: it is not in
// past.dev as it is now.
const hashes = plan.sittings.map((part) => part.hash);
for (const part of plan.kept) hashes[part.index] = plan.known[part.index] || null;
const record = {
sittings: plan.sittings.map((part) => part.hash),
sittings: hashes,
sittingMinutes: plan.minutes,
sentAt: new Date().toISOString(),
turns: parsed.turns.length,
Expand Down Expand Up @@ -652,6 +696,7 @@ async function modePrompt(config) {
appendJournal(chat, {
kind: 'prompt', at: new Date().toISOString(), generation: input.generation_id || '', text: prompt,
mode: input.composer_mode || '', ...place, cursor: input.cursor_version || cursorVersion,
connection: connectionOf(config), ...ranOn(input),
});
} catch { /* the prompt still goes through */ }
}
Expand Down Expand Up @@ -715,7 +760,7 @@ async function modeWake(config) {

// Bumped whenever the sender changes: a sender an older version started is replaced, because it is
// a long-lived process still running the code it was started with.
const SENDER_VERSION = 2;
const SENDER_VERSION = 3;
const SENDER_SLICE_MS = 60000;

function isAlive(pid) {
Expand Down Expand Up @@ -950,6 +995,8 @@ function when(ms) {
return `${today ? '' : `${date.toDateString().slice(4, 10)} `}${date.toTimeString().slice(0, 5)}`;
}

const NOTHING_TO_SEND = 'Nothing to send from that chat: it holds no prompt typed under the key this machine is connected with.';

// What would leave the machine, before it leaves: every sitting of a chat, priced.
function modeCut(config, argv) {
const { target, error } = targetChat(argv);
Expand All @@ -958,14 +1005,18 @@ function modeCut(config, argv) {
if (!parsed) { console.log('Nothing to send from that chat: no prompt typed in it was recorded.'); return; }
const record = book(loadState()).chats[target.chat];
const plan = planSend(parsed, record, config);
// Sittings that stay on this machine are not shown.
const shown = plan.sittings.filter((part) => !plan.kept.includes(part));
if (!shown.length) { console.log(NOTHING_TO_SEND); return; }
// As the sender sees it: a chat whose journal has not changed since its send is not sent again.
if (record && record.sentAt && Date.parse(record.sentAt) >= target.mtime) plan.changed = [];
const held = plan.sittings.length - plan.changed.length;
const held = shown.length - plan.changed.length;
const cost = !plan.changed.length
? `${kilobytes(plan.sittings)} KB, all in past.dev`
? `${kilobytes(shown)} KB, all in past.dev`
: `${kilobytes(plan.changed)} KB to send · about ${creditsOf(plan.changed)} credits` + (held ? ` · ${held} sitting(s) already in past.dev` : '');
console.error(`# chat ${short(target.chat)} · ${parsed.turns.length} turns in ${plan.sittings.length} sitting(s) · ${cost}\n`);
console.log(plan.sittings.map((part) => part.content).join('\n'));
const turns = shown.reduce((sum, part) => sum + part.sitting.turns.length, 0);
console.error(`# chat ${short(target.chat)} · ${turns} turns in ${shown.length} sitting(s) · ${cost}\n`);
console.log(shown.map((part) => part.content).join('\n'));
let next;
if (!plan.changed.length) next = 'Already in past.dev, unchanged.';
else {
Expand All @@ -985,7 +1036,10 @@ async function modeIngest(config, argv) {
const parsed = readJournal(target.path);
if (!parsed) { console.log('Nothing to send from that chat: no prompt typed in it was recorded.'); return; }
const plan = planSend(parsed, book(loadState()).chats[target.chat], config);
if (!plan.changed.length) { console.log(`Chat ${short(target.chat)} is already in past.dev, unchanged.`); return; }
if (!plan.changed.length) {
console.log(plan.kept.length ? NOTHING_TO_SEND : `Chat ${short(target.chat)} is already in past.dev, unchanged.`);
return;
}
const outcome = await sendChat(config, target.chat, parsed, plan);
if (outcome.error) {
console.log(`past.dev refused the send: ${outcome.error}${outcome.code ? ` ${outcome.code}` : ''}. ${commandOf('status')} has the details.`);
Expand Down
Loading