@codeworksh/plugin 0.0.1-dev.20260922103030

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/error-ClDISWlT.d.mts +11 -0
  4. package/event-rIZpnOTo.d.mts +895 -0
  5. package/event.d.mts +2 -0
  6. package/event.mjs +125 -0
  7. package/event.mjs.map +1 -0
  8. package/filesystem-Cp-KapCE.d.mts +142 -0
  9. package/ids-CHjmAdTc.d.mts +43 -0
  10. package/ids.d.mts +2 -0
  11. package/ids.mjs +48 -0
  12. package/ids.mjs.map +1 -0
  13. package/index.d.mts +3 -0
  14. package/index.mjs +3 -0
  15. package/io-BYs7hbiY.d.mts +497 -0
  16. package/location-D4hAfuXF.d.mts +61 -0
  17. package/location.d.mts +2 -0
  18. package/location.mjs +48 -0
  19. package/location.mjs.map +1 -0
  20. package/package.json +200 -0
  21. package/plugin/prompt.d.mts +2 -0
  22. package/plugin/prompt.mjs +7 -0
  23. package/plugin/prompt.mjs.map +1 -0
  24. package/plugin/tool.d.mts +2 -0
  25. package/plugin/tool.mjs +29 -0
  26. package/plugin/tool.mjs.map +1 -0
  27. package/plugin-DbJEpY3M.d.mts +140 -0
  28. package/plugin-lorpq7Oi.mjs +41 -0
  29. package/plugin-lorpq7Oi.mjs.map +1 -0
  30. package/plugin.d.mts +4 -0
  31. package/plugin.mjs +4 -0
  32. package/posix.d.mts +6 -0
  33. package/posix.mjs +8 -0
  34. package/posix.mjs.map +1 -0
  35. package/project-CLGsIFD-.d.mts +21 -0
  36. package/project.d.mts +2 -0
  37. package/project.mjs +22 -0
  38. package/project.mjs.map +1 -0
  39. package/prompt-BcpagjGh.d.mts +10 -0
  40. package/repo.d.mts +42 -0
  41. package/repo.mjs +46 -0
  42. package/repo.mjs.map +1 -0
  43. package/rolldown-runtime-D7D4PA-g.mjs +13 -0
  44. package/sandbox/driver.d.mts +2 -0
  45. package/sandbox/driver.mjs +63 -0
  46. package/sandbox/driver.mjs.map +1 -0
  47. package/sandbox/error.d.mts +7 -0
  48. package/sandbox/error.mjs +15 -0
  49. package/sandbox/error.mjs.map +1 -0
  50. package/sandbox/errors.d.mts +2 -0
  51. package/sandbox/errors.mjs +160 -0
  52. package/sandbox/errors.mjs.map +1 -0
  53. package/sandbox/filesystem.d.mts +2 -0
  54. package/sandbox/filesystem.mjs +142 -0
  55. package/sandbox/filesystem.mjs.map +1 -0
  56. package/sandbox/instance.d.mts +2 -0
  57. package/sandbox/instance.mjs +144 -0
  58. package/sandbox/instance.mjs.map +1 -0
  59. package/sandbox/io.d.mts +2 -0
  60. package/sandbox/io.mjs +127 -0
  61. package/sandbox/io.mjs.map +1 -0
  62. package/sandbox/resource.d.mts +28 -0
  63. package/sandbox/resource.mjs +29 -0
  64. package/sandbox/resource.mjs.map +1 -0
  65. package/sandbox/shell.d.mts +2 -0
  66. package/sandbox/shell.mjs +93 -0
  67. package/sandbox/shell.mjs.map +1 -0
  68. package/sandbox.d.mts +17 -0
  69. package/sandbox.mjs +39 -0
  70. package/sandbox.mjs.map +1 -0
  71. package/schema.d.mts +91 -0
  72. package/schema.mjs +105 -0
  73. package/schema.mjs.map +1 -0
  74. package/settings-CYL6yyDD.d.mts +193 -0
  75. package/settings.d.mts +2 -0
  76. package/settings.mjs +102 -0
  77. package/settings.mjs.map +1 -0
  78. package/shell-CZ6Y4lNU.d.mts +109 -0
  79. package/space-CR-9UxdT.d.mts +25 -0
  80. package/space.d.mts +2 -0
  81. package/space.mjs +33 -0
  82. package/space.mjs.map +1 -0
  83. package/tool/error.d.mts +2 -0
  84. package/tool/error.mjs +11 -0
  85. package/tool/error.mjs.map +1 -0
  86. package/tool/progress.d.mts +2 -0
  87. package/tool/progress.mjs +11 -0
  88. package/tool/progress.mjs.map +1 -0
  89. package/tool-BoVqkYvL.d.mts +287 -0
  90. package/tool-DuYBgiJf.d.mts +142 -0
  91. package/tool.d.mts +2 -0
  92. package/tool.mjs +71 -0
  93. package/tool.mjs.map +1 -0
@@ -0,0 +1,109 @@
1
+ import { Context, Effect, Schema, Stream } from "effect";
2
+ //#region src/sandbox/shell.d.ts
3
+ declare const ShellError_base: Schema.Class<ShellError, Schema.TaggedStruct<"ShellError", {
4
+ readonly command: Schema.String;
5
+ readonly cause: Schema.optional<Schema.Defect>;
6
+ }>, import("effect/Cause").YieldableError>;
7
+ /**
8
+ * The pluggable execution contract. Local sandboxes usually get a Shell through
9
+ * just-bash over the local `Local.Vfs`; remote sandboxes provide their own
10
+ * native Shell. Either way the rest of the harness depends only on this service
11
+ * tag.
12
+ */
13
+ declare class ShellError extends ShellError_base {}
14
+ interface ExecResult {
15
+ readonly stdout: string;
16
+ readonly stderr: string;
17
+ readonly exitCode: number;
18
+ }
19
+ /**
20
+ * One options shape for every entry point. `cwd` is the operation-level
21
+ * override: it wins over the mount's working directory, and a relative value
22
+ * resolves against it. Neither mutates shared state, so concurrent commands in
23
+ * one mount can run in different directories.
24
+ */
25
+ interface ShellOptions {
26
+ readonly env?: Record<string, string>;
27
+ readonly cwd?: string;
28
+ }
29
+ /**
30
+ * A streamed chunk of command output, terminated by a single `exit` carrying the
31
+ * exit code. (A backend-level mirror of the tool layer's event; kept here so
32
+ * `sandbox/` does not depend on `tool/`.)
33
+ */
34
+ type ExecChunk = {
35
+ readonly _tag: "stdout";
36
+ readonly bytes: Uint8Array;
37
+ } | {
38
+ readonly _tag: "stderr";
39
+ readonly bytes: Uint8Array;
40
+ } | {
41
+ readonly _tag: "exit";
42
+ readonly exitCode: number;
43
+ };
44
+ /**
45
+ * The command-execution capability a sandbox exposes. For an in-process
46
+ * backend this is just-bash; for a remote backend it is the sandbox's own
47
+ * shell. The {@link Shell} service tag carries this interface.
48
+ */
49
+ interface ISandboxExe {
50
+ readonly exec: (command: string, options?: ShellOptions) => Effect.Effect<ExecResult, ShellError>;
51
+ /**
52
+ * Run a program with an explicit argument vector, bypassing shell word
53
+ * splitting. Callers that build commands from untrusted values — branch
54
+ * names, file paths — must use this instead of interpolating into
55
+ * {@link exec}, where a space or `$(…)` would change what runs.
56
+ *
57
+ * Backends whose transport only accepts a string quote the vector with
58
+ * {@link quote}; backends that spawn directly pass it through untouched.
59
+ */
60
+ readonly execArgv: (argv: ReadonlyArray<string>, options?: ShellOptions) => Effect.Effect<ExecResult, ShellError>;
61
+ /**
62
+ * Optional streaming output: stdout/stderr chunks then a terminal `exit`.
63
+ * Backends that can stream (e.g. Vercel) implement it; `ToolShell.fromSandboxShell`
64
+ * bridges it to `ToolShell.stream` so the bash tool streams over them too.
65
+ */
66
+ readonly stream?: (command: string, options?: ShellOptions) => Stream.Stream<ExecChunk, ShellError>;
67
+ }
68
+ type MountFactory = (cwd: string) => ISandboxExe;
69
+ declare const perMount: (transport: ISandboxExe, make: MountFactory) => ISandboxExe;
70
+ /**
71
+ * POSIX single-quote escaping: wrap in `'…'` and rewrite each embedded quote as
72
+ * `'\''`. Everything inside single quotes is literal to the shell, so this is
73
+ * safe for arbitrary bytes.
74
+ */
75
+ declare const quote: (value: string) => string;
76
+ /** Render an argument vector as one shell-safe command string. */
77
+ declare const quoteArgv: (argv: ReadonlyArray<string>) => string;
78
+ /**
79
+ * Resolve a per-command cwd against the sandbox cwd. Passing a relative cwd
80
+ * straight to a host or remote process API would otherwise resolve it against
81
+ * that API's own default, which need not be the filesystem's configured cwd.
82
+ */
83
+ declare const resolveCwd: (base: string | undefined, cwd: string | undefined) => string | undefined;
84
+ /**
85
+ * Complete a string-only backend: `execArgv` quotes the vector and runs it
86
+ * through `exec`. Backends that spawn a real argument vector (Vercel) implement
87
+ * `execArgv` themselves instead, so the args never meet a shell parser at all.
88
+ *
89
+ * `cwd` rides the options rather than a `cd <dir> && …` prefix. Every backend
90
+ * we wrap takes a working directory natively, and the prefix form cannot tell a
91
+ * failed `cd` from a failed command — both arrive as one exit code.
92
+ */
93
+ declare const fromExec: (backend: Omit<ISandboxExe, "execArgv">) => ISandboxExe;
94
+ /**
95
+ * Bind a cwd-neutral backend to one mount's working directory.
96
+ *
97
+ * The transport is shared between mounts and must stay rooted at the namespace
98
+ * root, so the directory cannot live inside it: two mounts at different
99
+ * directories would otherwise see each other's. This wrapper is per mount, and
100
+ * an operation-level `cwd` still wins — resolved against the mount's, so a
101
+ * relative one means what it reads like.
102
+ */
103
+ declare const withCwd: (backend: ISandboxExe, cwd: string) => ISandboxExe;
104
+ declare const Shell_base: Context.ServiceClass<Shell, "@codeworksh/plugin/sandbox/shell", ISandboxExe>;
105
+ /** Execution service — the live {@link ISandboxExe} for the active sandbox. */
106
+ declare class Shell extends Shell_base {}
107
+ //#endregion
108
+ export { ShellError as a, perMount as c, resolveCwd as d, withCwd as f, Shell as i, quote as l, ExecResult as n, ShellOptions as o, ISandboxExe as r, fromExec as s, ExecChunk as t, quoteArgv as u };
109
+ //# sourceMappingURL=shell-CZ6Y4lNU.d.mts.map
@@ -0,0 +1,25 @@
1
+ import { Schema } from "effect";
2
+ declare namespace space_d_exports {
3
+ export { ID, Info, Kind, space_d_exports as SpaceSchema, Status };
4
+ }
5
+ declare const ID: Schema.brand<Schema.String, "Space.ID">;
6
+ type ID = typeof ID.Type;
7
+ declare const Kind: Schema.Literals<readonly ["primary", "linked", "copy", "plain"]>;
8
+ type Kind = typeof Kind.Type;
9
+ declare const Status: Schema.Literals<readonly ["active", "archived"]>;
10
+ type Status = typeof Status.Type;
11
+ declare const Info_base: Schema.Class<Info, Schema.Struct<{
12
+ readonly id: Schema.brand<Schema.String, "Space.ID">;
13
+ readonly projectId: Schema.brand<Schema.String, "Project.ID">;
14
+ readonly location: Schema.brand<Schema.String, "AbsolutePath">;
15
+ readonly kind: Schema.Literals<readonly ["primary", "linked", "copy", "plain"]>;
16
+ readonly env: Schema.brand<Schema.String, "SandboxInstance.ID"> & {
17
+ local: string & import("effect/Brand").Brand<"SandboxInstance.ID">;
18
+ create: () => string & import("effect/Brand").Brand<"SandboxInstance.ID">;
19
+ };
20
+ readonly status: Schema.Literals<readonly ["active", "archived"]>;
21
+ }>, {}>;
22
+ declare class Info extends Info_base {}
23
+ //#endregion
24
+ export { space_d_exports as a, Status as i, Info as n, Kind as r, ID as t };
25
+ //# sourceMappingURL=space-CR-9UxdT.d.mts.map
package/space.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { a as space_d_exports, i as Status, n as Info, r as Kind, t as ID } from "./space-CR-9UxdT.mjs";
2
+ export { ID, Info, Kind, space_d_exports as SpaceSchema, Status };
package/space.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { AbsolutePath } from "./schema.mjs";
3
+ import { ID as ID$1 } from "./project.mjs";
4
+ import { ID as ID$2 } from "./sandbox/instance.mjs";
5
+ import { Schema } from "effect";
6
+ //#region src/space.ts
7
+ var space_exports = /* @__PURE__ */ __exportAll({
8
+ ID: () => ID,
9
+ Info: () => Info,
10
+ Kind: () => Kind,
11
+ SpaceSchema: () => space_exports,
12
+ Status: () => Status
13
+ });
14
+ const ID = Schema.String.pipe(Schema.brand("Space.ID"));
15
+ const Kind = Schema.Literals([
16
+ "primary",
17
+ "linked",
18
+ "copy",
19
+ "plain"
20
+ ]);
21
+ const Status = Schema.Literals(["active", "archived"]);
22
+ var Info = class extends Schema.Class("Space.Info")({
23
+ id: ID,
24
+ projectId: ID$1,
25
+ location: AbsolutePath,
26
+ kind: Kind,
27
+ env: ID$2,
28
+ status: Status
29
+ }) {};
30
+ //#endregion
31
+ export { ID, Info, Kind, space_exports as SpaceSchema, Status };
32
+
33
+ //# sourceMappingURL=space.mjs.map
package/space.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.mjs","names":["ProjectSchema.ID","SandboxInstance.ID"],"sources":["../../src/space.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { ProjectSchema } from \"./project.ts\";\nimport { SandboxInstance } from \"./sandbox/instance.ts\";\nimport { AbsolutePath } from \"./schema.ts\";\n\n// hash(env, location) — no project component, so re-pointing a space to\n// another project never rewrites the key sessions reference.\nexport const ID = Schema.String.pipe(Schema.brand(\"Space.ID\"));\nexport type ID = typeof ID.Type;\n\n// primary: the main checkout (one per project+env); linked: a git worktree\n// sharing the primary's store; copy: another clone; plain: a non-git directory.\nexport const Kind = Schema.Literals([\"primary\", \"linked\", \"copy\", \"plain\"]);\nexport type Kind = typeof Kind.Type;\n\nexport const Status = Schema.Literals([\"active\", \"archived\"]);\nexport type Status = typeof Status.Type;\n\n// One directory in one env that belongs to a project; the unit sessions attach to.\nexport class Info extends Schema.Class<Info>(\"Space.Info\")({\n\tid: ID,\n\tprojectId: ProjectSchema.ID,\n\tlocation: AbsolutePath,\n\tkind: Kind,\n\tenv: SandboxInstance.ID,\n\tstatus: Status,\n}) {}\n\nexport * as SpaceSchema from \"./space.ts\";\n"],"mappings":";;;;;;;;;;;;;AAOA,MAAa,KAAK,OAAO,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAK7D,MAAa,OAAO,OAAO,SAAS;CAAC;CAAW;CAAU;CAAQ;AAAO,CAAC;AAG1E,MAAa,SAAS,OAAO,SAAS,CAAC,UAAU,UAAU,CAAC;AAI5D,IAAa,OAAb,cAA0B,OAAO,MAAY,YAAY,CAAC,CAAC;CAC1D,IAAI;CACJ,WAAWA;CACX,UAAU;CACV,MAAM;CACN,KAAKC;CACL,QAAQ;AACT,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { t as ToolExecutionError } from "../error-ClDISWlT.mjs";
2
+ export { ToolExecutionError };
package/tool/error.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { Schema } from "effect";
2
+ //#region src/tool/error.ts
3
+ /** A typed wrapper for a tool failure crossing the heterogeneous registry boundary. */
4
+ var ToolExecutionError = class extends Schema.TaggedError()("ToolExecutionError", {
5
+ toolName: Schema.String,
6
+ cause: Schema.Defect()
7
+ }) {};
8
+ //#endregion
9
+ export { ToolExecutionError };
10
+
11
+ //# sourceMappingURL=error.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.mjs","names":[],"sources":["../../../src/tool/error.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/** A typed wrapper for a tool failure crossing the heterogeneous registry boundary. */\nexport class ToolExecutionError extends Schema.TaggedError<ToolExecutionError>()(\"ToolExecutionError\", {\n\ttoolName: Schema.String,\n\tcause: Schema.Defect(),\n}) {}\n"],"mappings":";;;AAGA,IAAa,qBAAb,cAAwC,OAAO,YAAgC,CAAC,CAAC,sBAAsB;CACtG,UAAU,OAAO;CACjB,OAAO,OAAO,OAAO;AACtB,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { _ as IToolProgress, b as make, v as ToolProgress, x as noop, y as ToolProgressPartial } from "../tool-DuYBgiJf.mjs";
2
+ export { IToolProgress, ToolProgress, ToolProgressPartial, make, noop };
@@ -0,0 +1,11 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ //#region src/tool/progress.ts
3
+ var ToolProgress = class extends Context.Service()("@codeworksh/plugin/tool/progress/ToolProgress") {};
4
+ /** Build a `ToolProgress` Layer from a `report` implementation. */
5
+ const make = (report) => Layer.succeed(ToolProgress, ToolProgress.of({ report }));
6
+ /** Drops every update — the default until the executor wires a live event sink. */
7
+ const noop = make(() => Effect.void);
8
+ //#endregion
9
+ export { ToolProgress, make, noop };
10
+
11
+ //# sourceMappingURL=progress.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.mjs","names":[],"sources":["../../../src/tool/progress.ts"],"sourcesContent":["import { Context, Effect, Layer } from \"effect\";\nimport type { ModelContent } from \"../tool.ts\";\n\n/**\n * `ToolProgress` — the side-channel a long-running tool (e.g. streaming bash)\n * writes interim output to, instead of an `onUpdate` callback.\n *\n * Most tools never call `report` and keep a clean `Effect<Success, Failure>`\n * signature. Throttling / coalescing lives in the Layer (the live one routes to\n * the run's event PubSub, tagged with the active callID); the handler just\n * reports.\n */\n\n/** Mirror of aikit's `Message.ToolRunningPartial` (kept structural to stay decoupled). */\nexport interface ToolProgressPartial {\n\treadonly content?: ModelContent;\n\treadonly details?: unknown;\n}\n\nexport interface IToolProgress {\n\treadonly report: (partial: ToolProgressPartial) => Effect.Effect<void>;\n}\n\nexport class ToolProgress extends Context.Service<ToolProgress, IToolProgress>()(\n\t\"@codeworksh/plugin/tool/progress/ToolProgress\",\n) {}\n\n/** Build a `ToolProgress` Layer from a `report` implementation. */\nexport const make = (report: IToolProgress[\"report\"]): Layer.Layer<ToolProgress> =>\n\tLayer.succeed(ToolProgress, ToolProgress.of({ report }));\n\n/** Drops every update — the default until the executor wires a live event sink. */\nexport const noop: Layer.Layer<ToolProgress> = make(() => Effect.void);\n"],"mappings":";;AAuBA,IAAa,eAAb,cAAkC,QAAQ,QAAqC,CAAC,CAC/E,+CACD,CAAC,CAAC,CAAC;;AAGH,MAAa,QAAQ,WACpB,MAAM,QAAQ,cAAc,aAAa,GAAG,EAAE,OAAO,CAAC,CAAC;;AAGxD,MAAa,OAAkC,WAAW,OAAO,IAAI"}
@@ -0,0 +1,287 @@
1
+ import { a as RegisteredTool, i as ModelContent, t as AnyToolDef } from "./tool-DuYBgiJf.mjs";
2
+ import { Effect, Schema } from "effect";
3
+ declare namespace tool_d_exports {
4
+ export { HookReturn, ToolAddOptions, ToolAfter, ToolAfterFn, ToolAfterResult, ToolBefore, ToolBeforeFn, ToolBeforeResult, ToolDefPatch, ToolRegistration, ToolRegistry, ToolResultContent };
5
+ }
6
+ declare const ToolBefore: Schema.Struct<{
7
+ readonly callID: Schema.String;
8
+ readonly toolName: Schema.String;
9
+ readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
10
+ readonly sessionId: Schema.brand<Schema.String, "Session.ID"> & {
11
+ ascending: (id?: string) => string & import("effect/Brand").Brand<"Session.ID">;
12
+ create: () => string & import("effect/Brand").Brand<"Session.ID">;
13
+ };
14
+ readonly messageId: Schema.brand<Schema.String, "Message.ID"> & {
15
+ create: () => string & import("effect/Brand").Brand<"Message.ID">;
16
+ from: (id: string) => string & import("effect/Brand").Brand<"Message.ID">;
17
+ };
18
+ readonly params: Schema.Unknown;
19
+ }>;
20
+ type ToolBefore = typeof ToolBefore.Type;
21
+ declare const ToolAfter: Schema.Struct<{
22
+ readonly callID: Schema.String;
23
+ readonly toolName: Schema.String;
24
+ readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
25
+ readonly sessionId: Schema.brand<Schema.String, "Session.ID"> & {
26
+ ascending: (id?: string) => string & import("effect/Brand").Brand<"Session.ID">;
27
+ create: () => string & import("effect/Brand").Brand<"Session.ID">;
28
+ };
29
+ readonly messageId: Schema.brand<Schema.String, "Message.ID"> & {
30
+ create: () => string & import("effect/Brand").Brand<"Message.ID">;
31
+ from: (id: string) => string & import("effect/Brand").Brand<"Message.ID">;
32
+ };
33
+ readonly params: Schema.Unknown;
34
+ readonly terminal: Schema.decodeTo<Schema.declare<{
35
+ addedToolNames?: string[];
36
+ arguments: Record<string, any>;
37
+ callID: string;
38
+ name: string;
39
+ namespace?: string;
40
+ result: {
41
+ content: ({
42
+ type: "text";
43
+ text: string;
44
+ textSignature?: string;
45
+ } | {
46
+ type: "image";
47
+ data: string;
48
+ mimeType: string;
49
+ })[];
50
+ details?: any;
51
+ isError: false;
52
+ };
53
+ status: "completed";
54
+ thoughtSignature?: string;
55
+ time: {
56
+ start: number;
57
+ end: number;
58
+ };
59
+ type: "toolCall";
60
+ } | {
61
+ addedToolNames?: string[];
62
+ arguments: Record<string, any>;
63
+ callID: string;
64
+ name: string;
65
+ namespace?: string;
66
+ result: {
67
+ content: ({
68
+ type: "text";
69
+ text: string;
70
+ textSignature?: string;
71
+ } | {
72
+ type: "image";
73
+ data: string;
74
+ mimeType: string;
75
+ })[];
76
+ details?: any;
77
+ isError: true;
78
+ };
79
+ status: "error";
80
+ thoughtSignature?: string;
81
+ time: {
82
+ start: number;
83
+ end: number;
84
+ };
85
+ type: "toolCall";
86
+ } | {
87
+ addedToolNames?: string[];
88
+ arguments: Record<string, any>;
89
+ callID: string;
90
+ name: string;
91
+ namespace?: string;
92
+ result: {
93
+ content: ({
94
+ type: "text";
95
+ text: string;
96
+ textSignature?: string;
97
+ } | {
98
+ type: "image";
99
+ data: string;
100
+ mimeType: string;
101
+ })[];
102
+ details?: any;
103
+ isError: true;
104
+ };
105
+ status: "skipped";
106
+ thoughtSignature?: string;
107
+ time: {
108
+ start: number;
109
+ end: number;
110
+ };
111
+ type: "toolCall";
112
+ } | {
113
+ addedToolNames?: string[];
114
+ arguments: Record<string, any>;
115
+ callID: string;
116
+ name: string;
117
+ namespace?: string;
118
+ result: {
119
+ content: ({
120
+ type: "text";
121
+ text: string;
122
+ textSignature?: string;
123
+ } | {
124
+ type: "image";
125
+ data: string;
126
+ mimeType: string;
127
+ })[];
128
+ details?: any;
129
+ isError: true;
130
+ };
131
+ status: "aborted";
132
+ thoughtSignature?: string;
133
+ time: {
134
+ start: number;
135
+ end: number;
136
+ };
137
+ type: "toolCall";
138
+ }, {
139
+ addedToolNames?: string[];
140
+ arguments: Record<string, any>;
141
+ callID: string;
142
+ name: string;
143
+ namespace?: string;
144
+ result: {
145
+ content: ({
146
+ type: "text";
147
+ text: string;
148
+ textSignature?: string;
149
+ } | {
150
+ type: "image";
151
+ data: string;
152
+ mimeType: string;
153
+ })[];
154
+ details?: any;
155
+ isError: false;
156
+ };
157
+ status: "completed";
158
+ thoughtSignature?: string;
159
+ time: {
160
+ start: number;
161
+ end: number;
162
+ };
163
+ type: "toolCall";
164
+ } | {
165
+ addedToolNames?: string[];
166
+ arguments: Record<string, any>;
167
+ callID: string;
168
+ name: string;
169
+ namespace?: string;
170
+ result: {
171
+ content: ({
172
+ type: "text";
173
+ text: string;
174
+ textSignature?: string;
175
+ } | {
176
+ type: "image";
177
+ data: string;
178
+ mimeType: string;
179
+ })[];
180
+ details?: any;
181
+ isError: true;
182
+ };
183
+ status: "error";
184
+ thoughtSignature?: string;
185
+ time: {
186
+ start: number;
187
+ end: number;
188
+ };
189
+ type: "toolCall";
190
+ } | {
191
+ addedToolNames?: string[];
192
+ arguments: Record<string, any>;
193
+ callID: string;
194
+ name: string;
195
+ namespace?: string;
196
+ result: {
197
+ content: ({
198
+ type: "text";
199
+ text: string;
200
+ textSignature?: string;
201
+ } | {
202
+ type: "image";
203
+ data: string;
204
+ mimeType: string;
205
+ })[];
206
+ details?: any;
207
+ isError: true;
208
+ };
209
+ status: "skipped";
210
+ thoughtSignature?: string;
211
+ time: {
212
+ start: number;
213
+ end: number;
214
+ };
215
+ type: "toolCall";
216
+ } | {
217
+ addedToolNames?: string[];
218
+ arguments: Record<string, any>;
219
+ callID: string;
220
+ name: string;
221
+ namespace?: string;
222
+ result: {
223
+ content: ({
224
+ type: "text";
225
+ text: string;
226
+ textSignature?: string;
227
+ } | {
228
+ type: "image";
229
+ data: string;
230
+ mimeType: string;
231
+ })[];
232
+ details?: any;
233
+ isError: true;
234
+ };
235
+ status: "aborted";
236
+ thoughtSignature?: string;
237
+ time: {
238
+ start: number;
239
+ end: number;
240
+ };
241
+ type: "toolCall";
242
+ }>, Schema.Unknown, never, never>;
243
+ }>;
244
+ type ToolAfter = typeof ToolAfter.Type;
245
+ declare const ToolBeforeResult: Schema.Struct<{
246
+ readonly block: Schema.Boolean;
247
+ readonly reason: Schema.optional<Schema.String>;
248
+ }>;
249
+ type ToolBeforeResult = typeof ToolBeforeResult.Type;
250
+ type ToolResultContent = ModelContent;
251
+ interface ToolAfterResult {
252
+ readonly content?: ToolResultContent;
253
+ readonly details?: unknown;
254
+ readonly isError?: boolean;
255
+ }
256
+ type HookReturn<A> = A | void | Promise<A | void> | Effect.Effect<A | void, unknown>;
257
+ type ToolBeforeFn = (call: ToolBefore) => HookReturn<ToolBeforeResult>;
258
+ type ToolAfterFn = (call: ToolAfter) => HookReturn<ToolAfterResult>;
259
+ interface ToolAddOptions {
260
+ readonly beforeToolCall?: ToolBeforeFn;
261
+ readonly afterToolCall?: ToolAfterFn;
262
+ }
263
+ interface ToolDefPatch {
264
+ readonly description?: string;
265
+ readonly label?: string;
266
+ readonly promptSnippet?: string;
267
+ readonly promptGuidelines?: ReadonlyArray<string>;
268
+ }
269
+ /**
270
+ * One frozen bucket entry: the winning tool for a name together with the hooks that
271
+ * `add` declared alongside it. Kept here rather than in the bucket implementation so
272
+ * the executor shares the contract without importing plugin assembly.
273
+ */
274
+ interface ToolRegistration {
275
+ readonly tool: RegisteredTool;
276
+ readonly hooks: ToolAddOptions;
277
+ }
278
+ interface ToolRegistry {
279
+ readonly add: (tool: RegisteredTool, options?: ToolAddOptions) => void;
280
+ readonly update: (name: string, patch: ToolDefPatch) => void;
281
+ readonly list: () => ReadonlyArray<AnyToolDef>;
282
+ readonly get: (name: string) => AnyToolDef | undefined;
283
+ readonly has: (name: string) => boolean;
284
+ }
285
+ //#endregion
286
+ export { ToolAfterResult as a, ToolBeforeResult as c, ToolRegistry as d, ToolResultContent as f, ToolAfterFn as i, ToolDefPatch as l, ToolAddOptions as n, ToolBefore as o, tool_d_exports as p, ToolAfter as r, ToolBeforeFn as s, HookReturn as t, ToolRegistration as u };
287
+ //# sourceMappingURL=tool-BoVqkYvL.d.mts.map
@@ -0,0 +1,142 @@
1
+ import { t as ToolExecutionError } from "./error-ClDISWlT.mjs";
2
+ import { Message } from "@codeworksh/aikit";
3
+ import { Context, Effect, Layer, Schema } from "effect";
4
+ //#region src/tool/progress.d.ts
5
+ /**
6
+ * `ToolProgress` — the side-channel a long-running tool (e.g. streaming bash)
7
+ * writes interim output to, instead of an `onUpdate` callback.
8
+ *
9
+ * Most tools never call `report` and keep a clean `Effect<Success, Failure>`
10
+ * signature. Throttling / coalescing lives in the Layer (the live one routes to
11
+ * the run's event PubSub, tagged with the active callID); the handler just
12
+ * reports.
13
+ */
14
+ /** Mirror of aikit's `Message.ToolRunningPartial` (kept structural to stay decoupled). */
15
+ interface ToolProgressPartial {
16
+ readonly content?: ModelContent;
17
+ readonly details?: unknown;
18
+ }
19
+ interface IToolProgress {
20
+ readonly report: (partial: ToolProgressPartial) => Effect.Effect<void>;
21
+ }
22
+ declare const ToolProgress_base: Context.ServiceClass<ToolProgress, "@codeworksh/plugin/tool/progress/ToolProgress", IToolProgress>;
23
+ declare class ToolProgress extends ToolProgress_base {}
24
+ /** Build a `ToolProgress` Layer from a `report` implementation. */
25
+ declare const make$1: (report: IToolProgress["report"]) => Layer.Layer<ToolProgress>;
26
+ /** Drops every update — the default until the executor wires a live event sink. */
27
+ declare const noop: Layer.Layer<ToolProgress>;
28
+ declare namespace tool_d_exports {
29
+ export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
30
+ }
31
+ /**
32
+ * The tool definition + handler model.
33
+ *
34
+ * A tool definition is pure, serializable data: name, description, and Effect
35
+ * Schema for parameters / success / failure. Execution is a separate `Handler`
36
+ * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its
37
+ * requirements `R`, provided by a Layer at runtime. Separating the two is the
38
+ * main testing win: assert on the definition as plain data, and run the handler
39
+ * against a stub capability Layer.
40
+ *
41
+ * Effect Schema is the single source of truth. {@link toAikitTool} derives a
42
+ * provider-safe JSON Schema object for the aikit wire view; the harness
43
+ * decode/encodes arguments and results with Effect Schema natively (it does not
44
+ * use aikit's Typebox validators).
45
+ */
46
+ /** What the model reads next turn (the `content` side of content/details). */
47
+ type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;
48
+ /** Per-call metadata handed to a handler instead of positional args. */
49
+ declare const ToolCallContext: Schema.Struct<{
50
+ readonly callID: Schema.String;
51
+ readonly toolName: Schema.String;
52
+ readonly rawArgs: Schema.$Record<Schema.String, Schema.Unknown>;
53
+ }>;
54
+ type ToolCallContext = typeof ToolCallContext.Type;
55
+ /**
56
+ * A pure tool definition. Parametrised over the *schema* instances so the
57
+ * decoded parameter/success/failure types can be recovered via `["Type"]`.
58
+ */
59
+ interface ToolDef<Name extends string = string, Params extends Schema.Top = Schema.Top, Success extends Schema.Top = Schema.Top, Failure extends Schema.Top = Schema.Top> {
60
+ readonly name: Name;
61
+ readonly description: string;
62
+ /** Human-readable display label (kept from the previous `AgentTool`). */
63
+ readonly label?: string;
64
+ /**
65
+ * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),
66
+ * distinct from the fuller `description`.
67
+ */
68
+ readonly promptSnippet?: string;
69
+ /** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
70
+ readonly promptGuidelines?: ReadonlyArray<string>;
71
+ readonly parameters: Params;
72
+ readonly success: Success;
73
+ /** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */
74
+ readonly failure?: Failure;
75
+ /** Render success for the model. Omit → executor falls back to JSON text. */
76
+ readonly encodeContent?: (success: Success["Type"]) => ModelContent;
77
+ /** Render an expected failure for the model. Omit → executor falls back to JSON text. */
78
+ readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
79
+ }
80
+ /** A handler: validated params + context → typed success or typed failure. */
81
+ type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (params: Params["Type"], ctx: ToolCallContext) => Effect.Effect<Success["Type"], Failure["Type"], R>;
82
+ /** A definition paired with its handler (the unit the executor runs). */
83
+ interface ToolImpl<Name extends string = string, Params extends Schema.Top = Schema.Top, Success extends Schema.Top = Schema.Top, Failure extends Schema.Top = Schema.Top, R = never> {
84
+ readonly definition: ToolDef<Name, Params, Success, Failure>;
85
+ readonly handler: Handler<Params, Success, Failure, R>;
86
+ }
87
+ type AnyToolDef = ToolDef<string, any, any, any>;
88
+ type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;
89
+ interface DefineInput<Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top> {
90
+ readonly name: Name;
91
+ readonly description: string;
92
+ readonly label?: string;
93
+ readonly promptSnippet?: string;
94
+ readonly parameters: Params;
95
+ readonly success: Success;
96
+ readonly failure?: Failure;
97
+ readonly encodeContent?: (success: Success["Type"]) => ModelContent;
98
+ readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
99
+ }
100
+ /** Define a pure tool (handler attached later via {@link implement} or a toolkit). */
101
+ declare const define: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top = Schema.Top>(input: DefineInput<Name, Params, Success, Failure>) => ToolDef<Name, Params, Success, Failure>;
102
+ /** Attach a handler to an existing definition (the testable def/exec split). */
103
+ declare const implement: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never>(definition: ToolDef<Name, Params, Success, Failure>, handler: Handler<Params, Success, Failure, R>) => ToolImpl<Name, Params, Success, Failure, R>;
104
+ /** Sugar for the co-located case: a definition with its handler in one object. */
105
+ declare const make: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top = Schema.Top, R = never>(input: DefineInput<Name, Params, Success, Failure> & {
106
+ readonly handler: Handler<Params, Success, Failure, R>;
107
+ }) => ToolImpl<Name, Params, Success, Failure, R>;
108
+ /**
109
+ * A tool ready to register: its capability requirements have been discharged, leaving only
110
+ * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s
111
+ * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any
112
+ * number of tools — built-in or
113
+ * third-party/plugin — compose without a shared capability union
114
+ */
115
+ interface RegisteredTool {
116
+ readonly definition: AnyToolDef;
117
+ readonly handler: (params: unknown, ctx: ToolCallContext) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;
118
+ }
119
+ /** Register a tool whose only requirement is the executor-provided progress service. */
120
+ declare const register: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top>(impl: ToolImpl<Name, Params, Success, Failure, ToolProgress>) => RegisteredTool;
121
+ /**
122
+ * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`
123
+ * (the executor still provides `ToolProgress`). This is the registration boundary: a
124
+ * plugin/third-party tool provides its own fully-resolved capability Layer here, so the
125
+ * registry never has to unify anyone's `R`.
126
+ */
127
+ declare const provide: <Name extends string, Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R>(impl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>, layer: Layer.Layer<R>) => RegisteredTool;
128
+ /**
129
+ * Derive a provider-safe JSON Schema object from an Effect Schema. This is the
130
+ * single boundary that crosses into the provider wire; if a provider rejects a
131
+ * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).
132
+ */
133
+ declare const toProviderJsonSchema: (schema: Schema.Top) => Record<string, unknown>;
134
+ /**
135
+ * Build the aikit `Message.Tool` wire view from a definition. The derived JSON
136
+ * Schema object satisfies aikit's `parameters` slot structurally at runtime; the
137
+ * single localized cast keeps aikit untouched (decision 3-A).
138
+ */
139
+ declare const toAikitTool: (def: AnyToolDef) => Message.Tool;
140
+ //#endregion
141
+ export { IToolProgress as _, RegisteredTool as a, make$1 as b, ToolImpl as c, make as d, provide as f, tool_d_exports as g, toProviderJsonSchema as h, ModelContent as i, define as l, toAikitTool as m, AnyToolImpl as n, ToolCallContext as o, register as p, Handler as r, ToolDef as s, AnyToolDef as t, implement as u, ToolProgress as v, noop as x, ToolProgressPartial as y };
142
+ //# sourceMappingURL=tool-DuYBgiJf.d.mts.map
package/tool.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import { a as RegisteredTool, c as ToolImpl, d as make, f as provide, h as toProviderJsonSchema, i as ModelContent, l as define, m as toAikitTool, n as AnyToolImpl, o as ToolCallContext, p as register, r as Handler, s as ToolDef, t as AnyToolDef, u as implement } from "./tool-DuYBgiJf.mjs";
2
+ export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };