@ignitionai/cogitator 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  User-facing changes to Cogitator. GitHub development updates and npm releases are separate: an entry marked **Unreleased** is not yet available from npm.
4
4
 
5
+ ## [0.7.0] - 2026-11-22
6
+
7
+ **Highlight:** update Cogitator and your pi extensions in one click.
8
+
9
+ ### Added
10
+
11
+ - **One-click updates:** in **Updates**, “Update to X and restart” installs the new Cogitator release with pi, restarts the server and reloads the page. If conversations are still working, Cogitator asks before interrupting them. “Update all” updates every pi extension that has a newer release, then reloads extensions once, without interrupting active conversations. This works for installations managed by pi (`pi install`, server started with `/cogitator`). Source releases and system services (systemd) keep the VPS guide procedure: their code is protected from the server account. Set `COGITATOR_SELF_UPDATE=0` to turn it off.
12
+
5
13
  ## [0.6.0] - 2026-11-22
6
14
 
7
15
  **Highlight:** a terminal on your server, in the browser, with an agent at your side.
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  Cogitator is a **pi package and web UI**, not a separate hosted AI service. Connect your model providers, open a bot, and work through conversations, projects, skills and subagents. Your installation keeps its own data and credentials. The interface is available in **English and French**, including on mobile.
16
16
 
17
- > **Release status:** this README describes the current `dev` build. **0.6.0** is published on npm, and the badge above shows the latest published version. Any later entry marked **Unreleased** in the [changelog](https://github.com/IgnitionAI/cogitator/blob/dev/CHANGELOG.md) requires a source build until it is published.
17
+ > **Release status:** this README describes the current `dev` build. **0.7.0** is published on npm, and the badge above shows the latest published version. Any later entry marked **Unreleased** in the [changelog](https://github.com/IgnitionAI/cogitator/blob/dev/CHANGELOG.md) requires a source build until it is published.
18
18
 
19
19
  ![Cogitator bots: Majordome, Project Manager and Skills Architect](https://raw.githubusercontent.com/IgnitionAI/cogitator/dev/docs/images/bots.jpg)
20
20
 
@@ -58,6 +58,7 @@ These are editable agent presets, not separate subscriptions. Select their provi
58
58
  - **Conversations:** streaming responses, tool results, code, images, files and diffs. Change the model without discarding history once the current turn finishes.
59
59
  - **Projects:** import GitHub repositories, connect a private GitHub account, inspect project files, use a GitHub Issues board and start agent work from a ticket.
60
60
  - **Subagents:** install `@gotgenes/pi-subagents` from Extensions to enable delegation. Click a child in the Subagents panel to read its conversation in a large dialog, with live progress and expandable tools. The parent keeps working.
61
+ - **Updates:** update Cogitator and every pi extension in one click from **Updates**; Cogitator restarts and the page reloads (pi-managed installations).
61
62
  - **Extensions:** browse the pi catalog, install packages, check their versions, update individually and reload idle conversations. Active parents and background children keep running.
62
63
  - **Skills:** import reusable procedures, attach them to agents or invoke `/skill:name` in a message. Ask the Skills Architect to create a missing procedure.
63
64
  - **Terminal:** a shell on your server in the browser (protected mode), your agents running interactively in pi, and an assistant that turns `# a request` into a command, suggests the rest of what you type and explains errors. Nothing runs without you. See [Web terminal](https://github.com/IgnitionAI/cogitator/blob/dev/docs/terminal.md).
@@ -108,6 +108,42 @@ export class PackageManager {
108
108
  void this.perform(operation);
109
109
  return operation;
110
110
  }
111
+ /** Met à jour toutes les extensions qui ont une version plus récente, puis recharge une seule fois. */
112
+ startAll(exclude = []) {
113
+ if (this.operation?.status === "running")
114
+ throw new Error("Une installation est déjà en cours.");
115
+ const operation = { name: "*", action: "update-all", status: "running", updated: [], failed: [] };
116
+ this.operation = operation;
117
+ void this.performAll(operation, new Set(exclude));
118
+ return operation;
119
+ }
120
+ async performAll(operation, exclude) {
121
+ try {
122
+ const updates = (await packageUpdates(this.paths)).filter(u => u.available && u.latest && !exclude.has(u.name));
123
+ operation.total = updates.length;
124
+ for (const update of updates) {
125
+ try {
126
+ const meta = JSON.parse(await fetchText(`https://registry.npmjs.org/${encodeURIComponent(update.name)}/latest`));
127
+ if (meta.name !== update.name || !meta.keywords?.includes("pi-package") || !/^\d+\.\d+\.\d+$/.test(meta.version))
128
+ throw new Error("Ce package n’est pas un package pi valide.");
129
+ await this.run("install", `npm:${update.name}@${meta.version}`, this.paths);
130
+ operation.updated.push(update.name);
131
+ }
132
+ catch (error) {
133
+ operation.failed.push({ name: update.name, error: error instanceof Error ? error.message : "Mise à jour échouée." });
134
+ }
135
+ }
136
+ if (operation.updated.length)
137
+ operation.deferred = await this.refresh();
138
+ operation.status = operation.failed.length && !operation.updated.length ? "error" : "done";
139
+ if (operation.status === "error")
140
+ operation.error = operation.failed.map(f => `${f.name} : ${f.error}`).join("\n");
141
+ }
142
+ catch (error) {
143
+ operation.status = "error";
144
+ operation.error = error instanceof Error ? error.message : "Mise à jour échouée.";
145
+ }
146
+ }
111
147
  async perform(operation) {
112
148
  try {
113
149
  let source;
@@ -142,7 +178,7 @@ export class PackageManager {
142
178
  }
143
179
  }
144
180
  }
145
- function runPi(action, source, paths) {
181
+ export function runPi(action, source, paths) {
146
182
  return new Promise((resolve, reject) => {
147
183
  // Arguments, never shell text. Same executable environment and profile as chat RPC.
148
184
  const child = spawn("pi", [action, source], { cwd: paths.home, env: { ...process.env, PI_CODING_AGENT_DIR: paths.piAgentDir }, stdio: "ignore", detached: process.platform !== "win32" });
package/dist/src/pool.js CHANGED
@@ -142,6 +142,14 @@ export class PiPool {
142
142
  await this.evictIdle(handle);
143
143
  return this.handles.size;
144
144
  }
145
+ /** Conversations au travail (tour en cours, compaction ou sous-agent vivant). */
146
+ async busyCount() {
147
+ let busy = 0;
148
+ for (const handle of [...this.handles.values()])
149
+ if (!handle.dead && await this.streaming(handle))
150
+ busy++;
151
+ return busy;
152
+ }
145
153
  isLive(convId) {
146
154
  const h = this.handles.get(convId);
147
155
  return Boolean(h && !h.dead);
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Mise à jour de Cogitator en un clic, pour une installation gérée par pi
3
+ * (`pi install npm:@ignitionai/cogitator`, serveur lancé par `/cogitator`).
4
+ *
5
+ * 1. `pi install npm:@ignitionai/cogitator@<dernière>` : remplace le paquet sur place ;
6
+ * 2. un relanceur détaché attend la fin de ce processus puis relance la même commande ;
7
+ * 3. le serveur s'arrête proprement (SIGTERM → arrêt habituel de cli.ts).
8
+ *
9
+ * Refusé pour une release source ou un service systemd : leur code n'appartient pas au
10
+ * compte du serveur (protection voulue) ; l'UI affiche alors la procédure du guide VPS.
11
+ */
12
+ import { spawn } from "node:child_process";
13
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
14
+ import { join, sep } from "node:path";
15
+ import { findPackageRoot } from "./default-agent.js";
16
+ export const PACKAGE = "@ignitionai/cogitator";
17
+ export function selfUpdateSupport(paths, root = findPackageRoot(), env = process.env) {
18
+ if (!root)
19
+ return { supported: false, reason: "SOURCE_BUILD" };
20
+ const piModules = join(paths.piAgentDir, "npm", "node_modules");
21
+ let real, base;
22
+ try {
23
+ real = realpathSync(root);
24
+ base = realpathSync(piModules);
25
+ }
26
+ catch {
27
+ return { supported: false, reason: "NOT_PI_MANAGED" };
28
+ }
29
+ if (!real.startsWith(base + sep))
30
+ return { supported: false, reason: "NOT_PI_MANAGED" };
31
+ // Un service (systemd) gère lui-même le cycle de vie : pas de relance concurrente.
32
+ if (env.INVOCATION_ID || env.COGITATOR_SELF_UPDATE === "0")
33
+ return { supported: false, reason: "SERVICE_MANAGED" };
34
+ return { supported: true };
35
+ }
36
+ export class SelfUpdateError extends Error {
37
+ code;
38
+ status;
39
+ detail;
40
+ constructor(code, status = 409, detail) {
41
+ super(code);
42
+ this.code = code;
43
+ this.status = status;
44
+ this.detail = detail;
45
+ }
46
+ }
47
+ export class SelfUpdater {
48
+ deps;
49
+ state = { status: "idle" };
50
+ constructor(deps) {
51
+ this.deps = deps;
52
+ }
53
+ /** Lance la mise à jour ; l'installation se poursuit en tâche de fond (suivie par `state`). */
54
+ async start(force = false) {
55
+ if (this.state.status === "installing" || this.state.status === "restarting")
56
+ throw new SelfUpdateError("SELF_UPDATE_RUNNING");
57
+ const support = this.deps.support();
58
+ if (!support.supported)
59
+ throw new SelfUpdateError(`SELF_UPDATE_${support.reason}`, 400);
60
+ const release = await this.deps.release();
61
+ if (release.status !== "available")
62
+ throw new SelfUpdateError("SELF_UPDATE_NOT_AVAILABLE", 409, { current: release.current, latest: release.latest });
63
+ const busy = await this.deps.busy();
64
+ if (busy > 0 && !force)
65
+ throw new SelfUpdateError("SELF_UPDATE_BUSY", 409, { busy });
66
+ const target = release.latest;
67
+ this.state = { status: "installing", target };
68
+ void this.run(target);
69
+ return { ...this.state };
70
+ }
71
+ async run(target) {
72
+ try {
73
+ await this.deps.install(`npm:${PACKAGE}@${target}`);
74
+ const installed = this.deps.installedVersion();
75
+ if (installed !== target)
76
+ throw new Error(`Version installée inattendue : ${installed ?? "inconnue"}`);
77
+ this.state = { status: "restarting", target };
78
+ this.deps.relaunch();
79
+ // Laisse le temps à l'UI de lire l'état « restarting » avant l'arrêt.
80
+ setTimeout(() => this.deps.shutdown(), 500).unref();
81
+ }
82
+ catch (error) {
83
+ this.state = { status: "error", target, error: error instanceof Error ? error.message : String(error) };
84
+ }
85
+ }
86
+ }
87
+ export function installedPackageVersion(root = findPackageRoot()) {
88
+ if (!root)
89
+ return null;
90
+ const file = join(root, "package.json");
91
+ if (!existsSync(file))
92
+ return null;
93
+ try {
94
+ const v = JSON.parse(readFileSync(file, "utf8")).version;
95
+ return typeof v === "string" ? v : null;
96
+ }
97
+ catch {
98
+ return null;
99
+ }
100
+ }
101
+ /**
102
+ * Relanceur détaché : attend la sortie de ce processus (60 s max), puis relance
103
+ * exactement la même commande (`node …/cli.js [--auth-required]`) avec le même environnement.
104
+ */
105
+ export function spawnRelauncher(pid = process.pid, exec = process.execPath, args = process.argv.slice(1), env = process.env) {
106
+ const script = [
107
+ "const { spawn } = require('node:child_process');",
108
+ "const [pid, exec, ...args] = process.argv.slice(1);",
109
+ "const deadline = Date.now() + 60000;",
110
+ "const alive = () => { try { process.kill(Number(pid), 0); return true; } catch { return false; } };",
111
+ "(function wait() {",
112
+ " if (alive() && Date.now() < deadline) return setTimeout(wait, 200);",
113
+ " spawn(exec, args, { detached: true, stdio: 'ignore' }).unref();",
114
+ "})();",
115
+ ].join("\n");
116
+ spawn(process.execPath, ["-e", script, String(pid), exec, ...args], { detached: true, stdio: "ignore", env }).unref();
117
+ }
@@ -5,7 +5,7 @@ import { resourceInventory, probeCogitatorTools } from "./project-setup.js";
5
5
  import { importSkillUpload } from "./skills-upload.js";
6
6
  import { appUpdateStatus } from "./app-updates.js";
7
7
  import { GitHubLogin, githubEnv, githubConfigured } from "./github-login.js";
8
- import { catalog, installedPackages, packageUpdates, PackageManager } from "./packages.js";
8
+ import { catalog, installedPackages, packageUpdates, PackageManager, runPi } from "./packages.js";
9
9
  import { changeConfiguration, dismissConfiguration, ConfigurationError, recoverConfigurations } from "./classic-configuration.js";
10
10
  import { execFile } from "node:child_process";
11
11
  import { randomUUID } from "node:crypto";
@@ -46,6 +46,7 @@ import { cloneRepo, isInsideDir, localDirFor } from "./git-import.js";
46
46
  import { listSubagents, readSubagentTranscript } from "./subagents.js";
47
47
  import { MCP_HTTP_PATH, McpHttpEndpoint } from "./mcp-http.js";
48
48
  import { McpOAuth } from "./mcp-oauth.js";
49
+ import { installedPackageVersion, PACKAGE as SELF_PACKAGE, SelfUpdateError, SelfUpdater, selfUpdateSupport, spawnRelauncher } from "./self-update.js";
49
50
  import { loadPty, shellLaunch, terminalEnv, TerminalError, TerminalManager } from "./terminal.js";
50
51
  import { attachTerminalSocket, terminalRoutes } from "./terminal-http.js";
51
52
  import { piComplete } from "./terminal-assist.js";
@@ -272,6 +273,20 @@ function requireAgent(deps, ctx) {
272
273
  function registryRoutes(deps) {
273
274
  const { paths } = deps;
274
275
  const packages = new PackageManager(paths, () => deps.pool.refreshExtensions());
276
+ const selfUpdater = new SelfUpdater({
277
+ support: () => selfUpdateSupport(paths),
278
+ release: () => appUpdateStatus(),
279
+ busy: () => deps.pool.busyCount(),
280
+ install: (source) => runPi("install", source, paths),
281
+ installedVersion: () => installedPackageVersion(),
282
+ relaunch: () => spawnRelauncher(),
283
+ shutdown: () => {
284
+ // Arrêt habituel (cli.ts) ; filet de sécurité si une poignée retient le processus.
285
+ setTimeout(() => process.exit(0), 15_000).unref();
286
+ process.kill(process.pid, "SIGTERM");
287
+ },
288
+ ...deps.selfUpdate,
289
+ });
275
290
  const sampleMachine = machineMetrics(paths.home);
276
291
  return [
277
292
  ["GET", "/api/machine", async (ctx) => {
@@ -292,11 +307,40 @@ function registryRoutes(deps) {
292
307
  sendJson(ctx.res, 200, { ok: true });
293
308
  }],
294
309
  ["GET", "/api/app-updates", async (ctx) => {
310
+ const selfUpdate = { ...selfUpdateSupport(paths), state: selfUpdater.state };
295
311
  try {
296
- sendJson(ctx.res, 200, await appUpdateStatus());
312
+ sendJson(ctx.res, 200, { ...await appUpdateStatus(), selfUpdate });
297
313
  }
298
314
  catch {
299
- sendJson(ctx.res, 502, { error: "Release check unavailable" });
315
+ sendJson(ctx.res, 502, { error: "Release check unavailable", selfUpdate });
316
+ }
317
+ }],
318
+ ["GET", "/api/app-updates/state", (ctx) => {
319
+ sendJson(ctx.res, 200, { ...selfUpdateSupport(paths), state: selfUpdater.state, version: packageVersion() });
320
+ }],
321
+ ["POST", "/api/app-updates/apply", async (ctx) => {
322
+ ctx.check();
323
+ if (packages.operation?.status === "running")
324
+ return sendJson(ctx.res, 409, { error: "Une installation est déjà en cours." });
325
+ const force = ctx.body?.force === true;
326
+ try {
327
+ sendJson(ctx.res, 202, await selfUpdater.start(force));
328
+ }
329
+ catch (error) {
330
+ if (error instanceof SelfUpdateError)
331
+ return sendJson(ctx.res, error.status, { error: error.code, ...error.detail });
332
+ sendJson(ctx.res, 502, { error: error instanceof Error ? error.message : "Release check unavailable" });
333
+ }
334
+ }],
335
+ ["POST", "/api/packages/update-all", (ctx) => {
336
+ ctx.check();
337
+ if (selfUpdater.state.status === "installing")
338
+ return sendJson(ctx.res, 409, { error: "Une installation est déjà en cours." });
339
+ try {
340
+ sendJson(ctx.res, 202, packages.startAll([SELF_PACKAGE]));
341
+ }
342
+ catch (error) {
343
+ sendJson(ctx.res, 409, { error: error.message });
300
344
  }
301
345
  }],
302
346
  ["GET", "/api/packages", (ctx) => {
@@ -1618,6 +1662,7 @@ export function createApp(opts) {
1618
1662
  durable,
1619
1663
  createWorkspaceImpl: opts.createWorkspaceImpl,
1620
1664
  team,
1665
+ selfUpdate: opts.selfUpdate,
1621
1666
  };
1622
1667
  const browser = new SharedBrowser(paths.home, db, opts.auth?.config.origin);
1623
1668
  const routes = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ignitionai/cogitator",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A web control panel for pi: composable agents, workspaces, interactive conversations, and scheduled tasks. A pi package.",
5
5
  "type": "module",
6
6
  "keywords": [