@tackup/cli 0.0.0 → 0.1.1-exp.pr144.g5661267
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/LICENSE +21 -0
- package/README.md +16 -1
- package/dist/builtins/extensions/docs/guides/day-two.md +3 -0
- package/dist/builtins/extensions/docs/guides/onboarding-2.md +3 -0
- package/dist/builtins/extensions/docs/guides/onboarding-3.md +3 -0
- package/dist/builtins/extensions/docs/skills/use-tack-docs/SKILL.md +67 -0
- package/dist/builtins/extensions/docs/skills/use-tack-docs/references/declare-docs.md +71 -0
- package/dist/builtins/extensions/docs/skills/use-tack-docs/references/docs-in-profiles.md +25 -0
- package/dist/builtins/extensions/docs/skills/use-tack-docs/references/docs-maintenance.md +35 -0
- package/dist/builtins/extensions/docs/skills/use-tack-docs/references/review.md +34 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/SKILL.md +66 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figure-components.md +20 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/architecture-map.md +86 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/chart.md +52 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/figure.md +79 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/file-tree.md +74 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/schema.md +116 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/system.md +81 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/walkthrough.md +45 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/page-components.md +82 -0
- package/dist/builtins/extensions/docs/skills/write-reader-figures/references/rules.md +27 -0
- package/dist/builtins/extensions/docs/tack.yaml +10 -0
- package/dist/builtins/extensions/scripts/guides/day-two.md +3 -0
- package/dist/builtins/extensions/scripts/guides/onboarding-2.md +3 -0
- package/dist/builtins/extensions/scripts/skills/author-tack-scripts/SKILL.md +48 -0
- package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/run-scripts.md +23 -0
- package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/script-api.md +76 -0
- package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/scripts-in-profiles.md +35 -0
- package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/scripts-in-sources.md +56 -0
- package/dist/builtins/extensions/scripts/tack.yaml +10 -0
- package/dist/builtins/skills/author-tack-profiles/SKILL.md +68 -0
- package/dist/builtins/skills/author-tack-profiles/references/apply.md +33 -0
- package/dist/builtins/skills/author-tack-profiles/references/bundles.md +59 -0
- package/dist/builtins/skills/author-tack-profiles/references/copy-workflows.md +46 -0
- package/dist/builtins/skills/manage-tack-sources/SKILL.md +75 -0
- package/dist/builtins/skills/manage-tack-sources/references/catalog-issues.md +38 -0
- package/dist/builtins/skills/manage-tack-sources/references/metadata.md +35 -0
- package/dist/builtins/skills/manage-tack-sources/references/tack-yaml.md +114 -0
- package/dist/builtins/skills/manage-tack-sources/references/worked-source.md +126 -0
- package/dist/builtins/skills/prepare-tack-checkout/SKILL.md +52 -0
- package/dist/builtins/skills/use-tack/SKILL.md +65 -0
- package/dist/builtins/skills/use-tack/references/agent-instructions.md +38 -0
- package/dist/builtins/skills/use-tack/references/day-two.md +35 -0
- package/dist/builtins/skills/use-tack/references/explore.md +13 -0
- package/dist/builtins/skills/use-tack/references/imports.md +30 -0
- package/dist/builtins/skills/use-tack/references/maintenance.md +51 -0
- package/dist/builtins/skills/use-tack/references/onboarding-2.md +41 -0
- package/dist/builtins/skills/use-tack/references/onboarding-3.md +29 -0
- package/dist/builtins/skills/use-tack/references/onboarding.md +54 -0
- package/dist/builtins/skills/use-tack/references/output.md +15 -0
- package/dist/builtins/skills/use-tack/references/selection.md +61 -0
- package/dist/builtins/skills/use-tack/references/setup.md +69 -0
- package/dist/builtins/tack.yaml +10 -0
- package/dist/bundle-support-C7OD5JEG.js +16 -0
- package/dist/chunk-2RUJGM5D.js +56 -0
- package/dist/chunk-3KGEOW4B.js +225 -0
- package/dist/chunk-BDOOV5W7.js +26 -0
- package/dist/chunk-C3K3AFJD.js +16 -0
- package/dist/chunk-E2SJQHKZ.js +281 -0
- package/dist/chunk-EOACX6VI.js +12401 -0
- package/dist/chunk-I25CGFRW.js +36671 -0
- package/dist/chunk-QW47O677.js +162 -0
- package/dist/chunk-QXSQ5MEX.js +28 -0
- package/dist/chunk-RZQCGAJF.js +5733 -0
- package/dist/chunk-SMY7ZPQQ.js +52 -0
- package/dist/chunk-VV2YFWGB.js +1791 -0
- package/dist/chunk-W76JFI2G.js +18013 -0
- package/dist/chunk-XTWP3LBL.js +1017 -0
- package/dist/chunk-ZTKVYMVR.js +92 -0
- package/dist/corpus-effects-IKUFX5HQ.js +12069 -0
- package/dist/elk.bundled-A4NY77AZ.js +94125 -0
- package/dist/main-K4VB62TY.js +65517 -0
- package/dist/main.js +17 -0
- package/dist/reader/visuals.tsx +368 -0
- package/dist/script.d.ts +133 -0
- package/dist/script.js +90 -0
- package/dist/server-R3ERJ4GJ.js +308 -0
- package/dist/src-RDHNYJMO.js +1871 -0
- package/dist/src-XIWV5BGG.js +1126 -0
- package/dist/tack-env.d.ts +137 -0
- package/dist/third-party-licenses.txt +2467 -0
- package/dist/worker-XBNGNPT7.js +24246 -0
- package/package.json +29 -3
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
import { createRequire as tackCreateRequire } from "node:module"; const require = tackCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ScriptDeclarationsSchema,
|
|
4
|
+
executionLimits
|
|
5
|
+
} from "./chunk-EOACX6VI.js";
|
|
6
|
+
import {
|
|
7
|
+
Cause_exports,
|
|
8
|
+
Context_exports,
|
|
9
|
+
Data_exports,
|
|
10
|
+
Effect_exports,
|
|
11
|
+
Exit_exports,
|
|
12
|
+
Logger_exports,
|
|
13
|
+
Redacted_exports,
|
|
14
|
+
SchemaAST_exports,
|
|
15
|
+
Schema_exports,
|
|
16
|
+
Scope_exports
|
|
17
|
+
} from "./chunk-I25CGFRW.js";
|
|
18
|
+
import {
|
|
19
|
+
init_define_TACK_BUILD_INFO
|
|
20
|
+
} from "./chunk-2RUJGM5D.js";
|
|
21
|
+
|
|
22
|
+
// packages/core/src/definition.ts
|
|
23
|
+
init_define_TACK_BUILD_INFO();
|
|
24
|
+
|
|
25
|
+
// packages/core/src/capabilities.ts
|
|
26
|
+
init_define_TACK_BUILD_INFO();
|
|
27
|
+
var ShellFailureId = Symbol.for("@tackup/ShellFailure/1");
|
|
28
|
+
var ShellFailure = class extends Data_exports.TaggedError("ShellFailure") {
|
|
29
|
+
[ShellFailureId] = true;
|
|
30
|
+
};
|
|
31
|
+
var Shell = class extends Context_exports.Service()("@tackup/Shell") {
|
|
32
|
+
};
|
|
33
|
+
function Secret(name) {
|
|
34
|
+
return Context_exports.Service(`@tackup/Secret/${name}`);
|
|
35
|
+
}
|
|
36
|
+
function isCapabilityFailure(value) {
|
|
37
|
+
return typeof value === "object" && value !== null && ShellFailureId in value && value[ShellFailureId] === true && "operation" in value && (value.operation === "spawn" || value.operation === "io" || value.operation === "termination") && "message" in value && typeof value.message === "string";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// packages/core/src/strict-input.ts
|
|
41
|
+
init_define_TACK_BUILD_INFO();
|
|
42
|
+
var emptyObject = Schema_exports.makeFilter(
|
|
43
|
+
(value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0,
|
|
44
|
+
{ expected: "an empty JSON object" }
|
|
45
|
+
).abort();
|
|
46
|
+
var normalized = /* @__PURE__ */ new WeakMap();
|
|
47
|
+
function normalize(ast) {
|
|
48
|
+
const cached = normalized.get(ast);
|
|
49
|
+
if (cached !== void 0) return cached;
|
|
50
|
+
const result = normalizeNode(ast);
|
|
51
|
+
normalized.set(ast, result);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function normalizeNode(ast) {
|
|
55
|
+
if (ast.encoding !== void 0) {
|
|
56
|
+
const [first, ...rest] = ast.encoding;
|
|
57
|
+
const rewrite = (link) => new SchemaAST_exports.Link(normalize(link.to), link.transformation);
|
|
58
|
+
const encoding = [
|
|
59
|
+
rest.length === 0 ? rewrite(first) : first,
|
|
60
|
+
...rest.map((link, index) => index === rest.length - 1 ? rewrite(link) : link)
|
|
61
|
+
];
|
|
62
|
+
const descriptors = Object.getOwnPropertyDescriptors(ast);
|
|
63
|
+
const copy = Object.create(Object.getPrototypeOf(ast), {
|
|
64
|
+
...descriptors,
|
|
65
|
+
encoding: { ...descriptors.encoding, value: encoding }
|
|
66
|
+
});
|
|
67
|
+
if (!SchemaAST_exports.isAST(copy)) throw new Error("Could not preserve the input schema AST.");
|
|
68
|
+
return copy;
|
|
69
|
+
}
|
|
70
|
+
if (SchemaAST_exports.isObjects(ast)) {
|
|
71
|
+
const checks = ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0 ? [emptyObject, ...ast.checks ?? []] : ast.checks;
|
|
72
|
+
return new SchemaAST_exports.Objects(
|
|
73
|
+
ast.propertySignatures.map(
|
|
74
|
+
(property) => new SchemaAST_exports.PropertySignature(property.name, normalize(property.type))
|
|
75
|
+
),
|
|
76
|
+
ast.indexSignatures.map(
|
|
77
|
+
(index) => new SchemaAST_exports.IndexSignature(index.parameter, normalize(index.type))
|
|
78
|
+
),
|
|
79
|
+
ast.annotations,
|
|
80
|
+
checks,
|
|
81
|
+
void 0,
|
|
82
|
+
ast.context,
|
|
83
|
+
ast.encodingChecks
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (SchemaAST_exports.isArrays(ast))
|
|
87
|
+
return new SchemaAST_exports.Arrays(
|
|
88
|
+
ast.isMutable,
|
|
89
|
+
ast.elements.map((element) => normalize(element)),
|
|
90
|
+
ast.rest.map((element) => normalize(element)),
|
|
91
|
+
ast.annotations,
|
|
92
|
+
ast.checks,
|
|
93
|
+
void 0,
|
|
94
|
+
ast.context,
|
|
95
|
+
ast.encodingChecks
|
|
96
|
+
);
|
|
97
|
+
if (SchemaAST_exports.isUnion(ast))
|
|
98
|
+
return new SchemaAST_exports.Union(
|
|
99
|
+
ast.types.map((member) => normalize(member)),
|
|
100
|
+
ast.options,
|
|
101
|
+
ast.annotations,
|
|
102
|
+
ast.checks,
|
|
103
|
+
void 0,
|
|
104
|
+
ast.context,
|
|
105
|
+
ast.encodingChecks
|
|
106
|
+
);
|
|
107
|
+
if (SchemaAST_exports.isSuspend(ast))
|
|
108
|
+
return new SchemaAST_exports.Suspend(
|
|
109
|
+
() => normalize(ast.thunk()),
|
|
110
|
+
ast.annotations,
|
|
111
|
+
void 0,
|
|
112
|
+
void 0,
|
|
113
|
+
ast.context
|
|
114
|
+
);
|
|
115
|
+
if (SchemaAST_exports.isDeclaration(ast))
|
|
116
|
+
return new SchemaAST_exports.Declaration(
|
|
117
|
+
ast.typeParameters.map((parameter) => normalize(parameter)),
|
|
118
|
+
ast.run,
|
|
119
|
+
ast.annotations,
|
|
120
|
+
ast.checks,
|
|
121
|
+
void 0,
|
|
122
|
+
ast.context,
|
|
123
|
+
ast.encodingChecks,
|
|
124
|
+
ast.encodingRun
|
|
125
|
+
);
|
|
126
|
+
return ast;
|
|
127
|
+
}
|
|
128
|
+
function strictInputSchema(schema) {
|
|
129
|
+
return Schema_exports.make(normalize(schema.ast));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// packages/core/src/definition.ts
|
|
133
|
+
var ScriptContract = 1;
|
|
134
|
+
var NoExpectedFailure = "@tackup/NoExpectedFailure";
|
|
135
|
+
var DefinitionId = Symbol.for("@tackup/ScriptDefinition");
|
|
136
|
+
var BoundaryParserId = Symbol.for("@tackup/ScriptBoundaryParser/1");
|
|
137
|
+
var parseAuthorBoundary = (schema, value, direction) => {
|
|
138
|
+
if (direction === "encode") return Schema_exports.encodeUnknownExit(schema)(value);
|
|
139
|
+
const input = strictInputSchema(schema);
|
|
140
|
+
return direction === "encodeInput" ? Schema_exports.encodeUnknownExit(input)(value) : Schema_exports.decodeUnknownExit(input, { onExcessProperty: "error" })(value);
|
|
141
|
+
};
|
|
142
|
+
function defineScript(definition, ..._agreement) {
|
|
143
|
+
return Object.freeze({
|
|
144
|
+
...definition,
|
|
145
|
+
secrets: Object.freeze([...definition.secrets]),
|
|
146
|
+
services: Object.freeze([...definition.services]),
|
|
147
|
+
[DefinitionId]: true,
|
|
148
|
+
[BoundaryParserId]: parseAuthorBoundary
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
var definitionFailureCodes = [
|
|
152
|
+
"invalid_definition",
|
|
153
|
+
"unsupported_contract",
|
|
154
|
+
"unknown_capability"
|
|
155
|
+
];
|
|
156
|
+
function inspectScriptDefinition(value) {
|
|
157
|
+
if (typeof value !== "object" || value === null || !(DefinitionId in value) || value[DefinitionId] !== true || !(BoundaryParserId in value) || typeof value[BoundaryParserId] !== "function") {
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
code: "invalid_definition",
|
|
161
|
+
message: "Expected a definition created by defineScript."
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (!("contract" in value) || value.contract !== ScriptContract) {
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
code: "unsupported_contract",
|
|
168
|
+
message: "Unsupported script contract version."
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (!("services" in value) || !Array.isArray(value.services) || value.services.some((service) => service !== "Shell")) {
|
|
172
|
+
return { ok: false, code: "unknown_capability", message: "Unknown service capability." };
|
|
173
|
+
}
|
|
174
|
+
if (!("secrets" in value) || !Array.isArray(value.secrets) || value.secrets.some(
|
|
175
|
+
(name) => typeof name !== "string" || !/^[A-Z][A-Z0-9_]*$/.test(name) || name.startsWith("TACK_")
|
|
176
|
+
)) {
|
|
177
|
+
return {
|
|
178
|
+
ok: false,
|
|
179
|
+
code: "unknown_capability",
|
|
180
|
+
message: "Secret names must be unprefixed uppercase environment names."
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (!("input" in value) || !Schema_exports.isSchema(value.input) || !("output" in value) || !Schema_exports.isSchema(value.output) || !("error" in value) || value.error !== NoExpectedFailure && !Schema_exports.isSchema(value.error) || !("run" in value) || typeof value.run !== "function") {
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
code: "invalid_definition",
|
|
187
|
+
message: "Missing script schemas or program constructor."
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, definition: value };
|
|
191
|
+
}
|
|
192
|
+
function parseScriptBoundary(definition, schema, value, direction) {
|
|
193
|
+
return definition[BoundaryParserId](schema, value, direction);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// packages/core/src/outcome.ts
|
|
197
|
+
init_define_TACK_BUILD_INFO();
|
|
198
|
+
var RunLimits = {
|
|
199
|
+
inputBytes: 1024 * 1024,
|
|
200
|
+
boundaryBytes: 1024 * 1024,
|
|
201
|
+
logEventBytes: 64 * 1024,
|
|
202
|
+
logBytes: 10 * 1024 * 1024,
|
|
203
|
+
logEvents: 1e4
|
|
204
|
+
};
|
|
205
|
+
function copyJson(value) {
|
|
206
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
207
|
+
const copy = (item) => {
|
|
208
|
+
if (item === null || typeof item === "string" || typeof item === "boolean") return item;
|
|
209
|
+
if (typeof item === "number" && Number.isFinite(item)) return item;
|
|
210
|
+
if (typeof item !== "object" || item === null || ancestors.has(item))
|
|
211
|
+
throw new Error("Value is not JSON data.");
|
|
212
|
+
ancestors.add(item);
|
|
213
|
+
try {
|
|
214
|
+
if (Array.isArray(item)) {
|
|
215
|
+
if (Object.getPrototypeOf(item) !== Array.prototype)
|
|
216
|
+
throw new Error("Value is not a plain JSON array.");
|
|
217
|
+
const result2 = [];
|
|
218
|
+
for (let index = 0; index < item.length; index += 1) {
|
|
219
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, index);
|
|
220
|
+
if (descriptor === void 0 || !("value" in descriptor))
|
|
221
|
+
throw new Error("JSON arrays must contain plain values.");
|
|
222
|
+
result2.push(copy(descriptor.value));
|
|
223
|
+
}
|
|
224
|
+
return result2;
|
|
225
|
+
}
|
|
226
|
+
const prototype = Object.getPrototypeOf(item);
|
|
227
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
228
|
+
throw new Error("Value is not a JSON object.");
|
|
229
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
230
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(item))) {
|
|
231
|
+
if (descriptor.enumerable !== true) continue;
|
|
232
|
+
if (!("value" in descriptor)) throw new Error("JSON data cannot contain accessors.");
|
|
233
|
+
result[key] = copy(descriptor.value);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
} finally {
|
|
237
|
+
ancestors.delete(item);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
return copy(value);
|
|
241
|
+
}
|
|
242
|
+
function encodeRunOutcome(outcome) {
|
|
243
|
+
const primary = outcome.primary.status === "success" ? {
|
|
244
|
+
status: outcome.primary.status,
|
|
245
|
+
stage: outcome.primary.stage,
|
|
246
|
+
code: outcome.primary.code,
|
|
247
|
+
encoded: outcome.primary.encoded
|
|
248
|
+
} : {
|
|
249
|
+
status: outcome.primary.status,
|
|
250
|
+
stage: outcome.primary.stage,
|
|
251
|
+
code: outcome.primary.code,
|
|
252
|
+
message: outcome.primary.message,
|
|
253
|
+
...outcome.primary.encoded === void 0 ? {} : { encoded: outcome.primary.encoded },
|
|
254
|
+
...outcome.primary.encodedFailures === void 0 ? {} : { encodedFailures: outcome.primary.encodedFailures },
|
|
255
|
+
...outcome.primary.diagnostics === void 0 ? {} : { diagnostics: outcome.primary.diagnostics }
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
status: outcome.status,
|
|
259
|
+
stage: outcome.stage,
|
|
260
|
+
code: outcome.code,
|
|
261
|
+
primary,
|
|
262
|
+
finalization: outcome.finalization.status === "failed" ? { status: "failed", diagnostics: outcome.finalization.diagnostics } : outcome.finalization,
|
|
263
|
+
logs: outcome.logs,
|
|
264
|
+
truncation: outcome.truncation,
|
|
265
|
+
...outcome.encodedInput === void 0 ? {} : { encodedInput: outcome.encodedInput }
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
var ScriptError = class extends Error {
|
|
269
|
+
name = "ScriptError";
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// packages/core/src/run-script.ts
|
|
273
|
+
init_define_TACK_BUILD_INFO();
|
|
274
|
+
var bytes = (value) => new TextEncoder().encode(value).byteLength;
|
|
275
|
+
function describe(value) {
|
|
276
|
+
try {
|
|
277
|
+
if (Redacted_exports.isRedacted(value)) return "<redacted>";
|
|
278
|
+
if (typeof value === "string") return value.slice(0, 4096);
|
|
279
|
+
if (value instanceof Error) return value.message.slice(0, 4096);
|
|
280
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0)
|
|
281
|
+
return String(value);
|
|
282
|
+
return "<runtime value>";
|
|
283
|
+
} catch {
|
|
284
|
+
return "<unavailable diagnostic>";
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function diagnostics(cause) {
|
|
288
|
+
return cause.reasons.slice(0, 100).map((reason) => ({
|
|
289
|
+
kind: Cause_exports.isDieReason(reason) ? "Die" : Cause_exports.isFailReason(reason) ? "Fail" : "Interrupt",
|
|
290
|
+
message: Cause_exports.isDieReason(reason) ? describe(reason.defect) : Cause_exports.isFailReason(reason) ? describe(reason.error) : "Execution interrupted."
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
function failure(stage, code, message, cause) {
|
|
294
|
+
return {
|
|
295
|
+
status: "failure",
|
|
296
|
+
stage,
|
|
297
|
+
code,
|
|
298
|
+
message,
|
|
299
|
+
...cause === void 0 ? {} : { cause, diagnostics: diagnostics(cause) }
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function schemaBoundary(definition, schema, value, direction, stage) {
|
|
303
|
+
try {
|
|
304
|
+
const result = parseScriptBoundary(
|
|
305
|
+
definition,
|
|
306
|
+
schema,
|
|
307
|
+
value,
|
|
308
|
+
direction === "encode" && stage === "input" ? "encodeInput" : direction
|
|
309
|
+
);
|
|
310
|
+
if (Exit_exports.isSuccess(result)) return { ok: true, value: result.value };
|
|
311
|
+
const ordinary = result.cause.reasons.length > 0 && result.cause.reasons.every(
|
|
312
|
+
(reason) => Cause_exports.isFailReason(reason) && Schema_exports.isSchemaError(reason.error)
|
|
313
|
+
);
|
|
314
|
+
return {
|
|
315
|
+
ok: false,
|
|
316
|
+
failure: failure(
|
|
317
|
+
stage,
|
|
318
|
+
ordinary ? stage === "input" ? "invalid_input" : stage === "output" ? "invalid_output" : "invalid_expected_failure" : "schema_defect",
|
|
319
|
+
ordinary ? "Value does not satisfy its boundary schema." : "Boundary schema failed outside validation.",
|
|
320
|
+
result.cause
|
|
321
|
+
)
|
|
322
|
+
};
|
|
323
|
+
} catch (error) {
|
|
324
|
+
return {
|
|
325
|
+
ok: false,
|
|
326
|
+
failure: failure(
|
|
327
|
+
stage,
|
|
328
|
+
"schema_defect",
|
|
329
|
+
"Boundary schema threw during validation.",
|
|
330
|
+
Cause_exports.die(error)
|
|
331
|
+
)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function encodedBoundary(definition, schema, value, stage) {
|
|
336
|
+
const encoded = schemaBoundary(definition, schema, value, "encode", stage);
|
|
337
|
+
if (!encoded.ok) return encoded;
|
|
338
|
+
try {
|
|
339
|
+
const json = copyJson(encoded.value);
|
|
340
|
+
if (bytes(JSON.stringify(json)) > RunLimits.boundaryBytes)
|
|
341
|
+
return {
|
|
342
|
+
ok: false,
|
|
343
|
+
failure: failure(stage, "boundary_too_large", "Encoded boundary exceeds its byte limit.")
|
|
344
|
+
};
|
|
345
|
+
return { ok: true, value: json };
|
|
346
|
+
} catch {
|
|
347
|
+
return {
|
|
348
|
+
ok: false,
|
|
349
|
+
failure: failure(
|
|
350
|
+
stage,
|
|
351
|
+
stage === "output" ? "invalid_output" : stage === "execution" ? "invalid_expected_failure" : "invalid_input",
|
|
352
|
+
"Encoded boundary is not JSON data."
|
|
353
|
+
)
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function classify(definition, exit) {
|
|
358
|
+
if (Exit_exports.isSuccess(exit)) {
|
|
359
|
+
const encoded = encodedBoundary(definition, definition.output, exit.value, "output");
|
|
360
|
+
return encoded.ok ? {
|
|
361
|
+
status: "success",
|
|
362
|
+
stage: "output",
|
|
363
|
+
code: "success",
|
|
364
|
+
value: exit.value,
|
|
365
|
+
encoded: encoded.value
|
|
366
|
+
} : encoded.failure;
|
|
367
|
+
}
|
|
368
|
+
const cause = exit.cause;
|
|
369
|
+
const defect = cause.reasons.find((reason) => Cause_exports.isDieReason(reason));
|
|
370
|
+
if (defect !== void 0)
|
|
371
|
+
return failure(
|
|
372
|
+
"execution",
|
|
373
|
+
"executed_defect",
|
|
374
|
+
defect.defect instanceof ScriptError ? defect.defect.message : "Program execution defect.",
|
|
375
|
+
cause
|
|
376
|
+
);
|
|
377
|
+
if (cause.reasons.some((reason) => Cause_exports.isInterruptReason(reason)))
|
|
378
|
+
return failure("execution", "interrupted", "Program execution interrupted.", cause);
|
|
379
|
+
if (cause.reasons.some((reason) => Cause_exports.isFailReason(reason) && isCapabilityFailure(reason.error)))
|
|
380
|
+
return failure("execution", "capability_failure", "A Tack capability failed.", cause);
|
|
381
|
+
if (definition.error === NoExpectedFailure)
|
|
382
|
+
return failure(
|
|
383
|
+
"execution",
|
|
384
|
+
"unexpected_failure",
|
|
385
|
+
"Program failed despite declaring no expected failure.",
|
|
386
|
+
cause
|
|
387
|
+
);
|
|
388
|
+
const encodedFailures = [];
|
|
389
|
+
for (const reason of cause.reasons) {
|
|
390
|
+
if (!Cause_exports.isFailReason(reason)) continue;
|
|
391
|
+
const encoded = encodedBoundary(definition, definition.error, reason.error, "execution");
|
|
392
|
+
if (!encoded.ok)
|
|
393
|
+
return {
|
|
394
|
+
...encoded.failure,
|
|
395
|
+
cause,
|
|
396
|
+
diagnostics: [...diagnostics(cause), ...encoded.failure.diagnostics ?? []]
|
|
397
|
+
};
|
|
398
|
+
encodedFailures.push(encoded.value);
|
|
399
|
+
if (bytes(JSON.stringify(encodedFailures)) > RunLimits.boundaryBytes)
|
|
400
|
+
return failure(
|
|
401
|
+
"execution",
|
|
402
|
+
"boundary_too_large",
|
|
403
|
+
"Encoded failures exceed their aggregate byte limit.",
|
|
404
|
+
cause
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (encodedFailures.length === 0)
|
|
408
|
+
return failure(
|
|
409
|
+
"execution",
|
|
410
|
+
"unexpected_failure",
|
|
411
|
+
"Program failed without a declared domain failure.",
|
|
412
|
+
cause
|
|
413
|
+
);
|
|
414
|
+
return {
|
|
415
|
+
...failure("execution", "expected_failure", "Program reported an expected failure.", cause),
|
|
416
|
+
encoded: encodedFailures[0],
|
|
417
|
+
encodedFailures
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
async function runScript(definition, options) {
|
|
421
|
+
const logs = [];
|
|
422
|
+
const truncation = [];
|
|
423
|
+
let observedEvents = 0;
|
|
424
|
+
let observedBytes = 0;
|
|
425
|
+
const truncate = (reason, observed, limit) => {
|
|
426
|
+
const index = truncation.findIndex((entry2) => entry2.reason === reason);
|
|
427
|
+
const entry = { reason, observed, limit };
|
|
428
|
+
if (index === -1) truncation.push(entry);
|
|
429
|
+
else truncation[index] = entry;
|
|
430
|
+
};
|
|
431
|
+
const logger = Logger_exports.make(({ message, logLevel, date }) => {
|
|
432
|
+
observedEvents += 1;
|
|
433
|
+
const content = Array.isArray(message) ? message.map((part) => typeof part === "string" ? part : describe(part)).join(" ") : describe(message);
|
|
434
|
+
const length = bytes(content);
|
|
435
|
+
observedBytes += length;
|
|
436
|
+
if (observedEvents > RunLimits.logEvents) {
|
|
437
|
+
truncate("event_count", observedEvents, RunLimits.logEvents);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (observedBytes > RunLimits.logBytes) {
|
|
441
|
+
truncate("total_bytes", observedBytes, RunLimits.logBytes);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const bounded = length > RunLimits.logEventBytes ? new TextDecoder().decode(new TextEncoder().encode(content).slice(0, RunLimits.logEventBytes)).replace(/\uFFFD$/, "") : content;
|
|
445
|
+
if (length > RunLimits.logEventBytes) truncate("event_bytes", length, RunLimits.logEventBytes);
|
|
446
|
+
const event = {
|
|
447
|
+
source: "script",
|
|
448
|
+
sequence: logs.length + 1,
|
|
449
|
+
timestamp: date.toISOString(),
|
|
450
|
+
content: bounded,
|
|
451
|
+
level: logLevel
|
|
452
|
+
};
|
|
453
|
+
logs.push(event);
|
|
454
|
+
options.onLog?.(event);
|
|
455
|
+
});
|
|
456
|
+
const finish = (primary2, finalization2 = { status: "not_started" }, encodedInput2, execution) => ({
|
|
457
|
+
status: finalization2.status === "failed" ? "failure" : primary2.status,
|
|
458
|
+
stage: finalization2.status === "failed" ? "cleanup" : primary2.stage,
|
|
459
|
+
code: finalization2.status === "failed" ? "cleanup_failed" : primary2.code,
|
|
460
|
+
primary: primary2,
|
|
461
|
+
finalization: finalization2,
|
|
462
|
+
logs,
|
|
463
|
+
truncation,
|
|
464
|
+
...encodedInput2 === void 0 ? {} : { encodedInput: encodedInput2 },
|
|
465
|
+
...execution === void 0 ? {} : { execution }
|
|
466
|
+
});
|
|
467
|
+
const inspected = inspectScriptDefinition(definition);
|
|
468
|
+
if (!inspected.ok) return finish(failure("preflight", inspected.code, inspected.message));
|
|
469
|
+
const script = inspected.definition;
|
|
470
|
+
let context = Context_exports.empty();
|
|
471
|
+
for (const name of script.secrets) {
|
|
472
|
+
const value = options.services.secrets?.[name];
|
|
473
|
+
if (typeof value !== "string")
|
|
474
|
+
return finish(failure("preflight", "missing_capability", `Missing declared secret ${name}.`));
|
|
475
|
+
context = Context_exports.add(context, Secret(name), Redacted_exports.make(value));
|
|
476
|
+
}
|
|
477
|
+
if (script.services.includes("Shell")) {
|
|
478
|
+
if (options.services.Shell === void 0 || typeof options.services.Shell.execute !== "function")
|
|
479
|
+
return finish(
|
|
480
|
+
failure("preflight", "missing_capability", "Missing declared Shell implementation.")
|
|
481
|
+
);
|
|
482
|
+
context = Context_exports.add(context, Shell, options.services.Shell);
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const input2 = copyJson(options.input);
|
|
486
|
+
if (bytes(JSON.stringify(input2)) > RunLimits.inputBytes)
|
|
487
|
+
return finish(failure("input", "input_too_large", "Input exceeds its byte limit."));
|
|
488
|
+
} catch {
|
|
489
|
+
return finish(failure("input", "invalid_input", "Input must be JSON data."));
|
|
490
|
+
}
|
|
491
|
+
const input = schemaBoundary(script, script.input, options.input, "decode", "input");
|
|
492
|
+
if (!input.ok) return finish(input.failure);
|
|
493
|
+
const encodedInputResult = encodedBoundary(script, script.input, input.value, "input");
|
|
494
|
+
if (!encodedInputResult.ok && encodedInputResult.failure.code === "schema_defect")
|
|
495
|
+
return finish(encodedInputResult.failure);
|
|
496
|
+
const encodedInput = encodedInputResult.ok ? encodedInputResult.value : void 0;
|
|
497
|
+
if (options.signal?.aborted === true)
|
|
498
|
+
return finish(
|
|
499
|
+
failure(
|
|
500
|
+
"execution",
|
|
501
|
+
"interrupted",
|
|
502
|
+
"Program execution interrupted before construction.",
|
|
503
|
+
Cause_exports.interrupt()
|
|
504
|
+
),
|
|
505
|
+
void 0,
|
|
506
|
+
encodedInput
|
|
507
|
+
);
|
|
508
|
+
let program;
|
|
509
|
+
try {
|
|
510
|
+
program = script.run(input.value);
|
|
511
|
+
} catch (error) {
|
|
512
|
+
return finish(
|
|
513
|
+
failure(
|
|
514
|
+
"construction",
|
|
515
|
+
"construction_defect",
|
|
516
|
+
"Program construction threw.",
|
|
517
|
+
Cause_exports.die(error)
|
|
518
|
+
),
|
|
519
|
+
void 0,
|
|
520
|
+
encodedInput
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
if (!Effect_exports.isEffect(program))
|
|
524
|
+
return finish(
|
|
525
|
+
failure("construction", "invalid_program", "Program constructor must return an Effect."),
|
|
526
|
+
void 0,
|
|
527
|
+
encodedInput
|
|
528
|
+
);
|
|
529
|
+
const scope = Scope_exports.makeUnsafe();
|
|
530
|
+
const provided = Effect_exports.provideContext(
|
|
531
|
+
Scope_exports.provide(program, scope),
|
|
532
|
+
Context_exports.makeUnsafe(context.mapUnsafe)
|
|
533
|
+
);
|
|
534
|
+
const exit = await Effect_exports.runPromiseExit(
|
|
535
|
+
Effect_exports.provide(provided, Logger_exports.layer([logger])),
|
|
536
|
+
options.signal === void 0 ? void 0 : { signal: options.signal }
|
|
537
|
+
);
|
|
538
|
+
const primary = classify(script, exit);
|
|
539
|
+
const cleanup = await Effect_exports.runPromiseExit(
|
|
540
|
+
Effect_exports.provide(Scope_exports.close(scope, exit), Logger_exports.layer([logger]))
|
|
541
|
+
);
|
|
542
|
+
const finalization = Exit_exports.isSuccess(cleanup) ? { status: "complete" } : { status: "failed", cause: cleanup.cause, diagnostics: diagnostics(cleanup.cause) };
|
|
543
|
+
return finish(
|
|
544
|
+
primary,
|
|
545
|
+
finalization,
|
|
546
|
+
encodedInput,
|
|
547
|
+
Exit_exports.isSuccess(exit) ? { status: "success", value: exit.value } : { status: "failure", cause: exit.cause }
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// packages/core/src/index.ts
|
|
552
|
+
init_define_TACK_BUILD_INFO();
|
|
553
|
+
|
|
554
|
+
// packages/core/src/outcome-schema.ts
|
|
555
|
+
init_define_TACK_BUILD_INFO();
|
|
556
|
+
var byteLength = (value) => new TextEncoder().encode(value).byteLength;
|
|
557
|
+
var BoundedJson = Schema_exports.declare(
|
|
558
|
+
(value) => {
|
|
559
|
+
try {
|
|
560
|
+
return byteLength(JSON.stringify(copyJson(value))) <= RunLimits.boundaryBytes;
|
|
561
|
+
} catch {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
{ description: "Plain JSON data within the script boundary byte limit" }
|
|
566
|
+
);
|
|
567
|
+
var Message = Schema_exports.String.check(Schema_exports.isMaxLength(4096));
|
|
568
|
+
var Diagnostic = Schema_exports.Struct({
|
|
569
|
+
kind: Schema_exports.Literals(["Fail", "Die", "Interrupt"]),
|
|
570
|
+
message: Message
|
|
571
|
+
});
|
|
572
|
+
var Diagnostics = Schema_exports.Array(Diagnostic).check(Schema_exports.isMaxLength(200));
|
|
573
|
+
var Stage = Schema_exports.Literals([
|
|
574
|
+
"preflight",
|
|
575
|
+
"input",
|
|
576
|
+
"construction",
|
|
577
|
+
"execution",
|
|
578
|
+
"output",
|
|
579
|
+
"cleanup"
|
|
580
|
+
]);
|
|
581
|
+
var FailureCode = Schema_exports.Literals([
|
|
582
|
+
"invalid_definition",
|
|
583
|
+
"unsupported_contract",
|
|
584
|
+
"unknown_capability",
|
|
585
|
+
"missing_capability",
|
|
586
|
+
"invalid_input",
|
|
587
|
+
"input_too_large",
|
|
588
|
+
"schema_defect",
|
|
589
|
+
"construction_defect",
|
|
590
|
+
"invalid_program",
|
|
591
|
+
"expected_failure",
|
|
592
|
+
"capability_failure",
|
|
593
|
+
"executed_defect",
|
|
594
|
+
"interrupted",
|
|
595
|
+
"unexpected_failure",
|
|
596
|
+
"invalid_expected_failure",
|
|
597
|
+
"invalid_output",
|
|
598
|
+
"boundary_too_large",
|
|
599
|
+
"cleanup_failed"
|
|
600
|
+
]);
|
|
601
|
+
var primaryFailureStages = {
|
|
602
|
+
invalid_definition: ["preflight"],
|
|
603
|
+
unsupported_contract: ["preflight"],
|
|
604
|
+
unknown_capability: ["preflight"],
|
|
605
|
+
missing_capability: ["preflight"],
|
|
606
|
+
invalid_input: ["input"],
|
|
607
|
+
input_too_large: ["input"],
|
|
608
|
+
schema_defect: ["input", "output", "execution"],
|
|
609
|
+
construction_defect: ["construction"],
|
|
610
|
+
invalid_program: ["construction"],
|
|
611
|
+
expected_failure: ["execution"],
|
|
612
|
+
capability_failure: ["execution"],
|
|
613
|
+
executed_defect: ["execution"],
|
|
614
|
+
interrupted: ["execution"],
|
|
615
|
+
unexpected_failure: ["execution"],
|
|
616
|
+
invalid_expected_failure: ["execution"],
|
|
617
|
+
invalid_output: ["output"],
|
|
618
|
+
boundary_too_large: ["output", "execution"],
|
|
619
|
+
cleanup_failed: []
|
|
620
|
+
};
|
|
621
|
+
var PrimaryFailure = Schema_exports.Struct({
|
|
622
|
+
status: Schema_exports.Literal("failure"),
|
|
623
|
+
stage: Stage,
|
|
624
|
+
code: FailureCode,
|
|
625
|
+
message: Message,
|
|
626
|
+
diagnostics: Schema_exports.optionalKey(Diagnostics),
|
|
627
|
+
encoded: Schema_exports.optionalKey(BoundedJson),
|
|
628
|
+
encodedFailures: Schema_exports.optionalKey(
|
|
629
|
+
Schema_exports.Array(BoundedJson).check(
|
|
630
|
+
Schema_exports.makeFilter((values) => byteLength(JSON.stringify(values)) <= RunLimits.boundaryBytes)
|
|
631
|
+
)
|
|
632
|
+
)
|
|
633
|
+
}).check(
|
|
634
|
+
Schema_exports.makeFilter((failure2) => {
|
|
635
|
+
if (!primaryFailureStages[failure2.code].includes(failure2.stage))
|
|
636
|
+
return "Failure code does not belong to its stage.";
|
|
637
|
+
if (failure2.code === "expected_failure" && (!Object.hasOwn(failure2, "encoded") || failure2.encodedFailures === void 0 || failure2.encodedFailures.length === 0))
|
|
638
|
+
return "Expected failure requires encoded domain failure values.";
|
|
639
|
+
return true;
|
|
640
|
+
})
|
|
641
|
+
);
|
|
642
|
+
var Primary = Schema_exports.Union([
|
|
643
|
+
Schema_exports.Struct({
|
|
644
|
+
status: Schema_exports.Literal("success"),
|
|
645
|
+
stage: Schema_exports.Literal("output"),
|
|
646
|
+
code: Schema_exports.Literal("success"),
|
|
647
|
+
encoded: BoundedJson
|
|
648
|
+
}),
|
|
649
|
+
PrimaryFailure
|
|
650
|
+
]);
|
|
651
|
+
var Finalization = Schema_exports.Union([
|
|
652
|
+
Schema_exports.Struct({ status: Schema_exports.Literals(["not_started", "complete"]) }),
|
|
653
|
+
Schema_exports.Struct({ status: Schema_exports.Literal("failed"), diagnostics: Diagnostics })
|
|
654
|
+
]);
|
|
655
|
+
var Log = Schema_exports.Struct({
|
|
656
|
+
source: Schema_exports.Literal("script"),
|
|
657
|
+
sequence: Schema_exports.Natural.check(Schema_exports.isGreaterThan(0)),
|
|
658
|
+
timestamp: Schema_exports.String.check(
|
|
659
|
+
Schema_exports.makeFilter(
|
|
660
|
+
(value) => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value) && Number.isFinite(Date.parse(value))
|
|
661
|
+
)
|
|
662
|
+
),
|
|
663
|
+
content: Schema_exports.String.check(
|
|
664
|
+
Schema_exports.makeFilter((value) => byteLength(value) <= RunLimits.logEventBytes)
|
|
665
|
+
),
|
|
666
|
+
level: Schema_exports.Literals(["All", "Fatal", "Error", "Warn", "Info", "Debug", "Trace", "None"])
|
|
667
|
+
});
|
|
668
|
+
var Truncation = Schema_exports.Struct({
|
|
669
|
+
reason: Schema_exports.Literals(["event_bytes", "total_bytes", "event_count"]),
|
|
670
|
+
observed: Schema_exports.Natural,
|
|
671
|
+
limit: Schema_exports.Natural
|
|
672
|
+
}).check(
|
|
673
|
+
Schema_exports.makeFilter((entry) => {
|
|
674
|
+
const limit = entry.reason === "event_bytes" ? RunLimits.logEventBytes : entry.reason === "total_bytes" ? RunLimits.logBytes : RunLimits.logEvents;
|
|
675
|
+
return entry.limit === limit && entry.observed > limit;
|
|
676
|
+
})
|
|
677
|
+
);
|
|
678
|
+
var EncodedRunOutcomeSchema = Schema_exports.Struct({
|
|
679
|
+
status: Schema_exports.Literals(["success", "failure"]),
|
|
680
|
+
stage: Stage,
|
|
681
|
+
code: Schema_exports.Union([Schema_exports.Literal("success"), FailureCode]),
|
|
682
|
+
primary: Primary,
|
|
683
|
+
finalization: Finalization,
|
|
684
|
+
encodedInput: Schema_exports.optionalKey(BoundedJson),
|
|
685
|
+
logs: Schema_exports.Array(Log).check(Schema_exports.isMaxLength(RunLimits.logEvents)),
|
|
686
|
+
truncation: Schema_exports.Array(Truncation).check(Schema_exports.isMaxLength(3))
|
|
687
|
+
}).check(
|
|
688
|
+
Schema_exports.makeFilter((outcome) => {
|
|
689
|
+
if (outcome.finalization.status === "failed") {
|
|
690
|
+
if (outcome.status !== "failure" || outcome.stage !== "cleanup" || outcome.code !== "cleanup_failed")
|
|
691
|
+
return "Failed finalization requires an outer cleanup failure.";
|
|
692
|
+
} else if (outcome.status !== outcome.primary.status || outcome.stage !== outcome.primary.stage || outcome.code !== outcome.primary.code) {
|
|
693
|
+
return "Terminal status, stage and code must match the primary outcome.";
|
|
694
|
+
}
|
|
695
|
+
if (outcome.finalization.status === "not_started" && (outcome.primary.status === "success" || outcome.primary.stage === "execution" && outcome.primary.code !== "interrupted" || outcome.primary.stage === "output"))
|
|
696
|
+
return "Executed outcomes require completed or failed finalization.";
|
|
697
|
+
if (outcome.finalization.status !== "not_started" && ["preflight", "input", "construction"].includes(outcome.primary.stage))
|
|
698
|
+
return "Pre-execution failures cannot have started finalization.";
|
|
699
|
+
if (outcome.logs.some((log, index) => log.sequence !== index + 1))
|
|
700
|
+
return "Log sequence must be contiguous and ordered.";
|
|
701
|
+
if (outcome.logs.reduce((total, log) => total + byteLength(log.content), 0) > RunLimits.logBytes)
|
|
702
|
+
return "Captured logs exceed their total byte limit.";
|
|
703
|
+
if (new Set(outcome.truncation.map((entry) => entry.reason)).size !== outcome.truncation.length)
|
|
704
|
+
return "Log truncation reasons must be unique.";
|
|
705
|
+
return true;
|
|
706
|
+
})
|
|
707
|
+
);
|
|
708
|
+
|
|
709
|
+
// packages/extension-scripts/src/platform/protocol.ts
|
|
710
|
+
init_define_TACK_BUILD_INFO();
|
|
711
|
+
var maximumFrameBytes = 16 * 1024 * 1024;
|
|
712
|
+
var FrameSchema = Schema_exports.Struct({
|
|
713
|
+
version: Schema_exports.Literal(1),
|
|
714
|
+
runId: Schema_exports.String,
|
|
715
|
+
kind: Schema_exports.Literals([
|
|
716
|
+
"start",
|
|
717
|
+
"stage",
|
|
718
|
+
"requirements",
|
|
719
|
+
"capabilities",
|
|
720
|
+
"cancel",
|
|
721
|
+
"log",
|
|
722
|
+
"shell-start",
|
|
723
|
+
"shell-end",
|
|
724
|
+
"terminal"
|
|
725
|
+
]),
|
|
726
|
+
payload: Schema_exports.Json
|
|
727
|
+
});
|
|
728
|
+
var StartPayloadSchema = Schema_exports.Struct({
|
|
729
|
+
entrypoint: Schema_exports.String,
|
|
730
|
+
cwd: Schema_exports.String,
|
|
731
|
+
input: Schema_exports.Json,
|
|
732
|
+
words: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.String)),
|
|
733
|
+
/** Load the script and report what it declares instead of running it. */
|
|
734
|
+
describe: Schema_exports.optionalKey(Schema_exports.Literal(true))
|
|
735
|
+
});
|
|
736
|
+
var CapabilitiesPayloadSchema = Schema_exports.Struct({
|
|
737
|
+
secrets: Schema_exports.Record(Schema_exports.String, Schema_exports.String)
|
|
738
|
+
});
|
|
739
|
+
var StagePayloadSchema = Schema_exports.Struct({ stage: Schema_exports.Literals(["load", "execution"]) });
|
|
740
|
+
var RequirementsPayloadSchema = Schema_exports.Struct({
|
|
741
|
+
secrets: Schema_exports.Array(Schema_exports.String),
|
|
742
|
+
services: Schema_exports.Array(Schema_exports.Literal("Shell"))
|
|
743
|
+
});
|
|
744
|
+
var LogPayloadSchema = Schema_exports.Struct({
|
|
745
|
+
source: Schema_exports.Literals(["script", "shell"]),
|
|
746
|
+
content: Schema_exports.String
|
|
747
|
+
});
|
|
748
|
+
var ShellGroupPayloadSchema = Schema_exports.Struct({
|
|
749
|
+
pid: Schema_exports.Number.check(Schema_exports.isInt(), Schema_exports.isGreaterThan(0))
|
|
750
|
+
});
|
|
751
|
+
var workerFailureCodes = [
|
|
752
|
+
"dependency_unavailable",
|
|
753
|
+
"module_load_failed",
|
|
754
|
+
"invalid_args",
|
|
755
|
+
...definitionFailureCodes,
|
|
756
|
+
"protocol_failure",
|
|
757
|
+
"worker_failure"
|
|
758
|
+
];
|
|
759
|
+
var TerminalPayloadSchema = Schema_exports.Struct({
|
|
760
|
+
core: Schema_exports.optionalKey(Schema_exports.Json),
|
|
761
|
+
coreTruncation: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.Json)),
|
|
762
|
+
failure: Schema_exports.optionalKey(
|
|
763
|
+
Schema_exports.Struct({
|
|
764
|
+
stage: Schema_exports.Literals(["load", "preflight", "worker"]),
|
|
765
|
+
code: Schema_exports.Literals(workerFailureCodes),
|
|
766
|
+
message: Schema_exports.String
|
|
767
|
+
})
|
|
768
|
+
),
|
|
769
|
+
diagnostics: Schema_exports.optionalKey(Schema_exports.Json),
|
|
770
|
+
/** What the script declares, in place of a run, when the start asked to describe it. */
|
|
771
|
+
described: Schema_exports.optionalKey(ScriptDeclarationsSchema)
|
|
772
|
+
});
|
|
773
|
+
var ProtocolFailure = class extends Error {
|
|
774
|
+
constructor() {
|
|
775
|
+
super("The worker sent invalid private protocol traffic.");
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
var decodePayload = (schema, payload) => Schema_exports.decodeUnknownSync(schema, { onExcessProperty: "error" })(payload);
|
|
779
|
+
var terminalMatchesState = (state, terminal) => state !== "starting" && [terminal.core, terminal.failure, terminal.described].filter((item) => item !== void 0).length === 1 && (terminal.core === void 0 || state === "running") && (terminal.described === void 0 || state === "loading") && (terminal.failure?.stage !== "load" || state === "loading") && (terminal.failure?.stage !== "preflight" || state === "loading" || state === "requirements");
|
|
780
|
+
var admit = (state, frame) => {
|
|
781
|
+
if (state === "terminal") throw new ProtocolFailure();
|
|
782
|
+
if (frame.kind === "stage") {
|
|
783
|
+
const { stage } = decodePayload(StagePayloadSchema, frame.payload);
|
|
784
|
+
if (stage === "load" && state === "starting")
|
|
785
|
+
return { kind: "stage", next: "loading", lastStage: "load" };
|
|
786
|
+
if (stage === "execution" && state === "prepared")
|
|
787
|
+
return { kind: "stage", next: "running", lastStage: "execution" };
|
|
788
|
+
throw new ProtocolFailure();
|
|
789
|
+
}
|
|
790
|
+
if (frame.kind === "requirements" && state === "loading")
|
|
791
|
+
return {
|
|
792
|
+
kind: "requirements",
|
|
793
|
+
next: "requirements",
|
|
794
|
+
lastStage: "preflight",
|
|
795
|
+
requirements: decodePayload(RequirementsPayloadSchema, frame.payload)
|
|
796
|
+
};
|
|
797
|
+
if (frame.kind === "log" && state === "running")
|
|
798
|
+
return { kind: "log", log: decodePayload(LogPayloadSchema, frame.payload) };
|
|
799
|
+
if ((frame.kind === "shell-start" || frame.kind === "shell-end") && state === "running")
|
|
800
|
+
return { kind: frame.kind, pid: decodePayload(ShellGroupPayloadSchema, frame.payload).pid };
|
|
801
|
+
if (frame.kind === "terminal") {
|
|
802
|
+
const terminal = decodePayload(TerminalPayloadSchema, frame.payload);
|
|
803
|
+
if (terminalMatchesState(state, terminal) === true)
|
|
804
|
+
return { kind: "terminal", next: "terminal", terminal };
|
|
805
|
+
}
|
|
806
|
+
throw new ProtocolFailure();
|
|
807
|
+
};
|
|
808
|
+
var admitFrame = (state, frame) => {
|
|
809
|
+
try {
|
|
810
|
+
return admit(state, frame);
|
|
811
|
+
} catch {
|
|
812
|
+
throw new ProtocolFailure();
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
var encodeFrame = (frame) => {
|
|
816
|
+
const body = Buffer.from(JSON.stringify(frame));
|
|
817
|
+
if (body.length > maximumFrameBytes) throw new ProtocolFailure();
|
|
818
|
+
const header = Buffer.alloc(4);
|
|
819
|
+
header.writeUInt32BE(body.length);
|
|
820
|
+
return Buffer.concat([header, body]);
|
|
821
|
+
};
|
|
822
|
+
var FrameDecoder = class {
|
|
823
|
+
buffered = Buffer.alloc(0);
|
|
824
|
+
push(chunk) {
|
|
825
|
+
this.buffered = Buffer.concat([this.buffered, chunk]);
|
|
826
|
+
const frames = [];
|
|
827
|
+
while (this.buffered.length >= 4) {
|
|
828
|
+
const length = this.buffered.readUInt32BE();
|
|
829
|
+
if (length === 0 || length > maximumFrameBytes) throw new ProtocolFailure();
|
|
830
|
+
if (this.buffered.length < length + 4) break;
|
|
831
|
+
try {
|
|
832
|
+
frames.push(
|
|
833
|
+
Schema_exports.decodeUnknownSync(FrameSchema, { onExcessProperty: "error" })(
|
|
834
|
+
JSON.parse(this.buffered.subarray(4, length + 4).toString("utf8"))
|
|
835
|
+
)
|
|
836
|
+
);
|
|
837
|
+
} catch {
|
|
838
|
+
throw new ProtocolFailure();
|
|
839
|
+
}
|
|
840
|
+
this.buffered = this.buffered.subarray(length + 4);
|
|
841
|
+
}
|
|
842
|
+
return frames;
|
|
843
|
+
}
|
|
844
|
+
end() {
|
|
845
|
+
if (this.buffered.length !== 0) throw new ProtocolFailure();
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// packages/extension-scripts/src/platform/shell.ts
|
|
850
|
+
init_define_TACK_BUILD_INFO();
|
|
851
|
+
import { StringDecoder } from "node:string_decoder";
|
|
852
|
+
import { spawn } from "node:child_process";
|
|
853
|
+
var signalCommandTree = (pid, signal) => {
|
|
854
|
+
try {
|
|
855
|
+
process.kill(-pid, signal);
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (error instanceof Error && "code" in error && error.code === "ESRCH") return;
|
|
858
|
+
throw new ShellFailure({
|
|
859
|
+
operation: "termination",
|
|
860
|
+
message: "The command tree could not be terminated."
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
var makeLiveShell = (options) => ({
|
|
865
|
+
execute: (command) => Effect_exports.acquireUseRelease(
|
|
866
|
+
Effect_exports.try({
|
|
867
|
+
try: () => {
|
|
868
|
+
const child = spawn(command.executable, [...command.args], {
|
|
869
|
+
cwd: command.cwd ?? options.cwd,
|
|
870
|
+
env: { ...options.environment, ...command.env },
|
|
871
|
+
detached: true,
|
|
872
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
873
|
+
});
|
|
874
|
+
const pid = child.pid;
|
|
875
|
+
if (pid !== void 0) options.onStart(pid);
|
|
876
|
+
const stdoutDecoder = new StringDecoder("utf8");
|
|
877
|
+
const stderrDecoder = new StringDecoder("utf8");
|
|
878
|
+
let stdout = Buffer.alloc(0);
|
|
879
|
+
let stderr = Buffer.alloc(0);
|
|
880
|
+
let stdoutTruncated = false;
|
|
881
|
+
let stderrTruncated = false;
|
|
882
|
+
let closed = false;
|
|
883
|
+
let failure2;
|
|
884
|
+
const completion = new Promise((resolve, reject) => {
|
|
885
|
+
child.stdout.on("data", (chunk) => {
|
|
886
|
+
const decoded = stdoutDecoder.write(chunk);
|
|
887
|
+
if (decoded.length > 0) options.onOutput(decoded);
|
|
888
|
+
const remaining = executionLimits.valueBytes - stdout.length;
|
|
889
|
+
if (chunk.length > remaining) stdoutTruncated = true;
|
|
890
|
+
if (remaining > 0) stdout = Buffer.concat([stdout, chunk.subarray(0, remaining)]);
|
|
891
|
+
});
|
|
892
|
+
child.stderr.on("data", (chunk) => {
|
|
893
|
+
const decoded = stderrDecoder.write(chunk);
|
|
894
|
+
if (decoded.length > 0) options.onOutput(decoded);
|
|
895
|
+
const remaining = executionLimits.valueBytes - stderr.length;
|
|
896
|
+
if (chunk.length > remaining) stderrTruncated = true;
|
|
897
|
+
if (remaining > 0) stderr = Buffer.concat([stderr, chunk.subarray(0, remaining)]);
|
|
898
|
+
});
|
|
899
|
+
const ioFailure = () => {
|
|
900
|
+
failure2 = new ShellFailure({
|
|
901
|
+
operation: "io",
|
|
902
|
+
message: "The command streams could not be read."
|
|
903
|
+
});
|
|
904
|
+
if (pid !== void 0) {
|
|
905
|
+
try {
|
|
906
|
+
signalCommandTree(pid, "SIGKILL");
|
|
907
|
+
} catch (error) {
|
|
908
|
+
if (error instanceof ShellFailure) failure2 = error;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
child.stdout.once("error", ioFailure);
|
|
913
|
+
child.stderr.once("error", ioFailure);
|
|
914
|
+
child.once("error", () => {
|
|
915
|
+
failure2 = new ShellFailure({
|
|
916
|
+
operation: "spawn",
|
|
917
|
+
message: "The command could not be started."
|
|
918
|
+
});
|
|
919
|
+
});
|
|
920
|
+
child.once("close", (exitCode) => {
|
|
921
|
+
closed = true;
|
|
922
|
+
for (const tail of [stdoutDecoder.end(), stderrDecoder.end()]) {
|
|
923
|
+
if (tail.length > 0) options.onOutput(tail);
|
|
924
|
+
}
|
|
925
|
+
if (failure2 !== void 0) reject(failure2);
|
|
926
|
+
else if (exitCode === null)
|
|
927
|
+
reject(
|
|
928
|
+
new ShellFailure({
|
|
929
|
+
operation: "termination",
|
|
930
|
+
message: "The command terminated without an exit status."
|
|
931
|
+
})
|
|
932
|
+
);
|
|
933
|
+
else
|
|
934
|
+
resolve({
|
|
935
|
+
stdout: new StringDecoder("utf8").write(stdout),
|
|
936
|
+
stderr: new StringDecoder("utf8").write(stderr),
|
|
937
|
+
exitCode,
|
|
938
|
+
...stdoutTruncated === true ? { stdoutTruncated } : {},
|
|
939
|
+
...stderrTruncated === true ? { stderrTruncated } : {}
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
});
|
|
943
|
+
void completion.catch(() => void 0);
|
|
944
|
+
return { completion, pid, closed: () => closed };
|
|
945
|
+
},
|
|
946
|
+
catch: () => new ShellFailure({ operation: "spawn", message: "The command could not be started." })
|
|
947
|
+
}),
|
|
948
|
+
(owned) => Effect_exports.tryPromise({
|
|
949
|
+
try: () => owned.completion,
|
|
950
|
+
catch: (error) => error instanceof ShellFailure ? error : new ShellFailure({
|
|
951
|
+
operation: "io",
|
|
952
|
+
message: "The command streams could not be read."
|
|
953
|
+
})
|
|
954
|
+
}),
|
|
955
|
+
(owned) => Effect_exports.tryPromise({
|
|
956
|
+
try: async () => {
|
|
957
|
+
if (owned.pid === void 0) {
|
|
958
|
+
await owned.completion.catch(() => void 0);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const pid = owned.pid;
|
|
962
|
+
if (owned.closed() === true) {
|
|
963
|
+
signalCommandTree(pid, "SIGKILL");
|
|
964
|
+
options.onEnd(pid);
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
signalCommandTree(pid, "SIGTERM");
|
|
968
|
+
options.onOutput("Command interruption requested.\n");
|
|
969
|
+
let escalationFailure;
|
|
970
|
+
const escalation = setTimeout(() => {
|
|
971
|
+
try {
|
|
972
|
+
signalCommandTree(pid, "SIGKILL");
|
|
973
|
+
} catch (error) {
|
|
974
|
+
escalationFailure = error;
|
|
975
|
+
}
|
|
976
|
+
}, 1e3);
|
|
977
|
+
try {
|
|
978
|
+
await owned.completion.catch(() => void 0);
|
|
979
|
+
} finally {
|
|
980
|
+
clearTimeout(escalation);
|
|
981
|
+
signalCommandTree(pid, "SIGKILL");
|
|
982
|
+
options.onEnd(pid);
|
|
983
|
+
}
|
|
984
|
+
if (escalationFailure !== void 0) throw escalationFailure;
|
|
985
|
+
},
|
|
986
|
+
// Coverage skip: signalling this call's own process group fails only with ESRCH.
|
|
987
|
+
/* v8 ignore next -- @preserve */
|
|
988
|
+
catch: () => new ShellFailure({
|
|
989
|
+
operation: "termination",
|
|
990
|
+
message: "The command tree could not be terminated."
|
|
991
|
+
})
|
|
992
|
+
})
|
|
993
|
+
)
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
export {
|
|
997
|
+
Shell,
|
|
998
|
+
Secret,
|
|
999
|
+
defineScript,
|
|
1000
|
+
inspectScriptDefinition,
|
|
1001
|
+
encodeRunOutcome,
|
|
1002
|
+
ScriptError,
|
|
1003
|
+
runScript,
|
|
1004
|
+
EncodedRunOutcomeSchema,
|
|
1005
|
+
StartPayloadSchema,
|
|
1006
|
+
CapabilitiesPayloadSchema,
|
|
1007
|
+
ProtocolFailure,
|
|
1008
|
+
decodePayload,
|
|
1009
|
+
admitFrame,
|
|
1010
|
+
encodeFrame,
|
|
1011
|
+
FrameDecoder,
|
|
1012
|
+
signalCommandTree,
|
|
1013
|
+
makeLiveShell
|
|
1014
|
+
};
|
|
1015
|
+
/* v8 ignore next -- @preserve */
|
|
1016
|
+
/* v8 ignore start -- @preserve */
|
|
1017
|
+
/* v8 ignore stop -- @preserve */
|