@fungi.computer/knapsack 0.0.1 → 0.1.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.
@@ -1,10 +1,10 @@
1
1
  import * as z from "zod";
2
2
  /** Browser-safe patch contracts shared by native Files tools and Computer HTTP. */
3
- export declare const patchInputSchema: z.ZodObject<{
3
+ export declare const patchInputSchema: z.ZodLazy<z.ZodObject<{
4
4
  patch: z.ZodString;
5
- }, z.core.$strict>;
5
+ }, z.core.$strict>>;
6
6
  /** Native patch completion, cancellation or failure, including an optional mismatch. */
7
- export declare const patchOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
7
+ export declare const patchOutputSchema: z.ZodLazy<z.ZodUnion<readonly [z.ZodObject<{
8
8
  status: z.ZodEnum<{
9
9
  completed: "completed";
10
10
  failed: "failed";
@@ -27,4 +27,4 @@ export declare const patchOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
27
27
  error: z.ZodObject<{
28
28
  kind: z.ZodLiteral<"mismatch">;
29
29
  }, z.core.$strict>;
30
- }, z.core.$strict>]>;
30
+ }, z.core.$strict>]>>;
@@ -1,11 +1,11 @@
1
1
  import * as z from "zod";
2
2
  import { boundedTextSchema, maximumReadBytes } from "./files-read.js";
3
3
  /** Browser-safe patch contracts shared by native Files tools and Computer HTTP. */
4
- export const patchInputSchema = z.strictObject({
4
+ export const patchInputSchema = z.lazy(() => z.strictObject({
5
5
  patch: boundedTextSchema(1).meta({
6
6
  description: `Codex patch text, at most ${String(maximumReadBytes)} UTF-8 bytes.`,
7
7
  }),
8
- });
8
+ }));
9
9
  const patchResultSchema = z.strictObject({
10
10
  status: z.enum(["completed", "failed", "cancelled"]),
11
11
  exitCode: z.number().int(),
@@ -14,9 +14,9 @@ const patchResultSchema = z.strictObject({
14
14
  truncated: z.boolean(),
15
15
  });
16
16
  /** Native patch completion, cancellation or failure, including an optional mismatch. */
17
- export const patchOutputSchema = z.union([
17
+ export const patchOutputSchema = z.lazy(() => z.union([
18
18
  patchResultSchema,
19
19
  patchResultSchema.extend({
20
20
  error: z.strictObject({ kind: z.literal("mismatch") }),
21
21
  }),
22
- ]);
22
+ ]));
@@ -2,24 +2,24 @@ import * as z from "zod";
2
2
  /** Maximum UTF-8 byte length of a Files text page. */
3
3
  export declare const maximumReadBytes: number;
4
4
  /** Nonempty file path bounded to 4,096 characters, without null bytes. */
5
- export declare const pathSchema: z.ZodString;
5
+ export declare const pathSchema: z.ZodLazy<z.ZodString>;
6
6
  /** Validate text against a minimum character length and the Files UTF-8 byte limit. */
7
7
  export declare function boundedTextSchema(minimumLength?: number): z.ZodString;
8
8
  /** Canonical bounded Files read request and result, shared with display consumers. */
9
- export declare const readInputSchema: z.ZodObject<{
10
- path: z.ZodString;
9
+ export declare const readInputSchema: z.ZodLazy<z.ZodObject<{
10
+ path: z.ZodLazy<z.ZodString>;
11
11
  offset: z.ZodDefault<z.ZodNumber>;
12
12
  limit: z.ZodDefault<z.ZodNumber>;
13
- }, z.core.$strict>;
13
+ }, z.core.$strict>>;
14
14
  /** Bounded text page, continuation offset and optional hosted file identity. */
15
- export declare const readOutputSchema: z.ZodObject<{
16
- path: z.ZodString;
15
+ export declare const readOutputSchema: z.ZodLazy<z.ZodObject<{
16
+ path: z.ZodLazy<z.ZodString>;
17
17
  content: z.ZodString;
18
18
  offset: z.ZodNumber;
19
19
  nextOffset: z.ZodNullable<z.ZodNumber>;
20
20
  truncated: z.ZodBoolean;
21
21
  file: z.ZodExactOptional<z.ZodObject<{
22
22
  computerId: z.ZodString;
23
- path: z.ZodString;
23
+ path: z.ZodLazy<z.ZodString>;
24
24
  }, z.core.$strict>>;
25
- }, z.core.$strict>;
25
+ }, z.core.$strict>>;
@@ -3,11 +3,11 @@ import * as z from "zod";
3
3
  export const maximumReadBytes = 128 * 1_024;
4
4
  const utf8 = new TextEncoder();
5
5
  /** Nonempty file path bounded to 4,096 characters, without null bytes. */
6
- export const pathSchema = z
6
+ export const pathSchema = z.lazy(() => z
7
7
  .string()
8
8
  .min(1)
9
9
  .max(4_096)
10
- .refine((path) => !path.includes("\0"), "Path cannot contain null bytes");
10
+ .refine((path) => !path.includes("\0"), "Path cannot contain null bytes"));
11
11
  /** Validate text against a minimum character length and the Files UTF-8 byte limit. */
12
12
  export function boundedTextSchema(minimumLength = 0) {
13
13
  return z
@@ -16,7 +16,7 @@ export function boundedTextSchema(minimumLength = 0) {
16
16
  .refine((content) => utf8.encode(content).byteLength <= maximumReadBytes, `Text exceeds the ${String(maximumReadBytes)}-byte Files bound`);
17
17
  }
18
18
  /** Canonical bounded Files read request and result, shared with display consumers. */
19
- export const readInputSchema = z.strictObject({
19
+ export const readInputSchema = z.lazy(() => z.strictObject({
20
20
  path: pathSchema,
21
21
  offset: z.number().int().min(0).default(0),
22
22
  limit: z
@@ -25,9 +25,9 @@ export const readInputSchema = z.strictObject({
25
25
  .min(4)
26
26
  .max(maximumReadBytes)
27
27
  .default(maximumReadBytes),
28
- });
28
+ }));
29
29
  /** Bounded text page, continuation offset and optional hosted file identity. */
30
- export const readOutputSchema = z.strictObject({
30
+ export const readOutputSchema = z.lazy(() => z.strictObject({
31
31
  path: pathSchema,
32
32
  content: boundedTextSchema(),
33
33
  offset: z.number().int().min(0),
@@ -40,4 +40,4 @@ export const readOutputSchema = z.strictObject({
40
40
  path: pathSchema.refine((path) => path.startsWith("/"), "Computer file paths must be absolute"),
41
41
  })
42
42
  .exactOptional(),
43
- });
43
+ }));
package/dist/files.d.ts CHANGED
@@ -14,14 +14,14 @@ export declare class FilesEditError extends Error {
14
14
  }
15
15
  /** Bounded directory listing request. */
16
16
  export declare const listInputSchema: z.ZodObject<{
17
- path: z.ZodString;
17
+ path: z.ZodLazy<z.ZodString>;
18
18
  limit: z.ZodDefault<z.ZodNumber>;
19
19
  }, z.core.$strict>;
20
20
  /** Directory entries and an explicit truncation flag. */
21
- export declare const listOutputSchema: z.ZodObject<{
22
- path: z.ZodString;
23
- entries: z.ZodArray<z.ZodObject<{
24
- path: z.ZodString;
21
+ export declare const listOutputSchema: z.ZodLazy<z.ZodObject<{
22
+ path: z.ZodLazy<z.ZodString>;
23
+ entries: z.ZodArray<z.ZodLazy<z.ZodObject<{
24
+ path: z.ZodLazy<z.ZodString>;
25
25
  name: z.ZodString;
26
26
  type: z.ZodEnum<{
27
27
  file: "file";
@@ -30,47 +30,47 @@ export declare const listOutputSchema: z.ZodObject<{
30
30
  }>;
31
31
  size: z.ZodNumber;
32
32
  modifiedAt: z.ZodNumber;
33
- }, z.core.$strict>>;
33
+ }, z.core.$strict>>>;
34
34
  truncated: z.ZodBoolean;
35
- }, z.core.$strict>;
35
+ }, z.core.$strict>>;
36
36
  /** Bounded path-pattern search request. */
37
- export declare const globInputSchema: z.ZodObject<{
38
- path: z.ZodString;
37
+ export declare const globInputSchema: z.ZodLazy<z.ZodObject<{
38
+ path: z.ZodLazy<z.ZodString>;
39
39
  pattern: z.ZodString;
40
40
  limit: z.ZodDefault<z.ZodNumber>;
41
- }, z.core.$strict>;
41
+ }, z.core.$strict>>;
42
42
  /** Matching paths and an explicit truncation flag. */
43
- export declare const globOutputSchema: z.ZodObject<{
44
- path: z.ZodString;
45
- matches: z.ZodArray<z.ZodString>;
43
+ export declare const globOutputSchema: z.ZodLazy<z.ZodObject<{
44
+ path: z.ZodLazy<z.ZodString>;
45
+ matches: z.ZodArray<z.ZodLazy<z.ZodString>>;
46
46
  truncated: z.ZodBoolean;
47
- }, z.core.$strict>;
47
+ }, z.core.$strict>>;
48
48
  /** Bounded content-search request with optional regular-expression matching. */
49
- export declare const grepInputSchema: z.ZodObject<{
50
- path: z.ZodString;
49
+ export declare const grepInputSchema: z.ZodLazy<z.ZodObject<{
50
+ path: z.ZodLazy<z.ZodString>;
51
51
  pattern: z.ZodString;
52
52
  regex: z.ZodDefault<z.ZodBoolean>;
53
53
  ignoreCase: z.ZodDefault<z.ZodBoolean>;
54
54
  limit: z.ZodDefault<z.ZodNumber>;
55
- }, z.core.$strict>;
55
+ }, z.core.$strict>>;
56
56
  /** Content matches and an explicit truncation flag. */
57
- export declare const grepOutputSchema: z.ZodObject<{
58
- path: z.ZodString;
57
+ export declare const grepOutputSchema: z.ZodLazy<z.ZodObject<{
58
+ path: z.ZodLazy<z.ZodString>;
59
59
  matches: z.ZodArray<z.ZodObject<{
60
- path: z.ZodString;
60
+ path: z.ZodLazy<z.ZodString>;
61
61
  line: z.ZodNumber;
62
62
  text: z.ZodString;
63
63
  }, z.core.$strict>>;
64
64
  truncated: z.ZodBoolean;
65
- }, z.core.$strict>;
65
+ }, z.core.$strict>>;
66
66
  /** Text replacement request decoded before the captured Files port is called. */
67
- export declare const editInputSchema: z.ZodObject<{
68
- path: z.ZodString;
67
+ export declare const editInputSchema: z.ZodLazy<z.ZodObject<{
68
+ path: z.ZodLazy<z.ZodString>;
69
69
  oldText: z.ZodString;
70
70
  newText: z.ZodString;
71
- }, z.core.$strict>;
71
+ }, z.core.$strict>>;
72
72
  /** Structured edit refusal, including its reason and affected path. */
73
- export declare const filesEditFailureSchema: z.ZodObject<{
73
+ export declare const filesEditFailureSchema: z.ZodLazy<z.ZodObject<{
74
74
  status: z.ZodLiteral<"failed">;
75
75
  error: z.ZodObject<{
76
76
  kind: z.ZodEnum<{
@@ -81,13 +81,13 @@ export declare const filesEditFailureSchema: z.ZodObject<{
81
81
  unchanged: "unchanged";
82
82
  conflict: "conflict";
83
83
  }>;
84
- path: z.ZodString;
84
+ path: z.ZodLazy<z.ZodString>;
85
85
  message: z.ZodString;
86
86
  }, z.core.$strict>;
87
- }, z.core.$strict>;
87
+ }, z.core.$strict>>;
88
88
  /** Successful edit metadata or a typed edit refusal. */
89
- export declare const editOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
90
- path: z.ZodString;
89
+ export declare const editOutputSchema: z.ZodUnion<readonly [z.ZodLazy<z.ZodObject<{
90
+ path: z.ZodLazy<z.ZodString>;
91
91
  bytes: z.ZodNumber;
92
92
  diff: z.ZodString;
93
93
  firstChangedLine: z.ZodNullable<z.ZodNumber>;
@@ -96,7 +96,7 @@ export declare const editOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
96
96
  unifiedPatchAddedLines: z.ZodNumber;
97
97
  unifiedPatchRemovedLines: z.ZodNumber;
98
98
  unifiedPatchTruncated: z.ZodBoolean;
99
- }, z.core.$strict>, z.ZodObject<{
99
+ }, z.core.$strict>>, z.ZodLazy<z.ZodObject<{
100
100
  status: z.ZodLiteral<"failed">;
101
101
  error: z.ZodObject<{
102
102
  kind: z.ZodEnum<{
@@ -107,10 +107,10 @@ export declare const editOutputSchema: z.ZodUnion<readonly [z.ZodObject<{
107
107
  unchanged: "unchanged";
108
108
  conflict: "conflict";
109
109
  }>;
110
- path: z.ZodString;
110
+ path: z.ZodLazy<z.ZodString>;
111
111
  message: z.ZodString;
112
112
  }, z.core.$strict>;
113
- }, z.core.$strict>]>;
113
+ }, z.core.$strict>>]>;
114
114
  /** Host-owned native patch operation receiving the invocation's deadline and signal. */
115
115
  export type FilesPatch = (input: z.output<typeof patchInputSchema>, context: InvocationContext) => Promise<z.output<typeof patchOutputSchema>>;
116
116
  /** Captured host file authority; the host owns path confinement and atomic replacement. */
package/dist/files.js CHANGED
@@ -35,21 +35,21 @@ export const listInputSchema = z.strictObject({
35
35
  .max(maximumResultEntries)
36
36
  .default(maximumResultEntries),
37
37
  });
38
- const listEntrySchema = z.strictObject({
38
+ const listEntrySchema = z.lazy(() => z.strictObject({
39
39
  path: pathSchema,
40
40
  name: z.string().min(1),
41
41
  type: z.enum(["file", "directory", "symlink"]),
42
42
  size: z.number().int().nonnegative(),
43
43
  modifiedAt: z.number(),
44
- });
44
+ }));
45
45
  /** Directory entries and an explicit truncation flag. */
46
- export const listOutputSchema = z.strictObject({
46
+ export const listOutputSchema = z.lazy(() => z.strictObject({
47
47
  path: pathSchema,
48
48
  entries: z.array(listEntrySchema).max(maximumResultEntries),
49
49
  truncated: z.boolean(),
50
- });
50
+ }));
51
51
  /** Bounded path-pattern search request. */
52
- export const globInputSchema = z.strictObject({
52
+ export const globInputSchema = z.lazy(() => z.strictObject({
53
53
  path: pathSchema,
54
54
  pattern: z.string().min(1).max(maximumPatternCharacters),
55
55
  limit: z
@@ -58,15 +58,15 @@ export const globInputSchema = z.strictObject({
58
58
  .min(1)
59
59
  .max(maximumResultEntries)
60
60
  .default(maximumResultEntries),
61
- });
61
+ }));
62
62
  /** Matching paths and an explicit truncation flag. */
63
- export const globOutputSchema = z.strictObject({
63
+ export const globOutputSchema = z.lazy(() => z.strictObject({
64
64
  path: pathSchema,
65
65
  matches: z.array(pathSchema).max(maximumResultEntries),
66
66
  truncated: z.boolean(),
67
- });
67
+ }));
68
68
  /** Bounded content-search request with optional regular-expression matching. */
69
- export const grepInputSchema = z.strictObject({
69
+ export const grepInputSchema = z.lazy(() => z.strictObject({
70
70
  path: pathSchema,
71
71
  pattern: z.string().min(1).max(maximumPatternCharacters),
72
72
  regex: z.boolean().default(false),
@@ -77,9 +77,9 @@ export const grepInputSchema = z.strictObject({
77
77
  .min(1)
78
78
  .max(maximumResultEntries)
79
79
  .default(maximumResultEntries),
80
- });
80
+ }));
81
81
  /** Content matches and an explicit truncation flag. */
82
- export const grepOutputSchema = z.strictObject({
82
+ export const grepOutputSchema = z.lazy(() => z.strictObject({
83
83
  path: pathSchema,
84
84
  matches: z
85
85
  .array(z.strictObject({
@@ -89,14 +89,14 @@ export const grepOutputSchema = z.strictObject({
89
89
  }))
90
90
  .max(maximumResultEntries),
91
91
  truncated: z.boolean(),
92
- });
92
+ }));
93
93
  /** Text replacement request decoded before the captured Files port is called. */
94
- export const editInputSchema = z.strictObject({
94
+ export const editInputSchema = z.lazy(() => z.strictObject({
95
95
  path: pathSchema,
96
96
  oldText: boundedTextSchema(1),
97
97
  newText: boundedTextSchema(),
98
- });
99
- const editSuccessSchema = z.strictObject({
98
+ }));
99
+ const editSuccessSchema = z.lazy(() => z.strictObject({
100
100
  path: pathSchema,
101
101
  bytes: z.number().int().nonnegative(),
102
102
  diff: z.string(),
@@ -106,9 +106,9 @@ const editSuccessSchema = z.strictObject({
106
106
  unifiedPatchAddedLines: z.number().int().nonnegative(),
107
107
  unifiedPatchRemovedLines: z.number().int().nonnegative(),
108
108
  unifiedPatchTruncated: z.boolean(),
109
- });
109
+ }));
110
110
  /** Structured edit refusal, including its reason and affected path. */
111
- export const filesEditFailureSchema = z.strictObject({
111
+ export const filesEditFailureSchema = z.lazy(() => z.strictObject({
112
112
  status: z.literal("failed"),
113
113
  error: z.strictObject({
114
114
  kind: z.enum([
@@ -122,14 +122,12 @@ export const filesEditFailureSchema = z.strictObject({
122
122
  path: pathSchema,
123
123
  message: z.string(),
124
124
  }),
125
- });
125
+ }));
126
126
  /** Successful edit metadata or a typed edit refusal. */
127
127
  export const editOutputSchema = z.union([
128
128
  editSuccessSchema,
129
129
  filesEditFailureSchema,
130
130
  ]);
131
- /** Model-facing parameters derived from the one Zod decoder `prepare` uses. */
132
- const patchParameters = z.toJSONSchema(patchInputSchema);
133
131
  const fileToolBrand = Symbol("KnapsackFileTool");
134
132
  /** The one module id that a host's grant for Files names. */
135
133
  const filesModuleId = "files";
@@ -369,7 +367,8 @@ function patchTool(invokePatch) {
369
367
  descriptor: {
370
368
  name: "apply_patch",
371
369
  description: "Apply a Codex patch to the selected Files root. Example:\n*** Begin Patch\n*** Update File: path/to/file\n@@\n context line\n-old line\n+new line\n*** End Patch\nUse @@ alone or followed by an existing context line; unified-diff @@ line numbers are not supported. Add/Delete File and optional Move to are also supported. Paths stay inside the root; symlinks and parent traversal are rejected. A failure returns recovery guidance and may follow earlier file writes; inspect the result before retrying. Prefer this to shell or Python replacement.",
372
- parameters: patchParameters,
370
+ // Model-facing parameters derived from the one Zod decoder `prepare` uses.
371
+ parameters: z.toJSONSchema(patchInputSchema),
373
372
  constrainedSampling: {
374
373
  type: "grammar",
375
374
  variants: { openai_lark: patchGrammar },
package/dist/index.js CHANGED
@@ -9,21 +9,21 @@ const describeConcurrency = 8;
9
9
  const defaultDescribeTimeoutMillis = 10_000;
10
10
  const utf8 = new TextEncoder();
11
11
  const jsonValueSchema = z.json();
12
- const jsonSchemaDocument = z.custom((value) => jsonValueSchema.safeParse(value).success);
13
- const capabilityNameSchema = z
12
+ const jsonSchemaDocument = z.lazy(() => z.custom((value) => jsonValueSchema.safeParse(value).success));
13
+ const capabilityNameSchema = z.lazy(() => z
14
14
  .string()
15
15
  .min(1)
16
16
  .max(128)
17
- .regex(/^[A-Za-z][A-Za-z0-9_]*$/);
18
- const capabilitySchema = z.strictObject({
17
+ .regex(/^[A-Za-z][A-Za-z0-9_]*$/));
18
+ const capabilitySchema = z.lazy(() => z.strictObject({
19
19
  id: capabilityNameSchema,
20
20
  name: capabilityNameSchema,
21
21
  kind: z.string().min(1).max(128),
22
22
  description: z.string().min(1).max(2_048),
23
23
  parameters: jsonSchemaDocument,
24
24
  output: jsonSchemaDocument.optional(),
25
- });
26
- const capabilitiesSchema = z.array(capabilitySchema).max(maximumCapabilities);
25
+ }));
26
+ const capabilitiesSchema = z.lazy(() => z.array(capabilitySchema).max(maximumCapabilities));
27
27
  function operationSchema(document) {
28
28
  return z.fromJSONSchema(document).pipe(jsonValueSchema);
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/knapsack",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Agent tool connections projected into Mycelium capability sources",
6
6
  "type": "module",
@@ -38,9 +38,9 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@fungi.computer/cairn": "0.0.1",
41
- "@fungi.computer/forage": "0.0.1",
42
- "@fungi.computer/mule": "0.0.1",
43
- "@fungi.computer/mycelium": "0.0.1",
41
+ "@fungi.computer/forage": "0.1.0",
42
+ "@fungi.computer/mule": "0.0.2",
43
+ "@fungi.computer/mycelium": "0.1.0",
44
44
  "@modelcontextprotocol/client": "2.0.0",
45
45
  "diff": "8.0.4",
46
46
  "effect": "4.0.2",