@lastweek-work/cli 0.1.1 → 0.3.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 +13 -1
- package/dist/agents.js +245 -0
- package/dist/cli.js +52 -16
- package/dist/connect.js +26 -8
- package/dist/git.js +6 -1
- package/dist/hook.js +31 -8
- package/dist/mcp.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Config: `~/.config/lastweek/config.json` (override with `LASTWEEK_CONFIG`), vali
|
|
|
23
23
|
"deviceToken": "<rwd_… from the web app, Devices page>",
|
|
24
24
|
"repoRoots": ["~/Work"],
|
|
25
25
|
"authorEmails": ["you@example.com", "you@client.de"],
|
|
26
|
-
"agentEmails": ["noreply@anthropic.com", "cursoragent@cursor.com"] }
|
|
26
|
+
"agentEmails": ["noreply@anthropic.com", "cursoragent@cursor.com", "198982749+copilot@users.noreply.github.com"] }
|
|
27
27
|
```
|
|
28
28
|
`ingestUrl`/`deviceToken` may be omitted for `--dry-run`. Emails match case-insensitively.
|
|
29
29
|
|
|
@@ -63,6 +63,18 @@ Add to `~/.claude/settings.json` (merge with existing hooks). Fires on every edi
|
|
|
63
63
|
out with the next flush or scan. Errors land in `~/.local/state/lastweek/agent.log`.
|
|
64
64
|
- **Same session as your commits:** events carry the repo root (not Claude's working subfolder).
|
|
65
65
|
|
|
66
|
+
## GitHub Copilot (CLI and VS Code)
|
|
67
|
+
|
|
68
|
+
`lastweek agents` (or `lastweek connect`) sets Copilot up the same way as Claude Code, when Copilot CLI or the
|
|
69
|
+
VS Code Copilot extension is installed:
|
|
70
|
+
|
|
71
|
+
- a hook file of its own, `~/.copilot/hooks/lastweek.json` (`postToolUse` and `userPromptSubmitted` →
|
|
72
|
+
`lastweek log --agent copilot`): Copilot sessions become bursts like Claude Code's, labelled "GitHub Copilot";
|
|
73
|
+
- the MCP server in `~/.copilot/mcp-config.json` (other servers are kept, the file is backed up first).
|
|
74
|
+
|
|
75
|
+
Both files are read by Copilot CLI and by Copilot in VS Code; `$COPILOT_HOME` is respected. The same privacy rules
|
|
76
|
+
apply: session id, timestamps, tool names and file paths only.
|
|
77
|
+
|
|
66
78
|
## MCP server
|
|
67
79
|
|
|
68
80
|
Optional, for outcome summaries in the agent's own words. Claude Code:
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// Registers lastweek's stdio MCP server (`lastweek mcp`) with coding agents other than Claude Code (which has its
|
|
5
|
+
// own CLI, see connectClaude). Local file edits only; a tool whose config directory doesn't exist is never touched.
|
|
6
|
+
// Config locations, as documented (checked 2026-11):
|
|
7
|
+
// Cursor ~/.cursor/mcp.json { "mcpServers": { name: { type: "stdio", command, args } } } cursor.com/docs/context/mcp
|
|
8
|
+
// Codex CLI ~/.codex/config.toml [mcp_servers.<name>] command = "…" args = […] learn.chatgpt.com/docs/extend/mcp
|
|
9
|
+
// Gemini CLI ~/.gemini/settings.json { "mcpServers": { name: { command, args } } } github.com/google-gemini/gemini-cli docs/tools/mcp-server.md
|
|
10
|
+
// Copilot ~/.copilot/mcp-config.json { "mcpServers": { name: { type: "local", command, args, tools } } }
|
|
11
|
+
// + ~/.copilot/hooks/lastweek.json (our own file). Both read by Copilot CLI and by Copilot in VS Code
|
|
12
|
+
// ($COPILOT_HOME if set). docs.github.com/copilot/reference/hooks-reference,
|
|
13
|
+
// code.visualstudio.com/docs/agents/reference/mcp-configuration (checked 2026-11-17)
|
|
14
|
+
export const SERVER_NAME = "lastweek";
|
|
15
|
+
/** The server's name before the rename; removed when it is clearly ours, so tools don't show up twice. */
|
|
16
|
+
const LEGACY_NAME = "rewind";
|
|
17
|
+
const isDir = (p) => {
|
|
18
|
+
try {
|
|
19
|
+
return statSync(p).isDirectory();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** Copies a file before we change it. The first backup (.bak-lastweek) is never overwritten; later ones get a stamp. */
|
|
26
|
+
export function backup(path) {
|
|
27
|
+
if (!existsSync(path))
|
|
28
|
+
return;
|
|
29
|
+
copyFileSync(path, existsSync(`${path}.bak-lastweek`) ? `${path}.bak-lastweek-${Date.now()}` : `${path}.bak-lastweek`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Adds/replaces `mcpServers.lastweek` in a JSON config and keeps every other key. A file that exists but isn't a JSON
|
|
33
|
+
* object (or whose mcpServers isn't one) is never touched.
|
|
34
|
+
*/
|
|
35
|
+
function registerJson(agent, label, dir, file, entry) {
|
|
36
|
+
const path = join(dir, file);
|
|
37
|
+
const result = (status) => ({ agent, label, path, status });
|
|
38
|
+
if (!isDir(dir))
|
|
39
|
+
return result("not-installed");
|
|
40
|
+
let current = {};
|
|
41
|
+
if (existsSync(path)) {
|
|
42
|
+
let parsed;
|
|
43
|
+
try {
|
|
44
|
+
const text = readFileSync(path, "utf8");
|
|
45
|
+
parsed = text.trim() ? JSON.parse(text) : {};
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return result("unreadable");
|
|
49
|
+
}
|
|
50
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
51
|
+
return result("unreadable");
|
|
52
|
+
current = parsed;
|
|
53
|
+
}
|
|
54
|
+
const servers = current.mcpServers ?? {};
|
|
55
|
+
if (servers === null || typeof servers !== "object" || Array.isArray(servers))
|
|
56
|
+
return result("unreadable");
|
|
57
|
+
const next = { ...servers };
|
|
58
|
+
const legacy = next[LEGACY_NAME];
|
|
59
|
+
const dropLegacy = legacy !== undefined && (legacy?.command === "rewind" || legacy?.command === "lastweek");
|
|
60
|
+
if (dropLegacy)
|
|
61
|
+
delete next[LEGACY_NAME];
|
|
62
|
+
if (!dropLegacy && JSON.stringify(next[SERVER_NAME]) === JSON.stringify(entry))
|
|
63
|
+
return result("already");
|
|
64
|
+
next[SERVER_NAME] = entry;
|
|
65
|
+
backup(path);
|
|
66
|
+
writeFileSync(path, `${JSON.stringify({ ...current, mcpServers: next }, null, 2)}\n`);
|
|
67
|
+
return result("registered");
|
|
68
|
+
}
|
|
69
|
+
export const registerCursor = (home = homedir()) => registerJson("cursor", "Cursor", join(home, ".cursor"), "mcp.json", {
|
|
70
|
+
// Cursor's field table marks `type` as required for stdio servers.
|
|
71
|
+
type: "stdio",
|
|
72
|
+
command: SERVER_NAME,
|
|
73
|
+
args: ["mcp"],
|
|
74
|
+
});
|
|
75
|
+
export const registerGemini = (home = homedir()) => registerJson("gemini", "Gemini CLI", join(home, ".gemini"), "settings.json", {
|
|
76
|
+
command: SERVER_NAME,
|
|
77
|
+
args: ["mcp"],
|
|
78
|
+
});
|
|
79
|
+
const KEY = `(?:lastweek|"lastweek"|'lastweek')`;
|
|
80
|
+
const HEADER = /^[ \t]*\[\[?[ \t]*([^\]#]*?)[ \t]*\]/;
|
|
81
|
+
const OURS_HEADER = new RegExp(String.raw `^mcp_servers[ \t]*\.[ \t]*${KEY}[ \t]*(\.|$)`);
|
|
82
|
+
const OURS_ROOT_KEY = new RegExp(String.raw `^[ \t]*mcp_servers[ \t]*\.[ \t]*${KEY}[ \t]*[.=]`);
|
|
83
|
+
const OURS_SECTION_KEY = new RegExp(String.raw `^[ \t]*${KEY}[ \t]*[.=]`);
|
|
84
|
+
/**
|
|
85
|
+
* How config.toml defines lastweek's server: "ours" if a `[mcp_servers.lastweek]` table (or a sub-table, or a dotted
|
|
86
|
+
* / inline key of it) exists; "inline" if `mcp_servers = { … }` is written inline, where appending a table would make
|
|
87
|
+
* the file invalid TOML. Line-based on purpose: we only ever append, so we only need to know whether we may.
|
|
88
|
+
*/
|
|
89
|
+
export function codexState(toml) {
|
|
90
|
+
let section = null; // null = root table
|
|
91
|
+
for (const line of toml.split(/\r?\n/)) {
|
|
92
|
+
const h = HEADER.exec(line);
|
|
93
|
+
if (h) {
|
|
94
|
+
section = h[1].replace(/[ \t]*\.[ \t]*/g, ".");
|
|
95
|
+
if (OURS_HEADER.test(section))
|
|
96
|
+
return "ours";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (section === null) {
|
|
100
|
+
if (OURS_ROOT_KEY.test(line))
|
|
101
|
+
return "ours";
|
|
102
|
+
if (/^[ \t]*mcp_servers[ \t]*=/.test(line))
|
|
103
|
+
return "inline";
|
|
104
|
+
}
|
|
105
|
+
else if (section === "mcp_servers" && OURS_SECTION_KEY.test(line))
|
|
106
|
+
return "ours";
|
|
107
|
+
}
|
|
108
|
+
return "absent";
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Codex CLI: appends a `[mcp_servers.lastweek]` table to ~/.codex/config.toml. The user's content is never rewritten
|
|
112
|
+
* or reordered (bytes before the appended table stay identical); an existing table is left as it is.
|
|
113
|
+
*/
|
|
114
|
+
export function registerCodex(home = homedir()) {
|
|
115
|
+
const dir = join(home, ".codex");
|
|
116
|
+
const path = join(dir, "config.toml");
|
|
117
|
+
const result = (status) => ({ agent: "codex", label: "Codex CLI", path, status });
|
|
118
|
+
if (!isDir(dir))
|
|
119
|
+
return result("not-installed");
|
|
120
|
+
let text = "";
|
|
121
|
+
if (existsSync(path)) {
|
|
122
|
+
try {
|
|
123
|
+
text = readFileSync(path, "utf8");
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return result("unreadable");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const state = codexState(text);
|
|
130
|
+
if (state === "ours")
|
|
131
|
+
return result("already");
|
|
132
|
+
if (state === "inline")
|
|
133
|
+
return result("unreadable");
|
|
134
|
+
const nl = text.includes("\r\n") ? "\r\n" : "\n";
|
|
135
|
+
const lead = text === "" ? "" : text.endsWith("\n") ? nl : nl + nl;
|
|
136
|
+
const table = [`[mcp_servers.${SERVER_NAME}]`, `command = "${SERVER_NAME}"`, `args = ["mcp"]`].join(nl);
|
|
137
|
+
backup(path);
|
|
138
|
+
appendFileSync(path, `${lead}${table}${nl}`);
|
|
139
|
+
return result("registered");
|
|
140
|
+
}
|
|
141
|
+
/** Copilot's config directory: $COPILOT_HOME, else ~/.copilot. */
|
|
142
|
+
export const copilotDir = (home = homedir(), env = process.env) => env.COPILOT_HOME?.trim() || join(home, ".copilot");
|
|
143
|
+
/** The GitHub Copilot extension in VS Code (stable or Insiders), for people who never ran Copilot CLI. */
|
|
144
|
+
function vscodeCopilot(home) {
|
|
145
|
+
for (const d of [".vscode", ".vscode-insiders"]) {
|
|
146
|
+
try {
|
|
147
|
+
if (readdirSync(join(home, d, "extensions")).some((e) => e.toLowerCase().startsWith("github.copilot")))
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// no VS Code here
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
export const copilotInstalled = (home = homedir(), env = process.env) => isDir(copilotDir(home, env)) || vscodeCopilot(home);
|
|
157
|
+
/** The hook command; like Claude Code's it must never fail or block the agent. */
|
|
158
|
+
export const COPILOT_HOOK = "lastweek log --agent copilot";
|
|
159
|
+
const COPILOT_HOOKS = {
|
|
160
|
+
version: 1,
|
|
161
|
+
hooks: Object.fromEntries(
|
|
162
|
+
// After every tool call and on every prompt: the times a session was working, never its contents.
|
|
163
|
+
["postToolUse", "userPromptSubmitted"].map((event) => [
|
|
164
|
+
event,
|
|
165
|
+
[{ type: "command", bash: `${COPILOT_HOOK} 2>/dev/null || true`, command: COPILOT_HOOK, timeoutSec: 10 }],
|
|
166
|
+
])),
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* GitHub Copilot (CLI and VS Code): the MCP server in mcp-config.json (other servers kept) and a hook file of our
|
|
170
|
+
* own, hooks/lastweek.json, so Copilot's working time is recorded like Claude Code's, without the model having to
|
|
171
|
+
* call a tool. Only when Copilot is installed; the directory is created for VS Code users without the CLI.
|
|
172
|
+
*/
|
|
173
|
+
export function registerCopilot(home = homedir(), env = process.env) {
|
|
174
|
+
const dir = copilotDir(home, env);
|
|
175
|
+
const label = "GitHub Copilot";
|
|
176
|
+
if (!copilotInstalled(home, env))
|
|
177
|
+
return { agent: "copilot", label, path: join(dir, "mcp-config.json"), status: "not-installed" };
|
|
178
|
+
mkdirSync(join(dir, "hooks"), { recursive: true });
|
|
179
|
+
const mcp = registerJson("copilot", label, dir, "mcp-config.json", {
|
|
180
|
+
type: "local",
|
|
181
|
+
command: SERVER_NAME,
|
|
182
|
+
args: ["mcp"],
|
|
183
|
+
tools: ["*"],
|
|
184
|
+
});
|
|
185
|
+
const hookPath = join(dir, "hooks", `${SERVER_NAME}.json`);
|
|
186
|
+
const want = `${JSON.stringify(COPILOT_HOOKS, null, 2)}\n`;
|
|
187
|
+
let hookChanged = false;
|
|
188
|
+
let current = null;
|
|
189
|
+
try {
|
|
190
|
+
current = readFileSync(hookPath, "utf8");
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// not there yet
|
|
194
|
+
}
|
|
195
|
+
if (current !== want) {
|
|
196
|
+
backup(hookPath);
|
|
197
|
+
writeFileSync(hookPath, want);
|
|
198
|
+
hookChanged = true;
|
|
199
|
+
}
|
|
200
|
+
if (mcp.status === "unreadable")
|
|
201
|
+
return mcp;
|
|
202
|
+
return { ...mcp, status: mcp.status === "registered" || hookChanged ? "registered" : "already" };
|
|
203
|
+
}
|
|
204
|
+
/** Every supported coding agent besides Claude Code, in a fixed order. */
|
|
205
|
+
export const registerCodingAgents = (home = homedir(), env = process.env) => [
|
|
206
|
+
registerCursor(home),
|
|
207
|
+
registerCodex(home),
|
|
208
|
+
registerGemini(home),
|
|
209
|
+
registerCopilot(home, env),
|
|
210
|
+
];
|
|
211
|
+
/** Labels of the coding agents (besides Claude Code) that are installed. */
|
|
212
|
+
export const installedCodingAgents = (home = homedir(), env = process.env) => [
|
|
213
|
+
...[
|
|
214
|
+
[".cursor", "Cursor"],
|
|
215
|
+
[".codex", "Codex CLI"],
|
|
216
|
+
[".gemini", "Gemini CLI"],
|
|
217
|
+
]
|
|
218
|
+
.filter(([dir]) => isDir(join(home, dir)))
|
|
219
|
+
.map(([, label]) => label),
|
|
220
|
+
...(copilotInstalled(home, env) ? ["GitHub Copilot"] : []),
|
|
221
|
+
];
|
|
222
|
+
/**
|
|
223
|
+
* The MCP client's self-reported name (initialize → clientInfo.name) as a short agent id, e.g. "cursor-vscode" →
|
|
224
|
+
* "cursor", "codex-mcp-client" → "codex". Unknown clients keep their own name, cleaned up; no name → undefined.
|
|
225
|
+
*/
|
|
226
|
+
export function agentFromClient(name) {
|
|
227
|
+
const n = name?.trim().toLowerCase();
|
|
228
|
+
if (!n)
|
|
229
|
+
return undefined;
|
|
230
|
+
if (n.startsWith("claude-code") || n === "claude code")
|
|
231
|
+
return "claude-code";
|
|
232
|
+
if (n.includes("cursor"))
|
|
233
|
+
return "cursor";
|
|
234
|
+
if (n.includes("codex"))
|
|
235
|
+
return "codex";
|
|
236
|
+
if (n.includes("gemini"))
|
|
237
|
+
return "gemini-cli";
|
|
238
|
+
// Copilot CLI, and VS Code itself (its MCP client is Copilot's agent mode; Cursor, a fork, is caught above).
|
|
239
|
+
if (n.includes("copilot") || n === "visual studio code" || n.startsWith("vscode"))
|
|
240
|
+
return "copilot";
|
|
241
|
+
return (n
|
|
242
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
243
|
+
.replace(/^-+|-+$/g, "")
|
|
244
|
+
.slice(0, 40) || undefined);
|
|
245
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -4,11 +4,12 @@ import { appendFileSync, mkdirSync } from "node:fs";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
|
+
import { installedCodingAgents, registerCodingAgents } from "./agents.js";
|
|
7
8
|
import { openBursts, recordCall, spoolIdle } from "./bursts.js";
|
|
8
9
|
import { configPath, loadConfig } from "./config.js";
|
|
9
10
|
import { ask, claudeInstalled, connectClaude, detectAuthorEmails, detectRepoRoots, gitEmail, mergeConfig, pair, readJson, say, writeConfig, } from "./connect.js";
|
|
10
11
|
import { authorWarning, findRepos, mainRepoPath, scanRepos } from "./git.js";
|
|
11
|
-
import { callFromInput } from "./hook.js";
|
|
12
|
+
import { callFromInput, isHookAgent } from "./hook.js";
|
|
12
13
|
import { ingest } from "./ingest.js";
|
|
13
14
|
import { runMcp } from "./mcp.js";
|
|
14
15
|
import { installedPlist, installSchedule, scheduleInstalled, uninstallSchedule } from "./schedule.js";
|
|
@@ -18,7 +19,8 @@ import { openTasks } from "./tasks.js";
|
|
|
18
19
|
const USAGE = `usage:
|
|
19
20
|
lastweek connect <CODE> --server <url> [--name <device>] [--yes] [--no-agents] [--no-schedule] [--no-scan]
|
|
20
21
|
set everything up with a code from the web app's setup tour
|
|
21
|
-
lastweek connect --repos <folder> | --agents later additions: another code folder /
|
|
22
|
+
lastweek connect --repos <folder> | --agents later additions: another code folder / coding agents
|
|
23
|
+
lastweek agents register with Cursor, Codex CLI, Gemini CLI, GitHub Copilot
|
|
22
24
|
lastweek scan [since-iso] [--since <iso>] [--dry-run] collect git evidence (default since: last successful scan, else 8 days)
|
|
23
25
|
lastweek log Claude Code hook: reads hook JSON on stdin, never fails, returns fast
|
|
24
26
|
lastweek flush send spooled hook/MCP events now
|
|
@@ -176,28 +178,44 @@ async function connect(args) {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
|
-
// Claude Code
|
|
180
|
-
// A temporary npx copy would leave hooks pointing at a `lastweek` that isn't installed.
|
|
181
|
+
// Coding agents: Claude Code and GitHub Copilot (hook + MCP), Cursor / Codex CLI / Gemini CLI (MCP), only after asking (or --yes /
|
|
182
|
+
// --agents). A temporary npx copy would leave hooks and MCP entries pointing at a `lastweek` that isn't installed.
|
|
181
183
|
const temporary = /[\\/]_npx[\\/]/.test(process.argv[1] ?? "");
|
|
182
|
-
|
|
184
|
+
const claude = claudeInstalled();
|
|
185
|
+
const others = installedCodingAgents();
|
|
186
|
+
if ((code || values.agents) && !values["no-agents"] && (claude || others.length)) {
|
|
183
187
|
if (temporary)
|
|
184
|
-
console.log(say.claudeTemp);
|
|
185
|
-
else if (values.yes ||
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
console.log(others.length ? say.agentsTemp : say.claudeTemp);
|
|
189
|
+
else if (values.yes ||
|
|
190
|
+
values.agents ||
|
|
191
|
+
(await ask(say.agentsAsk([...(claude ? ["Claude Code"] : []), ...others])))) {
|
|
192
|
+
if (claude) {
|
|
193
|
+
const r = connectClaude();
|
|
194
|
+
if (r.unreadable)
|
|
195
|
+
console.error(say.claudeUnreadable(r.unreadable));
|
|
196
|
+
else
|
|
197
|
+
console.log(r.changed || r.mcp ? say.claudeDone(r.mcp) : say.claudeAlready);
|
|
198
|
+
}
|
|
199
|
+
// Tools that aren't installed are neither touched nor mentioned here; `lastweek agents` lists them.
|
|
200
|
+
for (const r of registerCodingAgents()) {
|
|
201
|
+
if (r.status === "unreadable")
|
|
202
|
+
console.error(say.agent(r));
|
|
203
|
+
else if (r.status !== "not-installed")
|
|
204
|
+
console.log(say.agent(r));
|
|
205
|
+
}
|
|
191
206
|
}
|
|
192
207
|
else
|
|
193
|
-
console.log(say.claudeSkipped);
|
|
208
|
+
console.log(others.length ? say.agentsSkipped : say.claudeSkipped);
|
|
194
209
|
}
|
|
195
210
|
// First scan right away, so the browser shows data while the user is still there.
|
|
196
211
|
if (code && !values["no-scan"]) {
|
|
197
212
|
try {
|
|
198
213
|
const cfg = loadConfig();
|
|
199
|
-
|
|
214
|
+
// Name the real gap: no folder, or no commit email (then every commit would be skipped as someone else's).
|
|
215
|
+
if (!cfg.repoRoots.length)
|
|
200
216
|
throw new Error(say.noFolders);
|
|
217
|
+
if (!cfg.authorEmails.length)
|
|
218
|
+
throw new Error(say.noEmails);
|
|
201
219
|
console.log(say.scanning);
|
|
202
220
|
const r = await runScan(cfg, resolveSince(undefined));
|
|
203
221
|
console.log(say.scanned(r.events, r.repos));
|
|
@@ -240,12 +258,16 @@ async function main() {
|
|
|
240
258
|
break;
|
|
241
259
|
}
|
|
242
260
|
case "log": {
|
|
243
|
-
// Claude Code hook. Must never fail or block the agent: no config needed,
|
|
261
|
+
// Claude Code / GitHub Copilot hook (`--agent copilot`). Must never fail or block the agent: no config needed,
|
|
262
|
+
// no network, always exit 0.
|
|
244
263
|
try {
|
|
264
|
+
const i = rest.indexOf("--agent");
|
|
265
|
+
const named = i >= 0 ? rest[i + 1] : undefined;
|
|
266
|
+
const agent = isHookAgent(named) ? named : "claude-code";
|
|
245
267
|
const raw = await readStdin();
|
|
246
268
|
const input = (raw.trim() ? JSON.parse(raw) : {});
|
|
247
269
|
const repo = typeof input.cwd === "string" && input.cwd ? mainRepoPath(input.cwd) : null;
|
|
248
|
-
recordCall(callFromInput(input, repo), Date.now());
|
|
270
|
+
recordCall(callFromInput(input, repo, agent), Date.now());
|
|
249
271
|
if (spoolSize() > 0)
|
|
250
272
|
flushInBackground();
|
|
251
273
|
}
|
|
@@ -314,6 +336,20 @@ async function main() {
|
|
|
314
336
|
}
|
|
315
337
|
break;
|
|
316
338
|
}
|
|
339
|
+
case "agents": {
|
|
340
|
+
// Cursor / Codex CLI / Gemini CLI (MCP) and GitHub Copilot (MCP + hook); Claude Code stays with `connect --agents`.
|
|
341
|
+
if (/[\\/]_npx[\\/]/.test(process.argv[1] ?? "")) {
|
|
342
|
+
console.log(say.agentsTemp);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
for (const r of registerCodingAgents()) {
|
|
346
|
+
if (r.status === "unreadable")
|
|
347
|
+
console.error(say.agent(r));
|
|
348
|
+
else
|
|
349
|
+
console.log(say.agent(r));
|
|
350
|
+
}
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
317
353
|
case "mcp":
|
|
318
354
|
await runMcp();
|
|
319
355
|
break;
|
package/dist/connect.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { chmodSync,
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { backup } from "./agents.js";
|
|
6
7
|
// `lastweek connect <CODE>`: everything a non-technical user would otherwise do by hand, in one command.
|
|
7
8
|
// Pair with the web app, find project folders and commit emails, write the config, start the background scan,
|
|
8
9
|
// connect Claude Code (asks first, backs up its settings), run the first scan. Pure helpers are exported for tests.
|
|
@@ -191,9 +192,9 @@ export const say = {
|
|
|
191
192
|
claudeTemp: de
|
|
192
193
|
? "ℹ Claude Code übersprungen: lastweek läuft nur temporär (npx). Dauerhaft installieren: npm install -g @lastweek-work/cli"
|
|
193
194
|
: "ℹ Claude Code skipped: lastweek runs temporarily (npx). Install it for good: npm install -g @lastweek-work/cli",
|
|
194
|
-
|
|
195
|
-
? "
|
|
196
|
-
:
|
|
195
|
+
agentsAsk: (found) => de
|
|
196
|
+
? `${found.join(", ")} gefunden. Soll lastweek die Arbeit deiner Agenten mitzählen? (Hook/MCP, Sicherung wird angelegt) [J/n] `
|
|
197
|
+
: `Found ${found.join(", ")}. Should lastweek count your agents' work? (hook/MCP, a backup is made) [Y/n] `,
|
|
197
198
|
claudeDone: (mcp) => de
|
|
198
199
|
? `✓ Claude Code verbunden (Hook${mcp ? " + MCP" : ""})`
|
|
199
200
|
: `✓ Claude Code connected (hook${mcp ? " + MCP" : ""})`,
|
|
@@ -201,6 +202,26 @@ export const say = {
|
|
|
201
202
|
claudeSkipped: de
|
|
202
203
|
? "– Claude Code übersprungen. Später: lastweek connect --agents"
|
|
203
204
|
: "– Claude Code skipped. Later: lastweek connect --agents",
|
|
205
|
+
agentsTemp: de
|
|
206
|
+
? "ℹ Coding-Agenten übersprungen: lastweek läuft nur temporär (npx). Dauerhaft installieren: npm install -g @lastweek-work/cli"
|
|
207
|
+
: "ℹ Coding agents skipped: lastweek runs temporarily (npx). Install it for good: npm install -g @lastweek-work/cli",
|
|
208
|
+
agentsSkipped: de
|
|
209
|
+
? "– Coding-Agenten übersprungen. Später: lastweek agents"
|
|
210
|
+
: "– Coding agents skipped. Later: lastweek agents",
|
|
211
|
+
agent: (r) => {
|
|
212
|
+
switch (r.status) {
|
|
213
|
+
case "registered":
|
|
214
|
+
return de ? `✓ ${r.label} verbunden (MCP)` : `✓ ${r.label} connected (MCP)`;
|
|
215
|
+
case "already":
|
|
216
|
+
return de ? `✓ ${r.label} war schon verbunden` : `✓ ${r.label} was already connected`;
|
|
217
|
+
case "unreadable":
|
|
218
|
+
return de
|
|
219
|
+
? `⚠ ${r.label} übersprungen: ${r.path} ließ sich nicht lesen; nichts geändert. Nach dem Prüfen der Datei: lastweek agents`
|
|
220
|
+
: `⚠ ${r.label} skipped (unreadable config): ${r.path}; nothing changed. After checking the file: lastweek agents`;
|
|
221
|
+
default:
|
|
222
|
+
return de ? `– ${r.label} nicht installiert` : `– ${r.label} not installed`;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
204
225
|
scanning: de ? "Erster Scan der letzten 8 Tage …" : "First scan of the last 8 days …",
|
|
205
226
|
scanFailed: (reason) => de
|
|
206
227
|
? `⚠ Der erste Scan hat nicht geklappt (${reason}). Er läuft automatisch erneut; sofort geht es mit: lastweek scan`
|
|
@@ -246,10 +267,7 @@ export function connectClaude(home = homedir()) {
|
|
|
246
267
|
const { settings, changed } = mergeClaudeHooks(current);
|
|
247
268
|
if (changed) {
|
|
248
269
|
mkdirSync(dirname(path), { recursive: true });
|
|
249
|
-
|
|
250
|
-
const backup = existsSync(`${path}.bak-lastweek`) ? `${path}.bak-lastweek-${Date.now()}` : `${path}.bak-lastweek`;
|
|
251
|
-
copyFileSync(path, backup);
|
|
252
|
-
}
|
|
270
|
+
backup(path);
|
|
253
271
|
writeFileSync(path, `${JSON.stringify(settings, null, 2)}\n`);
|
|
254
272
|
}
|
|
255
273
|
let mcp = false;
|
package/dist/git.js
CHANGED
|
@@ -70,7 +70,12 @@ export function findRepos(roots, depth = 3, warn = console.warn) {
|
|
|
70
70
|
return [...out];
|
|
71
71
|
}
|
|
72
72
|
/** Commit addresses of coding agents. Their commits count only when made or merged on this machine (see below). */
|
|
73
|
-
export const DEFAULT_AGENT_EMAILS = [
|
|
73
|
+
export const DEFAULT_AGENT_EMAILS = [
|
|
74
|
+
"noreply@anthropic.com",
|
|
75
|
+
"cursoragent@cursor.com",
|
|
76
|
+
// GitHub Copilot's cloud agent (commits authored by "Copilot"); counts only when merged on this machine.
|
|
77
|
+
"198982749+copilot@users.noreply.github.com",
|
|
78
|
+
];
|
|
74
79
|
/**
|
|
75
80
|
* Commits that entered this worktree through its own reflog: created here (`commit…` entries) or brought in by a
|
|
76
81
|
* local merge (`merge <branch>: …` → everything between the previous HEAD and the merge). This is how agent commits
|
package/dist/hook.js
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Coalescing of Claude Code
|
|
2
|
+
* Coalescing of coding-agent hook calls (Claude Code; GitHub Copilot since Phase 27b). Calls of one session that arrive within GAP of each other extend one burst;
|
|
3
3
|
* a burst becomes a single interval event [first call, last call]. Pure: time and state are passed in.
|
|
4
4
|
*/
|
|
5
5
|
export const GAP_MS = 60_000;
|
|
6
6
|
/** Long continuous bursts are cut so events reach the server regularly. */
|
|
7
7
|
export const MAX_BURST_MS = 15 * 60_000;
|
|
8
8
|
const MAX_FILES = 10;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Agents that report through `lastweek log`; anything else is recorded as Claude Code, the original hook. */
|
|
10
|
+
export const HOOK_AGENTS = { "claude-code": "Claude Code", copilot: "GitHub Copilot" };
|
|
11
|
+
export const isHookAgent = (v) => typeof v === "string" && v in HOOK_AGENTS;
|
|
12
|
+
const str = (v) => (typeof v === "string" && v ? v : undefined);
|
|
13
|
+
export function callFromInput(input, repo, agent = "claude-code") {
|
|
14
|
+
const args = (input.tool_input ??
|
|
15
|
+
(input.toolArgs && typeof input.toolArgs === "object" ? input.toolArgs : {}));
|
|
16
|
+
const raw = args.file_path ?? args.filePath ?? args.notebook_path ?? args.path;
|
|
11
17
|
let file = typeof raw === "string" ? raw : null;
|
|
12
18
|
if (file && repo && file.startsWith(`${repo}/`))
|
|
13
19
|
file = file.slice(repo.length + 1);
|
|
20
|
+
const session = str(input.session_id) ?? str(input.sessionId) ?? "unknown";
|
|
14
21
|
return {
|
|
15
|
-
|
|
22
|
+
// Prefixed for Copilot so its session files can never collide with Claude Code's.
|
|
23
|
+
session: agent === "claude-code" ? session : `${agent}-${session}`,
|
|
16
24
|
repo,
|
|
17
|
-
|
|
25
|
+
// Copilot's prompt hook carries no event name: no tool means a prompt.
|
|
26
|
+
label: str(input.tool_name) ??
|
|
27
|
+
str(input.toolName) ??
|
|
28
|
+
str(input.hook_event_name) ??
|
|
29
|
+
(agent === "copilot" ? "prompt" : "unknown"),
|
|
18
30
|
file,
|
|
31
|
+
...(agent === "claude-code" ? {} : { agent }),
|
|
19
32
|
};
|
|
20
33
|
}
|
|
21
34
|
/** Folds one call into the session's burst. Returns the burst to keep and any finished burst to emit. */
|
|
@@ -27,7 +40,16 @@ export function applyCall(current, call, now) {
|
|
|
27
40
|
now >= current.last;
|
|
28
41
|
const base = continues
|
|
29
42
|
? current
|
|
30
|
-
: {
|
|
43
|
+
: {
|
|
44
|
+
session: call.session,
|
|
45
|
+
...(call.agent ? { agent: call.agent } : {}),
|
|
46
|
+
repo: call.repo,
|
|
47
|
+
start: now,
|
|
48
|
+
last: now,
|
|
49
|
+
count: 0,
|
|
50
|
+
tools: {},
|
|
51
|
+
files: [],
|
|
52
|
+
};
|
|
31
53
|
const burst = {
|
|
32
54
|
...base,
|
|
33
55
|
last: now,
|
|
@@ -41,7 +63,8 @@ export function applyCall(current, call, now) {
|
|
|
41
63
|
}
|
|
42
64
|
/** A burst nobody has extended for longer than GAP is finished. */
|
|
43
65
|
export const isIdle = (b, now) => now - b.last > GAP_MS;
|
|
44
|
-
export function burstToEvent(b
|
|
66
|
+
export function burstToEvent(b) {
|
|
67
|
+
const agent = b.agent ?? "claude-code";
|
|
45
68
|
const start = new Date(b.start).toISOString();
|
|
46
69
|
const tools = Object.entries(b.tools)
|
|
47
70
|
.sort((x, y) => y[1] - x[1] || x[0].localeCompare(y[0]))
|
|
@@ -52,7 +75,7 @@ export function burstToEvent(b, agent = "claude-code") {
|
|
|
52
75
|
occurred_at: start,
|
|
53
76
|
ended_at: b.last > b.start ? new Date(b.last).toISOString() : undefined,
|
|
54
77
|
repo: b.repo ?? undefined,
|
|
55
|
-
summary:
|
|
78
|
+
summary: `${HOOK_AGENTS[agent]}: ${b.count} ${b.count === 1 ? "Aktion" : "Aktionen"} (${tools})${b.files.length ? ` · ${b.files.length} ${b.files.length === 1 ? "Datei" : "Dateien"}` : ""}`,
|
|
56
79
|
payload: { kind: "hook", agent, session: b.session, count: b.count, tools: b.tools, files: b.files },
|
|
57
80
|
dedupe_key: `hook:${b.session}:${start}`,
|
|
58
81
|
};
|
package/dist/mcp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { agentFromClient } from "./agents.js";
|
|
4
5
|
import { loadConfig } from "./config.js";
|
|
5
6
|
import { mainRepoPath } from "./git.js";
|
|
6
7
|
import { ingest } from "./ingest.js";
|
|
@@ -12,8 +13,10 @@ import { endTask, startTask } from "./tasks.js";
|
|
|
12
13
|
*/
|
|
13
14
|
export async function runMcp() {
|
|
14
15
|
const cfg = loadConfig();
|
|
15
|
-
const
|
|
16
|
+
const configured = process.env.LASTWEEK_AGENT_NAME || process.env.REWIND_AGENT_NAME || undefined;
|
|
16
17
|
const server = new McpServer({ name: "lastweek", version: "0.1.0" });
|
|
18
|
+
// An explicit env name wins; otherwise the client's own name from the initialize request (clientInfo.name).
|
|
19
|
+
const agentName = () => configured ?? agentFromClient(server.server.getClientVersion()?.name) ?? "unknown";
|
|
17
20
|
const repoOf = (repo) => (repo ? mainRepoPath(repo) : undefined);
|
|
18
21
|
const flush = async () => {
|
|
19
22
|
const r = await flushSpool((events) => ingest(cfg, events));
|
|
@@ -34,7 +37,7 @@ export async function runMcp() {
|
|
|
34
37
|
ended_at: started_at && started_at !== at ? at : undefined,
|
|
35
38
|
repo: r,
|
|
36
39
|
summary,
|
|
37
|
-
payload: { kind: "activity", agent },
|
|
40
|
+
payload: { kind: "activity", agent: agentName() },
|
|
38
41
|
dedupe_key: `mcp:${r ?? "-"}:${at}:${summary.slice(0, 40)}`,
|
|
39
42
|
},
|
|
40
43
|
]);
|
|
@@ -44,7 +47,7 @@ export async function runMcp() {
|
|
|
44
47
|
summary: z.string().describe("What you are about to do, one line, in the user's language."),
|
|
45
48
|
repo: z.string().optional().describe("Absolute repo path if known"),
|
|
46
49
|
}, async ({ summary, repo }) => {
|
|
47
|
-
const t = startTask(summary, repoOf(repo), new Date(),
|
|
50
|
+
const t = startTask(summary, repoOf(repo), new Date(), agentName());
|
|
48
51
|
return { content: [{ type: "text", text: `task ${t.id} started` }] };
|
|
49
52
|
});
|
|
50
53
|
server.tool("end_task", "Mark the end of a task started with start_task (the most recent one if no id is given).", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lastweek-work/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The lastweek agent: collects git and coding-agent evidence on your machine and sends it to your lastweek account.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://lastweek.work",
|