@inhuman.tools/scheme-program 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/dist/emission.d.ts +10 -0
- package/dist/emission.d.ts.map +1 -0
- package/dist/emission.js +74 -0
- package/dist/emission.js.map +1 -0
- package/dist/eval.d.ts +7 -0
- package/dist/eval.d.ts.map +1 -0
- package/dist/eval.js +6 -0
- package/dist/eval.js.map +1 -0
- package/dist/evaluate.d.ts +90 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +316 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/failure.d.ts +10 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +30 -0
- package/dist/failure.js.map +1 -0
- package/dist/file-path.d.ts +9 -0
- package/dist/file-path.d.ts.map +1 -0
- package/dist/file-path.js +25 -0
- package/dist/file-path.js.map +1 -0
- package/dist/host.d.ts +55 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/notes.d.ts +12 -0
- package/dist/notes.d.ts.map +1 -0
- package/dist/notes.js +12 -0
- package/dist/notes.js.map +1 -0
- package/dist/open.d.ts +23 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +53 -0
- package/dist/open.js.map +1 -0
- package/dist/replay-eval.d.ts +5 -0
- package/dist/replay-eval.d.ts.map +1 -0
- package/dist/replay-eval.js +72 -0
- package/dist/replay-eval.js.map +1 -0
- package/dist/run.d.ts +4 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +81 -0
- package/dist/run.js.map +1 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +77 -0
- package/dist/runtime.js.map +1 -0
- package/dist/source-fs.d.ts +4 -0
- package/dist/source-fs.d.ts.map +1 -0
- package/dist/source-fs.js +36 -0
- package/dist/source-fs.js.map +1 -0
- package/dist/source.d.ts +22 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +76 -0
- package/dist/source.js.map +1 -0
- package/package.json +67 -3
- package/src/emission.ts +82 -0
- package/src/eval.ts +20 -0
- package/src/evaluate.ts +398 -0
- package/src/failure.ts +35 -0
- package/src/file-path.ts +27 -0
- package/src/host.ts +57 -0
- package/src/index.ts +8 -0
- package/src/notes.ts +15 -0
- package/src/open.ts +73 -0
- package/src/replay-eval.ts +84 -0
- package/src/run.ts +103 -0
- package/src/runtime.ts +99 -0
- package/src/source-fs.ts +35 -0
- package/src/source.ts +78 -0
- package/README.md +0 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path stamp on a `read_file` string. Identity-keyed: substring/append mint a
|
|
3
|
+
* new `AString` and drop it. `withProvenance` clones the same box — copy the
|
|
4
|
+
* stamp onto the clone. Not provenance.
|
|
5
|
+
*/
|
|
6
|
+
import { AString } from "@here.build/arrival/reflect-internals";
|
|
7
|
+
const paths = new WeakMap();
|
|
8
|
+
const originalWithProvenance = AString.prototype.withProvenance;
|
|
9
|
+
Object.defineProperty(AString.prototype, "withProvenance", {
|
|
10
|
+
value(p) {
|
|
11
|
+
const next = originalWithProvenance.call(this, p);
|
|
12
|
+
const path = paths.get(this);
|
|
13
|
+
if (path !== undefined && next instanceof AString)
|
|
14
|
+
paths.set(next, path);
|
|
15
|
+
return next;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export function stampFilePath(value, path) {
|
|
19
|
+
paths.set(value, path);
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
export function filePathOf(value) {
|
|
23
|
+
return value instanceof AString ? paths.get(value) : undefined;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=file-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-path.js","sourceRoot":"","sources":["../src/file-path.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAEhE,MAAM,KAAK,GAAG,IAAI,OAAO,EAAmB,CAAC;AAE7C,MAAM,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC;AAChE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,gBAAgB,EAAE;IACzD,KAAK,CAAgB,CAAsB;QACzC,MAAM,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,YAAY,OAAO;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,IAAY;IACxD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EnvCapability } from "@here.build/arrival";
|
|
2
|
+
import type { EvalTrace } from "@here.build/arrival/provenance";
|
|
3
|
+
import type { AgentCallNotification, ApprovableJob, ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
4
|
+
import type { BoundTool } from "@inhuman.tools/substrate/bound-tool";
|
|
5
|
+
import type { DoorSession } from "@inhuman.tools/substrate/doors";
|
|
6
|
+
export type PreparedProgram = {
|
|
7
|
+
readonly capabilities: readonly EnvCapability[];
|
|
8
|
+
readonly config: object;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* What the interpreter needs from an engine. Catalog, secrets, and tool bodies
|
|
12
|
+
* stay in the capabilities `prepare` returns. This package does not look them up.
|
|
13
|
+
*/
|
|
14
|
+
export type ProgramHost = {
|
|
15
|
+
/** Stable across wrappers. The runtime map keys on this, not on the wrapper. */
|
|
16
|
+
readonly identity: object;
|
|
17
|
+
readonly signal?: AbortSignal;
|
|
18
|
+
readonly doors: DoorSession;
|
|
19
|
+
readonly root: string;
|
|
20
|
+
readonly abort?: (leaf: ApprovableJob, reason?: unknown) => void;
|
|
21
|
+
readonly notify?: (note: AgentCallNotification) => void;
|
|
22
|
+
readonly evalProgram?: boolean;
|
|
23
|
+
readonly moduleRoot?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Wraps one run of the program (the whole one-shot, or one period tick) so the host owns its trace.
|
|
26
|
+
* The host mints the trace, arms what it reads, and reads it as the run goes; when `run` settles, the run is over.
|
|
27
|
+
*/
|
|
28
|
+
readonly observe?: <T>(run: (trace: EvalTrace) => Promise<T>) => Promise<T>;
|
|
29
|
+
/** Unbound-variable door. Called per evaluation; `prepare` snapshots tools onto config separately. */
|
|
30
|
+
readonly tools: () => ReadonlyMap<string, BoundTool>;
|
|
31
|
+
/** Engine vocabulary. The interpreter appends display. The watchdog wraps this to append meta-reactivity. */
|
|
32
|
+
readonly prepare: (opts: {
|
|
33
|
+
readonly moduleRoot: string | undefined;
|
|
34
|
+
readonly job: ProgrammaticJob;
|
|
35
|
+
}) => PreparedProgram;
|
|
36
|
+
/** Read recorded children. Do not mint, do not append notes, do not seal the job. */
|
|
37
|
+
readonly replayOnly?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type ProgramRuntime = {
|
|
40
|
+
arm(opts: {
|
|
41
|
+
readonly moduleRoot: string | undefined;
|
|
42
|
+
/** Accepted so existing arm calls typecheck. The watchdog roots meta-reactivity by wrapping prepare. */
|
|
43
|
+
readonly watching?: boolean;
|
|
44
|
+
}): void;
|
|
45
|
+
beginTick(tick: {
|
|
46
|
+
readonly signal: AbortSignal;
|
|
47
|
+
readonly origin: number;
|
|
48
|
+
readonly maxInternalCalls: number | undefined;
|
|
49
|
+
}): void;
|
|
50
|
+
clearFailure(): void;
|
|
51
|
+
failureCode(): string | undefined;
|
|
52
|
+
readonly capabilities: readonly EnvCapability[];
|
|
53
|
+
readonly config: object;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAA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G,SAAS,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,CAAC;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
package/dist/host.js
ADDED
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { appendNotify, failureCodeOf, SchemeReplToolFailure } from "./failure.js";
|
|
2
|
+
export { filePathOf, stampFilePath } from "./file-path.js";
|
|
3
|
+
export { type ProgramHost, type ProgramRuntime } from "./host.js";
|
|
4
|
+
export { SCHEME_REPL_DISPLAY_NOTE } from "./notes.js";
|
|
5
|
+
export { replayEvaluation } from "./replay-eval.js";
|
|
6
|
+
export { runProgram } from "./run.js";
|
|
7
|
+
export { detachedRuntime, programRuntimeOf } from "./runtime.js";
|
|
8
|
+
export { recordedModuleLoader } from "./source.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { appendNotify, failureCodeOf, SchemeReplToolFailure } from "./failure.js";
|
|
2
|
+
export { filePathOf, stampFilePath } from "./file-path.js";
|
|
3
|
+
export { SCHEME_REPL_DISPLAY_NOTE } from "./notes.js";
|
|
4
|
+
export { replayEvaluation } from "./replay-eval.js";
|
|
5
|
+
export { runProgram } from "./run.js";
|
|
6
|
+
export { detachedRuntime, programRuntimeOf } from "./runtime.js";
|
|
7
|
+
export { recordedModuleLoader } from "./source.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/notes.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Own tool text part per spliced wrapper spelling. Not a statement value. */
|
|
2
|
+
export declare const SCHEME_REPL_UNWRAP_NOTES: {
|
|
3
|
+
readonly begin: ";; unwrapped (begin …): each statement is returned as its own result. Write consecutive top-level forms.";
|
|
4
|
+
readonly list: ";; unwrapped (list …): each statement is returned as its own result. Write consecutive top-level forms.";
|
|
5
|
+
readonly vector: ";; unwrapped []: each statement is returned as its own result. Write consecutive top-level forms.";
|
|
6
|
+
};
|
|
7
|
+
/** Attached to a top-level statement that was a `(display X)` — the rewrite unwrapped it to X and
|
|
8
|
+
* X's value IS the answer block, so this teaches that the display spelling was unnecessary:
|
|
9
|
+
* scheme_repl already returns each top-level statement as its own tool response. scheme_watch is
|
|
10
|
+
* repl-only and does not surface per-statement responses, so it does not attach this note. */
|
|
11
|
+
export declare const SCHEME_REPL_DISPLAY_NOTE = ";; you do not need to use (display ...) \u2014 each top-level statement of scheme_repl is written as a tool response";
|
|
12
|
+
//# sourceMappingURL=notes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.d.ts","sourceRoot":"","sources":["../src/notes.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,eAAO,MAAM,wBAAwB;;;;CAIc,CAAC;AAEpD;;;+FAG+F;AAC/F,eAAO,MAAM,wBAAwB,yHAC8E,CAAC"}
|
package/dist/notes.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Own tool text part per spliced wrapper spelling. Not a statement value. */
|
|
2
|
+
export const SCHEME_REPL_UNWRAP_NOTES = {
|
|
3
|
+
begin: ";; unwrapped (begin …): each statement is returned as its own result. Write consecutive top-level forms.",
|
|
4
|
+
list: ";; unwrapped (list …): each statement is returned as its own result. Write consecutive top-level forms.",
|
|
5
|
+
vector: ";; unwrapped []: each statement is returned as its own result. Write consecutive top-level forms.",
|
|
6
|
+
};
|
|
7
|
+
/** Attached to a top-level statement that was a `(display X)` — the rewrite unwrapped it to X and
|
|
8
|
+
* X's value IS the answer block, so this teaches that the display spelling was unnecessary:
|
|
9
|
+
* scheme_repl already returns each top-level statement as its own tool response. scheme_watch is
|
|
10
|
+
* repl-only and does not surface per-statement responses, so it does not attach this note. */
|
|
11
|
+
export const SCHEME_REPL_DISPLAY_NOTE = ";; you do not need to use (display ...) — each top-level statement of scheme_repl is written as a tool response";
|
|
12
|
+
//# sourceMappingURL=notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.js","sourceRoot":"","sources":["../src/notes.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE,0GAA0G;IACjH,IAAI,EAAE,yGAAyG;IAC/G,MAAM,EAAE,mGAAmG;CAC1D,CAAC;AAEpD;;;+FAG+F;AAC/F,MAAM,CAAC,MAAM,wBAAwB,GACnC,iHAAiH,CAAC"}
|
package/dist/open.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SchemeValue } from "@here.build/arrival";
|
|
2
|
+
import { ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
3
|
+
import { type TopLevelSplice } from "@inhuman.tools/substrate/unwrap-begin";
|
|
4
|
+
import type { ProgramHost } from "./host.js";
|
|
5
|
+
import { type ProgramSource } from "./source.js";
|
|
6
|
+
export type OpenedProgram = {
|
|
7
|
+
readonly forms: readonly SchemeValue[];
|
|
8
|
+
readonly kinds: readonly TopLevelSplice[];
|
|
9
|
+
readonly timeoutMs: number | undefined;
|
|
10
|
+
readonly maxInternalCalls: number | undefined;
|
|
11
|
+
readonly periodMs: number | undefined;
|
|
12
|
+
readonly source: ProgramSource;
|
|
13
|
+
/** Jail root for a one-shot, including `sourcePath`'s directory. */
|
|
14
|
+
readonly moduleRoot: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
/** Schema already accepted. Seals empty expr, a source without a path, and a program that does not parse. */
|
|
17
|
+
export declare function openProgram(chunk: ProgrammaticJob, host: ProgramHost, data: {
|
|
18
|
+
readonly expr: string;
|
|
19
|
+
readonly timeoutMs?: number;
|
|
20
|
+
readonly maxInternalCalls?: number;
|
|
21
|
+
readonly period?: string;
|
|
22
|
+
}, seal?: boolean): Promise<OpenedProgram | undefined>;
|
|
23
|
+
//# sourceMappingURL=open.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":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_REPL_NAMING, SCHEME_REPL_TOOL_NAME } from "@inhuman.tools/harness-model";
|
|
3
|
+
import { emptyExprDoor, isUnterminatedDictLiteral, unterminatedDictDoor } from "@inhuman.tools/substrate/doors";
|
|
4
|
+
import { unwrapTopLevel } from "@inhuman.tools/substrate/unwrap-begin";
|
|
5
|
+
import { errorText, fail, sealChunk } from "./evaluate.js";
|
|
6
|
+
import { moduleRootOf, programSourceOf } from "./source.js";
|
|
7
|
+
function cappedCalls(value) {
|
|
8
|
+
if (value == null)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (!Number.isFinite(value))
|
|
11
|
+
return 1;
|
|
12
|
+
return Math.max(1, Math.floor(value));
|
|
13
|
+
}
|
|
14
|
+
/** Schema already accepted. Seals empty expr, a source without a path, and a program that does not parse. */
|
|
15
|
+
export async function openProgram(chunk, host, data, seal = true) {
|
|
16
|
+
const refuse = (result) => {
|
|
17
|
+
if (seal)
|
|
18
|
+
sealChunk(chunk, result);
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
21
|
+
if (data.expr.trim() === "") {
|
|
22
|
+
return refuse(fail(host.doors.render(emptyExprDoor(SCHEME_REPL_NAMING), SCHEME_REPL_TOOL_NAME)));
|
|
23
|
+
}
|
|
24
|
+
const source = programSourceOf(chunk.args, host.evalProgram === true);
|
|
25
|
+
if (source.source != null && source.sourcePath == null) {
|
|
26
|
+
return refuse(fail("Error: source requires sourcePath"));
|
|
27
|
+
}
|
|
28
|
+
let forms;
|
|
29
|
+
let kinds = [];
|
|
30
|
+
try {
|
|
31
|
+
const unwrapped = unwrapTopLevel(await parse(data.expr));
|
|
32
|
+
forms = unwrapped.forms;
|
|
33
|
+
kinds = unwrapped.kinds;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
const text = errorText(error);
|
|
37
|
+
if (isUnterminatedDictLiteral(text)) {
|
|
38
|
+
return refuse(fail(host.doors.render(unterminatedDictDoor(), SCHEME_REPL_TOOL_NAME)));
|
|
39
|
+
}
|
|
40
|
+
return refuse(fail(text));
|
|
41
|
+
}
|
|
42
|
+
const periodMs = typeof data.period === "string" ? periodMsOf(data.period) : undefined;
|
|
43
|
+
return {
|
|
44
|
+
forms,
|
|
45
|
+
kinds,
|
|
46
|
+
timeoutMs: data.timeoutMs,
|
|
47
|
+
maxInternalCalls: cappedCalls(data.maxInternalCalls),
|
|
48
|
+
periodMs,
|
|
49
|
+
source,
|
|
50
|
+
moduleRoot: moduleRootOf(source.sourcePath, host.moduleRoot, host.root),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=open.js.map
|
package/dist/open.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.js","sourceRoot":"","sources":["../src/open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAoB,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAmB,UAAU,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAChH,OAAO,EAAuB,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE5F,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAsB,MAAM,aAAa,CAAC;AAahF,SAAS,WAAW,CAAC,KAAyB;IAC5C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACxC,CAAC;AAED,6GAA6G;AAC7G,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAsB,EAC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ACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5B,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvF,OAAO;QACL,KAAK;QACL,KAAK;QACL,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,gBAAgB,EAAE,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC;QACpD,QAAQ;QACR,MAAM;QACN,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;KACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EvalTrace } from "@here.build/arrival/provenance";
|
|
2
|
+
import { ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
3
|
+
import type { ProgramHost } from "./host.js";
|
|
4
|
+
export declare function replayEvaluation(job: ProgrammaticJob, host: ProgramHost, trace: EvalTrace): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=replay-eval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-eval.d.ts","sourceRoot":"","sources":["../src/replay-eval.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAsC,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAMnG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAwD7C,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAe/G"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-run a program against the children it already minted. Does not seal the
|
|
3
|
+
* job, does not append notes, and does not move the watch cursor.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from "@here.build/arrival";
|
|
6
|
+
import { crossingEpoch, crossingOriginAfter } from "@inhuman.tools/harness-model";
|
|
7
|
+
import { callArgsSchema } from "@inhuman.tools/harness-model/schemas";
|
|
8
|
+
import { unwrapTopLevelBegins } from "@inhuman.tools/substrate/unwrap-begin";
|
|
9
|
+
import { when } from "mobx";
|
|
10
|
+
import { evaluateForms, observed } from "./evaluate.js";
|
|
11
|
+
import { openProgram } from "./open.js";
|
|
12
|
+
import { detachedRuntime } from "./runtime.js";
|
|
13
|
+
async function once(job, host, opened, runtime, trace) {
|
|
14
|
+
const limits = { timeoutMs: undefined, maxInternalCalls: opened.maxInternalCalls, trace };
|
|
15
|
+
const sourceText = opened.source.source;
|
|
16
|
+
if (sourceText == null) {
|
|
17
|
+
await evaluateForms(job, host, opened.forms, { kind: "once", ...limits }, runtime);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const sourceForms = unwrapTopLevelBegins(await parse(sourceText));
|
|
21
|
+
const shared = { signal: host.signal ?? new AbortController().signal };
|
|
22
|
+
const loaded = await evaluateForms(job, host, sourceForms, { kind: "source-load", ...limits, shared }, runtime);
|
|
23
|
+
if (loaded.kind !== "ok")
|
|
24
|
+
return;
|
|
25
|
+
await evaluateForms(job, host, opened.forms, { kind: "source-body", ...limits, shared }, runtime);
|
|
26
|
+
}
|
|
27
|
+
async function periods(job, host, opened, runtime, trace) {
|
|
28
|
+
const limits = { timeoutMs: undefined, maxInternalCalls: opened.maxInternalCalls, trace };
|
|
29
|
+
let origin = 0;
|
|
30
|
+
while (host.signal?.aborted !== true) {
|
|
31
|
+
if ((job.completed || job.cancelled) && origin >= job.toolCalls.length)
|
|
32
|
+
return;
|
|
33
|
+
const before = job.toolCalls.length;
|
|
34
|
+
const epoch = crossingEpoch(job, origin);
|
|
35
|
+
await evaluateForms(job, host, opened.forms, { kind: "period", tick: { origin }, ...limits }, runtime);
|
|
36
|
+
const next = crossingOriginAfter(job, origin, epoch);
|
|
37
|
+
if (next > origin) {
|
|
38
|
+
origin = next;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (job.completed || job.cancelled || before < job.toolCalls.length)
|
|
42
|
+
return;
|
|
43
|
+
const joined = when(() => host.signal?.aborted === true || job.completed || job.cancelled || job.toolCalls.length > before);
|
|
44
|
+
try {
|
|
45
|
+
await joined;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
joined.cancel();
|
|
49
|
+
}
|
|
50
|
+
if (job.toolCalls.length === before)
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function replayEvaluation(job, host, trace) {
|
|
55
|
+
const parsed = callArgsSchema.safeParse(job.args);
|
|
56
|
+
if (!parsed.success)
|
|
57
|
+
return;
|
|
58
|
+
const opened = await openProgram(job, host, parsed.data, false);
|
|
59
|
+
if (opened == null)
|
|
60
|
+
return;
|
|
61
|
+
const runtime = detachedRuntime(job, host);
|
|
62
|
+
runtime.arm({ watching: opened.periodMs != null, moduleRoot: opened.moduleRoot });
|
|
63
|
+
await observed(host, async (live) => {
|
|
64
|
+
const tap = live ?? trace;
|
|
65
|
+
if (opened.periodMs == null) {
|
|
66
|
+
await once(job, host, opened, runtime, tap);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await periods(job, host, opened, runtime, tap);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=replay-eval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-eval.js","sourceRoot":"","sources":["../src/replay-eval.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAmB,MAAM,8BAA8B,CAAC;AACnG,OAAO,EAAE,cAAc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GAAG,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAiB/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAQ7C,wBAAsB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAwEzF"}
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot Scheme program. The host passes the vocabulary. `period` is rejected
|
|
3
|
+
* here; ongoing evaluation is the watchdog.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from "@here.build/arrival";
|
|
6
|
+
import { callArgsSchema, REPL_PERIOD_ERR } from "@inhuman.tools/harness-model/schemas";
|
|
7
|
+
import { unwrapTopLevelBegins } from "@inhuman.tools/substrate/unwrap-begin";
|
|
8
|
+
import { createEvaluationTimeout, displayPrinted, errorText, evaluateForms, fail, guardProgram, observed, printedValues, sealChunk, } from "./evaluate.js";
|
|
9
|
+
import { openProgram } from "./open.js";
|
|
10
|
+
import { programRuntimeOf } from "./runtime.js";
|
|
11
|
+
function rawHasPeriod(raw) {
|
|
12
|
+
return raw !== null && typeof raw === "object" && "period" in raw;
|
|
13
|
+
}
|
|
14
|
+
export async function runProgram(chunk, host) {
|
|
15
|
+
await guardProgram(chunk, host, async () => {
|
|
16
|
+
const rawArgs = chunk.args;
|
|
17
|
+
if (rawHasPeriod(rawArgs)) {
|
|
18
|
+
sealChunk(chunk, fail(`Error: ${REPL_PERIOD_ERR}`));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const parsed = callArgsSchema.safeParse(rawArgs);
|
|
22
|
+
if (!parsed.success) {
|
|
23
|
+
const issue = parsed.error.issues[0]?.message ?? "invalid arguments";
|
|
24
|
+
sealChunk(chunk, fail(`Error: ${issue}`));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const opened = await openProgram(chunk, host, parsed.data);
|
|
28
|
+
if (opened == null)
|
|
29
|
+
return;
|
|
30
|
+
const runtime = programRuntimeOf(chunk, host);
|
|
31
|
+
runtime.arm({ watching: false, moduleRoot: opened.moduleRoot });
|
|
32
|
+
const sourceText = opened.source.source;
|
|
33
|
+
let sourceForms;
|
|
34
|
+
if (sourceText != null) {
|
|
35
|
+
try {
|
|
36
|
+
sourceForms = unwrapTopLevelBegins(await parse(sourceText));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
sealChunk(chunk, fail(errorText(error)));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const limits = { timeoutMs: opened.timeoutMs, maxInternalCalls: opened.maxInternalCalls };
|
|
44
|
+
const outcome = await observed(host, async (trace) => {
|
|
45
|
+
if (sourceForms === undefined) {
|
|
46
|
+
return evaluateForms(chunk, host, opened.forms, { kind: "once", ...limits, trace }, runtime);
|
|
47
|
+
}
|
|
48
|
+
const timeout = createEvaluationTimeout(host.signal, opened.timeoutMs);
|
|
49
|
+
const shared = { signal: timeout.signal };
|
|
50
|
+
try {
|
|
51
|
+
const loaded = await evaluateForms(chunk, host, sourceForms, { kind: "source-load", ...limits, shared, trace }, runtime);
|
|
52
|
+
return loaded.kind === "ok"
|
|
53
|
+
? await evaluateForms(chunk, host, opened.forms, { kind: "source-body", ...limits, shared, trace }, runtime)
|
|
54
|
+
: loaded;
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
timeout.dispose();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (outcome.kind === "park")
|
|
61
|
+
return;
|
|
62
|
+
if (outcome.kind === "halt") {
|
|
63
|
+
sealChunk(chunk, outcome.result);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (outcome.kind === "fail") {
|
|
67
|
+
sealChunk(chunk, fail(outcome.values.map(displayPrinted).join("\n\n"), outcome.code));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const sealed = {
|
|
71
|
+
ok: true,
|
|
72
|
+
value: printedValues(outcome.values, opened.kinds),
|
|
73
|
+
};
|
|
74
|
+
if (outcome.jsonError != null)
|
|
75
|
+
sealed.jsonError = outcome.jsonError;
|
|
76
|
+
else if ("json" in outcome)
|
|
77
|
+
sealed.json = outcome.json;
|
|
78
|
+
sealChunk(chunk, sealed);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAoB,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,SAAS,EACT,aAAa,EACb,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,SAAS,GAGV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,QAAQ,IAAI,GAAG,CAAC;AACpE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAsB,EAAE,IAAiB;IACxE,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,I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CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACjC,OAAO;QACT,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5B,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YACtF,OAAO;QACT,CAAC;QACD,MAAM,MAAM,GAKR;YACF,EAAE,EAAE,IAAI;YACR,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;SACnD,CAAC;QACF,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI;YAAE,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;aAC/D,IAAI,MAAM,IAAI,OAAO;YAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACvD,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
2
|
+
import type { ProgramHost, ProgramRuntime } from "./host.js";
|
|
3
|
+
/** One runtime per job. A new host is legal only after the previous signal parked. The first prepare wins. */
|
|
4
|
+
export declare function programRuntimeOf(job: ProgrammaticJob, host: ProgramHost): ProgramRuntime;
|
|
5
|
+
/** A second host reading the same job (the browser's replay) must not take the daemon's runtime. */
|
|
6
|
+
export declare function detachedRuntime(job: ProgrammaticJob, host: ProgramHost): ProgramRuntime;
|
|
7
|
+
export { type ProgramRuntime } from "./host.js";
|
|
8
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAIpE,OAAO,KAAK,EAAmB,WAAW,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAuE9E,8GAA8G;AAC9G,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,cAAc,CAcxF;AAED,oGAAoG;AACpG,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,GAAG,cAAc,CAEvF;AAED,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EnvCapability } from "@here.build/arrival";
|
|
2
|
+
import { DISPLAY_INTERNAL, displaySymbol } from "@inhuman.tools/substrate";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
4
|
+
/** `(display …)` is a host verb. Arrival has no IO; the runner rewrites the call onto this symbol. */
|
|
5
|
+
const displayCapability = EnvCapability.define("harness/scheme-repl-display", {
|
|
6
|
+
symbols: () => ({
|
|
7
|
+
[DISPLAY_INTERNAL]: displaySymbol(),
|
|
8
|
+
}),
|
|
9
|
+
});
|
|
10
|
+
const runtimes = new WeakMap();
|
|
11
|
+
function runtimeFor(job, host) {
|
|
12
|
+
const rig = {
|
|
13
|
+
signal: new AbortController().signal,
|
|
14
|
+
origin: 0,
|
|
15
|
+
replayAt: 0,
|
|
16
|
+
formAt: 0,
|
|
17
|
+
maxInternalCalls: undefined,
|
|
18
|
+
failureCode: undefined,
|
|
19
|
+
};
|
|
20
|
+
let armed;
|
|
21
|
+
const view = () => {
|
|
22
|
+
if (armed === undefined)
|
|
23
|
+
throw new Error("scheme-repl: arm the runtime before evaluating");
|
|
24
|
+
return armed;
|
|
25
|
+
};
|
|
26
|
+
const runtime = {
|
|
27
|
+
arm(opts) {
|
|
28
|
+
if (armed !== undefined)
|
|
29
|
+
return;
|
|
30
|
+
const prepared = host.prepare({ moduleRoot: opts.moduleRoot, job });
|
|
31
|
+
armed = {
|
|
32
|
+
capabilities: [...prepared.capabilities, displayCapability],
|
|
33
|
+
config: { ...prepared.config, job, rig },
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
beginTick(tick) {
|
|
37
|
+
rig.signal = tick.signal;
|
|
38
|
+
rig.origin = tick.origin;
|
|
39
|
+
rig.replayAt = tick.origin;
|
|
40
|
+
rig.maxInternalCalls = tick.maxInternalCalls;
|
|
41
|
+
rig.failureCode = undefined;
|
|
42
|
+
},
|
|
43
|
+
clearFailure() {
|
|
44
|
+
rig.formAt = job.toolCalls.length;
|
|
45
|
+
rig.failureCode = undefined;
|
|
46
|
+
},
|
|
47
|
+
failureCode() {
|
|
48
|
+
return rig.failureCode;
|
|
49
|
+
},
|
|
50
|
+
get capabilities() {
|
|
51
|
+
return view().capabilities;
|
|
52
|
+
},
|
|
53
|
+
get config() {
|
|
54
|
+
return view().config;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
return runtime;
|
|
58
|
+
}
|
|
59
|
+
/** One runtime per job. A new host is legal only after the previous signal parked. The first prepare wins. */
|
|
60
|
+
export function programRuntimeOf(job, host) {
|
|
61
|
+
const existing = runtimes.get(job);
|
|
62
|
+
if (existing !== undefined) {
|
|
63
|
+
if (existing.identity === host.identity)
|
|
64
|
+
return existing.runtime;
|
|
65
|
+
const stale = existing.signal;
|
|
66
|
+
invariant(stale != null && stale.aborted && stale.reason === "park", "scheme-repl: ProgrammaticJob rebound to a different host");
|
|
67
|
+
runtimes.delete(job);
|
|
68
|
+
}
|
|
69
|
+
const runtime = runtimeFor(job, host);
|
|
70
|
+
runtimes.set(job, { identity: host.identity, signal: host.signal, runtime });
|
|
71
|
+
return runtime;
|
|
72
|
+
}
|
|
73
|
+
/** A second host reading the same job (the browser's replay) must not take the daemon's runtime. */
|
|
74
|
+
export function detachedRuntime(job, host) {
|
|
75
|
+
return runtimeFor(job,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,CAAC,MAAM,KAAK,MAAM,EACzD,0DAA0D,CAC3D,CAAC;QACF,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACtC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,eAAe,CAAC,GAAoB,EAAE,IAAiB;IACrE,OAAO,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-fs.d.ts","sourceRoot":"","sources":["../src/source-fs.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAGpE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,eAAe,GAAG,MAAM,CAwB/E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disk `require` jail. Replay never imports this: it reads `job.modules`.
|
|
3
|
+
*/
|
|
4
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
5
|
+
import { join as posixJoin } from "node:path/posix";
|
|
6
|
+
import { makeFsLoader } from "@here.build/arrival-modules";
|
|
7
|
+
import { runInAction } from "mobx";
|
|
8
|
+
export function programSourceLoader(root, job) {
|
|
9
|
+
return makeFsLoader({
|
|
10
|
+
async readFile(key) {
|
|
11
|
+
if (job !== undefined) {
|
|
12
|
+
const recorded = job.modules[key];
|
|
13
|
+
if (recorded !== undefined)
|
|
14
|
+
return recorded;
|
|
15
|
+
}
|
|
16
|
+
const abs = posixJoin(root, key);
|
|
17
|
+
const realRoot = await realpath(root);
|
|
18
|
+
let real;
|
|
19
|
+
try {
|
|
20
|
+
real = await realpath(abs);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error(`no such file: ${key}`);
|
|
24
|
+
}
|
|
25
|
+
const prefix = realRoot.endsWith("/") ? realRoot : `${realRoot}/`;
|
|
26
|
+
if (real !== realRoot && !real.startsWith(prefix)) {
|
|
27
|
+
throw new Error(`require path escapes program source root: ${key}`);
|
|
28
|
+
}
|
|
29
|
+
const text = await readFile(real, "utf8");
|
|
30
|
+
if (job !== undefined)
|
|
31
|
+
runInAction(() => (job.modules[key] = text));
|
|
32
|
+
return text;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=source-fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-fs.js","sourceRoot":"","sources":["../src/source-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAe,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,GAAqB;IACrE,OAAO,YAAY,CAAC;QAClB,KAAK,CAAC,QAAQ,CAAC,GAAW;YACxB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,QAAQ,KAAK,SAAS;oBAAE,OAAO,QAAQ,CAAC;YAC9C,CAAC;YACD,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,IAAY,CAAC;YACjB,IAAI,CAAC;gBACH,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC7B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,EAAE,CAAC,CAAC;YAC1C,CAAC;YACD,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC;YAClE,IAAI,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,6CAA6C,GAAG,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC1C,IAAI,GAAG,KAAK,SAAS;gBAAE,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module `require` jail. Eval with `sourcePath` stays under the entry file's
|
|
3
|
+
* directory. Interactive `scheme_repl` / `scheme_watch` jail at the workspace
|
|
4
|
+
* (`host.root`). Skill inputs stay on licensed `read_file`.
|
|
5
|
+
*/
|
|
6
|
+
import { type SchemeValue } from "@here.build/arrival";
|
|
7
|
+
import { type Loader } from "@here.build/arrival-modules";
|
|
8
|
+
import type { ProgrammaticJob } from "@inhuman.tools/harness-model";
|
|
9
|
+
export type ProgramSource = {
|
|
10
|
+
readonly source?: string;
|
|
11
|
+
readonly sourcePath?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function programSourceOf(raw: unknown, allow: boolean): ProgramSource;
|
|
14
|
+
export declare function moduleRootOf(sourcePath: string | undefined, override?: string, workspaceRoot?: string): string | undefined;
|
|
15
|
+
/** Replay read. The live loader records the same key the first time it touches disk. */
|
|
16
|
+
export declare function recordedModuleLoader(job: ProgrammaticJob): Loader;
|
|
17
|
+
/** Objects/arrays become the additive `json` sibling. Scalars stay display-only. */
|
|
18
|
+
export declare function structuredJson(value: SchemeValue): {
|
|
19
|
+
json?: unknown;
|
|
20
|
+
jsonError?: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,aAAa,CAO3E;AAQD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,CAAC,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,GAAG,SAAS,CAKpB;AAED,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAQjE;AAiBD,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAUzF"}
|