@chopin-ai/harness-pi 0.0.0-stage → 0.2.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 (51) hide show
  1. package/LICENSE +202 -0
  2. package/dist/acp.d.ts +42 -0
  3. package/dist/acp.js +122 -0
  4. package/dist/acp.js.map +1 -0
  5. package/dist/auth.d.ts +25 -0
  6. package/dist/auth.js +56 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/backoff.d.ts +5 -0
  9. package/dist/backoff.js +13 -0
  10. package/dist/backoff.js.map +1 -0
  11. package/dist/bridge.d.ts +11 -0
  12. package/dist/bridge.js +259 -0
  13. package/dist/bridge.js.map +1 -0
  14. package/dist/http.d.ts +7 -0
  15. package/dist/http.js +73 -0
  16. package/dist/http.js.map +1 -0
  17. package/dist/index.d.ts +17 -0
  18. package/dist/index.js +11 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/layer.d.ts +8 -0
  21. package/dist/layer.js +84 -0
  22. package/dist/layer.js.map +1 -0
  23. package/dist/mcp.d.ts +24 -0
  24. package/dist/mcp.js +126 -0
  25. package/dist/mcp.js.map +1 -0
  26. package/dist/mode.d.ts +11 -0
  27. package/dist/mode.js +33 -0
  28. package/dist/mode.js.map +1 -0
  29. package/dist/pages.d.ts +8 -0
  30. package/dist/pages.js +12 -0
  31. package/dist/pages.js.map +1 -0
  32. package/dist/project-context.d.ts +18 -0
  33. package/dist/project-context.js +77 -0
  34. package/dist/project-context.js.map +1 -0
  35. package/dist/protocol.d.ts +247 -0
  36. package/dist/protocol.js +327 -0
  37. package/dist/protocol.js.map +1 -0
  38. package/dist/server.d.ts +25 -0
  39. package/dist/server.js +349 -0
  40. package/dist/server.js.map +1 -0
  41. package/dist/service.d.ts +96 -0
  42. package/dist/service.js +493 -0
  43. package/dist/service.js.map +1 -0
  44. package/dist/shell.d.ts +31 -0
  45. package/dist/shell.js +57 -0
  46. package/dist/shell.js.map +1 -0
  47. package/dist/submissions.d.ts +22 -0
  48. package/dist/submissions.js +33 -0
  49. package/dist/submissions.js.map +1 -0
  50. package/package.json +48 -3
  51. package/README.md +0 -3
package/dist/mcp.js ADDED
@@ -0,0 +1,126 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { Type } from "@earendil-works/pi-ai";
3
+ import { defineExtension } from "@earendil-works/pi-durable";
4
+ import { McpClient, StdioTransport, StreamableHttpTransport, toLlmContent } from "@earendil-works/pi-mcp";
5
+ import { mcpToolName } from "@chopin-ai/core";
6
+ let version;
7
+ /** This package's version, which MCP servers are told; "unknown" when the package cannot say. */
8
+ function packageVersion() {
9
+ version ??= readFile(new URL("../package.json", import.meta.url), "utf8")
10
+ .then((text) => JSON.parse(text).version ?? "unknown", () => "unknown");
11
+ return version;
12
+ }
13
+ /**
14
+ * One owner's MCP servers. A command server runs inside the owner's workspace, never on the service host: the
15
+ * layer may change, and what it starts must stay as confined as the agent itself.
16
+ */
17
+ export class McpServers {
18
+ #servers;
19
+ #workspace;
20
+ #clients = new Map();
21
+ #closed = false;
22
+ /** Names of the offered tools that declare they change nothing. */
23
+ readOnly = new Set();
24
+ /** Servers that could not be reached when their tools were offered. */
25
+ unavailable = new Set();
26
+ constructor(servers, workspace) {
27
+ this.#servers = servers;
28
+ this.#workspace = workspace;
29
+ }
30
+ /** Connects every server and offers its tools, one extension per server; one that cannot be reached is left out. */
31
+ connect(report) {
32
+ return this.#offer(Object.keys(this.#servers), report);
33
+ }
34
+ /**
35
+ * Tries the unavailable servers again and offers the tools of those that answer now; a server in the workspace is
36
+ * tried only while the workspace runs, so trying never wakes one stopped for being idle.
37
+ */
38
+ async retry(report) {
39
+ const inWorkspace = (server) => "command" in this.#servers[server];
40
+ const unavailable = [...this.unavailable];
41
+ const running = unavailable.some(inWorkspace) && (await this.#workspace.state().catch(() => undefined)) === "running";
42
+ return this.#offer(unavailable.filter((server) => running || !inWorkspace(server)), report, false);
43
+ }
44
+ /** Closes every client, and refuses to connect another, such as for a retry still under way. */
45
+ async close() {
46
+ this.#closed = true;
47
+ const clients = [...this.#clients.values()];
48
+ this.#clients.clear();
49
+ await Promise.allSettled(clients.map(async (client) => (await client).close()));
50
+ }
51
+ async #offer(servers, report, wake = true) {
52
+ const offered = await Promise.all(servers.map(async (server) => {
53
+ const client = this.#client(server, wake);
54
+ try {
55
+ const listed = await (await client).listTools();
56
+ const unique = [...new Map(listed.map((tool) => [tool.name, tool])).values()];
57
+ if (unique.length < listed.length)
58
+ report(new Error(`MCP server ${server} lists a tool name twice; one of each is offered`));
59
+ this.unavailable.delete(server);
60
+ return [defineExtension({ name: `chopin-mcp-${server}`, tools: unique.map((tool) => this.#tool(server, tool)) })];
61
+ }
62
+ catch (error) {
63
+ // A client that connected but cannot list its tools is let go, so the next try starts afresh.
64
+ this.#drop(server, client);
65
+ if (this.#closed)
66
+ return [];
67
+ if (!this.unavailable.has(server))
68
+ report(new Error(`MCP server ${server} is unavailable: ${error.message}`));
69
+ this.unavailable.add(server);
70
+ return [];
71
+ }
72
+ }));
73
+ return this.#closed ? [] : offered.flat();
74
+ }
75
+ #client(server, wake = true) {
76
+ if (this.#closed)
77
+ return Promise.reject(new Error("the MCP servers were closed"));
78
+ let client = this.#clients.get(server);
79
+ if (client === undefined) {
80
+ client = this.#connect(server, wake);
81
+ this.#clients.set(server, client);
82
+ const forget = () => {
83
+ if (this.#clients.get(server) === client)
84
+ this.#clients.delete(server);
85
+ };
86
+ client.then((connected) => connected.onClose(forget), forget);
87
+ }
88
+ return client;
89
+ }
90
+ #drop(server, client) {
91
+ if (this.#clients.get(server) === client)
92
+ this.#clients.delete(server);
93
+ void client.then((connected) => connected.close()).catch(() => { });
94
+ }
95
+ async #connect(server, wake) {
96
+ // A server that never answers must not hold its owner's agent back for good.
97
+ const client = new McpClient({ name: "chopin-ai", version: await packageVersion(), requestTimeoutMs: 30_000 });
98
+ await client.connect(await this.#transport(this.#servers[server], wake));
99
+ return client;
100
+ }
101
+ async #transport(server, wake) {
102
+ if (!("command" in server))
103
+ return new StreamableHttpTransport({ url: server.url, ...(server.headers && { headers: server.headers }) });
104
+ if (wake)
105
+ await this.#workspace.start();
106
+ const { argv: [command, ...args], env } = this.#workspace.command([server.command, ...(server.args ?? [])], server.env);
107
+ return new StdioTransport({ command: command, args, env });
108
+ }
109
+ #tool(server, tool) {
110
+ const name = mcpToolName(server, tool.name);
111
+ if (tool.annotations?.readOnlyHint === true)
112
+ this.readOnly.add(name);
113
+ return {
114
+ name,
115
+ description: tool.description ?? tool.name,
116
+ parameters: Type.Unsafe({ ...tool.inputSchema, type: "object", properties: tool.inputSchema.properties ?? {} }),
117
+ execute: async (args, _api, context) => {
118
+ const client = await this.#client(server);
119
+ const signal = context.abortSignal;
120
+ const result = await client.callTool(tool.name, args, signal === undefined ? {} : { signal });
121
+ return { output: toLlmContent(result), isError: result.isError === true };
122
+ },
123
+ };
124
+ }
125
+ }
126
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAyC,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,uBAAuB,EAAE,YAAY,EAAqB,MAAM,wBAAwB,CAAC;AAC7H,OAAO,EAAE,WAAW,EAAkB,MAAM,iBAAiB,CAAC;AAK9D,IAAI,OAAoC,CAAC;AAEzC,iGAAiG;AACjG,SAAS,cAAc;IACrB,OAAO,KAAK,QAAQ,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;SACtE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAA0B,CAAC,OAAO,IAA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AE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;gBACzH,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC5E,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
package/dist/mode.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { type Extension } from "@earendil-works/pi-durable";
2
+ import type { Mode } from "./protocol.js";
3
+ /** A conversation's mode, as the store keeps it. */
4
+ export declare const ModeDoc: import("@earendil-works/pi-durable").ConversationDocToken<{
5
+ mode: Mode;
6
+ }>;
7
+ /** A conversation's name, as its owner gave it; empty until then. */
8
+ export declare const NameDoc: import("@earendil-works/pi-durable").ConversationDocToken<{
9
+ name: string;
10
+ }>;
11
+ export declare function modeExtension(readOnly: (tool: string) => boolean): Extension;
package/dist/mode.js ADDED
@@ -0,0 +1,33 @@
1
+ import { defineDoc, defineExtension, hook, ToolTask } from "@earendil-works/pi-durable";
2
+ /** A conversation's mode, as the store keeps it. */
3
+ export const ModeDoc = defineDoc({
4
+ kind: "chopin.mode",
5
+ version: 1,
6
+ scope: "conversation",
7
+ history: "latest",
8
+ fork: "current",
9
+ initial: () => ({ mode: "full" }),
10
+ });
11
+ /** A conversation's name, as its owner gave it; empty until then. */
12
+ export const NameDoc = defineDoc({
13
+ kind: "chopin.name",
14
+ version: 1,
15
+ scope: "conversation",
16
+ history: "latest",
17
+ fork: "current",
18
+ initial: () => ({ name: "" }),
19
+ });
20
+ export function modeExtension(readOnly) {
21
+ return defineExtension({
22
+ name: "chopin-mode",
23
+ hooks: [hook(ToolTask, {
24
+ beforeTool: async (call, api, context) => {
25
+ const mode = (await api.snapshot(ModeDoc, api.conversationId, context))?.mode ?? "full";
26
+ if (mode === "full" || readOnly(call.name))
27
+ return undefined;
28
+ return { block: "This conversation is read-only: only tools that change nothing may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AAO,SAAS,CAAC;oBAC7D,OAAO,EAAE,KAAK,EAAE,yEAAyE,EAAE,CAAC;gBAC9F,CAAC;aACF,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** One page of a listing that continues from a cursor. */
2
+ interface Page<T, C> {
3
+ readonly items: readonly T[];
4
+ readonly next?: C | undefined;
5
+ }
6
+ /** Reads a listing page by page, keeping the items `keep` admits, until it ends or `enough` of them are kept. */
7
+ export declare function drain<T, C>(page: (cursor: C | undefined) => Promise<Page<T, C>>, keep?: (item: T) => boolean, enough?: number): Promise<T[]>;
8
+ export {};
package/dist/pages.js ADDED
@@ -0,0 +1,12 @@
1
+ /** Reads a listing page by page, keeping the items `keep` admits, until it ends or `enough` of them are kept. */
2
+ export async function drain(page, keep = () => true, enough = Infinity) {
3
+ const kept = [];
4
+ let cursor;
5
+ do {
6
+ const read = await page(cursor);
7
+ kept.push(...read.items.filter(keep));
8
+ cursor = read.next;
9
+ } while (kept.length < enough && cursor !== undefined);
10
+ return kept.slice(0, enough);
11
+ }
12
+ //# sourceMappingURL=pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAMA,iHAAiH;AACjH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,IAAoD,EACpD,IAAI,GAAyB,GAAG,EAAE,CAAC,IAAI,EACvC,MAAM,GAAG,QAAQ;IAEjB,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,IAAI,MAAqB,CAAC;IAC1B,GAAG,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,MAAM,KAAK,SAAS,EAAE;IACvD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import { type Extension } from "@earendil-works/pi-durable";
3
+ import type { ExecutionEnv } from "@earendil-works/pi-durable/env";
4
+ /** An instruction file of the project the agent works in. */
5
+ export interface ContextFile {
6
+ path: string;
7
+ content: string;
8
+ }
9
+ /**
10
+ * The project's own instructions, as the coding agent gives them to its model. They are read from the workspace
11
+ * before each request, so an edit holds from the next one.
12
+ */
13
+ export declare const projectContext: Extension;
14
+ /**
15
+ * One file per directory, from the root of the file system down to `env`'s working directory; a linked worktree
16
+ * nested in its main repository stands in for that repository's file, which covers the same code.
17
+ */
18
+ export declare function contextFiles(env: ExecutionEnv, context: Context): Promise<ContextFile[]>;
@@ -0,0 +1,77 @@
1
+ import { posix } from "node:path";
2
+ import { defineExtension, section } from "@earendil-works/pi-durable";
3
+ /** The names a directory's instructions go by, the first one present winning, as the coding agent reads them. */
4
+ const NAMES = ["AGENTS.override.md", "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"];
5
+ /**
6
+ * The project's own instructions, as the coding agent gives them to its model. They are read from the workspace
7
+ * before each request, so an edit holds from the next one.
8
+ */
9
+ export const projectContext = defineExtension({
10
+ name: "chopin-project",
11
+ sections: [section("project_context", async ({ env }, context) => {
12
+ const files = env === undefined ? [] : await contextFiles(env, context);
13
+ if (files.length === 0)
14
+ return undefined;
15
+ return [
16
+ "Project-specific instructions and guidelines:",
17
+ ...files.map(({ path, content }) => `<project_instructions path="${path}">\n${content}\n</project_instructions>`),
18
+ ].join("\n\n");
19
+ })],
20
+ });
21
+ /**
22
+ * One file per directory, from the root of the file system down to `env`'s working directory; a linked worktree
23
+ * nested in its main repository stands in for that repository's file, which covers the same code.
24
+ */
25
+ export async function contextFiles(env, context) {
26
+ const dirs = [];
27
+ for (let dir = env.cwd;; dir = posix.dirname(dir)) {
28
+ dirs.push(dir);
29
+ if (posix.dirname(dir) === dir)
30
+ break;
31
+ }
32
+ const listed = await Promise.all(dirs.map(async (dir) => {
33
+ const entries = await env.listDir(dir, context);
34
+ return new Set(entries.ok ? entries.value.map((entry) => entry.name) : []);
35
+ }));
36
+ const shadowed = await shadowedFile(env, dirs, listed, context);
37
+ const files = [];
38
+ for (const [index, dir] of dirs.entries()) {
39
+ for (const name of NAMES.filter((each) => listed[index]?.has(each))) {
40
+ const read = await env.readTextFile(posix.join(dir, name), context);
41
+ if (!read.ok)
42
+ continue;
43
+ const own = shadowed === undefined || posix.join(await canonical(env, dir, context), name) !== shadowed;
44
+ if (own)
45
+ files.unshift({ path: posix.join(dir, name), content: read.value.replace(/^/, "") });
46
+ break;
47
+ }
48
+ }
49
+ return files;
50
+ }
51
+ /** The main repository's file that a linked worktree nested inside it shadows with its own; undefined in any other case. */
52
+ async function shadowedFile(env, dirs, listed, context) {
53
+ const at = listed.findIndex((names) => names.has(".git"));
54
+ const worktree = dirs[at];
55
+ if (worktree === undefined)
56
+ return undefined;
57
+ // A worktree's .git is a file naming its git directory, whose commondir leads to the main repository's.
58
+ const pointer = await env.readTextFile(posix.join(worktree, ".git"), context);
59
+ if (!pointer.ok || !pointer.value.startsWith("gitdir: "))
60
+ return undefined;
61
+ const gitDir = posix.resolve(worktree, pointer.value.slice("gitdir: ".length).trim());
62
+ const common = await env.readTextFile(posix.join(gitDir, "commondir"), context);
63
+ if (!common.ok)
64
+ return undefined;
65
+ const commonGitDir = await canonical(env, posix.resolve(gitDir, common.value.trim()), context);
66
+ const main = posix.dirname(commonGitDir);
67
+ const nested = (await canonical(env, worktree, context)).startsWith(`${main}/`);
68
+ if (!nested || await canonical(env, posix.join(main, ".git"), context) !== commonGitDir)
69
+ return undefined;
70
+ const own = NAMES.find((name) => listed[at]?.has(name));
71
+ return own === undefined ? undefined : posix.join(main, own);
72
+ }
73
+ async function canonical(env, path, context) {
74
+ const found = await env.canonicalPath(path, context);
75
+ return found.ok ? found.value : path;
76
+ }
77
+ //# sourceMappingURL=project-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-context.js","sourceRoot":"","sources":["../src/project-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAkB,MAAM,4BAA4B,CAAC;AAGtF,iHAAiH;AACjH,MAAM,KAAK,GAAG,CAAC,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAQzF;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAc,eAAe,CAAC;IACvD,IAAI,EAAE,gBAAgB;IACtB,QAAQ,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE;YAC/D,MAAM,KAAK,GAAG,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACxE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,SAAS,CAAC;YACzC,OAAO;gBACL,+CAA+C;gBAC/C,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,+BAA+B,IAAI,OAAO,OAAO,2BAA2B,CAAC;aAClH,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;CACJ,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAiB,EAAE,OAAgB;IACpE,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,GAAI,GAAG,GAAG,KAAK,CAAC,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F,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,SAAS,CAAC;IACjC,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAC/F,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IAChF,IAAI,CAAC,MAAM,IAAI,MAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IAC1G,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC/D,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,GAAiB,EAAE,IAAY,EAAE,OAAgB;IACxE,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC"}
@@ -0,0 +1,247 @@
1
+ import { method, type Ctx, type Host, type Ref } from "@earendil-works/chord";
2
+ import { Type, type Static, type TArray, type TNumber, type TObject, type TSchema, type TUnknown } from "typebox";
3
+ /**
4
+ * The client protocol: remote objects over a WebSocket. A client sees each object's state as a snapshot followed by
5
+ * deltas, and after a reconnect it gets the current state again instead of a replay. This module has no Node
6
+ * dependency, so browsers and terminals share it.
7
+ */
8
+ /** Who a request acts as: an owner named by the authenticator, or the service's own code. */
9
+ export type Principal = {
10
+ kind: "owner";
11
+ owner: string;
12
+ } | {
13
+ kind: "host";
14
+ };
15
+ export declare const HOST = "chopin";
16
+ /** What a conversation may do: `read` admits only tools that change nothing; `full` admits every tool. */
17
+ export declare const ModeSchema: Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"full">]>;
18
+ export type Mode = Static<typeof ModeSchema>;
19
+ export declare const MODES: readonly Mode[];
20
+ /** How a submission made through this object ended, or that it has not yet. */
21
+ export declare const SubmissionSchema: Type.TUnion<[TObject<{
22
+ status: Type.TLiteral<"pending">;
23
+ }>, TObject<{
24
+ status: Type.TLiteral<"done">;
25
+ }>, TObject<{
26
+ status: Type.TLiteral<"unanswered">;
27
+ reason: Type.TString;
28
+ detail: Type.TOptional<Type.TString>;
29
+ }>]>;
30
+ /**
31
+ * Why the latest submission got no answer, unless it was stopped on purpose; `undefined` while it runs or once it
32
+ * was answered.
33
+ */
34
+ export declare function lastFailure(submissions: Readonly<Record<string, Static<typeof SubmissionSchema>>>): string | undefined;
35
+ type Call<A extends TSchema> = ReturnType<typeof method<A>> & {};
36
+ type Query<A extends TSchema | undefined, R extends TSchema> = ReturnType<typeof method<A, R>> & {};
37
+ declare const ForkArgs: TObject<{
38
+ conversation: TNumber;
39
+ at: TNumber;
40
+ }>;
41
+ /** `request`, chosen by the client, makes sending the same message again harmless: it is admitted once. */
42
+ declare const SubmitArgs: TObject<{
43
+ text: Type.TString;
44
+ steer: Type.TOptional<Type.TBoolean>;
45
+ request: Type.TOptional<Type.TString>;
46
+ }>;
47
+ declare const ModeArgs: TObject<{
48
+ mode: Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"full">]>;
49
+ }>;
50
+ /** A model as the model library names it: its provider and its id there. */
51
+ declare const ModelArgs: TObject<{
52
+ provider: Type.TString;
53
+ modelId: Type.TString;
54
+ }>;
55
+ declare const NameArgs: TObject<{
56
+ name: Type.TString;
57
+ }>;
58
+ /** A thinking level as the model library names them; the service takes only those the conversation's model has. */
59
+ declare const ThinkingArgs: TObject<{
60
+ level: Type.TString;
61
+ }>;
62
+ declare const CompactArgs: TObject<{
63
+ instructions: Type.TOptional<Type.TString>;
64
+ }>;
65
+ /** A command of the user's, run in the workspace; an excluded one the model never sees. */
66
+ declare const ShellArgs: TObject<{
67
+ command: Type.TString;
68
+ excluded: Type.TOptional<Type.TBoolean>;
69
+ }>;
70
+ declare const Texts: TArray<Type.TString>;
71
+ /** The command the user is running in a conversation and its output so far; null while none runs. */
72
+ export declare const RunningSchema: Type.TUnion<[Type.TNull, TObject<{
73
+ command: Type.TString;
74
+ output: Type.TString;
75
+ excluded: Type.TBoolean;
76
+ }>]>;
77
+ export type Running = Static<typeof RunningSchema>;
78
+ /**
79
+ * What an owner's agent loads besides its tools: whether the layer has instructions, the paths of the project's
80
+ * instruction files in the workspace, the skills, the MCP servers.
81
+ */
82
+ export declare const LoadedSchema: TObject<{
83
+ instructions: Type.TBoolean;
84
+ projectInstructions: TArray<Type.TString>;
85
+ skills: TArray<Type.TString>;
86
+ mcpServers: TArray<Type.TString>;
87
+ }>;
88
+ export type Loaded = Static<typeof LoadedSchema>;
89
+ /** A line about one conversation, for picking one to resume: times in milliseconds since the epoch. */
90
+ export declare const SummarySchema: TObject<{
91
+ id: TNumber;
92
+ name: Type.TString;
93
+ first: Type.TString;
94
+ messages: TNumber;
95
+ created: TNumber;
96
+ modified: TNumber;
97
+ }>;
98
+ export type Summary = Static<typeof SummarySchema>;
99
+ declare const Summaries: TArray<TObject<{
100
+ id: TNumber;
101
+ name: Type.TString;
102
+ first: Type.TString;
103
+ messages: TNumber;
104
+ created: TNumber;
105
+ modified: TNumber;
106
+ }>>;
107
+ /** An owner's conversations. */
108
+ export declare const Conversations: import("@earendil-works/chord").RemoteContract<{
109
+ readonly version: 1;
110
+ readonly input: TObject<{}>;
111
+ readonly host: import("@earendil-works/chord").HostNamed;
112
+ readonly variants: {
113
+ owner: {
114
+ state: {
115
+ ids: TArray<TNumber>;
116
+ };
117
+ methods: {
118
+ create: Query<undefined, TNumber>;
119
+ /** Asks the workspace, so it is not part of the list's state, which would start a workspace just to list. */
120
+ loaded: Query<undefined, typeof LoadedSchema>;
121
+ fork: Query<typeof ForkArgs, TNumber>;
122
+ summaries: Query<undefined, typeof Summaries>;
123
+ };
124
+ };
125
+ };
126
+ }>;
127
+ /**
128
+ * One conversation: its durable view (transcript, live generation, inbox, usage), what it may do, and how the
129
+ * submissions made through it ended, keyed by the id `submit` returned.
130
+ */
131
+ export declare const Conversation: import("@earendil-works/chord").RemoteContract<{
132
+ readonly version: 1;
133
+ readonly input: TObject<{
134
+ conversation: TNumber;
135
+ }>;
136
+ readonly host: import("@earendil-works/chord").HostNamed;
137
+ readonly variants: {
138
+ owner: {
139
+ state: {
140
+ view: TUnknown;
141
+ mode: Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"full">]>;
142
+ name: Type.TString;
143
+ submissions: Type.TRecord<"^.*$", Type.TUnion<[TObject<{
144
+ status: Type.TLiteral<"pending">;
145
+ }>, TObject<{
146
+ status: Type.TLiteral<"done">;
147
+ }>, TObject<{
148
+ status: Type.TLiteral<"unanswered">;
149
+ reason: Type.TString;
150
+ detail: Type.TOptional<Type.TString>;
151
+ }>]>>;
152
+ running: Type.TUnion<[Type.TNull, TObject<{
153
+ command: Type.TString;
154
+ output: Type.TString;
155
+ excluded: Type.TBoolean;
156
+ }>]>;
157
+ };
158
+ methods: {
159
+ submit: Query<typeof SubmitArgs, TNumber>;
160
+ /** Runs to the command's end, which may take long; `stopCommand` ends it sooner. */
161
+ shell: Call<typeof ShellArgs>;
162
+ stopCommand: Call<TObject<{}>>;
163
+ /** The whole conversation as transcript lines, what compaction took from the view included. */
164
+ transcript: Query<TObject<{}>, TArray<TUnknown>>;
165
+ /** Takes back every message still queued, answering with their texts in the order they were sent. */
166
+ withdraw: Query<TObject<{}>, typeof Texts>;
167
+ abort: Call<TObject<{}>>;
168
+ setMode: Call<typeof ModeArgs>;
169
+ setModel: Call<typeof ModelArgs>;
170
+ setName: Call<typeof NameArgs>;
171
+ setThinking: Call<typeof ThinkingArgs>;
172
+ compact: Call<typeof CompactArgs>;
173
+ };
174
+ };
175
+ };
176
+ }>;
177
+ export interface ConnectOptions {
178
+ /** A credential sent as a bearer header, kept out of the address and so out of any proxy's logs; not in browsers. */
179
+ token?: string;
180
+ /** Finds the service again before each redial: where it is and the credential it takes, either may have changed. */
181
+ find?: () => Promise<{
182
+ url: string | URL;
183
+ token?: string;
184
+ }>;
185
+ }
186
+ /**
187
+ * A client host connected to the agent service at `url`, which carries the client's credential. A link that drops
188
+ * is dialled again, waiting longer each time, until the host is closed; references come back live once the service
189
+ * answers. Only a link that held for a while resets the wait, so a refused one is not dialled ever faster.
190
+ */
191
+ export declare function connect(url: string | URL, options?: ConnectOptions): Host;
192
+ /** How long a call waits for the service, through any reconnect, before it fails. */
193
+ export declare const CALL_TIMEOUT_MS = 30000;
194
+ /** A call that waited longer than its bound for the service. */
195
+ export declare class CallTimeout extends Error {
196
+ constructor(options?: ErrorOptions);
197
+ }
198
+ export interface CallOptions {
199
+ /** `CALL_TIMEOUT_MS` by default; `Infinity` waits for as long as the work takes. */
200
+ timeoutMs?: number;
201
+ /** Gives up the call. */
202
+ signal?: AbortSignal;
203
+ }
204
+ /** Runs `work` against the service, failing with `CallTimeout` once it has waited too long for an answer. */
205
+ export declare function call<T>(host: Host, work: (ctx: Ctx) => Promise<T>, options?: CallOptions): Promise<T>;
206
+ export type ConversationRef = Ref<typeof Conversation>;
207
+ /** One conversation of the service, held until released, waited for as long as a call. */
208
+ export declare function openConversation(host: Host, conversation: number, options?: CallOptions): Promise<ConversationRef>;
209
+ /**
210
+ * The owner's list of conversations as one client holds it: opened when first needed and again once it ended, one
211
+ * open at a time and each bounded as a call; once released, a list still being opened is let go as it arrives.
212
+ */
213
+ export interface HeldList {
214
+ /** The list, waited for no longer than `signal` allows; an open under way goes on for whoever asks next. */
215
+ get(signal?: AbortSignal): Promise<Ref<typeof Conversations>>;
216
+ release(): void;
217
+ }
218
+ export declare function heldList(host: Host, options?: CallOptions): HeldList;
219
+ /** Starts a new conversation in the owner's list and opens it, waiting no longer than any one call. */
220
+ export declare function startConversation(host: Host, list: (signal: AbortSignal) => Promise<Ref<typeof Conversations>>, options?: CallOptions): Promise<{
221
+ id: number;
222
+ conversation: ConversationRef;
223
+ }>;
224
+ /** The owner's list of conversations, held until released, waited for as long as a call. */
225
+ export declare function openConversations(host: Host, options?: CallOptions): Promise<Ref<typeof Conversations>>;
226
+ /** An error's text as every client shows it. */
227
+ export declare function errorText(error: unknown): string;
228
+ /**
229
+ * An error's text followed by what lies beneath it, for a log or a command's last word: an aggregate's failures,
230
+ * then its cause, each told once however many ways lead to it.
231
+ */
232
+ export declare function errorChain(error: unknown): string;
233
+ /** Why a reference ended: its error, or else its status. */
234
+ export declare function endText(ref: {
235
+ readonly status: string;
236
+ readonly error?: unknown;
237
+ }): string;
238
+ /** A random id; a page served over plain HTTP has no `crypto.randomUUID`, but every page has random values. */
239
+ export declare function randomId(): string;
240
+ /**
241
+ * Sends messages so that sending the same text straight after a failure is a resend under the same request, which
242
+ * the service admits once, whether or not the failed try reached it; any other message is a new one.
243
+ */
244
+ export declare function resender(): (text: string, submit: (request: string) => Promise<unknown>) => Promise<unknown>;
245
+ /** Runs `work` with a signal that aborts once `options` say to stop waiting, failing then with `CallTimeout`. */
246
+ export declare function within<T>(options: CallOptions, work: (signal: AbortSignal) => Promise<T>): Promise<T>;
247
+ export {};