@codeworksh/plugin 0.0.1-dev.20260925150557 → 0.1.0-canary.1.1.gc0ff5572
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -5
- package/{event-BnLveFBB.d.mts → event-6sTQ_4bq.d.mts} +53 -49
- package/event.d.mts +1 -1
- package/filesystem-CuGE9poU.d.mts +268 -0
- package/filesystem-omtKo08x.mjs +381 -0
- package/filesystem-omtKo08x.mjs.map +1 -0
- package/ids.mjs +1 -1
- package/ids.mjs.map +1 -1
- package/index.d.mts +4 -3
- package/index.mjs +3 -2
- package/io-Dgh8U41k.mjs +188 -0
- package/io-Dgh8U41k.mjs.map +1 -0
- package/{io-BYs7hbiY.d.mts → io-nhvNKC33.d.mts} +51 -8
- package/{location-D4hAfuXF.d.mts → location-Q39els63.d.mts} +9 -14
- package/location.d.mts +2 -2
- package/location.mjs +2 -5
- package/location.mjs.map +1 -1
- package/package.json +8 -3
- package/plugin/prompt.d.mts +1 -1
- package/plugin/prompt.mjs.map +1 -1
- package/plugin/section.d.mts +27 -0
- package/plugin/section.mjs +65 -0
- package/plugin/section.mjs.map +1 -0
- package/plugin/tool.d.mts +1 -1
- package/{plugin-B1M3SjEb.d.mts → plugin-Deb2QWIP.d.mts} +27 -9
- package/{plugin-lorpq7Oi.mjs → plugin-XaYYRsX-.mjs} +3 -1
- package/{plugin-lorpq7Oi.mjs.map → plugin-XaYYRsX-.mjs.map} +1 -1
- package/plugin.d.mts +5 -4
- package/plugin.mjs +3 -2
- package/prompt-DWaA5ZXj.d.mts +21 -0
- package/sandbox/driver.d.mts +1 -1
- package/sandbox/driver.mjs +7 -3
- package/sandbox/driver.mjs.map +1 -1
- package/sandbox/errors.d.mts +1 -1
- package/sandbox/filesystem.d.mts +2 -2
- package/sandbox/filesystem.mjs +2 -142
- package/sandbox/instance.d.mts +1 -1
- package/sandbox/io.d.mts +2 -2
- package/sandbox/io.mjs +3 -127
- package/sandbox.d.mts +3 -3
- package/sandbox.mjs +8 -5
- package/sandbox.mjs.map +1 -1
- package/schema.d.mts +3 -1
- package/schema.mjs +4 -2
- package/schema.mjs.map +1 -1
- package/settings-47Mzxhl0.d.mts +587 -0
- package/settings.d.mts +2 -2
- package/settings.mjs +56 -5
- package/settings.mjs.map +1 -1
- package/tool/progress.d.mts +1 -1
- package/{tool-BoVqkYvL.d.mts → tool-D4_I_rzy.d.mts} +2 -2
- package/{tool-DuYBgiJf.d.mts → tool-_ajVYIY5.d.mts} +20 -1
- package/tool.d.mts +1 -1
- package/tool.mjs +2 -1
- package/tool.mjs.map +1 -1
- package/filesystem-Cp-KapCE.d.mts +0 -142
- package/prompt-BcpagjGh.d.mts +0 -10
- package/sandbox/filesystem.mjs.map +0 -1
- package/sandbox/io.mjs.map +0 -1
- package/settings-bbJi7FiQ.d.mts +0 -207
package/settings.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { NonNegativeInt, isAikitModelInfo, validateAikitModelInfo } from "./schema.mjs";
|
|
1
2
|
import { Model as Model$1 } from "@codeworksh/aikit";
|
|
2
|
-
import { Schema } from "effect";
|
|
3
|
+
import { Effect, Schema, SchemaGetter, SchemaIssue } from "effect";
|
|
3
4
|
//#region src/settings.ts
|
|
4
5
|
const ThinkingLevel = Schema.Literals(Object.values(Model$1.ThinkingLevelEnum));
|
|
5
6
|
const ToolExecution = Schema.Literals(["sequential", "parallel"]);
|
|
@@ -15,12 +16,22 @@ const requestFields = {
|
|
|
15
16
|
])),
|
|
16
17
|
headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
17
18
|
timeoutMs: Schema.optional(Schema.Finite),
|
|
19
|
+
idleTimeoutMs: Schema.optional(Schema.Finite),
|
|
18
20
|
maxRetries: Schema.optional(Schema.Finite),
|
|
19
21
|
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
20
22
|
thinkingBudgets: Schema.optional(Budgets),
|
|
21
23
|
baseURL: Schema.optional(Schema.String),
|
|
22
24
|
method: Schema.optional(Schema.Literals(Object.values(Model$1.APIMethodEnum)))
|
|
23
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* An API key named, never written: `"${NAME}"`, read from the host process environment when the
|
|
28
|
+
* model is called. Settings only ever hold the variable's name.
|
|
29
|
+
*/
|
|
30
|
+
const keyReference = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
31
|
+
const keyReferenceError = "apiKey must reference an environment variable, e.g. \"${OPENAI_API_KEY}\"";
|
|
32
|
+
const KeyReference = Schema.String.check(Schema.makeFilter((value) => keyReference.test(value) || keyReferenceError));
|
|
33
|
+
/** The variable a `"${NAME}"` reference names. */
|
|
34
|
+
const keyName = (reference) => keyReference.exec(reference)?.[1] ?? reference;
|
|
24
35
|
const reserved = /* @__PURE__ */ new Set([
|
|
25
36
|
"toolChoice",
|
|
26
37
|
"activeTools",
|
|
@@ -30,7 +41,6 @@ const reserved = /* @__PURE__ */ new Set([
|
|
|
30
41
|
"sessionId",
|
|
31
42
|
"reasoning",
|
|
32
43
|
"modelId",
|
|
33
|
-
"apiKey",
|
|
34
44
|
"onPayload",
|
|
35
45
|
"api",
|
|
36
46
|
"npm",
|
|
@@ -46,6 +56,8 @@ const Block = Schema.StructWithRest(Schema.Struct({
|
|
|
46
56
|
thinkingLevel: Schema.optional(ThinkingLevel),
|
|
47
57
|
toolExecution: Schema.optional(ToolExecution),
|
|
48
58
|
contextWindow: Schema.optional(Schema.Finite),
|
|
59
|
+
/** Which environment variable holds the key for this model: `"${NAME}"`. */
|
|
60
|
+
apiKey: Schema.optional(KeyReference),
|
|
49
61
|
extras: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
50
62
|
}), [Schema.Record(Schema.String, Schema.Unknown)]).check(Schema.makeFilter((value) => Object.keys(value).every((key) => !reserved.has(key)) || "Reserved configuration key in model options"));
|
|
51
63
|
const Model = Schema.Struct({
|
|
@@ -57,6 +69,23 @@ const Model = Schema.Struct({
|
|
|
57
69
|
options: Schema.optional(Block),
|
|
58
70
|
providerOptions: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Block)))
|
|
59
71
|
});
|
|
72
|
+
const reasonOf = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
73
|
+
const decodeModelEntry = (value, options) => Effect.try({
|
|
74
|
+
try: () => {
|
|
75
|
+
const entry = validateAikitModelInfo(value, "models entry");
|
|
76
|
+
if (entry.provider.key !== void 0 && !keyReference.test(entry.provider.key)) throw new Error(`models entry ${entry.provider.id}/${entry.id}: provider.key: ${keyReferenceError}`);
|
|
77
|
+
return entry;
|
|
78
|
+
},
|
|
79
|
+
catch: (cause) => new SchemaIssue.InvalidValue({ message: reasonOf(cause) }, value, options)
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* A catalog entry in settings: an aikit `Model.Info`, read exactly like an entry of the generated
|
|
83
|
+
* catalog. The one difference is `provider.key`, which must be a `"${NAME}"` reference.
|
|
84
|
+
*/
|
|
85
|
+
const ModelEntry = Schema.Unknown.pipe(Schema.decodeTo(Schema.declare(isAikitModelInfo, { expected: "aikit Model.Info" }), {
|
|
86
|
+
decode: SchemaGetter.transformEffect(decodeModelEntry),
|
|
87
|
+
encode: SchemaGetter.transformEffect(decodeModelEntry)
|
|
88
|
+
}));
|
|
60
89
|
/** A module to load: a path, a `file:` URL, or a package spec. */
|
|
61
90
|
const PluginReference = Schema.String.check(Schema.isNonEmpty());
|
|
62
91
|
/**
|
|
@@ -76,15 +105,31 @@ const PluginPatch = Schema.Union([Schema.Struct({
|
|
|
76
105
|
...config
|
|
77
106
|
})], { mode: "oneOf" });
|
|
78
107
|
const PluginEntry = Schema.Union([PluginReference, PluginPatch]);
|
|
108
|
+
/**
|
|
109
|
+
* Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,
|
|
110
|
+
* 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;
|
|
111
|
+
* a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.
|
|
112
|
+
*
|
|
113
|
+
* Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to
|
|
114
|
+
* 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.
|
|
115
|
+
*/
|
|
116
|
+
const Retry = Schema.Struct({
|
|
117
|
+
maxRetries: Schema.optional(NonNegativeInt),
|
|
118
|
+
baseDelayMs: Schema.optional(NonNegativeInt),
|
|
119
|
+
maxDelayMs: Schema.optional(NonNegativeInt)
|
|
120
|
+
});
|
|
79
121
|
const Patch = Schema.Struct({
|
|
80
122
|
$schema: Schema.optional(Schema.String),
|
|
81
123
|
plugins: Schema.optional(Schema.Array(PluginEntry)),
|
|
82
|
-
model: Schema.optional(Model)
|
|
124
|
+
model: Schema.optional(Model),
|
|
125
|
+
models: Schema.optional(Schema.Array(ModelEntry)),
|
|
126
|
+
retry: Schema.optional(Retry)
|
|
83
127
|
});
|
|
84
128
|
/** Let aikit supply model-aware generation defaults. */
|
|
85
129
|
const defaults = {
|
|
86
130
|
plugins: [],
|
|
87
131
|
declared: [],
|
|
132
|
+
models: [],
|
|
88
133
|
model: {
|
|
89
134
|
provider: "openai",
|
|
90
135
|
id: "gpt-5.6-luna",
|
|
@@ -92,11 +137,17 @@ const defaults = {
|
|
|
92
137
|
toolExecution: "sequential",
|
|
93
138
|
options: {
|
|
94
139
|
timeoutMs: 36e5,
|
|
95
|
-
|
|
140
|
+
idleTimeoutMs: 3e5,
|
|
141
|
+
maxRetries: 0
|
|
96
142
|
}
|
|
143
|
+
},
|
|
144
|
+
retry: {
|
|
145
|
+
maxRetries: 3,
|
|
146
|
+
baseDelayMs: 2e3,
|
|
147
|
+
maxDelayMs: 6e4
|
|
97
148
|
}
|
|
98
149
|
};
|
|
99
150
|
//#endregion
|
|
100
|
-
export { Block, Model, ModelProtocol, Patch, PluginEntry, PluginPatch, ThinkingLevel, ToolExecution, defaults, requestFields };
|
|
151
|
+
export { Block, KeyReference, Model, ModelEntry, ModelProtocol, Patch, PluginEntry, PluginPatch, Retry, ThinkingLevel, ToolExecution, defaults, keyName, requestFields };
|
|
101
152
|
|
|
102
153
|
//# sourceMappingURL=settings.mjs.map
|
package/settings.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.mjs","names":["AikitModel"],"sources":["../../src/settings.ts"],"sourcesContent":["import { Model as AikitModel, type Protocol } from \"@codeworksh/aikit\";\nimport { Schema } from \"effect\";\n\nexport const ThinkingLevel = Schema.Literals(Object.values(AikitModel.ThinkingLevelEnum));\nexport const ToolExecution = Schema.Literals([\"sequential\", \"parallel\"]);\nexport type ToolExecution = typeof ToolExecution.Type;\nconst Budgets = Schema.Record(\n\tSchema.Literals(Object.values(AikitModel.ThinkingLevelEnum).filter((level) => level !== \"off\")),\n\tSchema.optional(Schema.Finite),\n);\n\n/** Aikit does not export its request schema; keep this routing surface checked against its public types. */\nexport const requestFields = {\n\ttemperature: Schema.optional(Schema.Finite),\n\tmaxTokens: Schema.optional(Schema.Finite),\n\tcacheRetention: Schema.optional(Schema.Literals([\"none\", \"short\", \"long\"])),\n\theaders: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n\ttimeoutMs: Schema.optional(Schema.Finite),\n\tmaxRetries: Schema.optional(Schema.Finite),\n\tmetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\tthinkingBudgets: Schema.optional(Budgets),\n\tbaseURL: Schema.optional(Schema.String),\n\tmethod: Schema.optional(Schema.Literals(Object.values(AikitModel.APIMethodEnum))),\n} satisfies Record<\n\t| Exclude<keyof Protocol.CommonOptions, \"signal\" | \"sessionId\" | \"reasoning\" | \"apiKey\" | \"onPayload\">\n\t| \"baseURL\"\n\t| \"method\",\n\tSchema.Top\n>;\n\nconst reserved = new Set([\n\t\"toolChoice\",\n\t\"activeTools\",\n\t\"provider\",\n\t\"id\",\n\t\"signal\",\n\t\"sessionId\",\n\t\"reasoning\",\n\t\"modelId\",\n\t\"apiKey\",\n\t\"onPayload\",\n\t\"api\",\n\t\"npm\",\n\t\"providerOptionsKey\",\n\t\"compat\",\n\t\"thinkingLevelMap\",\n]);\n\n/** The wire protocol a model speaks, which a catalog entry may have wrong for a local endpoint. */\nexport const ModelProtocol = Schema.Literals(Object.values(AikitModel.KnownProviderEnum));\n\nexport const Block = Schema.StructWithRest(\n\tSchema.Struct({\n\t\t...requestFields,\n\t\tprotocol: Schema.optional(ModelProtocol),\n\t\tthinkingLevel: Schema.optional(ThinkingLevel),\n\t\ttoolExecution: Schema.optional(ToolExecution),\n\t\tcontextWindow: Schema.optional(Schema.Finite),\n\t\textras: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\t}),\n\t[Schema.Record(Schema.String, Schema.Unknown)],\n).check(\n\tSchema.makeFilter(\n\t\t(value) => Object.keys(value).every((key) => !reserved.has(key)) || \"Reserved configuration key in model options\",\n\t),\n);\nexport type Block = typeof Block.Type;\n\nexport const Model = Schema.Struct({\n\tprovider: Schema.optional(Schema.String),\n\tid: Schema.optional(Schema.String),\n\tthinkingLevel: Schema.optional(ThinkingLevel),\n\ttoolExecution: Schema.optional(ToolExecution),\n\tthinkingBudgets: Schema.optional(Budgets),\n\toptions: Schema.optional(Block),\n\tproviderOptions: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Block))),\n});\n/** A module to load: a path, a `file:` URL, or a package spec. */\nconst PluginReference = Schema.String.check(Schema.isNonEmpty());\n/**\n * Configuration for a plugin something else already selected, named by its ID (`plugin`) or by\n * its registered module string (`package`). It never loads anything: an entry naming a plugin\n * that is not in the selection is ignored.\n */\nconst config = {\n\tenabled: Schema.optional(Schema.Boolean),\n\toptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n};\nexport const PluginPatch = Schema.Union(\n\t[Schema.Struct({ plugin: PluginReference, ...config }), Schema.Struct({ package: PluginReference, ...config })],\n\t// `oneOf`, so an entry carrying both keys is a decode failure rather than one of them being\n\t// quietly dropped -- naming a plugin two ways at once says two different things.\n\t{ mode: \"oneOf\" },\n);\nexport const PluginEntry = Schema.Union([PluginReference, PluginPatch]);\nexport type PluginEntry = typeof PluginEntry.Type;\n\nexport const Patch = Schema.Struct({\n\t$schema: Schema.optional(Schema.String),\n\tplugins: Schema.optional(Schema.Array(PluginEntry)),\n\tmodel: Schema.optional(Model),\n});\nexport type Patch = typeof Patch.Type;\n\n/**\n * One plugin entry, and where it came from.\n *\n * Flattening every layer's `plugins` into one array loses the file that declared each entry, and\n * that cannot be recovered afterwards: two layers may declare the same string, so attribution is\n * genuinely gone rather than merely inconvenient. Three things need it -- anchoring a relative\n * path, naming the declaring layer in `plugin list`, and the missing-plugin diagnostic -- so the\n * loaded shape carries it from the start.\n *\n * In simple terms:\n * `written` - is what module the developer is declaring - what\n * `file` - where the module is being declared - where\n * `entry` - the resolved path of the module, relative to the `file`; especially needed for local.\n *\n * Example:\n * written: \"@acme/x@^1\"\n * entry: \"@acme/x@^1\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n *\n * written: \"./plugins/mine.mjs\"\n * entry: \"/Users/me/.codework/plugins/mine.mjs\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n */\nexport interface Declared {\n\t/** The entry exactly as the file spells it, which is the string a person will search for. */\n\treadonly written: PluginEntry;\n\t/** The same entry with any relative path anchored to the directory of its declaring file. */\n\treadonly entry: PluginEntry;\n\t/** The settings file that declared it. */\n\treadonly file: string;\n}\n\nexport interface Info {\n\t/**\n\t * Plugin entries added to the harness selection, in order: every layer's entries, lowest\n\t * priority first, so a project's list extends the user's rather than replacing it.\n\t *\n\t * Anchored, and stripped of provenance: this is the list the loader consumes. {@link Info.declared}\n\t * is the same list with the file each entry came from.\n\t */\n\treadonly plugins: ReadonlyArray<PluginEntry>;\n\t/** {@link Info.plugins}, with the origin of each entry. Same order, same length. */\n\treadonly declared: ReadonlyArray<Declared>;\n\treadonly model: typeof Model.Type & {\n\t\treadonly provider: string;\n\t\treadonly id: string;\n\t\treadonly thinkingLevel: AikitModel.ThinkingLevel;\n\t\treadonly toolExecution: ToolExecution;\n\t};\n}\n\n/** Let aikit supply model-aware generation defaults. */\nexport const defaults: Info = {\n\tplugins: [],\n\tdeclared: [],\n\tmodel: {\n\t\tprovider: \"openai\",\n\t\tid: \"gpt-5.6-luna\",\n\t\tthinkingLevel: \"high\",\n\t\ttoolExecution: \"sequential\",\n\t\toptions: { timeoutMs: 3_600_000, maxRetries: 3 },\n\t},\n};\n"],"mappings":";;;AAGA,MAAa,gBAAgB,OAAO,SAAS,OAAO,OAAOA,QAAW,iBAAiB,CAAC;AACxF,MAAa,gBAAgB,OAAO,SAAS,CAAC,cAAc,UAAU,CAAC;AAEvE,MAAM,UAAU,OAAO,OACtB,OAAO,SAAS,OAAO,OAAOA,QAAW,iBAAiB,CAAC,CAAC,QAAQ,UAAU,UAAU,KAAK,CAAC,GAC9F,OAAO,SAAS,OAAO,MAAM,CAC9B;;AAGA,MAAa,gBAAgB;CAC5B,aAAa,OAAO,SAAS,OAAO,MAAM;CAC1C,WAAW,OAAO,SAAS,OAAO,MAAM;CACxC,gBAAgB,OAAO,SAAS,OAAO,SAAS;EAAC;EAAQ;EAAS;CAAM,CAAC,CAAC;CAC1E,SAAS,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM,CAAC;CACpE,WAAW,OAAO,SAAS,OAAO,MAAM;CACxC,YAAY,OAAO,SAAS,OAAO,MAAM;CACzC,UAAU,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;CACtE,iBAAiB,OAAO,SAAS,OAAO;CACxC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,QAAQ,OAAO,SAAS,OAAO,SAAS,OAAO,OAAOA,QAAW,aAAa,CAAC,CAAC;AACjF;AAOA,MAAM,2BAAW,IAAI,IAAI;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAa,gBAA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AM,CAAC,iBAAiB,WAAW,CAAC;AAGtE,MAAa,QAAQ,OAAO,OAAO;CAClC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,SAAS,OAAO,SAAS,OAAO,MAAM,WAAW,CAAC;CAClD,OAAO,OAAO,SAAS,KAAK;AAC7B,CAAC;;AAuDD,MAAa,WAAiB;CAC7B,SAAS,CAAC;CACV,UAAU,CAAC;CACX,OAAO;EACN,UAAU;EACV,IAAI;EACJ,eAAe;EACf,eAAe;EACf,SAAS;GAAE,WAAW;GAAW,YAAY;EAAE;CAChD;AACD"}
|
|
1
|
+
{"version":3,"file":"settings.mjs","names":["AikitModel"],"sources":["../../src/settings.ts"],"sourcesContent":["import { Model as AikitModel, type Protocol } from \"@codeworksh/aikit\";\nimport { Effect, Schema, type SchemaAST, SchemaGetter, SchemaIssue } from \"effect\";\nimport { isAikitModelInfo, NonNegativeInt, validateAikitModelInfo } from \"./schema.ts\";\n\nexport const ThinkingLevel = Schema.Literals(Object.values(AikitModel.ThinkingLevelEnum));\nexport const ToolExecution = Schema.Literals([\"sequential\", \"parallel\"]);\nexport type ToolExecution = typeof ToolExecution.Type;\nconst Budgets = Schema.Record(\n\tSchema.Literals(Object.values(AikitModel.ThinkingLevelEnum).filter((level) => level !== \"off\")),\n\tSchema.optional(Schema.Finite),\n);\n\n/** Aikit does not export its request schema; keep this routing surface checked against its public types. */\nexport const requestFields = {\n\ttemperature: Schema.optional(Schema.Finite),\n\tmaxTokens: Schema.optional(Schema.Finite),\n\tcacheRetention: Schema.optional(Schema.Literals([\"none\", \"short\", \"long\"])),\n\theaders: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n\ttimeoutMs: Schema.optional(Schema.Finite),\n\tidleTimeoutMs: Schema.optional(Schema.Finite),\n\tmaxRetries: Schema.optional(Schema.Finite),\n\tmetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\tthinkingBudgets: Schema.optional(Budgets),\n\tbaseURL: Schema.optional(Schema.String),\n\tmethod: Schema.optional(Schema.Literals(Object.values(AikitModel.APIMethodEnum))),\n} satisfies Record<\n\t| Exclude<keyof Protocol.CommonOptions, \"signal\" | \"sessionId\" | \"reasoning\" | \"apiKey\" | \"onPayload\">\n\t| \"baseURL\"\n\t| \"method\",\n\tSchema.Top\n>;\n\n/**\n * An API key named, never written: `\"${NAME}\"`, read from the host process environment when the\n * model is called. Settings only ever hold the variable's name.\n */\nconst keyReference = /^\\$\\{([A-Za-z_][A-Za-z0-9_]*)\\}$/;\nconst keyReferenceError = 'apiKey must reference an environment variable, e.g. \"${OPENAI_API_KEY}\"';\nexport const KeyReference = Schema.String.check(\n\tSchema.makeFilter((value) => keyReference.test(value) || keyReferenceError),\n);\n\n/** The variable a `\"${NAME}\"` reference names. */\nexport const keyName = (reference: string): string => keyReference.exec(reference)?.[1] ?? reference;\n\nconst reserved = new Set([\n\t\"toolChoice\",\n\t\"activeTools\",\n\t\"provider\",\n\t\"id\",\n\t\"signal\",\n\t\"sessionId\",\n\t\"reasoning\",\n\t\"modelId\",\n\t\"onPayload\",\n\t\"api\",\n\t\"npm\",\n\t\"providerOptionsKey\",\n\t\"compat\",\n\t\"thinkingLevelMap\",\n]);\n\n/** The wire protocol a model speaks, which a catalog entry may have wrong for a local endpoint. */\nexport const ModelProtocol = Schema.Literals(Object.values(AikitModel.KnownProviderEnum));\n\nexport const Block = Schema.StructWithRest(\n\tSchema.Struct({\n\t\t...requestFields,\n\t\tprotocol: Schema.optional(ModelProtocol),\n\t\tthinkingLevel: Schema.optional(ThinkingLevel),\n\t\ttoolExecution: Schema.optional(ToolExecution),\n\t\tcontextWindow: Schema.optional(Schema.Finite),\n\t\t/** Which environment variable holds the key for this model: `\"${NAME}\"`. */\n\t\tapiKey: Schema.optional(KeyReference),\n\t\textras: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n\t}),\n\t[Schema.Record(Schema.String, Schema.Unknown)],\n).check(\n\tSchema.makeFilter(\n\t\t(value) => Object.keys(value).every((key) => !reserved.has(key)) || \"Reserved configuration key in model options\",\n\t),\n);\nexport type Block = typeof Block.Type;\n\nexport const Model = Schema.Struct({\n\tprovider: Schema.optional(Schema.String),\n\tid: Schema.optional(Schema.String),\n\tthinkingLevel: Schema.optional(ThinkingLevel),\n\ttoolExecution: Schema.optional(ToolExecution),\n\tthinkingBudgets: Schema.optional(Budgets),\n\toptions: Schema.optional(Block),\n\tproviderOptions: Schema.optional(Schema.Record(Schema.String, Schema.Record(Schema.String, Block))),\n});\nconst reasonOf = (cause: unknown): string => (cause instanceof Error ? cause.message : String(cause));\n\nconst decodeModelEntry = (value: unknown, options: SchemaAST.ParseOptions) =>\n\tEffect.try({\n\t\ttry: () => {\n\t\t\tconst entry = validateAikitModelInfo(value, \"models entry\");\n\t\t\tif (entry.provider.key !== undefined && !keyReference.test(entry.provider.key)) {\n\t\t\t\tthrow new Error(`models entry ${entry.provider.id}/${entry.id}: provider.key: ${keyReferenceError}`);\n\t\t\t}\n\t\t\treturn entry;\n\t\t},\n\t\tcatch: (cause) => new SchemaIssue.InvalidValue({ message: reasonOf(cause) }, value, options),\n\t});\n\n/**\n * A catalog entry in settings: an aikit `Model.Info`, read exactly like an entry of the generated\n * catalog. The one difference is `provider.key`, which must be a `\"${NAME}\"` reference.\n */\nexport const ModelEntry = Schema.Unknown.pipe(\n\tSchema.decodeTo(Schema.declare<AikitModel.Info>(isAikitModelInfo, { expected: \"aikit Model.Info\" }), {\n\t\tdecode: SchemaGetter.transformEffect(decodeModelEntry),\n\t\tencode: SchemaGetter.transformEffect(decodeModelEntry),\n\t}),\n);\nexport type ModelEntry = typeof ModelEntry.Type;\n\n/** A module to load: a path, a `file:` URL, or a package spec. */\nconst PluginReference = Schema.String.check(Schema.isNonEmpty());\n/**\n * Configuration for a plugin something else already selected, named by its ID (`plugin`) or by\n * its registered module string (`package`). It never loads anything: an entry naming a plugin\n * that is not in the selection is ignored.\n */\nconst config = {\n\tenabled: Schema.optional(Schema.Boolean),\n\toptions: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n};\nexport const PluginPatch = Schema.Union(\n\t[Schema.Struct({ plugin: PluginReference, ...config }), Schema.Struct({ package: PluginReference, ...config })],\n\t// `oneOf`, so an entry carrying both keys is a decode failure rather than one of them being\n\t// quietly dropped -- naming a plugin two ways at once says two different things.\n\t{ mode: \"oneOf\" },\n);\nexport const PluginEntry = Schema.Union([PluginReference, PluginPatch]);\nexport type PluginEntry = typeof PluginEntry.Type;\n\n/**\n * Agent-level retry of a turn whose provider request failed transiently (rate limit, overload,\n * 5xx, dropped connection). Delays double from `baseDelayMs` and stop growing at `maxDelayMs`;\n * a server that asks for a longer wait than `maxDelayMs` is not retried. `maxRetries: 0` is off.\n *\n * Separate from `model.options.maxRetries`, which retries inside the provider SDK and defaults to\n * 0 so that the two do not multiply, and so a quota error reaches the loop instead of being retried.\n */\nexport const Retry = Schema.Struct({\n\tmaxRetries: Schema.optional(NonNegativeInt),\n\tbaseDelayMs: Schema.optional(NonNegativeInt),\n\tmaxDelayMs: Schema.optional(NonNegativeInt),\n});\nexport interface RetryPolicy {\n\treadonly maxRetries: number;\n\treadonly baseDelayMs: number;\n\treadonly maxDelayMs: number;\n}\n\nexport const Patch = Schema.Struct({\n\t$schema: Schema.optional(Schema.String),\n\tplugins: Schema.optional(Schema.Array(PluginEntry)),\n\tmodel: Schema.optional(Model),\n\tmodels: Schema.optional(Schema.Array(ModelEntry)),\n\tretry: Schema.optional(Retry),\n});\nexport type Patch = typeof Patch.Type;\n\n/**\n * One plugin entry, and where it came from.\n *\n * Flattening every layer's `plugins` into one array loses the file that declared each entry, and\n * that cannot be recovered afterwards: two layers may declare the same string, so attribution is\n * genuinely gone rather than merely inconvenient. Three things need it -- anchoring a relative\n * path, naming the declaring layer in `plugin list`, and the missing-plugin diagnostic -- so the\n * loaded shape carries it from the start.\n *\n * In simple terms:\n * `written` - is what module the developer is declaring - what\n * `file` - where the module is being declared - where\n * `entry` - the resolved path of the module, relative to the `file`; especially needed for local.\n *\n * Example:\n * written: \"@acme/x@^1\"\n * entry: \"@acme/x@^1\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n *\n * written: \"./plugins/mine.mjs\"\n * entry: \"/Users/me/.codework/plugins/mine.mjs\"\n * file: \"/Users/me/.codework/settings.jsonc\"\n */\nexport interface Declared {\n\t/** The entry exactly as the file spells it, which is the string a person will search for. */\n\treadonly written: PluginEntry;\n\t/** The same entry with any relative path anchored to the directory of its declaring file. */\n\treadonly entry: PluginEntry;\n\t/** The settings file that declared it. */\n\treadonly file: string;\n}\n\n/** A `models` entry, and the settings file that declared it. */\nexport interface DeclaredModel {\n\treadonly entry: AikitModel.Info;\n\treadonly file: string;\n}\n\nexport interface Info {\n\t/**\n\t * Plugin entries added to the harness selection, in order: every layer's entries, lowest\n\t * priority first, so a project's list extends the user's rather than replacing it.\n\t *\n\t * Anchored, and stripped of provenance: this is the list the loader consumes. {@link Info.declared}\n\t * is the same list with the file each entry came from.\n\t */\n\treadonly plugins: ReadonlyArray<PluginEntry>;\n\t/** {@link Info.plugins}, with the origin of each entry. Same order, same length. */\n\treadonly declared: ReadonlyArray<Declared>;\n\t/**\n\t * Catalog entries from every layer, lowest priority first. Applied over the generated catalog\n\t * in this order, so for one `provider.id` + `id` the last entry wins.\n\t */\n\treadonly models: ReadonlyArray<DeclaredModel>;\n\treadonly model: typeof Model.Type & {\n\t\treadonly provider: string;\n\t\treadonly id: string;\n\t\treadonly thinkingLevel: AikitModel.ThinkingLevel;\n\t\treadonly toolExecution: ToolExecution;\n\t};\n\treadonly retry: RetryPolicy;\n}\n\n/** Let aikit supply model-aware generation defaults. */\nexport const defaults: Info = {\n\tplugins: [],\n\tdeclared: [],\n\tmodels: [],\n\tmodel: {\n\t\tprovider: \"openai\",\n\t\tid: \"gpt-5.6-luna\",\n\t\tthinkingLevel: \"high\",\n\t\ttoolExecution: \"sequential\",\n\t\toptions: { timeoutMs: 3_600_000, idleTimeoutMs: 300_000, maxRetries: 0 },\n\t},\n\tretry: { max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;GAAE,WAAW;GAAW,eAAe;GAAS,YAAY;EAAE;CACxE;CACA,OAAO;EAAE,YAAY;EAAG,aAAa;EAAO,YAAY;CAAO;AAChE"}
|
package/tool/progress.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as IToolProgress, b as make, v as ToolProgress, x as noop, y as ToolProgressPartial } from "../tool-
|
|
1
|
+
import { _ as IToolProgress, b as make, v as ToolProgress, x as noop, y as ToolProgressPartial } from "../tool-_ajVYIY5.mjs";
|
|
2
2
|
export { IToolProgress, ToolProgress, ToolProgressPartial, make, noop };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as RegisteredTool, i as ModelContent, t as AnyToolDef } from "./tool-
|
|
1
|
+
import { a as RegisteredTool, i as ModelContent, t as AnyToolDef } from "./tool-_ajVYIY5.mjs";
|
|
2
2
|
import { Effect, Schema } from "effect";
|
|
3
3
|
declare namespace tool_d_exports {
|
|
4
4
|
export { HookReturn, ToolAddOptions, ToolAfter, ToolAfterFn, ToolAfterResult, ToolBefore, ToolBeforeFn, ToolBeforeResult, ToolDefPatch, ToolRegistration, ToolRegistry, ToolResultContent };
|
|
@@ -284,4 +284,4 @@ interface ToolRegistry {
|
|
|
284
284
|
}
|
|
285
285
|
//#endregion
|
|
286
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-
|
|
287
|
+
//# sourceMappingURL=tool-D4_I_rzy.d.mts.map
|
|
@@ -68,7 +68,17 @@ interface ToolDef<Name extends string = string, Params extends Schema.Top = Sche
|
|
|
68
68
|
readonly promptSnippet?: string;
|
|
69
69
|
/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */
|
|
70
70
|
readonly promptGuidelines?: ReadonlyArray<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Repair argument shapes models commonly send before they are validated against
|
|
73
|
+
* `parameters`. Return a copy; a throw makes the arguments invalid.
|
|
74
|
+
*/
|
|
75
|
+
readonly prepareArguments?: (args: unknown) => unknown;
|
|
71
76
|
readonly parameters: Params;
|
|
77
|
+
/**
|
|
78
|
+
* How the provider constrains the generated arguments. `{ type: "json_schema", strict: "prefer" }` sends
|
|
79
|
+
* `parameters` in strict mode where the provider can express it and falls back to non-strict otherwise.
|
|
80
|
+
*/
|
|
81
|
+
readonly constrainedSampling?: Message.Tool["constrainedSampling"];
|
|
72
82
|
readonly success: Success;
|
|
73
83
|
/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */
|
|
74
84
|
readonly failure?: Failure;
|
|
@@ -76,6 +86,11 @@ interface ToolDef<Name extends string = string, Params extends Schema.Top = Sche
|
|
|
76
86
|
readonly encodeContent?: (success: Success["Type"]) => ModelContent;
|
|
77
87
|
/** Render an expected failure for the model. Omit → executor falls back to JSON text. */
|
|
78
88
|
readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
|
|
89
|
+
/**
|
|
90
|
+
* The `details` kept with a success, for UIs and programmatic consumers. Omit → the encoded
|
|
91
|
+
* success. Set it when `encodeContent` already carries the payload, so it is not stored twice.
|
|
92
|
+
*/
|
|
93
|
+
readonly encodeDetails?: (success: Success["Type"]) => unknown;
|
|
79
94
|
}
|
|
80
95
|
/** A handler: validated params + context → typed success or typed failure. */
|
|
81
96
|
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>;
|
|
@@ -91,11 +106,15 @@ interface DefineInput<Name extends string, Params extends Schema.Top, Success ex
|
|
|
91
106
|
readonly description: string;
|
|
92
107
|
readonly label?: string;
|
|
93
108
|
readonly promptSnippet?: string;
|
|
109
|
+
readonly promptGuidelines?: ReadonlyArray<string>;
|
|
110
|
+
readonly prepareArguments?: (args: unknown) => unknown;
|
|
94
111
|
readonly parameters: Params;
|
|
112
|
+
readonly constrainedSampling?: Message.Tool["constrainedSampling"];
|
|
95
113
|
readonly success: Success;
|
|
96
114
|
readonly failure?: Failure;
|
|
97
115
|
readonly encodeContent?: (success: Success["Type"]) => ModelContent;
|
|
98
116
|
readonly encodeFailureContent?: (failure: Failure["Type"]) => ModelContent;
|
|
117
|
+
readonly encodeDetails?: (success: Success["Type"]) => unknown;
|
|
99
118
|
}
|
|
100
119
|
/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */
|
|
101
120
|
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>;
|
|
@@ -139,4 +158,4 @@ declare const toProviderJsonSchema: (schema: Schema.Top) => Record<string, unkno
|
|
|
139
158
|
declare const toAikitTool: (def: AnyToolDef) => Message.Tool;
|
|
140
159
|
//#endregion
|
|
141
160
|
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-
|
|
161
|
+
//# sourceMappingURL=tool-_ajVYIY5.d.mts.map
|
package/tool.d.mts
CHANGED
|
@@ -1,2 +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-
|
|
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-_ajVYIY5.mjs";
|
|
2
2
|
export { AnyToolDef, AnyToolImpl, Handler, ModelContent, RegisteredTool, ToolCallContext, ToolDef, ToolImpl, define, implement, make, provide, register, toAikitTool, toProviderJsonSchema };
|
package/tool.mjs
CHANGED
|
@@ -63,7 +63,8 @@ const toProviderJsonSchema = (schema) => Schema.toStandardJSONSchemaV1(schema)["
|
|
|
63
63
|
const toAikitTool = (def) => ({
|
|
64
64
|
name: def.name,
|
|
65
65
|
description: def.description,
|
|
66
|
-
parameters: toProviderJsonSchema(def.parameters)
|
|
66
|
+
parameters: toProviderJsonSchema(def.parameters),
|
|
67
|
+
...def.constrainedSampling === void 0 ? {} : { constrainedSampling: def.constrainedSampling }
|
|
67
68
|
});
|
|
68
69
|
//#endregion
|
|
69
70
|
export { ToolCallContext, define, implement, make, provide, register, tool_exports as t, toAikitTool, toProviderJsonSchema };
|
package/tool.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.mjs","names":[],"sources":["../../src/tool.ts"],"sourcesContent":["import type { Message } from \"@codeworksh/aikit\";\nimport { Effect, type Layer, Schema } from \"effect\";\nimport type { TSchema } from \"typebox\";\nimport { ToolExecutionError } from \"./tool/error.ts\";\nimport type { ToolProgress } from \"./tool/progress.ts\";\n\n/**\n * The tool definition + handler model.\n *\n * A tool definition is pure, serializable data: name, description, and Effect\n * Schema for parameters / success / failure. Execution is a separate `Handler`\n * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its\n * requirements `R`, provided by a Layer at runtime. Separating the two is the\n * main testing win: assert on the definition as plain data, and run the handler\n * against a stub capability Layer.\n *\n * Effect Schema is the single source of truth. {@link toAikitTool} derives a\n * provider-safe JSON Schema object for the aikit wire view; the harness\n * decode/encodes arguments and results with Effect Schema natively (it does not\n * use aikit's Typebox validators).\n */\n\n/** What the model reads next turn (the `content` side of content/details). */\nexport type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;\n\n/** Per-call metadata handed to a handler instead of positional args. */\nexport const ToolCallContext = Schema.Struct({\n\tcallID: Schema.String,\n\ttoolName: Schema.String,\n\trawArgs: Schema.Record(Schema.String, Schema.Unknown),\n});\nexport type ToolCallContext = typeof ToolCallContext.Type;\n\n/**\n * A pure tool definition. Parametrised over the *schema* instances so the\n * decoded parameter/success/failure types can be recovered via `[\"Type\"]`.\n */\nexport interface ToolDef<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\t/** Human-readable display label (kept from the previous `AgentTool`). */\n\treadonly label?: string;\n\t/**\n\t * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),\n\t * distinct from the fuller `description`.\n\t */\n\treadonly promptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\treadonly parameters: Params;\n\treadonly success: Success;\n\t/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */\n\treadonly failure?: Failure;\n\t/** Render success for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\t/** Render an expected failure for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n}\n\n/** A handler: validated params + context → typed success or typed failure. */\nexport type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (\n\tparams: Params[\"Type\"],\n\tctx: ToolCallContext,\n) => Effect.Effect<Success[\"Type\"], Failure[\"Type\"], R>;\n\n/** A definition paired with its handler (the unit the executor runs). */\nexport interface ToolImpl<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n> {\n\treadonly definition: ToolDef<Name, Params, Success, Failure>;\n\treadonly handler: Handler<Params, Success, Failure, R>;\n}\n\n// Heterogeneous-collection aliases. `any` for the schema generics keeps handlers\n// of differing parameter types assignable into one array (the precise generics\n// live on the authoring helpers below).\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolDef = ToolDef<string, any, any, any>;\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;\n\ninterface DefineInput<\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\treadonly label?: string;\n\treadonly promptSnippet?: string;\n\treadonly parameters: Params;\n\treadonly success: Success;\n\treadonly failure?: Failure;\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n}\n\n/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */\nexport const define = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure>,\n): ToolDef<Name, Params, Success, Failure> => ({\n\t...input,\n});\n\n/** Attach a handler to an existing definition (the testable def/exec split). */\nexport const implement = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR = never,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, R>,\n): ToolImpl<Name, Params, Success, Failure, R> => ({ definition, handler });\n\n/** Sugar for the co-located case: a definition with its handler in one object. */\nexport const make = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure> & {\n\t\treadonly handler: Handler<Params, Success, Failure, R>;\n\t},\n): ToolImpl<Name, Params, Success, Failure, R> => {\n\tconst { handler, ...rest } = input;\n\treturn { definition: define(rest), handler };\n};\n\n/**\n * A tool ready to register: its capability requirements have been discharged, leaving only\n * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s\n * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any\n * number of tools — built-in or\n * third-party/plugin — compose without a shared capability union\n */\nexport interface RegisteredTool {\n\treadonly definition: AnyToolDef;\n\treadonly handler: (\n\t\tparams: unknown,\n\t\tctx: ToolCallContext,\n\t) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;\n}\n\nconst toRegistered = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, ToolProgress>,\n): RegisteredTool => ({\n\tdefinition,\n\t// The executor decodes with `definition.parameters` before invoking this\n\t// erased handler, so restoring the authored parameter type is safe here.\n\thandler: (params, ctx) =>\n\t\thandler(params as Params[\"Type\"], ctx).pipe(\n\t\t\tEffect.mapError((cause) => new ToolExecutionError({ toolName: definition.name, cause })),\n\t\t),\n});\n\n/** Register a tool whose only requirement is the executor-provided progress service. */\nexport const register = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, ToolProgress>,\n): RegisteredTool => toRegistered(impl.definition, impl.handler);\n\n/**\n * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`\n * (the executor still provides `ToolProgress`). This is the registration boundary: a\n * plugin/third-party tool provides its own fully-resolved capability Layer here, so the\n * registry never has to unify anyone's `R`.\n */\nexport const provide = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>,\n\tlayer: Layer.Layer<R>,\n): RegisteredTool =>\n\t// `Effect.provide` discharges `R`, leaving `ToolProgress`. TS can't simplify\n\t// `Exclude<ToolProgress, R>` for a generic `R`, so localize the cast before\n\t// crossing the registered-tool boundary.\n\ttoRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))) as Handler<\n\t\tParams,\n\t\tSuccess,\n\t\tFailure,\n\t\tToolProgress\n\t>);\n\n/**\n * Derive a provider-safe JSON Schema object from an Effect Schema. This is the\n * single boundary that crosses into the provider wire; if a provider rejects a\n * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).\n */\nexport const toProviderJsonSchema = (schema: Schema.Top): Record<string, unknown> =>\n\tSchema.toStandardJSONSchemaV1(schema)[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n\n/**\n * Build the aikit `Message.Tool` wire view from a definition. The derived JSON\n * Schema object satisfies aikit's `parameters` slot structurally at runtime; the\n * single localized cast keeps aikit untouched (decision 3-A).\n */\nexport const toAikitTool = (def: AnyToolDef): Message.Tool => ({\n\tname: def.name,\n\tdescription: def.description,\n\tparameters: toProviderJsonSchema(def.parameters) as unknown as TSchema,\n});\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,OAAO,OAAO;CAC5C,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACrD,CAAC;;AA8ED,MAAa,UAMZ,WAC8C,EAC9C,GAAG,MACJ;;AAGA,MAAa,aAOZ,YACA,aACkD;CAAE;CAAY;AAAQ;;AAGzE,MAAa,QAOZ,UAGiD;CACjD,MAAM,EAAE,SAAS,GAAG,SAAS;CAC7B,OAAO;EAAE,YAAY,OAAO,IAAI;EAAG;CAAQ;AAC5C;AAiBA,MAAM,gBAML,YACA,aACqB;CACrB;CAGA,UAAU,QAAQ,QACjB,QAAQ,QAA0B,GAAG,CAAC,CAAC,KACtC,OAAO,UAAU,UAAU,IAAI,mBAAmB;EAAE,UAAU,WAAW;EAAM;CAAM,CAAC,CAAC,CACxF;AACF;;AAGA,MAAa,YAMZ,SACoB,aAAa,KAAK,YAAY,KAAK,OAAO;;;;;;;AAQ/D,MAAa,WAOZ,MACA,UAKA,aAAa,KAAK,cAAc,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,QAAQ,KAAK,CAAC,EAKnG;;;;;;AAOF,MAAa,wBAAwB,WACpC,OAAO,uBAAuB,MAAM,CAAC,CAAC,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,WAAW,CAAC;;;;;;AAO3F,MAAa,eAAe,SAAmC;CAC9D,MAAM,IAAI;CACV,aAAa,IAAI;CACjB,YAAY,qBAAqB,IAAI,UAAU;AAChD"}
|
|
1
|
+
{"version":3,"file":"tool.mjs","names":[],"sources":["../../src/tool.ts"],"sourcesContent":["import type { Message } from \"@codeworksh/aikit\";\nimport { Effect, type Layer, Schema } from \"effect\";\nimport type { TSchema } from \"typebox\";\nimport { ToolExecutionError } from \"./tool/error.ts\";\nimport type { ToolProgress } from \"./tool/progress.ts\";\n\n/**\n * The tool definition + handler model.\n *\n * A tool definition is pure, serializable data: name, description, and Effect\n * Schema for parameters / success / failure. Execution is a separate `Handler`\n * — an `Effect` whose capability dependencies (e.g. `ToolShell`) live in its\n * requirements `R`, provided by a Layer at runtime. Separating the two is the\n * main testing win: assert on the definition as plain data, and run the handler\n * against a stub capability Layer.\n *\n * Effect Schema is the single source of truth. {@link toAikitTool} derives a\n * provider-safe JSON Schema object for the aikit wire view; the harness\n * decode/encodes arguments and results with Effect Schema natively (it does not\n * use aikit's Typebox validators).\n */\n\n/** What the model reads next turn (the `content` side of content/details). */\nexport type ModelContent = ReadonlyArray<Message.TextContent | Message.ImageContent>;\n\n/** Per-call metadata handed to a handler instead of positional args. */\nexport const ToolCallContext = Schema.Struct({\n\tcallID: Schema.String,\n\ttoolName: Schema.String,\n\trawArgs: Schema.Record(Schema.String, Schema.Unknown),\n});\nexport type ToolCallContext = typeof ToolCallContext.Type;\n\n/**\n * A pure tool definition. Parametrised over the *schema* instances so the\n * decoded parameter/success/failure types can be recovered via `[\"Type\"]`.\n */\nexport interface ToolDef<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\t/** Human-readable display label (kept from the previous `AgentTool`). */\n\treadonly label?: string;\n\t/**\n\t * A short one-line summary for compact tool listings (e.g. a system-prompt tool index),\n\t * distinct from the fuller `description`.\n\t */\n\treadonly promptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\t/**\n\t * Repair argument shapes models commonly send before they are validated against\n\t * `parameters`. Return a copy; a throw makes the arguments invalid.\n\t */\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\t/**\n\t * How the provider constrains the generated arguments. `{ type: \"json_schema\", strict: \"prefer\" }` sends\n\t * `parameters` in strict mode where the provider can express it and falls back to non-strict otherwise.\n\t */\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\t/** Declared, model-visible failures (typed). Omit for tools that cannot fail expectedly. */\n\treadonly failure?: Failure;\n\t/** Render success for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\t/** Render an expected failure for the model. Omit → executor falls back to JSON text. */\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\t/**\n\t * The `details` kept with a success, for UIs and programmatic consumers. Omit → the encoded\n\t * success. Set it when `encodeContent` already carries the payload, so it is not stored twice.\n\t */\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** A handler: validated params + context → typed success or typed failure. */\nexport type Handler<Params extends Schema.Top, Success extends Schema.Top, Failure extends Schema.Top, R = never> = (\n\tparams: Params[\"Type\"],\n\tctx: ToolCallContext,\n) => Effect.Effect<Success[\"Type\"], Failure[\"Type\"], R>;\n\n/** A definition paired with its handler (the unit the executor runs). */\nexport interface ToolImpl<\n\tName extends string = string,\n\tParams extends Schema.Top = Schema.Top,\n\tSuccess extends Schema.Top = Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n> {\n\treadonly definition: ToolDef<Name, Params, Success, Failure>;\n\treadonly handler: Handler<Params, Success, Failure, R>;\n}\n\n// Heterogeneous-collection aliases. `any` for the schema generics keeps handlers\n// of differing parameter types assignable into one array (the precise generics\n// live on the authoring helpers below).\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolDef = ToolDef<string, any, any, any>;\n// biome-ignore lint/suspicious/noExplicitAny: erased schema generics for storage\nexport type AnyToolImpl<R = never> = ToolImpl<string, any, any, any, R>;\n\ninterface DefineInput<\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n> {\n\treadonly name: Name;\n\treadonly description: string;\n\treadonly label?: string;\n\treadonly promptSnippet?: string;\n\treadonly promptGuidelines?: ReadonlyArray<string>;\n\treadonly prepareArguments?: (args: unknown) => unknown;\n\treadonly parameters: Params;\n\treadonly constrainedSampling?: Message.Tool[\"constrainedSampling\"];\n\treadonly success: Success;\n\treadonly failure?: Failure;\n\treadonly encodeContent?: (success: Success[\"Type\"]) => ModelContent;\n\treadonly encodeFailureContent?: (failure: Failure[\"Type\"]) => ModelContent;\n\treadonly encodeDetails?: (success: Success[\"Type\"]) => unknown;\n}\n\n/** Define a pure tool (handler attached later via {@link implement} or a toolkit). */\nexport const define = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure>,\n): ToolDef<Name, Params, Success, Failure> => ({\n\t...input,\n});\n\n/** Attach a handler to an existing definition (the testable def/exec split). */\nexport const implement = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR = never,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, R>,\n): ToolImpl<Name, Params, Success, Failure, R> => ({ definition, handler });\n\n/** Sugar for the co-located case: a definition with its handler in one object. */\nexport const make = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top = Schema.Top,\n\tR = never,\n>(\n\tinput: DefineInput<Name, Params, Success, Failure> & {\n\t\treadonly handler: Handler<Params, Success, Failure, R>;\n\t},\n): ToolImpl<Name, Params, Success, Failure, R> => {\n\tconst { handler, ...rest } = input;\n\treturn { definition: define(rest), handler };\n};\n\n/**\n * A tool ready to register: its capability requirements have been discharged, leaving only\n * the executor-provided {@link ToolProgress}. The registry and executor hold `RegisteredTool`s\n * and are non-generic (only `handle` is generic, over a progress sink's `RProgress`), so any\n * number of tools — built-in or\n * third-party/plugin — compose without a shared capability union\n */\nexport interface RegisteredTool {\n\treadonly definition: AnyToolDef;\n\treadonly handler: (\n\t\tparams: unknown,\n\t\tctx: ToolCallContext,\n\t) => Effect.Effect<unknown, ToolExecutionError, ToolProgress>;\n}\n\nconst toRegistered = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\tdefinition: ToolDef<Name, Params, Success, Failure>,\n\thandler: Handler<Params, Success, Failure, ToolProgress>,\n): RegisteredTool => ({\n\tdefinition,\n\t// The executor decodes with `definition.parameters` before invoking this\n\t// erased handler, so restoring the authored parameter type is safe here.\n\thandler: (params, ctx) =>\n\t\thandler(params as Params[\"Type\"], ctx).pipe(\n\t\t\tEffect.mapError((cause) => new ToolExecutionError({ toolName: definition.name, cause })),\n\t\t),\n});\n\n/** Register a tool whose only requirement is the executor-provided progress service. */\nexport const register = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, ToolProgress>,\n): RegisteredTool => toRegistered(impl.definition, impl.handler);\n\n/**\n * Discharge a tool's capability requirements into a {@link RegisteredTool}, erasing its `R`\n * (the executor still provides `ToolProgress`). This is the registration boundary: a\n * plugin/third-party tool provides its own fully-resolved capability Layer here, so the\n * registry never has to unify anyone's `R`.\n */\nexport const provide = <\n\tName extends string,\n\tParams extends Schema.Top,\n\tSuccess extends Schema.Top,\n\tFailure extends Schema.Top,\n\tR,\n>(\n\timpl: ToolImpl<Name, Params, Success, Failure, R | ToolProgress>,\n\tlayer: Layer.Layer<R>,\n): RegisteredTool =>\n\t// `Effect.provide` discharges `R`, leaving `ToolProgress`. TS can't simplify\n\t// `Exclude<ToolProgress, R>` for a generic `R`, so localize the cast before\n\t// crossing the registered-tool boundary.\n\ttoRegistered(impl.definition, ((params, ctx) => impl.handler(params, ctx).pipe(Effect.provide(layer))) as Handler<\n\t\tParams,\n\t\tSuccess,\n\t\tFailure,\n\t\tToolProgress\n\t>);\n\n/**\n * Derive a provider-safe JSON Schema object from an Effect Schema. This is the\n * single boundary that crosses into the provider wire; if a provider rejects a\n * construct, fix it here. Draft-07 inlines the root (no top-level `$ref`).\n */\nexport const toProviderJsonSchema = (schema: Schema.Top): Record<string, unknown> =>\n\tSchema.toStandardJSONSchemaV1(schema)[\"~standard\"].jsonSchema.input({ target: \"draft-07\" });\n\n/**\n * Build the aikit `Message.Tool` wire view from a definition. The derived JSON\n * Schema object satisfies aikit's `parameters` slot structurally at runtime; the\n * single localized cast keeps aikit untouched (decision 3-A).\n */\nexport const toAikitTool = (def: AnyToolDef): Message.Tool => ({\n\tname: def.name,\n\tdescription: def.description,\n\tparameters: toProviderJsonSchema(def.parameters) as unknown as TSchema,\n\t...(def.constrainedSampling === undefined ? {} : { constrainedSampling: def.constrainedSampling }),\n});\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,OAAO,OAAO;CAC5C,QAAQ,OAAO;CACf,UAAU,OAAO;CACjB,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACrD,CAAC;;AAiGD,MAAa,UAMZ,WAC8C,EAC9C,GAAG,MACJ;;AAGA,MAAa,aAOZ,YACA,aACkD;CAAE;CAAY;AAAQ;;AAGzE,MAAa,QAOZ,UAGiD;CACjD,MAAM,EAAE,SAAS,GAAG,SAAS;CAC7B,OAAO;EAAE,YAAY,OAAO,IAAI;EAAG;CAAQ;AAC5C;AAiBA,MAAM,gBAML,YACA,aACqB;CACrB;CAGA,UAAU,QAAQ,QACjB,QAAQ,QAA0B,GAAG,CAAC,CAAC,KACtC,OAAO,UAAU,UAAU,IAAI,mBAAmB;EAAE,UAAU,WAAW;EAAM;CAAM,CAAC,CAAC,CACxF;AACF;;AAGA,MAAa,YAMZ,SACoB,aAAa,KAAK,YAAY,KAAK,OAAO;;;;;;;AAQ/D,MAAa,WAOZ,MACA,UAKA,aAAa,KAAK,cAAc,QAAQ,QAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,QAAQ,KAAK,CAAC,EAKnG;;;;;;AAOF,MAAa,wBAAwB,WACpC,OAAO,uBAAuB,MAAM,CAAC,CAAC,YAAY,CAAC,WAAW,MAAM,EAAE,QAAQ,WAAW,CAAC;;;;;;AAO3F,MAAa,eAAe,SAAmC;CAC9D,MAAM,IAAI;CACV,aAAa,IAAI;CACjB,YAAY,qBAAqB,IAAI,UAAU;CAC/C,GAAI,IAAI,wBAAwB,KAAA,IAAY,CAAC,IAAI,EAAE,qBAAqB,IAAI,oBAAoB;AACjG"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Schema } from "effect";
|
|
2
|
-
declare namespace filesystem_d_exports {
|
|
3
|
-
export { FileStat, FileSystemError, Interface, OperationUnsupportedError, Provider, RmOptions, filesystem_d_exports as SandboxFileSystem, Service, fromProvider, isNotFoundError, realpathScripts, validateRmOptions, withCwd };
|
|
4
|
-
}
|
|
5
|
-
declare const OperationUnsupportedError_base: Schema.Class<OperationUnsupportedError, Schema.TaggedStruct<"OperationUnsupportedError", {
|
|
6
|
-
readonly operation: Schema.String;
|
|
7
|
-
readonly message: Schema.String;
|
|
8
|
-
}>, import("effect/Cause").YieldableError>;
|
|
9
|
-
/**
|
|
10
|
-
* The runtime filesystem contract, independent of any backend.
|
|
11
|
-
*
|
|
12
|
-
* Two surfaces, deliberately:
|
|
13
|
-
* - {@link Provider} is what a backend implements — plain promises that reject,
|
|
14
|
-
* matching every SDK we wrap.
|
|
15
|
-
* - {@link Interface} is what the harness consumes — Effect with a typed error
|
|
16
|
-
* channel and tracing spans. {@link fromProvider} bridges the two exactly
|
|
17
|
-
* once, so no consumer ever writes `Effect.tryPromise` against a filesystem.
|
|
18
|
-
*
|
|
19
|
-
* Implementations:
|
|
20
|
-
* - Local:
|
|
21
|
-
* implement it over a VFS (`./local`);
|
|
22
|
-
* local filesystem use OS primitives; hence have broader filesytem capabilities.
|
|
23
|
-
*
|
|
24
|
-
* - Remote:
|
|
25
|
-
* implement it over a provider (`./remote`).
|
|
26
|
-
* remote filesytems depends on the interface provided by the remote provider; hence can have limited filesytem capabilities.
|
|
27
|
-
*
|
|
28
|
-
* `isFile`/`isDirectory` are required booleans; size, mtime, and isSymbolicLink are omitted when the
|
|
29
|
-
* backend cannot report them — never fabricated.
|
|
30
|
-
*
|
|
31
|
-
* **Paths are POSIX, and the harness is Unix-only (for now!).** Every path uses `/`
|
|
32
|
-
* separators on both the host and inside a sandbox — Windows is not supported,
|
|
33
|
-
* so no translation layer exists. Consumers must use the shared Effect POSIX
|
|
34
|
-
* path implementation, never the platform default, or a host running the harness would
|
|
35
|
-
* impose its own flavour on a remote sandbox's paths. Relative paths resolve
|
|
36
|
-
* against the backend's configured `cwd`.
|
|
37
|
-
*/
|
|
38
|
-
declare class OperationUnsupportedError extends OperationUnsupportedError_base {}
|
|
39
|
-
declare const FileSystemError_base: Schema.Class<FileSystemError, Schema.TaggedStruct<"SandboxFileSystemError", {
|
|
40
|
-
readonly method: Schema.String;
|
|
41
|
-
readonly path: Schema.String;
|
|
42
|
-
readonly cause: Schema.optional<Schema.Defect>;
|
|
43
|
-
}>, import("effect/Cause").YieldableError>;
|
|
44
|
-
/** A backend operation failed. `cause` carries the provider's own rejection. */
|
|
45
|
-
declare class FileSystemError extends FileSystemError_base {}
|
|
46
|
-
interface FileStat {
|
|
47
|
-
readonly isFile: boolean;
|
|
48
|
-
readonly isDirectory: boolean;
|
|
49
|
-
readonly isSymbolicLink?: boolean;
|
|
50
|
-
readonly size?: number;
|
|
51
|
-
readonly mtime?: Date;
|
|
52
|
-
}
|
|
53
|
-
interface RmOptions {
|
|
54
|
-
readonly recursive?: boolean;
|
|
55
|
-
readonly force?: boolean;
|
|
56
|
-
}
|
|
57
|
-
/** Whether a provider failure means the path itself is definitively absent. */
|
|
58
|
-
declare const isNotFoundError: (cause: unknown) => boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Shell forms of `realpath` for backends that only expose a process API.
|
|
61
|
-
* `pwd -P` is the portable primitive: directories resolve directly, anything
|
|
62
|
-
* else resolves its parent and keeps the final name as given. Run as
|
|
63
|
-
* `sh -c <script> _ <path>`; try the first, fall back to the second.
|
|
64
|
-
*/
|
|
65
|
-
declare const realpathScripts: readonly ['cd -- "$1" && pwd -P', 'cd -- "$(dirname -- "$1")" && printf \'%s/%s\' "$(pwd -P)" "$(basename -- "$1")"'];
|
|
66
|
-
/**
|
|
67
|
-
* The backend-facing contract. Backends author plain promises and let them
|
|
68
|
-
* reject; {@link fromProvider} turns rejections into typed failures.
|
|
69
|
-
*/
|
|
70
|
-
interface Provider {
|
|
71
|
-
readonly readFile: (path: string) => Promise<string>;
|
|
72
|
-
readonly readFileBuffer: (path: string) => Promise<Uint8Array>;
|
|
73
|
-
/**
|
|
74
|
-
* Write the file. Parents may be missing — do not create them here;
|
|
75
|
-
* {@link fromProvider} owns that guarantee for every backend.
|
|
76
|
-
*/
|
|
77
|
-
readonly writeFile: (path: string, content: string | Uint8Array) => Promise<void>;
|
|
78
|
-
readonly stat: (path: string) => Promise<FileStat>;
|
|
79
|
-
readonly readdir: (path: string) => Promise<string[]>;
|
|
80
|
-
readonly exists: (path: string) => Promise<boolean>;
|
|
81
|
-
readonly mkdir: (path: string, options?: {
|
|
82
|
-
recursive?: boolean;
|
|
83
|
-
}) => Promise<void>;
|
|
84
|
-
readonly rm: (path: string, options?: RmOptions) => Promise<void>;
|
|
85
|
-
/** Canonical absolute path with symlinks resolved; rejects when the path does not exist. */
|
|
86
|
-
readonly realpath: (path: string) => Promise<string>;
|
|
87
|
-
/**
|
|
88
|
-
* Metadata for the directory entry itself rather than a symlink's target.
|
|
89
|
-
* Optional: a backend whose `stat` has mixed symlink semantics implements it
|
|
90
|
-
* so symlink identity is asked for explicitly, never inferred.
|
|
91
|
-
*/
|
|
92
|
-
readonly lstat?: (path: string) => Promise<FileStat>;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* The consumer-facing contract. `exists` distinguishes "absent" from "could not
|
|
96
|
-
* tell": a backend failure is a typed failure, not `false`, so a caller acting
|
|
97
|
-
* on absence never acts on a network blip. Use `SandboxFs.existsOrFalse` where
|
|
98
|
-
* a best-effort answer really is wanted.
|
|
99
|
-
*/
|
|
100
|
-
interface Interface {
|
|
101
|
-
readonly readFile: (path: string) => Effect.Effect<string, FileSystemError>;
|
|
102
|
-
readonly readFileBuffer: (path: string) => Effect.Effect<Uint8Array, FileSystemError>;
|
|
103
|
-
/** Creates missing parent directories, on every backend. */
|
|
104
|
-
readonly writeFile: (path: string, content: string | Uint8Array) => Effect.Effect<void, FileSystemError>;
|
|
105
|
-
readonly stat: (path: string) => Effect.Effect<FileStat, FileSystemError>;
|
|
106
|
-
readonly readdir: (path: string) => Effect.Effect<string[], FileSystemError>;
|
|
107
|
-
readonly exists: (path: string) => Effect.Effect<boolean, FileSystemError>;
|
|
108
|
-
readonly mkdir: (path: string, options?: {
|
|
109
|
-
recursive?: boolean;
|
|
110
|
-
}) => Effect.Effect<void, FileSystemError>;
|
|
111
|
-
readonly rm: (path: string, options?: RmOptions) => Effect.Effect<void, FileSystemError | OperationUnsupportedError>;
|
|
112
|
-
/** Canonical absolute path with symlinks resolved; fails when the path does not exist. */
|
|
113
|
-
readonly realpath: (path: string) => Effect.Effect<string, FileSystemError>;
|
|
114
|
-
readonly lstat?: (path: string) => Effect.Effect<FileStat, FileSystemError>;
|
|
115
|
-
}
|
|
116
|
-
declare const Service_base: Context.ServiceClass<Service, "@codeworksh/plugin/sandbox/filesystem/Service", Interface>;
|
|
117
|
-
/** The runtime filesystem service — the live {@link Interface} for the active sandbox. */
|
|
118
|
-
declare class Service extends Service_base {}
|
|
119
|
-
/**
|
|
120
|
-
* Reject `rm` options a provider does not implement, before any mutation. Only
|
|
121
|
-
* `recursive` and `force` are part of the contract; anything else is refused
|
|
122
|
-
* loudly rather than silently ignored.
|
|
123
|
-
*/
|
|
124
|
-
declare const validateRmOptions: (options: RmOptions | undefined, operation?: string) => Effect.Effect<void, OperationUnsupportedError>;
|
|
125
|
-
/**
|
|
126
|
-
* Lift a {@link Provider} into the runtime {@link Interface}: one place that
|
|
127
|
-
* converts rejections into {@link FileSystemError}, validates `rm` options,
|
|
128
|
-
* creates missing parents on write, and names a tracing span per operation.
|
|
129
|
-
*/
|
|
130
|
-
declare const fromProvider: (provider: Provider) => Interface;
|
|
131
|
-
/**
|
|
132
|
-
* Bind a cwd-neutral filesystem to one mount's working directory.
|
|
133
|
-
*
|
|
134
|
-
* The counterpart of `Shell.withCwd`, and the reason relative paths mean the
|
|
135
|
-
* same thing to both: a shared transport stays rooted at the namespace root, so
|
|
136
|
-
* resolution happens here, per mount, rather than inside a VFS whose `chdir` is
|
|
137
|
-
* global state two mounts would fight over.
|
|
138
|
-
*/
|
|
139
|
-
declare const withCwd: (fs: Interface, cwd: string) => Interface;
|
|
140
|
-
//#endregion
|
|
141
|
-
export { Provider as a, filesystem_d_exports as c, realpathScripts as d, validateRmOptions as f, OperationUnsupportedError as i, fromProvider as l, FileSystemError as n, RmOptions as o, withCwd as p, Interface as r, Service as s, FileStat as t, isNotFoundError as u };
|
|
142
|
-
//# sourceMappingURL=filesystem-Cp-KapCE.d.mts.map
|
package/prompt-BcpagjGh.d.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare namespace prompt_d_exports {
|
|
2
|
-
export { PromptRegistry };
|
|
3
|
-
}
|
|
4
|
-
interface PromptRegistry {
|
|
5
|
-
readonly set: (systemPrompt: string) => void;
|
|
6
|
-
readonly get: () => string | undefined;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { prompt_d_exports as n, PromptRegistry as t };
|
|
10
|
-
//# sourceMappingURL=prompt-BcpagjGh.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem.mjs","names":[],"sources":["../../../src/sandbox/filesystem.ts"],"sourcesContent":["import { Context, Effect, Schema } from \"effect\";\nimport { posix } from \"../posix.ts\";\n\n/**\n * The runtime filesystem contract, independent of any backend.\n *\n * Two surfaces, deliberately:\n * - {@link Provider} is what a backend implements — plain promises that reject,\n * matching every SDK we wrap.\n * - {@link Interface} is what the harness consumes — Effect with a typed error\n * channel and tracing spans. {@link fromProvider} bridges the two exactly\n * once, so no consumer ever writes `Effect.tryPromise` against a filesystem.\n *\n * Implementations:\n * - Local:\n * implement it over a VFS (`./local`);\n * local filesystem use OS primitives; hence have broader filesytem capabilities.\n *\n * - Remote:\n * implement it over a provider (`./remote`).\n * remote filesytems depends on the interface provided by the remote provider; hence can have limited filesytem capabilities.\n *\n * `isFile`/`isDirectory` are required booleans; size, mtime, and isSymbolicLink are omitted when the\n * backend cannot report them — never fabricated.\n *\n * **Paths are POSIX, and the harness is Unix-only (for now!).** Every path uses `/`\n * separators on both the host and inside a sandbox — Windows is not supported,\n * so no translation layer exists. Consumers must use the shared Effect POSIX\n * path implementation, never the platform default, or a host running the harness would\n * impose its own flavour on a remote sandbox's paths. Relative paths resolve\n * against the backend's configured `cwd`.\n */\n\nexport class OperationUnsupportedError extends Schema.TaggedError<OperationUnsupportedError>()(\n\t\"OperationUnsupportedError\",\n\t{\n\t\toperation: Schema.String,\n\t\tmessage: Schema.String,\n\t},\n) {}\n\n/** A backend operation failed. `cause` carries the provider's own rejection. */\nexport class FileSystemError extends Schema.TaggedError<FileSystemError>()(\"SandboxFileSystemError\", {\n\tmethod: Schema.String,\n\tpath: Schema.String,\n\tcause: Schema.optional(Schema.Defect()),\n}) {}\n\nexport interface FileStat {\n\treadonly isFile: boolean;\n\treadonly isDirectory: boolean;\n\treadonly isSymbolicLink?: boolean;\n\treadonly size?: number;\n\treadonly mtime?: Date;\n}\n\nexport interface RmOptions {\n\treadonly recursive?: boolean;\n\treadonly force?: boolean;\n}\n\n/** Whether a provider failure means the path itself is definitively absent. */\nexport const isNotFoundError = (cause: unknown) => {\n\tconst code = (cause as NodeJS.ErrnoException | undefined)?.code;\n\treturn code === \"ENOENT\" || code === \"ENOTDIR\";\n};\n\n/**\n * Shell forms of `realpath` for backends that only expose a process API.\n * `pwd -P` is the portable primitive: directories resolve directly, anything\n * else resolves its parent and keeps the final name as given. Run as\n * `sh -c <script> _ <path>`; try the first, fall back to the second.\n */\nexport const realpathScripts = [\n\t'cd -- \"$1\" && pwd -P',\n\t'cd -- \"$(dirname -- \"$1\")\" && printf \\'%s/%s\\' \"$(pwd -P)\" \"$(basename -- \"$1\")\"',\n] as const;\n\n/**\n * The backend-facing contract. Backends author plain promises and let them\n * reject; {@link fromProvider} turns rejections into typed failures.\n */\nexport interface Provider {\n\treadonly readFile: (path: string) => Promise<string>;\n\treadonly readFileBuffer: (path: string) => Promise<Uint8Array>;\n\t/**\n\t * Write the file. Parents may be missing — do not create them here;\n\t * {@link fromProvider} owns that guarantee for every backend.\n\t */\n\treadonly writeFile: (path: string, content: string | Uint8Array) => Promise<void>;\n\treadonly stat: (path: string) => Promise<FileStat>;\n\treadonly readdir: (path: string) => Promise<string[]>;\n\treadonly exists: (path: string) => Promise<boolean>;\n\treadonly mkdir: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n\treadonly rm: (path: string, options?: RmOptions) => Promise<void>;\n\t/** Canonical absolute path with symlinks resolved; rejects when the path does not exist. */\n\treadonly realpath: (path: string) => Promise<string>;\n\t/**\n\t * Metadata for the directory entry itself rather than a symlink's target.\n\t * Optional: a backend whose `stat` has mixed symlink semantics implements it\n\t * so symlink identity is asked for explicitly, never inferred.\n\t */\n\treadonly lstat?: (path: string) => Promise<FileStat>;\n}\n\n/**\n * The consumer-facing contract. `exists` distinguishes \"absent\" from \"could not\n * tell\": a backend failure is a typed failure, not `false`, so a caller acting\n * on absence never acts on a network blip. Use `SandboxFs.existsOrFalse` where\n * a best-effort answer really is wanted.\n */\nexport interface Interface {\n\treadonly readFile: (path: string) => Effect.Effect<string, FileSystemError>;\n\treadonly readFileBuffer: (path: string) => Effect.Effect<Uint8Array, FileSystemError>;\n\t/** Creates missing parent directories, on every backend. */\n\treadonly writeFile: (path: string, content: string | Uint8Array) => Effect.Effect<void, FileSystemError>;\n\treadonly stat: (path: string) => Effect.Effect<FileStat, FileSystemError>;\n\treadonly readdir: (path: string) => Effect.Effect<string[], FileSystemError>;\n\treadonly exists: (path: string) => Effect.Effect<boolean, FileSystemError>;\n\treadonly mkdir: (path: string, options?: { recursive?: boolean }) => Effect.Effect<void, FileSystemError>;\n\treadonly rm: (path: string, options?: RmOptions) => Effect.Effect<void, FileSystemError | OperationUnsupportedError>;\n\t/** Canonical absolute path with symlinks resolved; fails when the path does not exist. */\n\treadonly realpath: (path: string) => Effect.Effect<string, FileSystemError>;\n\t// `lstat` is present only when the backend supports it; check before calling.\n\treadonly lstat?: (path: string) => Effect.Effect<FileStat, FileSystemError>;\n}\n\n/** The runtime filesystem service — the live {@link Interface} for the active sandbox. */\nexport class Service extends Context.Service<Service, Interface>()(\"@codeworksh/plugin/sandbox/filesystem/Service\") {}\n\n/**\n * Reject `rm` options a provider does not implement, before any mutation. Only\n * `recursive` and `force` are part of the contract; anything else is refused\n * loudly rather than silently ignored.\n */\nexport const validateRmOptions = (\n\toptions: RmOptions | undefined,\n\toperation = \"rm\",\n): Effect.Effect<void, OperationUnsupportedError> =>\n\tEffect.suspend(() => {\n\t\tfor (const option of Object.keys((options ?? {}) as Record<string, unknown>)) {\n\t\t\tif (option === \"recursive\" || option === \"force\") continue;\n\t\t\treturn Effect.fail(new OperationUnsupportedError({ operation, message: `Unsupported rm option: ${option}` }));\n\t\t}\n\t\treturn Effect.void;\n\t});\n\n/**\n * Lift a {@link Provider} into the runtime {@link Interface}: one place that\n * converts rejections into {@link FileSystemError}, validates `rm` options,\n * creates missing parents on write, and names a tracing span per operation.\n */\nexport const fromProvider = (provider: Provider): Interface => {\n\tconst attempt = <A>(method: string, path: string, run: () => Promise<A>) =>\n\t\tEffect.tryPromise({ try: run, catch: (cause) => new FileSystemError({ method, path, cause }) });\n\n\t// The parent-creation guarantee, installed once for every backend instead of\n\t// re-implemented per provider: anything that reaches `Interface` reaches it\n\t// through here, so a backend cannot forget it.\n\t//\n\t// Lazy by design — try the write first, so the happy path stays a single call\n\t// and no remote backend pays a round-trip per write. A failure is usually a\n\t// missing parent, so create it and retry once. The mkdir's own error is\n\t// dropped on purpose: when the write failed for some other reason (EACCES,\n\t// EROFS, a dropped connection), the retry reproduces it, and *that* is the\n\t// failure the caller must see rather than a misleading mkdir error standing\n\t// in for it.\n\tconst writeCreatingParents = (path: string, content: string | Uint8Array) => {\n\t\tconst write = attempt(\"writeFile\", path, () => provider.writeFile(path, content));\n\t\tconst parent = posix.dirname(path);\n\t\treturn write.pipe(\n\t\t\tEffect.catch(() =>\n\t\t\t\tattempt(\"mkdir\", parent, () => provider.mkdir(parent, { recursive: true })).pipe(\n\t\t\t\t\tEffect.ignore,\n\t\t\t\t\tEffect.andThen(write),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t};\n\n\treturn {\n\t\treadFile: Effect.fn(\"SandboxFileSystem.readFile\")((path: string) =>\n\t\t\tattempt(\"readFile\", path, () => provider.readFile(path)),\n\t\t),\n\t\treadFileBuffer: Effect.fn(\"SandboxFileSystem.readFileBuffer\")((path: string) =>\n\t\t\tattempt(\"readFileBuffer\", path, () => provider.readFileBuffer(path)),\n\t\t),\n\t\twriteFile: Effect.fn(\"SandboxFileSystem.writeFile\")(writeCreatingParents),\n\t\tstat: Effect.fn(\"SandboxFileSystem.stat\")((path: string) => attempt(\"stat\", path, () => provider.stat(path))),\n\t\t// carried through only when the backend actually implements it\n\t\t...(provider.lstat === undefined\n\t\t\t? {}\n\t\t\t: {\n\t\t\t\t\tlstat: Effect.fn(\"SandboxFileSystem.lstat\")((path: string) =>\n\t\t\t\t\t\tattempt(\"lstat\", path, () => provider.lstat!(path)),\n\t\t\t\t\t),\n\t\t\t\t}),\n\t\treaddir: Effect.fn(\"SandboxFileSystem.readdir\")((path: string) =>\n\t\t\tattempt(\"readdir\", path, () => provider.readdir(path)),\n\t\t),\n\t\t// A backend that cannot answer fails; it does not report \"absent\". A\n\t\t// caller acting on absence — deleting a record, say — must not be told\n\t\t// the path is gone because a token expired or a request timed out.\n\t\texists: Effect.fn(\"SandboxFileSystem.exists\")((path: string) =>\n\t\t\tattempt(\"exists\", path, () => provider.exists(path)),\n\t\t),\n\t\tmkdir: Effect.fn(\"SandboxFileSystem.mkdir\")((path: string, options?: { recursive?: boolean }) =>\n\t\t\tattempt(\"mkdir\", path, () => provider.mkdir(path, options)),\n\t\t),\n\t\trm: Effect.fn(\"SandboxFileSystem.rm\")((path: string, options?: RmOptions) =>\n\t\t\tvalidateRmOptions(options).pipe(Effect.andThen(attempt(\"rm\", path, () => provider.rm(path, options)))),\n\t\t),\n\t\trealpath: Effect.fn(\"SandboxFileSystem.realpath\")((path: string) =>\n\t\t\tattempt(\"realpath\", path, () => provider.realpath(path)),\n\t\t),\n\t};\n};\n\n/**\n * Bind a cwd-neutral filesystem to one mount's working directory.\n *\n * The counterpart of `Shell.withCwd`, and the reason relative paths mean the\n * same thing to both: a shared transport stays rooted at the namespace root, so\n * resolution happens here, per mount, rather than inside a VFS whose `chdir` is\n * global state two mounts would fight over.\n */\nexport const withCwd = (fs: Interface, cwd: string): Interface => {\n\tconst at = (path: string) => posix.resolve(cwd, path);\n\treturn {\n\t\treadFile: (path) => fs.readFile(at(path)),\n\t\treadFileBuffer: (path) => fs.readFileBuffer(at(path)),\n\t\twriteFile: (path, content) => fs.writeFile(at(path), content),\n\t\tstat: (path) => fs.stat(at(path)),\n\t\treaddir: (path) => fs.readdir(at(path)),\n\t\texists: (path) => fs.exists(at(path)),\n\t\tmkdir: (path, options) => fs.mkdir(at(path), options),\n\t\trm: (path, options) => fs.rm(at(path), options),\n\t\trealpath: (path) => fs.realpath(at(path)),\n\t\t// carried through only when the backend implements it, so a caller can\n\t\t// still detect absence by checking the property\n\t\t...(fs.lstat === undefined ? {} : { lstat: (path: string) => fs.lstat!(at(path)) }),\n\t};\n};\n\nexport * as SandboxFileSystem from \"./filesystem.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,4BAAb,cAA+C,OAAO,YAAuC,CAAC,CAC7F,6BACA;CACC,WAAW,OAAO;CAClB,SAAS,OAAO;AACjB,CACD,CAAC,CAAC,CAAC;;AAGH,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CAAC,0BAA0B;CACpG,QAAQ,OAAO;CACf,MAAM,OAAO;CACb,OAAO,OAAO,SAAS,OAAO,OAAO,CAAC;AACvC,CAAC,CAAC,CAAC,CAAC;;AAgBJ,MAAa,mBAAmB,UAAmB;CAClD,MAAM,OAAQ,OAA6C;CAC3D,OAAO,SAAS,YAAY,SAAS;AACtC;;;;;;;AAQA,M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KAAK,MAAM,YAAY,GAAG,GAAG,GAAG,IAAI,GAAG,OAAO;EAC9C,WAAW,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;EAGxC,GAAI,GAAG,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,SAAiB,GAAG,MAAO,GAAG,IAAI,CAAC,EAAE;CAClF;AACD"}
|
package/sandbox/io.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"io.mjs","names":["SandboxFileSystem.Service","ShellTag","EffectLayer","SandboxFileSystem.withCwd","shellWithCwd"],"sources":["../../../src/sandbox/io.ts"],"sourcesContent":["import { Context, Effect, Layer as EffectLayer } from \"effect\";\nimport { posix } from \"../posix.ts\";\nimport type { SandboxDriver } from \"./driver.ts\";\nimport { SandboxFileSystem } from \"./filesystem.ts\";\nimport { SandboxInstance } from \"./instance.ts\";\nimport { type ISandboxExe, Shell as ShellTag, withCwd as shellWithCwd } from \"./shell.ts\";\n\n/**\n * `SandboxIO` is a **mount**: a filesystem, a shell, and the identity and\n * working directory they act on.\n *\n * It is the whole vocabulary a consumer needs. Project, Git, Copy, Location, and\n * every tool ask for `SandboxIO.FileSystem`, `SandboxIO.Shell`, and\n * `SandboxIO.Current` — never for a driver, an address, or a provider SDK — so\n * a host directory, an in-memory VFS, and a remote microVM are interchangeable\n * behind one contract.\n *\n * The mount neither creates nor destroys infrastructure. `SandboxInstance` is\n * the durable namespace it acts on — a device, which exists whether or not\n * anything has it mounted — and `Sandbox.Controller` is the only path that\n * creates, stops, or destroys one.\n */\n\n/**\n * The filesystem tag. Re-exported here so consumers import one namespace —\n * Project, Git, Copy, and the runner ask for `SandboxIO.FileSystem`, never for\n * the module that happens to define it. Code *inside* `sandbox/` keeps importing\n * the tag directly, since `io.ts` is built on top of it.\n */\nexport const FileSystem = SandboxFileSystem.Service;\nexport type FileSystem = SandboxFileSystem.Service;\n\n/** The shell tag. Re-exported here so consumers import one namespace. */\nexport const Shell = ShellTag;\nexport type Shell = ShellTag;\n\n/**\n * What a mount sees: immutable identity, plus the working directory resolved for\n * *this* mount.\n *\n * Nothing mutable belongs here. `status`, `usage`, and reference counts all\n * change while a mount is open, so a mount-time snapshot of them would be wrong\n * by construction — runtime code that needs live management state asks the\n * control plane. The driver's own resource locator is likewise absent: consumers\n * never parse a Vercel name or a Daytona id.\n */\nexport interface Identity {\n\treadonly id: SandboxInstance.ID;\n\treadonly driver: SandboxDriver.Name;\n\treadonly kind: SandboxInstance.Kind;\n\t/** Absolute, and always a path in *this* namespace. */\n\treadonly cwd: string;\n}\n\n/** Identity and working directory of the current mount. */\nexport class Current extends Context.Service<Current, Identity>()(\"@codeworksh/plugin/sandbox/io/Current\") {}\n\n/** Everything a mount provides. */\nexport type Provides = Current | SandboxFileSystem.Service | ShellTag;\n\n/** A built mount. */\nexport type Layer<E = never, RIn = never> = EffectLayer.Layer<Provides, E, RIn>;\n\n/**\n * Resolve a mount's cwd without consulting ambient process state.\n *\n * The default is supplied by the namespace adapter:\n * provider metadata remotely, `/` for a virtual filesystem, and `process.cwd()` for the host adapter.\n * An explicit absolute cwd replaces it; a relative cwd is resolved inside it. The\n * result is therefore always the one concrete absolute path `Current` requires.\n *\n * A non-absolute default throws rather than failing typed. It is the one\n * defect-level guard in this module, and deliberately so:\n * Adapters reading a value from a provider call this inside their own error channel,\n * where the throw becomes their typed failure (see `EnvDaytona.mountCwd`).\n */\nexport const resolveMountCwd = (defaultCwd: string, cwd?: string): string => {\n\tif (!posix.isAbsolute(defaultCwd)) {\n\t\tthrow new TypeError(`Sandbox default cwd must be absolute: ${defaultCwd}`);\n\t}\n\t// `resolve`, not `normalize`: normalize keeps a trailing slash, and `cwd` is\n\t// persisted — `space.location` and its id hash would read\n\t// `/workspace/` and `/workspace` as two directories and keep a row for each.\n\t//\n\t// A provider-reported default (`getWorkDir()`) or a config value is free to\n\t// carry one, so it is stripped here rather than at every reader.\n\tif (cwd === undefined) return posix.resolve(defaultCwd);\n\treturn posix.isAbsolute(cwd) ? posix.resolve(cwd) : posix.resolve(defaultCwd, cwd);\n};\n\n/**\n * Bind a cwd-neutral transport to one mount.\n *\n * The transport underneath is shared between\n * mounts and stays rooted at the namespace root, and everything directory-shaped\n * happens here, once per mount. Two mounts of one namespace at different working\n * directories therefore coexist without seeing or moving each other's.\n *\n * It consumes the same two tags it provides — the transport is supplied by the\n * layer this is composed over, not by itself.\n */\nexport const mount = (identity: Identity): EffectLayer.Layer<Provides, never, SandboxFileSystem.Service | ShellTag> =>\n\tEffectLayer.mergeAll(\n\t\tEffectLayer.succeed(Current, identity),\n\t\tEffectLayer.effect(\n\t\t\tSandboxFileSystem.Service,\n\t\t\tEffect.map(SandboxFileSystem.Service, (fs) => SandboxFileSystem.withCwd(fs, identity.cwd)),\n\t\t),\n\t\tEffectLayer.effect(\n\t\t\tShellTag,\n\t\t\tEffect.map(ShellTag, (shell: ISandboxExe) => shellWithCwd(shell, identity.cwd)),\n\t\t),\n\t);\n\n/**\n * Just the identity tag, with no filesystem or shell beneath it. For consumers\n * assembled from stubs — a test that runs `Project` over a fake filesystem still\n * needs to know which namespace it is in.\n */\nexport const identityLayer = (identity: Identity) => EffectLayer.succeed(Current, identity);\n\n/** The host identity alone. See {@link identityLayer}. */\nexport const hostLayer = (cwd: string) => identityLayer(host(cwd));\n\n/**\n * The host, rooted at `cwd`. Always `SandboxInstance.ID.local`: the working\n * directory selects where relative paths resolve, it does not make a second host\n * namespace — two mounts rooted at different directories still agree on absolute\n * paths.\n *\n * The host coordinate is explicit so a caller cannot accidentally substitute ambient process\n * state for the application or session directory it owns.\n */\nexport const host = (cwd: string): Identity => ({\n\tid: SandboxInstance.ID.local,\n\tdriver: \"local\" as SandboxDriver.Name,\n\tkind: \"local\",\n\tcwd: resolveMountCwd(cwd),\n});\n\n/**\n * A VFS-backed namespace. The id is minted per call unless one is named, because\n * building one of these builds a fresh VFS: N unnamed calls are N distinct\n * namespaces, none of which outlives the process. A file-backed store is the\n * exception — its file is the state, so whoever knows the file supplies the id\n * it was registered under.\n */\nexport const virtual = (input: {\n\treadonly driver: string;\n\treadonly id?: SandboxInstance.ID;\n\treadonly defaultCwd?: string;\n\treadonly cwd?: string;\n}): Identity => ({\n\tid: input.id ?? SandboxInstance.ID.create(),\n\tdriver: input.driver as SandboxDriver.Name,\n\tkind: \"virtual\",\n\tcwd: resolveMountCwd(input.defaultCwd ?? \"/\", input.cwd),\n});\n\n/**\n * A provider-hosted namespace. The id is always supplied: a remote resource's\n * durable identity is minted and recorded by whoever provisioned it, never\n * derived here from the provider's own locator.\n */\nexport const remote = (input: {\n\treadonly driver: string;\n\treadonly id: SandboxInstance.ID;\n\t/** Namespace-intrinsic default supplied or discovered by the driver. */\n\treadonly defaultCwd: string;\n\treadonly cwd?: string;\n}): Identity => ({\n\tid: input.id,\n\tdriver: input.driver as SandboxDriver.Name,\n\tkind: \"remote\",\n\tcwd: resolveMountCwd(input.defaultCwd, input.cwd),\n});\n\nexport * as SandboxIO from \"./io.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,aAAaA;;AAI1B,MAAa,QAAQC;;AAsBrB,IAAa,UAAb,cAA6B,QAAQ,QAA2B,CAAC,CAAC,uCAAuC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;AAqB5G,MAAa,mBAAmB,YAAoB,QAAyB;CAC5E,IAAI,CAAC,MAAM,WAAW,UAAU,GAC/B,MAAM,IAAI,UAAU,yCAAyC,YAAY;CAQ1E,IAAI,QAAQ,KAAA,GAAW,OAAO,MAAM,QAAQ,UAAU;CACtD,OAAO,MAAM,WAAW,GAAG,IAAI,MAAM,QAAQ,GAAG,IAAI,MAAM,QAAQ,YAAY,GAAG;AAClF;;;;;;;;;;;;AAaA,MAAa,SAAS,aACrBC,MAAY,SACXA,MAAY,QAAQ,SAAS,QAAQ,GACrCA,MAAY,OACXF,SACA,OAAO,IAAIA,UAA4B,OAAOG,QAA0B,IAAI,SAAS,GAAG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