@lastweek-work/cli 0.2.0 → 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 +84 -10
- package/dist/cli.js +14 -7
- package/dist/git.js +6 -1
- package/dist/hook.js +31 -8
- 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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { appendFileSync, copyFileSync, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
// Registers lastweek's stdio MCP server (`lastweek mcp`) with coding agents other than Claude Code (which has its
|
|
@@ -7,6 +7,10 @@ import { join } from "node:path";
|
|
|
7
7
|
// Cursor ~/.cursor/mcp.json { "mcpServers": { name: { type: "stdio", command, args } } } cursor.com/docs/context/mcp
|
|
8
8
|
// Codex CLI ~/.codex/config.toml [mcp_servers.<name>] command = "…" args = […] learn.chatgpt.com/docs/extend/mcp
|
|
9
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)
|
|
10
14
|
export const SERVER_NAME = "lastweek";
|
|
11
15
|
/** The server's name before the rename; removed when it is clearly ours, so tools don't show up twice. */
|
|
12
16
|
const LEGACY_NAME = "rewind";
|
|
@@ -134,20 +138,87 @@ export function registerCodex(home = homedir()) {
|
|
|
134
138
|
appendFileSync(path, `${lead}${table}${nl}`);
|
|
135
139
|
return result("registered");
|
|
136
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
|
+
}
|
|
137
204
|
/** Every supported coding agent besides Claude Code, in a fixed order. */
|
|
138
|
-
export const registerCodingAgents = (home = homedir()) => [
|
|
205
|
+
export const registerCodingAgents = (home = homedir(), env = process.env) => [
|
|
139
206
|
registerCursor(home),
|
|
140
207
|
registerCodex(home),
|
|
141
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"] : []),
|
|
142
221
|
];
|
|
143
|
-
/** Labels of the coding agents (besides Claude Code) whose config directory exists. */
|
|
144
|
-
export const installedCodingAgents = (home = homedir()) => [
|
|
145
|
-
[".cursor", "Cursor"],
|
|
146
|
-
[".codex", "Codex CLI"],
|
|
147
|
-
[".gemini", "Gemini CLI"],
|
|
148
|
-
]
|
|
149
|
-
.filter(([dir]) => isDir(join(home, dir)))
|
|
150
|
-
.map(([, label]) => label);
|
|
151
222
|
/**
|
|
152
223
|
* The MCP client's self-reported name (initialize → clientInfo.name) as a short agent id, e.g. "cursor-vscode" →
|
|
153
224
|
* "cursor", "codex-mcp-client" → "codex". Unknown clients keep their own name, cleaned up; no name → undefined.
|
|
@@ -164,6 +235,9 @@ export function agentFromClient(name) {
|
|
|
164
235
|
return "codex";
|
|
165
236
|
if (n.includes("gemini"))
|
|
166
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";
|
|
167
241
|
return (n
|
|
168
242
|
.replace(/[^a-z0-9._-]+/g, "-")
|
|
169
243
|
.replace(/^-+|-+$/g, "")
|
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ import { openBursts, recordCall, spoolIdle } from "./bursts.js";
|
|
|
9
9
|
import { configPath, loadConfig } from "./config.js";
|
|
10
10
|
import { ask, claudeInstalled, connectClaude, detectAuthorEmails, detectRepoRoots, gitEmail, mergeConfig, pair, readJson, say, writeConfig, } from "./connect.js";
|
|
11
11
|
import { authorWarning, findRepos, mainRepoPath, scanRepos } from "./git.js";
|
|
12
|
-
import { callFromInput } from "./hook.js";
|
|
12
|
+
import { callFromInput, isHookAgent } from "./hook.js";
|
|
13
13
|
import { ingest } from "./ingest.js";
|
|
14
14
|
import { runMcp } from "./mcp.js";
|
|
15
15
|
import { installedPlist, installSchedule, scheduleInstalled, uninstallSchedule } from "./schedule.js";
|
|
@@ -20,7 +20,7 @@ const USAGE = `usage:
|
|
|
20
20
|
lastweek connect <CODE> --server <url> [--name <device>] [--yes] [--no-agents] [--no-schedule] [--no-scan]
|
|
21
21
|
set everything up with a code from the web app's setup tour
|
|
22
22
|
lastweek connect --repos <folder> | --agents later additions: another code folder / coding agents
|
|
23
|
-
lastweek agents register
|
|
23
|
+
lastweek agents register with Cursor, Codex CLI, Gemini CLI, GitHub Copilot
|
|
24
24
|
lastweek scan [since-iso] [--since <iso>] [--dry-run] collect git evidence (default since: last successful scan, else 8 days)
|
|
25
25
|
lastweek log Claude Code hook: reads hook JSON on stdin, never fails, returns fast
|
|
26
26
|
lastweek flush send spooled hook/MCP events now
|
|
@@ -178,7 +178,7 @@ async function connect(args) {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
// Coding agents: Claude Code (hook + MCP)
|
|
181
|
+
// Coding agents: Claude Code and GitHub Copilot (hook + MCP), Cursor / Codex CLI / Gemini CLI (MCP), only after asking (or --yes /
|
|
182
182
|
// --agents). A temporary npx copy would leave hooks and MCP entries pointing at a `lastweek` that isn't installed.
|
|
183
183
|
const temporary = /[\\/]_npx[\\/]/.test(process.argv[1] ?? "");
|
|
184
184
|
const claude = claudeInstalled();
|
|
@@ -211,8 +211,11 @@ async function connect(args) {
|
|
|
211
211
|
if (code && !values["no-scan"]) {
|
|
212
212
|
try {
|
|
213
213
|
const cfg = loadConfig();
|
|
214
|
-
|
|
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)
|
|
215
216
|
throw new Error(say.noFolders);
|
|
217
|
+
if (!cfg.authorEmails.length)
|
|
218
|
+
throw new Error(say.noEmails);
|
|
216
219
|
console.log(say.scanning);
|
|
217
220
|
const r = await runScan(cfg, resolveSince(undefined));
|
|
218
221
|
console.log(say.scanned(r.events, r.repos));
|
|
@@ -255,12 +258,16 @@ async function main() {
|
|
|
255
258
|
break;
|
|
256
259
|
}
|
|
257
260
|
case "log": {
|
|
258
|
-
// 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.
|
|
259
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";
|
|
260
267
|
const raw = await readStdin();
|
|
261
268
|
const input = (raw.trim() ? JSON.parse(raw) : {});
|
|
262
269
|
const repo = typeof input.cwd === "string" && input.cwd ? mainRepoPath(input.cwd) : null;
|
|
263
|
-
recordCall(callFromInput(input, repo), Date.now());
|
|
270
|
+
recordCall(callFromInput(input, repo, agent), Date.now());
|
|
264
271
|
if (spoolSize() > 0)
|
|
265
272
|
flushInBackground();
|
|
266
273
|
}
|
|
@@ -330,7 +337,7 @@ async function main() {
|
|
|
330
337
|
break;
|
|
331
338
|
}
|
|
332
339
|
case "agents": {
|
|
333
|
-
//
|
|
340
|
+
// Cursor / Codex CLI / Gemini CLI (MCP) and GitHub Copilot (MCP + hook); Claude Code stays with `connect --agents`.
|
|
334
341
|
if (/[\\/]_npx[\\/]/.test(process.argv[1] ?? "")) {
|
|
335
342
|
console.log(say.agentsTemp);
|
|
336
343
|
break;
|
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/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",
|