@netnodeag/kraftwerk 0.95.0 → 0.97.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.
Files changed (83) hide show
  1. package/README.md +47 -7
  2. package/dist/acp.d.ts +31 -3
  3. package/dist/acp.js +63 -2
  4. package/dist/cli/boards.js +6 -5
  5. package/dist/cli/create-brief.js +2 -2
  6. package/dist/cli/daemon-login.d.ts +1 -1
  7. package/dist/cli/daemon-login.js +1 -1
  8. package/dist/cli/doctor.js +6 -3
  9. package/dist/cli/init.js +2 -0
  10. package/dist/cli/knowledge.js +9 -6
  11. package/dist/cli/presentations.js +8 -4
  12. package/dist/cli/projects.js +3 -3
  13. package/dist/client/index.d.ts +2 -0
  14. package/dist/client/index.js +3 -0
  15. package/dist/client/routes.d.ts +2 -0
  16. package/dist/client/routes.js +2 -0
  17. package/dist/config.d.ts +34 -0
  18. package/dist/config.js +28 -1
  19. package/dist/core/agents.js +1 -1
  20. package/dist/core/board-wake.d.ts +1 -1
  21. package/dist/core/boards.d.ts +1 -1
  22. package/dist/core/boards.js +10 -6
  23. package/dist/core/chat/acp.d.ts +6 -0
  24. package/dist/core/chat/acp.js +33 -7
  25. package/dist/core/chat/permissions.d.ts +2 -2
  26. package/dist/core/chat/permissions.js +4 -1
  27. package/dist/core/chat/pi.d.ts +12 -0
  28. package/dist/core/chat/pi.js +56 -5
  29. package/dist/core/chat/sessions.d.ts +13 -5
  30. package/dist/core/chat/sessions.js +34 -9
  31. package/dist/core/chat/types.d.ts +3 -1
  32. package/dist/core/cloud.d.ts +45 -0
  33. package/dist/core/cloud.js +35 -0
  34. package/dist/core/knowledge.d.ts +0 -7
  35. package/dist/core/knowledge.js +6 -6
  36. package/dist/core/person.d.ts +41 -0
  37. package/dist/core/person.js +47 -0
  38. package/dist/core/projects.d.ts +1 -1
  39. package/dist/core/projects.js +3 -2
  40. package/dist/harness.d.ts +3 -2
  41. package/dist/harnesses/acp.js +3 -1
  42. package/dist/harnesses/registry.js +2 -1
  43. package/dist/server/api/agents.js +2 -2
  44. package/dist/server/api/boards.js +1 -1
  45. package/dist/server/api/chats.d.ts +4 -1
  46. package/dist/server/api/chats.js +30 -12
  47. package/dist/server/api/cloud.d.ts +8 -0
  48. package/dist/server/api/index.d.ts +25 -3
  49. package/dist/server/api/presentations.js +2 -2
  50. package/dist/server/api/projects.d.ts +1 -1
  51. package/dist/server/api/projects.js +1 -1
  52. package/dist/server/api/router.js +5 -2
  53. package/dist/server/api/workspace.d.ts +14 -1
  54. package/dist/server/api/workspace.js +21 -1
  55. package/dist/server/cloud.d.ts +3 -0
  56. package/dist/server/cloud.js +20 -4
  57. package/dist/server/person.d.ts +9 -0
  58. package/dist/server/person.js +14 -0
  59. package/dist/server/server.js +60 -4
  60. package/dist/server/trust.d.ts +5 -1
  61. package/dist/server/users.d.ts +55 -0
  62. package/dist/server/users.js +258 -0
  63. package/package.json +1 -1
  64. package/schema/kraftwerk.schema.json +8 -0
  65. package/schema/workflow.schema.json +4 -3
  66. package/web/dist/assets/{dist--oB2_FQJ.js → dist-BD4ooe-Y.js} +1 -1
  67. package/web/dist/assets/{dist-WA1PTY07.js → dist-BduOHHOY.js} +1 -1
  68. package/web/dist/assets/{dist-CRqkyR9b.js → dist-BoajTxbz.js} +1 -1
  69. package/web/dist/assets/{dist-FlDPUw_l.js → dist-DGLb7wE6.js} +1 -1
  70. package/web/dist/assets/{dist-SHAE_oEQ.js → dist-DJACzcZZ.js} +1 -1
  71. package/web/dist/assets/{dist-SL9iU_p4.js → dist-DY6QplYX.js} +1 -1
  72. package/web/dist/assets/{dist-Tdda9sK7.js → dist-D_uWSMLk.js} +1 -1
  73. package/web/dist/assets/{dist-Ys1tb91R.js → dist-P7JCq9c3.js} +1 -1
  74. package/web/dist/assets/dist-ajNgHt2Q.js +1 -0
  75. package/web/dist/assets/{dist-BlxwNXF3.js → dist-lcPkaK4d.js} +1 -1
  76. package/web/dist/assets/{dist-DB33yOhN.js → dist-oRcLByHn.js} +1 -1
  77. package/web/dist/assets/{editor-Clx4xAh9.js → editor-hTceN7Iz.js} +3 -3
  78. package/web/dist/assets/index-BGgQaaA9.css +2 -0
  79. package/web/dist/assets/index-BOkjCxut.js +488 -0
  80. package/web/dist/index.html +2 -2
  81. package/web/dist/assets/dist-C3zyJ_nA.js +0 -1
  82. package/web/dist/assets/index-BJml45iw.js +0 -488
  83. package/web/dist/assets/index-CWopPK15.css +0 -2
@@ -96,3 +96,38 @@ export const machineGoodbye = (base, creds, version) => cloudPost(base, "/api/ma
96
96
  export const machineUnlink = (base, creds, version) => cloudPost(base, "/api/machines/unlink", { id: creds.id, secret: creds.secret }, { version });
97
97
  export const memberVerify = (base, creds, token, workspaceId, version) => cloudPost(base, "/api/members/verify", { id: creds.id, secret: creds.secret, token, workspaceId }, { version });
98
98
  export const workspaceInvite = (base, creds, workspaceId, role, version) => cloudPost(base, `/api/workspaces/${encodeURIComponent(workspaceId)}/invites`, { id: creds.id, secret: creds.secret, ...(role ? { role } : {}) }, { version });
99
+ export const signinExchange = (base, creds, code, redirect, version) => cloudPost(base, "/api/signin/exchange", { id: creds.id, secret: creds.secret, code, redirect }, { version });
100
+ export const signinVerify = (base, creds, workspace, user, version) => cloudPost(base, "/api/signin/verify", { id: creds.id, secret: creds.secret, workspace, user }, { version });
101
+ /** Where the browser goes to sign in to workspace `workspaceId` served by machine `machineId`. */
102
+ export function signinUrl(base, q) {
103
+ return `${base}/signin?${new URLSearchParams(q)}`;
104
+ }
105
+ /**
106
+ * ~/.kraftwerk/account.json — the account that claimed this machine
107
+ * ({id, email, handle}), written by the daemon when the cloud names it and
108
+ * removed when the claim ends. The machine's own shell (the CLI) acts as
109
+ * this person in a `users: cloud` workspace.
110
+ */
111
+ export const accountFilePath = () => path.join(kwHome(), "account.json");
112
+ export async function readAccountFile() {
113
+ try {
114
+ const raw = JSON.parse(await fs.readFile(accountFilePath(), "utf8"));
115
+ return typeof raw.id === "string" && typeof raw.email === "string" && typeof raw.handle === "string" ? { id: raw.id, email: raw.email, handle: raw.handle } : null;
116
+ }
117
+ catch {
118
+ return null;
119
+ }
120
+ }
121
+ /** Write (or with null remove) account.json; unchanged content is not rewritten. */
122
+ export async function writeAccountFile(user) {
123
+ const file = accountFilePath();
124
+ if (!user)
125
+ return void (await fs.rm(file, { force: true }).catch(() => { }));
126
+ const next = JSON.stringify({ id: user.id, email: user.email, handle: user.handle }, null, 2) + "\n";
127
+ if ((await fs.readFile(file, "utf8").catch(() => "")) === next)
128
+ return;
129
+ await fs.mkdir(path.dirname(file), { recursive: true });
130
+ const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
131
+ await fs.writeFile(tmp, next);
132
+ await fs.rename(tmp, file);
133
+ }
@@ -1,11 +1,4 @@
1
1
  import { type BundleInfo, type ConceptDetail, type ConceptInfo } from "../okf.js";
2
- /**
3
- * Knowledge for the inspector: a thin API layer over the OKF
4
- * core (src/okf.ts). Writes from the UI are stamped as `human:user` — the
5
- * browser user is the human in the loop; agents write through the CLI (or
6
- * chat) with their own actor.
7
- */
8
- export declare const UI_ACTOR = "human:user";
9
2
  export interface KnowledgeIndex {
10
3
  root: string;
11
4
  bundles: BundleInfo[];
@@ -4,13 +4,13 @@ import { resolveWorkspace } from "../config.js";
4
4
  import { getConcept, initBundle, knowledgeRoot, listBundles, listConcepts, safeBundleName, verifyConcept, writeConcept, } from "../okf.js";
5
5
  import { workspaceRoot } from "./context.js";
6
6
  import { moveToTrash } from "./trash.js";
7
+ import { actorFor } from "./person.js";
7
8
  /**
8
9
  * Knowledge for the inspector: a thin API layer over the OKF
9
- * core (src/okf.ts). Writes from the UI are stamped as `human:user` — the
10
- * browser user is the human in the loop; agents write through the CLI (or
11
- * chat) with their own actor.
10
+ * core (src/okf.ts). Writes from the UI are stamped as the person asking
11
+ * (`human:<handle>`, core/person.ts) — the browser user is the human in the
12
+ * loop; agents write through the CLI (or chat) with their own actor.
12
13
  */
13
- export const UI_ACTOR = "human:user";
14
14
  async function root() {
15
15
  const project = await resolveWorkspace(workspaceRoot());
16
16
  return knowledgeRoot(project.root, project.config.knowledge);
@@ -41,8 +41,8 @@ export async function conceptDetail(bundle, id) {
41
41
  return getConcept(await root(), bundle, id);
42
42
  }
43
43
  export async function putConcept(bundle, id, content) {
44
- return (await writeConcept(await root(), bundle, id, content, UI_ACTOR)).concept;
44
+ return (await writeConcept(await root(), bundle, id, content, await actorFor())).concept;
45
45
  }
46
46
  export async function verifyFromUi(bundle, id) {
47
- return verifyConcept(await root(), bundle, id, UI_ACTOR);
47
+ return verifyConcept(await root(), bundle, id, await actorFor());
48
48
  }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Who a human change is signed with — the person behind a request, else
3
+ * the machine's own.
4
+ *
5
+ * A person is a handle, and with `users: cloud` (kraftwerk.yml, see
6
+ * UsersConfig) also the cloud account's uuid and email: the same person on
7
+ * every machine and clone. Logs and provenance write `human:<handle>`
8
+ * (readable; the cloud keeps handles unique); chats keep the whole person.
9
+ *
10
+ * The server runs every API call as its caller (`runAs`, router.ts): a
11
+ * signed-in browser, a remote member, this machine. Outside a request —
12
+ * the CLI, a routine — it is the machine's person:
13
+ *
14
+ * users: local the identity handle (~/.kraftwerk/identity.json)
15
+ * users: cloud the account that claimed the machine (~/.kraftwerk/account.json),
16
+ * the identity handle while there is none
17
+ *
18
+ * A `human:` actor is never taken from what a caller of the API says:
19
+ * whoever asks is who it is (`actorFor`). The machine's own shell (the CLI,
20
+ * outside any request) may still name one — it can edit the files anyway.
21
+ * Other actors — `lisa/claude`, `process:sync` — are agents and processes
22
+ * naming themselves, and stand as given.
23
+ */
24
+ export interface Person {
25
+ handle: string;
26
+ /** The cloud account's uuid (users: cloud, or a remote member's when the cloud says it). */
27
+ id?: string;
28
+ email?: string;
29
+ }
30
+ /** Run `fn` as the person `who` resolves to (resolved once, when first asked). */
31
+ export declare function runAs<T>(who: () => Promise<Person>, fn: () => T): T;
32
+ /** This machine's person: the claiming account in a `users: cloud` workspace, else the identity handle. */
33
+ export declare function machinePerson(): Promise<Person>;
34
+ /** The person the current request runs as, else this machine's. */
35
+ export declare function currentPerson(): Promise<Person>;
36
+ export declare const humanActor: (p: Pick<Person, "handle">) => string;
37
+ /**
38
+ * The actor a change is stamped with: an agent's or a process's own name as
39
+ * given, else the person asking — in a request a given `human:…` too.
40
+ */
41
+ export declare function actorFor(given?: string): Promise<string>;
@@ -0,0 +1,47 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { resolveWorkspace, usersMode } from "../config.js";
3
+ import { readAccountFile } from "./cloud.js";
4
+ import { workspaceRoot } from "./context.js";
5
+ import { readIdentity } from "./identity.js";
6
+ const storage = new AsyncLocalStorage();
7
+ /** Run `fn` as the person `who` resolves to (resolved once, when first asked). */
8
+ export function runAs(who, fn) {
9
+ let memo;
10
+ return storage.run(() => (memo ??= who()), fn);
11
+ }
12
+ /** This machine's person: the claiming account in a `users: cloud` workspace, else the identity handle. */
13
+ export async function machinePerson() {
14
+ // The CLI runs outside any served workspace: the one around its cwd.
15
+ let root;
16
+ try {
17
+ root = workspaceRoot();
18
+ }
19
+ catch {
20
+ root = process.cwd();
21
+ }
22
+ const cloud = await resolveWorkspace(root)
23
+ .then((ws) => usersMode(ws.config) === "cloud")
24
+ .catch(() => false);
25
+ if (cloud) {
26
+ const account = await readAccountFile();
27
+ if (account)
28
+ return { handle: account.handle, id: account.id, email: account.email };
29
+ }
30
+ return { handle: (await readIdentity()).handle };
31
+ }
32
+ /** The person the current request runs as, else this machine's. */
33
+ export async function currentPerson() {
34
+ const who = storage.getStore();
35
+ return who ? who() : machinePerson();
36
+ }
37
+ export const humanActor = (p) => `human:${p.handle}`;
38
+ /**
39
+ * The actor a change is stamped with: an agent's or a process's own name as
40
+ * given, else the person asking — in a request a given `human:…` too.
41
+ */
42
+ export async function actorFor(given) {
43
+ const g = (given ?? "").trim();
44
+ if (g && (!g.startsWith("human:") || !storage.getStore()))
45
+ return g;
46
+ return humanActor(await currentPerson());
47
+ }
@@ -168,7 +168,7 @@ export declare function linkProject(slug: string, kind: string, target: string,
168
168
  * knowledge bundle's log). The actor is stamped so a line written by an
169
169
  * agent reads as such next to a human's.
170
170
  */
171
- export declare function appendProjectLog(slug: string, entry: string, actor: string): Promise<string>;
171
+ export declare function appendProjectLog(slug: string, entry: string, actor?: string): Promise<string>;
172
172
  /** Move the folder to the trash. */
173
173
  export declare function deleteProject(slug: string): Promise<void>;
174
174
  /**
@@ -13,6 +13,7 @@ import { listRepos } from "./repos.js";
13
13
  import { SLUG_RE, slugify } from "./slug.js";
14
14
  import { moveToTrash } from "./trash.js";
15
15
  import { filesContext } from "./files.js";
16
+ import { actorFor } from "./person.js";
16
17
  /**
17
18
  * Projects: a goal with everything the agents need to reach it gathered in
18
19
  * one folder — the brief, the systems of record where the truth is managed
@@ -302,7 +303,7 @@ export async function createProject(input) {
302
303
  for (const [name, content] of Object.entries(projectStarter(def))) {
303
304
  await fs.writeFile(path.join(dir, name), content);
304
305
  }
305
- await appendProjectLog(slug, `**Created**: project "${title}".`, "human:user");
306
+ await appendProjectLog(slug, `**Created**: project "${title}".`);
306
307
  return (await getProject(slug));
307
308
  }
308
309
  /** Merge the given fields into project.yml (and brief/state when given); lists replace wholesale. */
@@ -359,7 +360,7 @@ export async function appendProjectLog(slug, entry, actor) {
359
360
  const text = entry.trim().replace(/\s*\n\s*/g, " ");
360
361
  if (!text)
361
362
  throw new Error("entry is required");
362
- const who = actor.trim() || "human:user";
363
+ const who = await actorFor(actor);
363
364
  const file = path.join(dir, "log.md");
364
365
  const today = new Date().toISOString().slice(0, 10);
365
366
  let raw = await fs.readFile(file, "utf8").catch(() => null);
package/dist/harness.d.ts CHANGED
@@ -11,11 +11,12 @@
11
11
  * via resume; across harnesses, context travels through the files in the
12
12
  * run directory (the workspace-context contract).
13
13
  */
14
- export type HarnessId = "claude" | "codex" | "pi";
14
+ export type HarnessId = "claude" | "codex" | "pi" | "antigravity";
15
15
  /**
16
16
  * How the harness is driven: `cli` spawns the headless CLI per phase
17
17
  * (claude -p, codex exec, pi); `acp` keeps one Agent Client Protocol
18
- * adapter alive for the run (see harnesses/acp.ts). pi has no adapter.
18
+ * adapter alive for the run (see harnesses/acp.ts). pi has no adapter;
19
+ * antigravity has nothing but one (`agy acp`), so it always runs over ACP.
19
20
  */
20
21
  export type AgentProtocol = "cli" | "acp";
21
22
  /**
@@ -1,5 +1,5 @@
1
1
  import { RequestError, } from "@agentclientprotocol/sdk/unstable";
2
- import { acpMcpServers, adapterEnv, connectAcp, openSession } from "../acp.js";
2
+ import { acpMcpServers, adapterEnv, connectAcp, openSession, applyTuningConfig } from "../acp.js";
3
3
  import { declineOption, unattendedMode } from "../core/chat/permissions.js";
4
4
  const live = new Map();
5
5
  // The run process is the adapters' only owner: never leave one behind.
@@ -101,6 +101,8 @@ async function open(agent, inv, resume) {
101
101
  console.log(` ⚠ could not resume session ${resume} (${session.resumeError}) — a new ${agent} session starts without the earlier phases in context`);
102
102
  }
103
103
  state.sessionId = session.sessionId;
104
+ // Antigravity takes model and thinking depth as session settings.
105
+ await applyTuningConfig(agent, conn, session.sessionId, { model: inv.model, effort: inv.effort }, session.configOptions, (message) => console.log(` ⚠ ${message} — the ${agent} default applies`));
104
106
  const modeId = unattendedMode(agent, session.modes?.currentModeId);
105
107
  if (modeId) {
106
108
  await conn.setSessionMode({ sessionId: session.sessionId, modeId }).catch((err) => {
@@ -14,7 +14,8 @@ const HARNESSES = {
14
14
  pi: piHarness,
15
15
  };
16
16
  export function harnessFor(id = "claude", protocol = "cli") {
17
- if (protocol === "acp")
17
+ // Antigravity's CLI is its ACP server: there is no other way to drive it.
18
+ if (protocol === "acp" || id === "antigravity")
18
19
  return acpHarness(id);
19
20
  const harness = HARNESSES[id];
20
21
  if (!harness) {
@@ -1,7 +1,7 @@
1
1
  import * as z from "zod";
2
2
  import { agentsRoot, deleteAgent, getAgent, listAgents, safeAgentSlug, saveAgent, setAgentArchived } from "../../core/agents.js";
3
3
  import { appendJournal, readJournal } from "../../core/journal.js";
4
- import { UI_ACTOR } from "../../core/knowledge.js";
4
+ import { actorFor } from "../../core/person.js";
5
5
  import { adoptRoutine, deleteRoutine, listRoutines, routineStatuses, runRoutineNow, saveRoutine } from "../../core/routines.js";
6
6
  import { deleteAgentSkill, listAgentSkills, readSkill, saveAgentSkill } from "../../core/skills.js";
7
7
  import { fail, route } from "./router.js";
@@ -90,7 +90,7 @@ export const agentRoutes = [
90
90
  body: z.object({ entry: z.string().default(""), kind: z.string().optional() }),
91
91
  }, async (c) => {
92
92
  const { entry, kind } = await c.body();
93
- return { journal: await appendJournal(c.params.slug, entry, { kind, actor: UI_ACTOR }) };
93
+ return { journal: await appendJournal(c.params.slug, entry, { kind, actor: await actorFor() }) };
94
94
  }),
95
95
  route({ name: "agents.routines", method: "GET", path: "/api/agents/:slug/routines", summary: "the agent's routines with run state", errors: 400 }, async (c) => ({
96
96
  routines: await routineStatuses(own(c.params.slug)),
@@ -27,7 +27,7 @@ const TaskFields = z.object({
27
27
  tags: z.array(z.string()).optional(),
28
28
  refs: z.array(z.string()).optional(),
29
29
  notes: z.string().optional(),
30
- /** Who writes (human:user by default) and a line for the log. */
30
+ /** Who writes (an agent or process naming itself; a person is whoever asks) and a line for the log. */
31
31
  actor: z.string().optional(),
32
32
  message: z.string().optional(),
33
33
  });
@@ -1,6 +1,8 @@
1
1
  import * as z from "zod";
2
2
  /** Chats: ACP sessions with a coding agent, their event stream, and what a person does in them. */
3
- export declare const chatRoutes: (import("./router.js").Route<"agents.sessions", {
3
+ export declare const chatRoutes: (import("./router.js").Route<"agents.options", {
4
+ options: import("../../core/chat/types.js").ConfigOption[];
5
+ }, "/api/agent-options", undefined> | import("./router.js").Route<"agents.sessions", {
4
6
  sessions: {
5
7
  sessionId: string;
6
8
  title?: string;
@@ -36,6 +38,7 @@ export declare const chatRoutes: (import("./router.js").Route<"agents.sessions",
36
38
  resume: z.ZodOptional<z.ZodString>;
37
39
  project: z.ZodOptional<z.ZodString>;
38
40
  task: z.ZodOptional<z.ZodString>;
41
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
39
42
  }, z.core.$strip>> | import("./router.js").Route<"chats.delete", import("./router.js").Reply<{
40
43
  error?: string;
41
44
  }>, "/api/chats/:id", undefined> | import("./router.js").Route<"chats.elicitation", import("./router.js").Reply<{
@@ -2,15 +2,16 @@ import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import * as z from "zod";
4
4
  import { getAgent } from "../../core/agents.js";
5
- import { answerElicitation, cancelChat, createChat, deleteChat, forkChat, getChat, listAgentSessionsFor, listChats, localPerson, postMessage, renameChat, resetSession, resolvePermission, setChatConfig, setChatProject, setChatVibeable, steerChat, stopChatTask, subscribeChat, } from "../../core/chat/sessions.js";
5
+ import { answerElicitation, cancelChat, createChat, deleteChat, forkChat, getChat, listAgentSessionsFor, startOptionsFor, listChats, postMessage, renameChat, resetSession, resolvePermission, setChatConfig, setChatProject, setChatVibeable, steerChat, stopChatTask, subscribeChat, } from "../../core/chat/sessions.js";
6
6
  import { attachmentPath, readMeta, saveAttachment } from "../../core/chat/store.js";
7
7
  import { remoteCaller } from "../trust.js";
8
+ import { personOf } from "../person.js";
8
9
  import { findTask } from "../../core/boards.js";
9
10
  import { getProject } from "../../core/projects.js";
10
11
  import { MIME } from "./mime.js";
11
12
  import { projectErrors } from "./projects.js";
12
13
  import { ApiError, fail, readRawBody, reply, route } from "./router.js";
13
- const AGENTS = ["claude", "codex", "pi"];
14
+ const AGENTS = ["claude", "codex", "pi", "antigravity"];
14
15
  /** A chat id that names no chat folder (or a malformed one) is a 400. */
15
16
  const validChat = (p, message = "invalid chat id") => p.catch((err) => {
16
17
  throw err instanceof ApiError ? err : new ApiError(400, message);
@@ -31,6 +32,8 @@ const NewChat = z.object({
31
32
  project: z.string().optional(),
32
33
  /** The board task the chat works on (<project>/<board>/<task> or <board>/<task>): listed on the task's page (meta.task). */
33
34
  task: z.string().optional(),
35
+ /** Settings to start with, by config id (see agents.options): applied before the first prompt. */
36
+ config: z.record(z.string(), z.union([z.string(), z.boolean()])).optional(),
34
37
  });
35
38
  /** An action on a running chat: `{ok}` when it went through, 409 with the reason when the chat refused. */
36
39
  const act = (name, path, summary, body, run) => route({ name, method: "POST", path, summary, errors: 400, body }, async (c) => {
@@ -80,8 +83,11 @@ async function projectSlug(slug) {
80
83
  fail(404, "project not found");
81
84
  return found.slug;
82
85
  }
83
- /** Who a chat or message is signed with: a member session's member, else this machine's person. */
84
- const personOf = async (trust) => trust.kind === "member" ? { handle: trust.member.handle, email: trust.member.email } : localPerson();
86
+ /** Who a chat or message is signed with: the person asking (server/person.ts). */
87
+ const chatPersonOf = async (trust) => {
88
+ const p = await personOf(trust);
89
+ return { handle: p.handle, ...(p.id ? { id: p.id } : {}), ...(p.email ? { email: p.email } : {}) };
90
+ };
85
91
  /**
86
92
  * A private routine's run (meta.private) is not there for a remote caller
87
93
  * (trust.ts remoteCaller): a 404, as if it did not exist. This machine and
@@ -113,12 +119,12 @@ export const chatRoutes = [
113
119
  const chats = await listChats();
114
120
  return { chats: remoteCaller(c.trust) ? chats.filter((x) => !x.private) : chats };
115
121
  }),
116
- route({ name: "chats.create", method: "POST", path: "/api/chats", summary: "start a chat {agent, scope, resume?, project?, task?}", errors: 404, body: NewChat }, async (c) => {
122
+ route({ name: "chats.create", method: "POST", path: "/api/chats", summary: "start a chat {agent, scope, resume?, project?, task?, config?}", errors: 404, body: NewChat }, async (c) => {
117
123
  // `resume` continues one of the agent's own sessions (see agents.sessions).
118
124
  const body = await c.body();
119
125
  const { agent, scope } = await scopeOf(body);
120
126
  if (!AGENTS.includes(agent))
121
- fail(400, "agent must be claude, codex, or pi");
127
+ fail(400, "agent must be claude, codex, pi, or antigravity");
122
128
  if (body.project && scope.kind !== "agent")
123
129
  fail(400, "only an agent's chat takes a project");
124
130
  const project = body.project ? await projectSlug(body.project) : undefined;
@@ -127,22 +133,34 @@ export const chatRoutes = [
127
133
  return await createChat({
128
134
  agent: agent,
129
135
  scope,
130
- author: await personOf(c.trust),
136
+ author: await chatPersonOf(c.trust),
131
137
  ...(project ? { project } : {}),
132
138
  ...(task ? { task } : {}),
133
139
  ...(body.resume ? { resume: body.resume } : {}),
140
+ ...(body.config ? { config: body.config } : {}),
134
141
  });
135
142
  }
136
143
  catch (err) {
137
144
  throw new ApiError(400, err.message);
138
145
  }
139
146
  }),
140
- route({ name: "agents.sessions", method: "GET", path: "/api/agent-sessions", summary: "the agent's own sessions in the workspace ?agent=claude|codex|pi", errors: 502 }, async (c) => {
147
+ route({ name: "agents.sessions", method: "GET", path: "/api/agent-sessions", summary: "the agent's own sessions in the workspace ?agent=claude|codex|pi|antigravity", errors: 502 }, async (c) => {
141
148
  const agent = c.query.get("agent") ?? "claude";
142
149
  if (!AGENTS.includes(agent))
143
- fail(400, "agent must be claude, codex, or pi");
150
+ fail(400, "agent must be claude, codex, pi, or antigravity");
144
151
  return { sessions: await listAgentSessionsFor(agent) };
145
152
  }),
153
+ route({ name: "agents.options", method: "GET", path: "/api/agent-options", summary: "the model and thinking depth a new chat on ?agent= can start with, as the agent announces them", errors: 502 }, async (c) => {
154
+ const agent = c.query.get("agent") ?? "claude";
155
+ if (!AGENTS.includes(agent))
156
+ fail(400, "agent must be claude, codex, pi, or antigravity");
157
+ try {
158
+ return { options: await startOptionsFor(agent) };
159
+ }
160
+ catch (err) {
161
+ throw new ApiError(502, `${agent} did not answer: ${err.message}`);
162
+ }
163
+ }),
146
164
  route({ name: "chats.get", method: "GET", path: "/api/chats/:id", summary: "the chat's meta and events" }, async (c) => (await validChat(getChat(c.params.id))) ?? fail(404, "not found")),
147
165
  route({ name: "chats.delete", method: "DELETE", path: "/api/chats/:id", summary: "delete the chat" }, async (c) => {
148
166
  const result = await validChat(deleteChat(c.params.id));
@@ -189,7 +207,7 @@ export const chatRoutes = [
189
207
  const { slug } = await c.body();
190
208
  return metaOf(await setChatVibeable(c.params.id, slug || null));
191
209
  }),
192
- route({ name: "chats.fork", method: "POST", path: "/api/chats/:id/fork", summary: "a new chat continuing a copy of this one's session", errors: 400 }, async (c) => metaOf(await forkChat(c.params.id, await personOf(c.trust)))),
210
+ route({ name: "chats.fork", method: "POST", path: "/api/chats/:id/fork", summary: "a new chat continuing a copy of this one's session", errors: 400 }, async (c) => metaOf(await forkChat(c.params.id, await chatPersonOf(c.trust)))),
193
211
  route({ name: "chats.resetSession", method: "POST", path: "/api/chats/:id/reset-session", summary: "forget the agent's session; the next message starts fresh", errors: 400 }, async (c) => metaOf(await resetSession(c.params.id))),
194
212
  // The body is the file itself; x-file-name names it, content-type types it.
195
213
  route({ name: "chats.attach", method: "POST", path: "/api/chats/:id/attachments", summary: "upload an attachment for the next message", errors: 400, upload: true }, async (c) => {
@@ -221,8 +239,8 @@ export const chatRoutes = [
221
239
  res.end(data);
222
240
  }),
223
241
  // Channels: `from` is the poster's display name, which signs the message.
224
- act("chats.message", "/api/chats/:id/message", "send a message {text, attachments?, from?}", Said.extend({ from: z.string().optional() }), async (c, body) => postMessage(c.params.id, textOf(body), { from: body.from, attachments: body.attachments, by: await personOf(c.trust) })),
225
- act("chats.steer", "/api/chats/:id/steer", "add to the running turn {text, attachments?}", Said, async (c, body) => steerChat(c.params.id, textOf(body), body.attachments, await personOf(c.trust))),
242
+ act("chats.message", "/api/chats/:id/message", "send a message {text, attachments?, from?}", Said.extend({ from: z.string().optional() }), async (c, body) => postMessage(c.params.id, textOf(body), { from: body.from, attachments: body.attachments, by: await chatPersonOf(c.trust) })),
243
+ act("chats.steer", "/api/chats/:id/steer", "add to the running turn {text, attachments?}", Said, async (c, body) => steerChat(c.params.id, textOf(body), body.attachments, await chatPersonOf(c.trust))),
226
244
  act("chats.permission", "/api/chats/:id/permission", "answer a permission request {requestId, optionId | null}", z.object({ requestId: z.string().default(""), optionId: z.string().nullable().default(null) }), (c, body) => resolvePermission(c.params.id, body.requestId, body.optionId)),
227
245
  // Channels: `agent` stops one member; without it every agent in the chat.
228
246
  act("chats.cancel", "/api/chats/:id/cancel", "stop the running turn {agent?}", z.object({ agent: z.string().optional() }), (c, body) => cancelChat(c.params.id, body.agent || undefined)),
@@ -30,6 +30,8 @@ export declare const cloudRoutes: (import("./router.js").Route<"cloud.invite", i
30
30
  id?: string;
31
31
  machine?: string;
32
32
  account?: string | null;
33
+ accountId?: string | null;
34
+ accountHandle?: string | null;
33
35
  interval?: number;
34
36
  lastSeen?: string;
35
37
  claimCode?: string | null;
@@ -48,6 +50,8 @@ export declare const cloudRoutes: (import("./router.js").Route<"cloud.invite", i
48
50
  id?: string;
49
51
  machine?: string;
50
52
  account?: string | null;
53
+ accountId?: string | null;
54
+ accountHandle?: string | null;
51
55
  interval?: number;
52
56
  lastSeen?: string;
53
57
  claimCode?: string | null;
@@ -63,6 +67,8 @@ export declare const cloudRoutes: (import("./router.js").Route<"cloud.invite", i
63
67
  id?: string;
64
68
  machine?: string;
65
69
  account?: string | null;
70
+ accountId?: string | null;
71
+ accountHandle?: string | null;
66
72
  interval?: number;
67
73
  lastSeen?: string;
68
74
  claimCode?: string | null;
@@ -78,6 +84,8 @@ export declare const cloudRoutes: (import("./router.js").Route<"cloud.invite", i
78
84
  id?: string;
79
85
  machine?: string;
80
86
  account?: string | null;
87
+ accountId?: string | null;
88
+ accountHandle?: string | null;
81
89
  interval?: number;
82
90
  lastSeen?: string;
83
91
  claimCode?: string | null;
@@ -56,7 +56,9 @@ export declare const routes: (Route<"agents.addJournal", {
56
56
  }, "/api/agents/:slug/journal", undefined> | Route<"agents.list", {
57
57
  root: string;
58
58
  agents: import("../../core/agents.js").Agent[];
59
- }, "/api/agents", undefined> | Route<"agents.routines", {
59
+ }, "/api/agents", undefined> | Route<"agents.options", {
60
+ options: import("../../core/chat/types.js").ConfigOption[];
61
+ }, "/api/agent-options", undefined> | Route<"agents.routines", {
60
62
  routines: import("../../core/routines.js").RoutineStatus[];
61
63
  }, "/api/agents/:slug/routines", undefined> | Route<"agents.runRoutine", {
62
64
  chatId: string;
@@ -256,6 +258,7 @@ export declare const routes: (Route<"agents.addJournal", {
256
258
  resume: z.ZodOptional<z.ZodString>;
257
259
  project: z.ZodOptional<z.ZodString>;
258
260
  task: z.ZodOptional<z.ZodString>;
261
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
259
262
  }, z.core.$strip>> | Route<"chats.delete", import("./router.js").Reply<{
260
263
  error?: string;
261
264
  }>, "/api/chats/:id", undefined> | Route<"chats.elicitation", import("./router.js").Reply<{
@@ -347,6 +350,8 @@ export declare const routes: (Route<"agents.addJournal", {
347
350
  id?: string;
348
351
  machine?: string;
349
352
  account?: string | null;
353
+ accountId?: string | null;
354
+ accountHandle?: string | null;
350
355
  interval?: number;
351
356
  lastSeen?: string;
352
357
  claimCode?: string | null;
@@ -365,6 +370,8 @@ export declare const routes: (Route<"agents.addJournal", {
365
370
  id?: string;
366
371
  machine?: string;
367
372
  account?: string | null;
373
+ accountId?: string | null;
374
+ accountHandle?: string | null;
368
375
  interval?: number;
369
376
  lastSeen?: string;
370
377
  claimCode?: string | null;
@@ -380,6 +387,8 @@ export declare const routes: (Route<"agents.addJournal", {
380
387
  id?: string;
381
388
  machine?: string;
382
389
  account?: string | null;
390
+ accountId?: string | null;
391
+ accountHandle?: string | null;
383
392
  interval?: number;
384
393
  lastSeen?: string;
385
394
  claimCode?: string | null;
@@ -395,6 +404,8 @@ export declare const routes: (Route<"agents.addJournal", {
395
404
  id?: string;
396
405
  machine?: string;
397
406
  account?: string | null;
407
+ accountId?: string | null;
408
+ accountHandle?: string | null;
398
409
  interval?: number;
399
410
  lastSeen?: string;
400
411
  claimCode?: string | null;
@@ -558,7 +569,16 @@ export declare const routes: (Route<"agents.addJournal", {
558
569
  content: z.ZodDefault<z.ZodString>;
559
570
  }, z.core.$strip>> | Route<"knowledge.verify", import("../../okf.js").ConceptDetail, "/api/knowledge/:bundle/verify", z.ZodObject<{
560
571
  id: z.ZodDefault<z.ZodString>;
561
- }, z.core.$strip>> | Route<"meta.get", {
572
+ }, z.core.$strip>> | Route<"me.get", {
573
+ mode: import("../../config.js").UsersMode;
574
+ handle: string;
575
+ actor: string;
576
+ id?: string | undefined;
577
+ email?: string | undefined;
578
+ signedIn: boolean;
579
+ role?: "member" | "owner" | undefined;
580
+ via: "device" | "local" | "member";
581
+ }, "/api/me", undefined> | Route<"meta.get", {
562
582
  workspaceName: string;
563
583
  workspaceSlug: string;
564
584
  workspaceIcon: string;
@@ -595,6 +615,8 @@ export declare const routes: (Route<"agents.addJournal", {
595
615
  id?: string;
596
616
  machine?: string;
597
617
  account?: string | null;
618
+ accountId?: string | null;
619
+ accountHandle?: string | null;
598
620
  interval?: number;
599
621
  lastSeen?: string;
600
622
  claimCode?: string | null;
@@ -693,7 +715,7 @@ export declare const routes: (Route<"agents.addJournal", {
693
715
  log: string;
694
716
  }, "/api/projects/:slug/log", z.ZodObject<{
695
717
  entry: z.ZodString;
696
- actor: z.ZodDefault<z.ZodString>;
718
+ actor: z.ZodOptional<z.ZodString>;
697
719
  }, z.core.$strip>> | Route<"projects.save", import("../../core/projects.js").ProjectDetail, "/api/projects/:slug", z.ZodObject<{
698
720
  title: z.ZodOptional<z.ZodString>;
699
721
  status: z.ZodOptional<z.ZodString>;
@@ -3,7 +3,7 @@ import { stat } from "node:fs/promises";
3
3
  import * as z from "zod";
4
4
  import { createDeck, deckSlidePng, deleteDeck, exportBytes, getDeck, listAllDecks, listDecks, listTemplates, openPresentations, saveAsset, addComment, updateComment, deleteComment, StaleDeckError, existingDeckDir, deckVersions, deckVersion, deckFile, templateFile, saveDeck, } from "../../core/presentations/index.js";
5
5
  import { ApiError, fail, reply, route, statusByMessage } from "./router.js";
6
- import { localPerson } from "../../core/chat/sessions.js";
6
+ import { personOf } from "../person.js";
7
7
  import { tasksReferencing } from "../../core/boards.js";
8
8
  import { leavePresence, touchPresence } from "../../core/presentations/presence.js";
9
9
  /**
@@ -45,7 +45,7 @@ const refOf = (c) => {
45
45
  return { ...(project ? { project } : {}), name: c.params.name };
46
46
  };
47
47
  /** Who writes a comment: a member by their handle, else this machine's person. */
48
- const authorOf = async (trust) => (trust.kind === "member" ? trust.member.handle : (await localPerson()).handle);
48
+ const authorOf = async (trust) => (await personOf(trust)).handle;
49
49
  const requireOn = async () => {
50
50
  if ((await openPresentations()).off)
51
51
  fail(409, "presentations are off");
@@ -16,7 +16,7 @@ export declare const projectRoutes: (import("./router.js").Route<"projects.creat
16
16
  log: string;
17
17
  }, "/api/projects/:slug/log", z.ZodObject<{
18
18
  entry: z.ZodString;
19
- actor: z.ZodDefault<z.ZodString>;
19
+ actor: z.ZodOptional<z.ZodString>;
20
20
  }, z.core.$strip>> | import("./router.js").Route<"projects.save", import("../../core/projects.js").ProjectDetail, "/api/projects/:slug", z.ZodObject<{
21
21
  title: z.ZodOptional<z.ZodString>;
22
22
  status: z.ZodOptional<z.ZodString>;
@@ -58,7 +58,7 @@ export const projectRoutes = [
58
58
  path: "/api/projects/:slug/log",
59
59
  summary: "append a stamped line {entry, actor?} to log.md",
60
60
  errors: projectErrors,
61
- body: z.object({ entry: z.string(), actor: z.string().default("human:user") }),
61
+ body: z.object({ entry: z.string(), actor: z.string().optional() }),
62
62
  }, async (c) => {
63
63
  const { entry, actor } = await c.body();
64
64
  return { ok: true, log: await appendProjectLog(c.params.slug, entry, actor) };
@@ -1,5 +1,7 @@
1
1
  import * as z from "zod";
2
2
  import { touch } from "../live.js";
3
+ import { runAs } from "../../core/person.js";
4
+ import { personOf } from "../person.js";
3
5
  /** A result with a status other than 200 (201 created, 409 with a body, …), and headers for HTTP (a cookie); the socket ignores them. */
4
6
  export class Reply {
5
7
  status;
@@ -176,7 +178,8 @@ export function createRouter(routes) {
176
178
  return validate(route, parsed);
177
179
  })),
178
180
  };
179
- const result = await route.handle(c);
181
+ // Whoever asks is who a human change is signed with (core/person.ts).
182
+ const result = await runAs(() => personOf(trust), () => route.handle(c));
180
183
  if (route.method !== "GET")
181
184
  touch();
182
185
  if (route.raw)
@@ -225,7 +228,7 @@ export function createRouter(routes) {
225
228
  trust,
226
229
  body: async () => validate(route, input.body ?? {}),
227
230
  };
228
- const result = await route.handle(c);
231
+ const result = await runAs(() => personOf(trust), () => route.handle(c));
229
232
  if (route.method !== "GET")
230
233
  touch();
231
234
  return result instanceof Reply ? { status: result.status, data: result.body } : { status: 200, data: result };
@@ -11,7 +11,18 @@ export declare const workspaceRoutes: (import("./router.js").Route<"identity.get
11
11
  machine: string;
12
12
  identity: string;
13
13
  previous: string[];
14
- }, "/api/identity", undefined> | import("./router.js").Route<"meta.get", {
14
+ }, "/api/identity", undefined> | import("./router.js").Route<"me.get", {
15
+ mode: import("../../config.js").UsersMode;
16
+ handle: string;
17
+ actor: string;
18
+ id?: string | undefined;
19
+ email?: string | undefined;
20
+ /** A browser signed in with its cloud account (users: cloud); false for this machine's own shell, a device, a member. */
21
+ signedIn: boolean;
22
+ role?: "member" | "owner" | undefined;
23
+ /** How the signed-in person got here: through the relay as a member, or on this machine. */
24
+ via: "device" | "local" | "member";
25
+ }, "/api/me", undefined> | import("./router.js").Route<"meta.get", {
15
26
  workspaceName: string;
16
27
  workspaceSlug: string;
17
28
  workspaceIcon: string;
@@ -50,6 +61,8 @@ export declare const workspaceRoutes: (import("./router.js").Route<"identity.get
50
61
  id?: string;
51
62
  machine?: string;
52
63
  account?: string | null;
64
+ accountId?: string | null;
65
+ accountHandle?: string | null;
53
66
  interval?: number;
54
67
  lastSeen?: string;
55
68
  claimCode?: string | null;