amicooked 0.1.3 → 0.1.5

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 CHANGED
@@ -68,6 +68,8 @@ amicooked uninstall disconnect apps (--purge deletes your login and settings)
68
68
 
69
69
  Your settings and login live in `~/.amicooked`; downloaded files go to `~/Downloads/amicooked`.
70
70
 
71
+ The first time setup finishes on a computer, it sends one anonymous count: your school's preset name (or "custom") and your OS. Nothing from Brightspace, no IP or ID is stored. Set `AMICOOKED_NO_TELEMETRY=1` or `DO_NOT_TRACK=1` to turn it off.
72
+
71
73
  ## Development
72
74
 
73
75
  ```sh
@@ -76,6 +78,7 @@ npm test
76
78
  npm run build # TypeScript to dist/
77
79
  npm run build:bin # standalone binaries in build/ (uses Bun)
78
80
  node dist/cli.js setup
81
+ npm run stats # installs, npm downloads, setups, repo traffic
79
82
  ```
80
83
 
81
84
  `skill/SKILL.md` is the single source for the agent skill; `npm run sync:skill` copies it (and `install/`) into `src/skill.ts` and `site/`.
@@ -0,0 +1,55 @@
1
+ import { spawn } from "child_process";
2
+ import { APPS, isRunning, open } from "../clients/apps.js";
3
+ import { claudeDesktopDir, installClaudeDesktop } from "../clients/claudeDesktop.js";
4
+ import { selfCommand } from "../clients/self.js";
5
+ // When setup runs inside Claude Desktop (an agent in it, say), it can't quit the app without ending that
6
+ // session, and Claude Desktop would save over our config when it quits anyway. So setup leaves this
7
+ // running in the background: it waits for the student to quit Claude, writes the config again, and
8
+ // reopens Claude, so one Cmd+Q finishes the job.
9
+ const POLL_MS = 2000;
10
+ const GIVE_UP_MS = 12 * 60 * 60 * 1000;
11
+ /** Starts the background helper, detached so it outlives setup. */
12
+ export function scheduleAfterQuit() {
13
+ try {
14
+ const self = selfCommand(["finish-after-quit"]);
15
+ const child = spawn(self.command, self.args, {
16
+ stdio: "ignore",
17
+ detached: true,
18
+ env: { ...process.env, ...self.env },
19
+ });
20
+ child.on("error", () => { });
21
+ child.unref();
22
+ return true;
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ /** The hidden `finish-after-quit` command the helper runs. */
29
+ export async function finishAfterQuit(steps = defaultSteps()) {
30
+ if (!steps)
31
+ return 1;
32
+ const end = steps.now() + GIVE_UP_MS;
33
+ while (steps.running()) {
34
+ if (steps.now() > end)
35
+ return 1;
36
+ await steps.wait(POLL_MS);
37
+ }
38
+ // Give the app a moment to finish writing its own copy before ours goes on top
39
+ await steps.wait(1500);
40
+ steps.write();
41
+ steps.reopen();
42
+ return 0;
43
+ }
44
+ function defaultSteps() {
45
+ const dir = claudeDesktopDir();
46
+ if (!dir)
47
+ return null;
48
+ return {
49
+ running: () => isRunning(APPS.claude),
50
+ write: () => installClaudeDesktop(dir, selfCommand(["mcp"])),
51
+ reopen: () => void open(APPS.claude),
52
+ wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
53
+ now: () => Date.now(),
54
+ };
55
+ }
package/dist/cli/setup.js CHANGED
@@ -1,16 +1,22 @@
1
1
  import * as p from "@clack/prompts";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
2
4
  import { hasActiveSession, login } from "../auth.js";
3
5
  import { detectChannel } from "../browser.js";
4
- import { claudeDesktopDir, installClaudeDesktop, InvalidConfigError, isClaudeDesktopRunning, manualSnippet, openClaudeDesktop, quitClaudeDesktop, } from "../clients/claudeDesktop.js";
6
+ import { APPS, CLAUDE_CODE_DOWNLOAD, desktopAppsSupported, isRunning, isRunningInside, open, openUrl, quit } from "../clients/apps.js";
7
+ import { claudeDesktopDir, installClaudeDesktop, InvalidConfigError, manualSnippet } from "../clients/claudeDesktop.js";
8
+ import { scheduleAfterQuit } from "./afterQuit.js";
5
9
  import { hasClaudeCode, installClaudeCode, installSkill } from "../clients/claudeCode.js";
6
10
  import { chatgptSteps, installChatGPT } from "../clients/chatgpt.js";
7
- import { hasCodex, installCodex, installCodexSkill } from "../clients/codex.js";
11
+ import { codexEntryIs, codexSkillPath, hasCodex, installCodex, installCodexSkill } from "../clients/codex.js";
12
+ import { SKILL_MD } from "../skill.js";
8
13
  import { selfCommand } from "../clients/self.js";
9
14
  import { client } from "../client.js";
10
15
  import { getConfig, writeConfig } from "../config.js";
11
16
  import { listCourses } from "../courseResolver.js";
12
17
  import { detectSchool, findPreset, PRESETS } from "../schools.js";
13
18
  import { amICooked } from "../tools/cooked.js";
19
+ import { reportSetup } from "../telemetry.js";
14
20
  const PUBLIC_IDS = ["desktop", "code", "chatgpt-desktop"];
15
21
  const CLIENT_IDS = [...PUBLIC_IDS, "chatgpt"];
16
22
  const ALIASES = { codex: "chatgpt-desktop", "chatgpt-app": "chatgpt-desktop", "chatgpt-web": "chatgpt" };
@@ -92,71 +98,103 @@ async function chooseClients(flag, detected, yes) {
92
98
  throw new SetupStop("Setup cancelled.");
93
99
  return chosen;
94
100
  }
95
- /** Claude Desktop saves its own config over ours when it quits, so it has to be closed before we write. */
96
- async function closeClaudeDesktop() {
97
- if (!isClaudeDesktopRunning())
98
- return "not_running";
99
- // An agent may be running this from inside Claude Desktop; never close it without asking
100
- if (!interactive())
101
- return "left_open";
102
- const ok = await p.confirm({ message: "Claude Desktop is open and has to restart to pick this up. Quit it now? It reopens when setup is done." });
103
- if (p.isCancel(ok) || !ok)
104
- return "left_open";
105
- return (await quitClaudeDesktop()) ? "closed" : "left_open";
101
+ const quitHow = () => (process.platform === "darwin" ? "with Cmd+Q" : "fully, from its icon by the clock if it has one");
102
+ async function missingApp(app, name, url) {
103
+ if (interactive()) {
104
+ const ok = await p.confirm({ message: `${name} isn't installed. Open its download page?` });
105
+ if (ok === true)
106
+ openUrl(url);
107
+ }
108
+ return { app, next: `install ${name} from ${url}, then run \`amicooked setup\` again.`, ready: false, connected: false };
109
+ }
110
+ /**
111
+ * Connects a desktop app and leaves it open with the new config loaded, or says exactly what's left.
112
+ * `write` adds our server to the app's config; `current` says whether it's already there.
113
+ */
114
+ async function connectDesktopApp(app, label, write, current) {
115
+ const ask = "Ask it: am I cooked?";
116
+ if (current()) {
117
+ // Already set up. Make sure it's open; no restart needed
118
+ if (isRunning(app))
119
+ return { app: label, next: `already set up. ${ask}`, ready: true, connected: true };
120
+ return open(app)
121
+ ? { app: label, next: `already set up, and opening now. ${ask}`, ready: true, connected: true }
122
+ : { app: label, next: `already set up. Open ${app.name} and ask: am I cooked?`, ready: false, connected: true };
123
+ }
124
+ let running = isRunning(app);
125
+ const inside = running && isRunningInside(app);
126
+ // An open app only loads the change after a restart. Offer one, unless setup is running inside that app
127
+ // (an agent there) or nobody's at the keyboard to say yes
128
+ if (running && !inside && interactive()) {
129
+ const ok = await p.confirm({ message: `${app.name} is open and needs a restart to pick this up. Restart it now?` });
130
+ if (ok === true)
131
+ running = !(await quit(app));
132
+ }
133
+ write();
134
+ if (running && app.overwritesOnQuit) {
135
+ // Quitting it would save its old config over ours, so a background helper waits for the quit, writes
136
+ // the config again and reopens the app
137
+ return scheduleAfterQuit()
138
+ ? { app: label, next: `quit ${app.name} ${quitHow()}. Am I Cooked finishes setting it up and reopens it. Then ask it: am I cooked?`, ready: false, connected: true }
139
+ : { app: label, next: `quit ${app.name} ${quitHow()}, then run \`amicooked setup\` again.`, ready: false, connected: false };
140
+ }
141
+ if (running)
142
+ return { app: label, next: `quit ${app.name} ${quitHow()} and open it again. Then ask it: am I cooked?`, ready: false, connected: true };
143
+ return open(app)
144
+ ? { app: label, next: `set up, and opening now. ${ask}`, ready: true, connected: true }
145
+ : { app: label, next: `set up. Open ${app.name} and ask: am I cooked?`, ready: false, connected: true };
106
146
  }
107
147
  async function configureClients(clients) {
108
- const done = [];
148
+ const outcomes = [];
109
149
  const launch = selfCommand(["mcp"]);
110
150
  if (clients.includes("desktop")) {
111
151
  const dir = claudeDesktopDir();
112
- if (!dir) {
113
- p.log.warn("Claude Desktop isn't installed. Get it at https://claude.ai/download, then run `amicooked setup` again.");
152
+ if (!desktopAppsSupported()) {
153
+ outcomes.push({ app: "Claude Desktop", next: `isn't available on Linux. Use Claude Code instead: ${CLAUDE_CODE_DOWNLOAD}`, ready: false, connected: false });
154
+ }
155
+ else if (!dir) {
156
+ outcomes.push(await missingApp("Claude Desktop", "Claude Desktop", APPS.claude.download));
114
157
  }
115
158
  else {
116
159
  try {
117
- const state = await closeClaudeDesktop();
118
- const result = installClaudeDesktop(dir, launch);
119
- if (state === "left_open" && result !== "unchanged") {
120
- // Written, but the open app will save its own copy over it when it quits
121
- p.log.warn("Claude Desktop is open, so it will undo this when it quits. Quit it, then run `amicooked setup --clients desktop`.");
122
- }
123
- else {
124
- p.log.success(`Claude Desktop: ${result === "unchanged" ? "already set up" : "set up"}`);
125
- done.push(state === "closed" && openClaudeDesktop() ? "desktop-reopened" : "desktop");
126
- }
160
+ outcomes.push(await connectDesktopApp(APPS.claude, "Claude Desktop", () => installClaudeDesktop(dir, launch), () => desktopHas(dir, launch)));
127
161
  }
128
162
  catch (error) {
129
163
  if (!(error instanceof InvalidConfigError))
130
164
  throw error;
131
165
  p.log.warn(`${error.message}\nAdd this to it yourself:\n${manualSnippet(launch)}`);
166
+ outcomes.push({ app: "Claude Desktop", next: "add the snippet above to its config, then restart it.", ready: false, connected: false });
132
167
  }
133
168
  }
134
169
  }
135
170
  if (clients.includes("code")) {
136
171
  if (!hasClaudeCode()) {
137
- p.log.warn("Claude Code isn't installed, so it was skipped.");
172
+ outcomes.push(await missingApp("Claude Code", "Claude Code", CLAUDE_CODE_DOWNLOAD));
138
173
  }
139
174
  else {
140
175
  installClaudeCode(launch);
141
176
  installSkill();
142
- p.log.success("Claude Code: set up, with the amicooked skill");
143
- done.push("code");
177
+ // Claude Code loads servers when a session starts, so an agent already running needs a new one
178
+ outcomes.push({ app: "Claude Code", next: "set up. Start a new Claude Code session and ask: am I cooked?", ready: true, connected: true });
144
179
  }
145
180
  }
146
181
  if (clients.includes("chatgpt-desktop")) {
147
- if (!hasCodex()) {
148
- p.log.warn("The ChatGPT desktop app isn't installed. Get it at https://chatgpt.com/download, then run `amicooked setup` again.");
182
+ if (!hasCodex() && !desktopAppsSupported()) {
183
+ outcomes.push({ app: "ChatGPT app", next: `isn't available on Linux. Use Claude Code instead: ${CLAUDE_CODE_DOWNLOAD}`, ready: false, connected: false });
184
+ }
185
+ else if (!hasCodex()) {
186
+ outcomes.push(await missingApp("ChatGPT app", "the ChatGPT app", APPS.chatgpt.download));
149
187
  }
150
188
  else {
151
189
  // Runs on this computer like Claude Desktop does; no tunnel or domain involved
152
- const result = installCodex(launch);
153
- installCodexSkill();
154
- p.log.success(`ChatGPT desktop app: ${result === "unchanged" ? "already set up" : "set up"}, with the amicooked skill`);
155
- done.push("chatgpt-desktop");
190
+ outcomes.push(await connectDesktopApp(APPS.chatgpt, "ChatGPT app", () => {
191
+ installCodex(launch);
192
+ installCodexSkill();
193
+ }, () => codexHas(launch)));
156
194
  }
157
195
  }
158
196
  if (clients.includes("chatgpt") && !process.env.AMICOOKED_TUNNEL_API) {
159
- p.log.warn("ChatGPT on the web isn't available yet. For the ChatGPT desktop app, use `--clients chatgpt-desktop`.");
197
+ outcomes.push({ app: "ChatGPT on the web", next: "isn't available yet. Use the ChatGPT app instead: `--clients chatgpt-desktop`.", ready: false, connected: false });
160
198
  }
161
199
  else if (clients.includes("chatgpt")) {
162
200
  const spin = p.spinner();
@@ -165,13 +203,39 @@ async function configureClients(clients) {
165
203
  const { url, pairingCode } = await installChatGPT();
166
204
  spin.stop("ChatGPT: running in the background");
167
205
  p.note(chatgptSteps(url, pairingCode), "Connect ChatGPT");
168
- done.push("chatgpt");
206
+ outcomes.push({ app: "ChatGPT on the web", next: "finish connecting with the steps above, then ask: am I cooked?", ready: false, connected: true });
169
207
  }
170
208
  catch (error) {
171
209
  spin.stop(`ChatGPT: ${error instanceof Error ? error.message : error}`);
172
210
  }
173
211
  }
174
- return done;
212
+ return outcomes;
213
+ }
214
+ /** True when Claude Desktop's config already starts this exact install. */
215
+ function desktopHas(dir, launch) {
216
+ try {
217
+ const config = JSON.parse(fs.readFileSync(path.join(dir, "claude_desktop_config.json"), "utf8"));
218
+ const entry = { command: launch.command, args: launch.args, ...(launch.env ? { env: launch.env } : {}) };
219
+ return JSON.stringify(config.mcpServers?.amicooked) === JSON.stringify(entry);
220
+ }
221
+ catch {
222
+ return false;
223
+ }
224
+ }
225
+ /** True when the ChatGPT app's config already starts this exact install, and the skill is in place. */
226
+ function codexHas(launch) {
227
+ return codexEntryIs(launch) && fs.existsSync(codexSkillPath()) && fs.readFileSync(codexSkillPath(), "utf8") === SKILL_MD;
228
+ }
229
+ /** The end of setup: every app's next step, then one line saying whether they're done. */
230
+ export function finishMessage(outcomes) {
231
+ if (!outcomes.length) {
232
+ return {
233
+ steps: null,
234
+ outro: `Nothing was set up. Get Claude Desktop (${APPS.claude.download}) or the ChatGPT app (${APPS.chatgpt.download}), then run \`amicooked setup\` again.`,
235
+ };
236
+ }
237
+ const steps = outcomes.map((o) => `${o.app}: ${o.next}`).join("\n");
238
+ return { steps, outro: outcomes.some((o) => o.ready) ? "You're set." : "Almost there. Do the step above." };
175
239
  }
176
240
  async function firstRoast() {
177
241
  const spin = p.spinner();
@@ -206,21 +270,16 @@ export async function setup(options) {
206
270
  p.log.success(`Signed in${me.FirstName ? ` as ${me.FirstName}` : ""}. Found ${courses.length} course${courses.length === 1 ? "" : "s"}.`);
207
271
  }
208
272
  const detected = { desktop: Boolean(claudeDesktopDir()), code: hasClaudeCode(), "chatgpt-desktop": hasCodex(), chatgpt: false };
209
- const done = await configureClients(await chooseClients(options.clients, detected, Boolean(options.yes)));
273
+ const outcomes = await configureClients(await chooseClients(options.clients, detected, Boolean(options.yes)));
274
+ // Count the setup only if an app was connected. Started now so it runs alongside the first report
275
+ const reported = outcomes.some((o) => o.connected) ? reportSetup(school.id) : undefined;
210
276
  if (options.login !== false)
211
277
  await firstRoast();
212
- const next = done.includes("desktop-reopened")
213
- ? "Claude Desktop is reopening. Ask it: am I cooked?"
214
- : done.includes("desktop")
215
- ? "Open Claude Desktop and ask: am I cooked?"
216
- : done.includes("chatgpt-desktop")
217
- ? "Restart the ChatGPT desktop app, then ask: am I cooked?"
218
- : done.includes("code")
219
- ? "Start Claude Code and ask: am I cooked?"
220
- : done.includes("chatgpt")
221
- ? "Finish connecting in ChatGPT, then ask: am I cooked?"
222
- : "Nothing was set up. Run `amicooked setup` again and pick an app.";
223
- p.outro(next);
278
+ const { steps, outro } = finishMessage(outcomes);
279
+ if (steps)
280
+ p.note(steps, "Next");
281
+ p.outro(outro);
282
+ await reported;
224
283
  return 0;
225
284
  }
226
285
  catch (error) {
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { parseArgs } from "util";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { loginCommand, pairCommand, statusCommand, uninstallCommand } from "./cli/manage.js";
5
+ import { finishAfterQuit } from "./cli/afterQuit.js";
5
6
  import { serveCommand } from "./cli/serve.js";
6
7
  import { setup } from "./cli/setup.js";
7
8
  import { serverInstructions } from "./instructions.js";
@@ -65,6 +66,9 @@ async function main(argv) {
65
66
  return serveCommand({ quick: values.quick, local: values.local, port: values.port ? Number(values.port) : undefined });
66
67
  case "status":
67
68
  return statusCommand(Boolean(values.json));
69
+ case "finish-after-quit":
70
+ // Hidden: setup starts this in the background when it can't restart Claude Desktop itself
71
+ return finishAfterQuit();
68
72
  case "uninstall":
69
73
  return uninstallCommand(Boolean(values.purge));
70
74
  default:
@@ -0,0 +1,111 @@
1
+ import { spawn, spawnSync } from "child_process";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ export const APPS = {
5
+ claude: {
6
+ id: "claude",
7
+ name: "Claude Desktop",
8
+ download: "https://claude.ai/download",
9
+ macName: "Claude",
10
+ // Claude Code ships a lowercase claude.app inside Claude's support folder; only the real app counts
11
+ macExe: /\/Claude\.app\/Contents\/MacOS\/Claude$/m,
12
+ winProcess: "Claude.exe",
13
+ winExe: (env) => (env.LOCALAPPDATA ? path.join(env.LOCALAPPDATA, "AnthropicClaude", "claude.exe") : null),
14
+ overwritesOnQuit: true,
15
+ },
16
+ chatgpt: {
17
+ id: "chatgpt",
18
+ name: "the ChatGPT app",
19
+ download: "https://chatgpt.com/download",
20
+ macName: "ChatGPT",
21
+ macExe: /\/ChatGPT\.app\/Contents\/MacOS\/ChatGPT$/m,
22
+ winProcess: "ChatGPT.exe",
23
+ // The Windows app comes from the Microsoft Store, which has no fixed path to launch
24
+ winExe: () => null,
25
+ overwritesOnQuit: false,
26
+ },
27
+ };
28
+ export const CLAUDE_CODE_DOWNLOAD = "https://code.claude.com/docs/en/overview";
29
+ /** Desktop apps exist for macOS and Windows only. */
30
+ export const desktopAppsSupported = (platform = process.platform) => platform === "darwin" || platform === "win32";
31
+ const run = (command, args) => {
32
+ const r = spawnSync(command, args, { encoding: "utf8", timeout: 10000 });
33
+ return { status: r.error ? null : r.status, stdout: r.stdout ?? "" };
34
+ };
35
+ const host = () => ({ platform: process.platform, run, env: process.env });
36
+ export function isRunning(app, h = host()) {
37
+ // ps, not pgrep: pgrep skips its own ancestors, so it misses the app when setup runs from inside it
38
+ if (h.platform === "darwin")
39
+ return app.macExe.test(h.run("ps", ["-axo", "comm="]).stdout);
40
+ if (h.platform === "win32") {
41
+ return h.run("tasklist", ["/FI", `IMAGENAME eq ${app.winProcess}`, "/NH"]).stdout.toLowerCase().includes(app.winProcess.toLowerCase());
42
+ }
43
+ return false;
44
+ }
45
+ /**
46
+ * True when this process was started by the app, e.g. an agent in Claude Desktop running setup.
47
+ * Quitting that app would end the very session asking for it, so setup must not.
48
+ */
49
+ export function isRunningInside(app, h = host(), pid = process.pid) {
50
+ if (h.platform !== "darwin")
51
+ return false;
52
+ const table = new Map();
53
+ for (const line of h.run("ps", ["-axo", "pid=,ppid=,comm="]).stdout.split("\n")) {
54
+ const m = line.match(/^\s*(\d+)\s+(\d+)\s+(.*)$/);
55
+ if (m)
56
+ table.set(Number(m[1]), { ppid: Number(m[2]), comm: m[3] });
57
+ }
58
+ for (let p = pid, hops = 0; p > 1 && hops < 64; hops++) {
59
+ const row = table.get(p);
60
+ if (!row)
61
+ return false;
62
+ if (app.macExe.test(row.comm))
63
+ return true;
64
+ p = row.ppid;
65
+ }
66
+ return false;
67
+ }
68
+ /** Asks the app to quit and waits until it's gone. False if it's still open (unsaved work, a dialog). */
69
+ export async function quit(app, h = host(), waitMs = 15000) {
70
+ if (h.platform === "darwin")
71
+ h.run("osascript", ["-e", `tell application "${app.macName}" to quit`]);
72
+ else if (h.platform === "win32")
73
+ h.run("taskkill", ["/IM", app.winProcess]);
74
+ else
75
+ return false;
76
+ for (const end = Date.now() + waitMs; Date.now() < end;) {
77
+ if (!isRunning(app, h))
78
+ return true;
79
+ await new Promise((resolve) => setTimeout(resolve, 300));
80
+ }
81
+ return !isRunning(app, h);
82
+ }
83
+ /** Opens the app. False when there's no reliable way to on this computer; then the student opens it. */
84
+ export function open(app, h = host(), launch = detachedLaunch) {
85
+ if (h.platform === "darwin")
86
+ return launch("open", ["-a", app.macName]);
87
+ if (h.platform === "win32") {
88
+ const exe = app.winExe(h.env);
89
+ return exe !== null && fs.existsSync(exe) && launch(exe, []);
90
+ }
91
+ return false;
92
+ }
93
+ /** Opens a web page in the default browser. */
94
+ export function openUrl(url, platform = process.platform, launch = detachedLaunch) {
95
+ if (platform === "darwin")
96
+ return launch("open", [url]);
97
+ if (platform === "win32")
98
+ return launch("cmd", ["/c", "start", "", url]);
99
+ return launch("xdg-open", [url]);
100
+ }
101
+ function detachedLaunch(command, args) {
102
+ try {
103
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
104
+ child.on("error", () => { });
105
+ child.unref();
106
+ return true;
107
+ }
108
+ catch {
109
+ return false;
110
+ }
111
+ }
@@ -1,4 +1,3 @@
1
- import { spawn, spawnSync } from "child_process";
2
1
  import * as fs from "fs";
3
2
  import * as os from "os";
4
3
  import * as path from "path";
@@ -82,37 +81,3 @@ export function manualSnippet(launch) {
82
81
  const entry = { command: launch.command, args: launch.args, ...(launch.env ? { env: launch.env } : {}) };
83
82
  return JSON.stringify({ mcpServers: { [SERVER_NAME]: entry } }, null, 2);
84
83
  }
85
- const probe = (command, args) => {
86
- const r = spawnSync(command, args, { encoding: "utf8", timeout: 10000 });
87
- return { status: r.error ? null : r.status, stdout: r.stdout ?? "" };
88
- };
89
- export function isClaudeDesktopRunning(platform = process.platform, run = probe) {
90
- // ps, not pgrep: pgrep skips its own ancestors, so it misses the app when setup runs from inside it
91
- if (platform === "darwin")
92
- return /\/Claude\.app\/Contents\/MacOS\/Claude$/m.test(run("ps", ["-axo", "comm="]).stdout);
93
- if (platform === "win32")
94
- return /claude\.exe/i.test(run("tasklist", ["/FI", "IMAGENAME eq Claude.exe", "/NH"]).stdout);
95
- return false;
96
- }
97
- /** Asks the app to quit (never forces it) and waits until it's gone. False if it's still open. */
98
- export async function quitClaudeDesktop(platform = process.platform, run = probe, waitMs = 15000) {
99
- if (platform === "darwin")
100
- run("osascript", ["-e", 'tell application "Claude" to quit']);
101
- else if (platform === "win32")
102
- run("taskkill", ["/IM", "Claude.exe"]);
103
- else
104
- return false;
105
- for (const end = Date.now() + waitMs; Date.now() < end;) {
106
- if (!isClaudeDesktopRunning(platform, run))
107
- return true;
108
- await new Promise((resolve) => setTimeout(resolve, 300));
109
- }
110
- return !isClaudeDesktopRunning(platform, run);
111
- }
112
- /** Opens the app again. Only macOS has a reliable way to find it; elsewhere the student opens it. */
113
- export function openClaudeDesktop(platform = process.platform) {
114
- if (platform !== "darwin")
115
- return false;
116
- spawn("open", ["-a", "Claude"], { stdio: "ignore", detached: true }).unref();
117
- return true;
118
- }
@@ -94,6 +94,10 @@ export function uninstallCodex(file = codexConfigPath()) {
94
94
  writeAtomic(file, `${rest.replace(/\s+$/, "")}\n`);
95
95
  return "removed";
96
96
  }
97
+ /** True when config.toml already starts exactly this command. */
98
+ export function codexEntryIs(launch, file = codexConfigPath()) {
99
+ return fs.existsSync(file) && splitOurTable(fs.readFileSync(file, "utf8")).ours === tomlEntry(launch);
100
+ }
97
101
  export function codexConfigured(file = codexConfigPath()) {
98
102
  return fs.existsSync(file) && splitOurTable(fs.readFileSync(file, "utf8")).ours !== null;
99
103
  }
package/dist/skill.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated from skill/SKILL.md by scripts/sync-skill.mjs. Don't edit by hand.
2
- export const SKILL_MD = "---\nname: amicooked\ndescription: Use when a student asks about their D2L Brightspace courses, grades, deadlines, assignments, announcements or course files, asks \"am I cooked?\", or wants to set up Am I Cooked.\n---\n\n# Am I Cooked\n\nAm I Cooked connects an AI assistant to a student's D2L Brightspace account (Avenue to Learn, LEARN, onQ, OWL Brightspace, CourseLink, MyLearningSpace and others). It runs on the student's own computer and is read-only.\n\n## Setting it up (for agents)\n\n1. Ask the student which school they go to. Presets: mcmaster, waterloo, western, queens, guelph, laurier, tmu, uottawa, carleton, brock, windsor, laurentian, lakehead. Any other Brightspace school works with the URL they log in through.\n2. Install it:\n - macOS / Linux: `curl -fsSL https://amicooked-mcp.vercel.app/install.sh | sh -s -- --no-setup`\n - Windows (PowerShell): `$env:AMICOOKED_NO_SETUP=1; irm https://amicooked-mcp.vercel.app/install.ps1 | iex`\n - With Node.js installed, `npx -y amicooked@0` works in place of `amicooked` below.\n3. Run setup with flags, and a long command timeout (at least 5 minutes), because the student signs in through a browser window that opens:\n `amicooked setup --school mcmaster --clients desktop,code`\n Use `--school https://...` for schools without a preset. Add `chatgpt-desktop` to `--clients` if they use the ChatGPT desktop app, then tell them to restart it. ChatGPT and Claude on the web or on phones aren't supported.\n4. Tell the student to sign in to their school in the browser window. Never ask for their password; you never need it.\n5. If something fails, run `amicooked status` and read what it says.\n\n<!-- server-instructions -->\n## Answering questions\n\n- Start broad questions (\"am I cooked?\", \"what should I work on?\", \"how am I doing?\", \"what's due?\") with `am_i_cooked`. It covers every current course in one call.\n- Other tools take a course code directly, like `course: \"3BB4\"`. Only call `get_my_courses` when a code is ambiguous or the student asks what they're enrolled in.\n- Check `get_announcements` for a course before a final verdict on it; deadlines and exam details often change there.\n- To read slides, handouts or assignment PDFs: `get_course_content` to find the file, then `download_file`. Use `read_file` for files already downloaded.\n- If a tool says a login window opened, tell the student to sign in there and ask again.\n\n## The verdict\n\nUse `summary.heatLabel` from `am_i_cooked` to set the tone. Be playful, never mean, and always useful.\n\n| heatLabel | Tone |\n|---|---|\n| raw | Relaxed. Nothing urgent; maybe get ahead on something. |\n| warming up | Light nudge. One or two things to handle soon. |\n| toasty | Focused. A real plan for the next few days. |\n| cooked | Direct and supportive. Triage what matters most. |\n| well done | Calm and practical. Damage control, and who to talk to. |\n\n1. Lead with a one-line verdict, e.g. \"Toasty, not cooked.\"\n2. Then the top 3 actions, each with course, item and due time in the student's local time (D2L times are UTC).\n3. Say whether a grade is `final_calculated` or `estimated_from_items`; estimates ignore dropped and bonus items.\n - For an estimate, say how much is left, like \"67.6% so far. 60% of your grade is still to come.\" Use `weightRemaining` for that number.\n - Name the `keyItems` when a grade needs explaining, with their weight: \"the midterm (59.5%, worth 25%) is pulling it down.\"\n - Never work weights out backwards from a result. Use the `weight` values the tools return.\n - `basis: \"points\"` means the gradebook has no weights. Say the estimate is by points and the real weighting may differ. If the student asks how the grade is calculated, find the course outline with `get_course_content` and read the weights from it.\n4. `late_window_open` means a missed assignment can still be submitted: say so first, it's the easiest win.\n5. If `partial_data` appears, mention that some of a course couldn't be loaded.\n6. For grades under 60%, suggest office hours, the TA, or an academic advisor.\n\n## Integrity\n\nAm I Cooked only reads. Help the student understand material and plan their time, but don't write graded work for them to submit.\n<!-- /server-instructions -->\n";
2
+ export const SKILL_MD = "---\nname: amicooked\ndescription: Use when a student asks about their D2L Brightspace courses, grades, deadlines, assignments, announcements or course files, asks \"am I cooked?\", or wants to set up Am I Cooked.\n---\n\n# Am I Cooked\n\nAm I Cooked connects an AI assistant to a student's D2L Brightspace account (Avenue to Learn, LEARN, onQ, OWL Brightspace, CourseLink, MyLearningSpace and others). It runs on the student's own computer and is read-only.\n\n## Setting it up (for agents)\n\n**First, check that you can run commands on the student's computer.** Setup installs a program there, so it only works from an agent with a terminal, like Claude Code, Codex or the ChatGPT desktop app. If you're on a website (chatgpt.com, claude.ai, gemini.google.com), in a phone app, or in a chat with no command tool, don't try. Tell the student instead:\n\n- Get an app that can do it: Claude Desktop (https://claude.ai/download) or the ChatGPT app (https://chatgpt.com/download), then paste the same request there. Or install it themselves by pasting this into Terminal (Mac): `curl -fsSL https://amicooked-mcp.vercel.app/install.sh | sh`, or this into PowerShell (Windows): `irm https://amicooked-mcp.vercel.app/install.ps1 | iex`.\n- Either way, it ends by opening their AI app, ready to ask \"am I cooked?\".\n\nIf you can run commands:\n\n1. Ask the student which school they go to. Presets: mcmaster, waterloo, western, queens, guelph, laurier, tmu, uottawa, carleton, brock, windsor, laurentian, lakehead. Any other Brightspace school works with the URL they log in through.\n2. Install it:\n - macOS / Linux: `curl -fsSL https://amicooked-mcp.vercel.app/install.sh | sh -s -- --no-setup`\n - Windows (PowerShell): `$env:AMICOOKED_NO_SETUP=1; irm https://amicooked-mcp.vercel.app/install.ps1 | iex`\n - With Node.js installed, `npx -y amicooked@0` works in place of `amicooked` below.\n3. Run setup with flags, and a long command timeout (at least 5 minutes), because the student signs in through a browser window that opens:\n `amicooked setup --school mcmaster --clients desktop,code`\n Use `--school https://...` for schools without a preset. Add `chatgpt-desktop` to `--clients` if they use the ChatGPT desktop app, then tell them to restart it. ChatGPT and Claude on the web or on phones aren't supported.\n4. Tell the student to sign in to their school in the browser window. Never ask for their password; you never need it.\n5. Setup ends with a \"Next\" list: one line per app saying it's open and ready, needs a restart, needs opening, or needs installing (with a link). Tell the student each line as written. If you're running inside Claude Desktop, they need to quit it; Am I Cooked then reopens it with everything set up.\n6. If something fails, run `amicooked status` and read what it says.\n\n<!-- server-instructions -->\n## Answering questions\n\n- Start broad questions (\"am I cooked?\", \"what should I work on?\", \"how am I doing?\", \"what's due?\") with `am_i_cooked`. It covers every current course in one call.\n- Other tools take a course code directly, like `course: \"3BB4\"`. Only call `get_my_courses` when a code is ambiguous or the student asks what they're enrolled in.\n- Check `get_announcements` for a course before a final verdict on it; deadlines and exam details often change there.\n- To read slides, handouts or assignment PDFs: `get_course_content` to find the file, then `download_file`. Use `read_file` for files already downloaded.\n- If a tool says a login window opened, tell the student to sign in there and ask again.\n\n## The verdict\n\nUse `summary.heatLabel` from `am_i_cooked` to set the tone. Be playful, never mean, and always useful.\n\n| heatLabel | Tone |\n|---|---|\n| raw | Relaxed. Nothing urgent; maybe get ahead on something. |\n| warming up | Light nudge. One or two things to handle soon. |\n| toasty | Focused. A real plan for the next few days. |\n| cooked | Direct and supportive. Triage what matters most. |\n| well done | Calm and practical. Damage control, and who to talk to. |\n\n1. Lead with a one-line verdict, e.g. \"Toasty, not cooked.\"\n2. Then the top 3 actions, each with course, item and due time in the student's local time (D2L times are UTC).\n3. Say whether a grade is `final_calculated` or `estimated_from_items`; estimates ignore dropped and bonus items.\n - For an estimate, say how much is left, like \"67.6% so far. 60% of your grade is still to come.\" Use `weightRemaining` for that number.\n - Name the `keyItems` when a grade needs explaining, with their weight: \"the midterm (59.5%, worth 25%) is pulling it down.\"\n - Never work weights out backwards from a result. Use the `weight` values the tools return.\n - `basis: \"points\"` means the gradebook has no weights. Say the estimate is by points and the real weighting may differ. If the student asks how the grade is calculated, find the course outline with `get_course_content` and read the weights from it.\n4. `late_window_open` means a missed assignment can still be submitted: say so first, it's the easiest win.\n5. If `partial_data` appears, mention that some of a course couldn't be loaded.\n6. For grades under 60%, suggest office hours, the TA, or an academic advisor.\n\n## Integrity\n\nAm I Cooked only reads. Help the student understand material and plan their time, but don't write graded work for them to submit.\n<!-- /server-instructions -->\n";
@@ -0,0 +1,39 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { homeDir } from "./config.js";
4
+ import { findPreset } from "./schools.js";
5
+ /** Counts finished setups; see site/api/e.js. */
6
+ export const REPORT_URL = "https://amicooked-mcp.vercel.app/api/e";
7
+ export function telemetryOff(env = process.env) {
8
+ const on = (v) => Boolean(v) && v !== "0" && v !== "false";
9
+ return on(env.AMICOOKED_NO_TELEMETRY) || on(env.DO_NOT_TRACK);
10
+ }
11
+ /**
12
+ * Sends one anonymous "setup finished" count, the first time setup finishes on this computer. It carries the
13
+ * school preset id (or "custom", never the URL) and the platform. A marker file in ~/.amicooked stops repeat
14
+ * setups being counted again, so nothing identifying is sent. Never throws and gives up after 1.5 s.
15
+ */
16
+ export async function reportSetup(schoolId, options = {}) {
17
+ const { env = process.env, fetchImpl = fetch, platform = `${process.platform}-${process.arch}` } = options;
18
+ if (telemetryOff(env))
19
+ return false;
20
+ const marker = path.join(homeDir(), "setup-reported");
21
+ if (fs.existsSync(marker))
22
+ return false;
23
+ try {
24
+ const res = await fetchImpl(REPORT_URL, {
25
+ method: "POST",
26
+ headers: { "content-type": "application/json" },
27
+ body: JSON.stringify({ e: "setup", school: findPreset(schoolId)?.id ?? "custom", platform }),
28
+ signal: AbortSignal.timeout(1500),
29
+ });
30
+ if (!res.ok)
31
+ return false;
32
+ fs.mkdirSync(path.dirname(marker), { recursive: true });
33
+ fs.writeFileSync(marker, "");
34
+ return true;
35
+ }
36
+ catch {
37
+ return false;
38
+ }
39
+ }
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Must match package.json; a unit test checks this
2
- export const VERSION = "0.1.3";
2
+ export const VERSION = "0.1.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amicooked",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Ask your AI if you're cooked. A local MCP server for D2L Brightspace: grades, deadlines and announcements in Claude and ChatGPT.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,7 +19,10 @@
19
19
  "test": "vitest run",
20
20
  "test:watch": "vitest",
21
21
  "prepack": "npm run build",
22
- "build:bin": "node scripts/sync-skill.mjs && node scripts/build-binaries.mjs"
22
+ "build:bin": "node scripts/sync-skill.mjs && node scripts/build-binaries.mjs",
23
+ "preversion": "npm test",
24
+ "version": "node scripts/sync-version.mjs && git add src/version.ts",
25
+ "stats": "node --env-file-if-exists=.env.local scripts/stats.mjs"
23
26
  },
24
27
  "keywords": [
25
28
  "mcp",
package/skill/SKILL.md CHANGED
@@ -9,6 +9,13 @@ Am I Cooked connects an AI assistant to a student's D2L Brightspace account (Ave
9
9
 
10
10
  ## Setting it up (for agents)
11
11
 
12
+ **First, check that you can run commands on the student's computer.** Setup installs a program there, so it only works from an agent with a terminal, like Claude Code, Codex or the ChatGPT desktop app. If you're on a website (chatgpt.com, claude.ai, gemini.google.com), in a phone app, or in a chat with no command tool, don't try. Tell the student instead:
13
+
14
+ - Get an app that can do it: Claude Desktop (https://claude.ai/download) or the ChatGPT app (https://chatgpt.com/download), then paste the same request there. Or install it themselves by pasting this into Terminal (Mac): `curl -fsSL https://amicooked-mcp.vercel.app/install.sh | sh`, or this into PowerShell (Windows): `irm https://amicooked-mcp.vercel.app/install.ps1 | iex`.
15
+ - Either way, it ends by opening their AI app, ready to ask "am I cooked?".
16
+
17
+ If you can run commands:
18
+
12
19
  1. Ask the student which school they go to. Presets: mcmaster, waterloo, western, queens, guelph, laurier, tmu, uottawa, carleton, brock, windsor, laurentian, lakehead. Any other Brightspace school works with the URL they log in through.
13
20
  2. Install it:
14
21
  - macOS / Linux: `curl -fsSL https://amicooked-mcp.vercel.app/install.sh | sh -s -- --no-setup`
@@ -18,7 +25,8 @@ Am I Cooked connects an AI assistant to a student's D2L Brightspace account (Ave
18
25
  `amicooked setup --school mcmaster --clients desktop,code`
19
26
  Use `--school https://...` for schools without a preset. Add `chatgpt-desktop` to `--clients` if they use the ChatGPT desktop app, then tell them to restart it. ChatGPT and Claude on the web or on phones aren't supported.
20
27
  4. Tell the student to sign in to their school in the browser window. Never ask for their password; you never need it.
21
- 5. If something fails, run `amicooked status` and read what it says.
28
+ 5. Setup ends with a "Next" list: one line per app saying it's open and ready, needs a restart, needs opening, or needs installing (with a link). Tell the student each line as written. If you're running inside Claude Desktop, they need to quit it; Am I Cooked then reopens it with everything set up.
29
+ 6. If something fails, run `amicooked status` and read what it says.
22
30
 
23
31
  <!-- server-instructions -->
24
32
  ## Answering questions