@inhuman.tools/env-capability-module-prompt 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 ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Merkle Bonsai
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * One rendered `.prompt` call, and the host port for an isolated completion.
3
+ * A ProgrammaticJob parents an omitted-spec AgentCallJob instead of calling the port.
4
+ */
5
+ import type { ReasoningEffort } from "@inhuman.tools/env-capability-dotprompt";
6
+ import type { CompletionExpectation, PromptMessageRole } from "@inhuman.tools/harness-model";
7
+ /** Session/research intern port. Homed `round` is mutated in place. `responseSchemaJson` is the serialized schema, matching CompleteFields. */
8
+ export type PromptCompleteRequest = {
9
+ readonly connectionId: string;
10
+ readonly model: string;
11
+ readonly promptText?: string;
12
+ readonly responseSchemaJson?: string;
13
+ readonly signal?: AbortSignal;
14
+ readonly round: CompletionExpectation;
15
+ };
16
+ export type PromptComplete = (req: PromptCompleteRequest) => Promise<{
17
+ readonly text: string;
18
+ readonly thought?: string;
19
+ readonly thoughtKind?: string;
20
+ }>;
21
+ export declare class RenderedPrompt {
22
+ readonly model: string | null;
23
+ readonly reasoningEffort: ReasoningEffort | null;
24
+ readonly responseSchema: Record<string, unknown> | null;
25
+ readonly faceName: string;
26
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
27
+ readonly tools: readonly string[] | null;
28
+ readonly messages: readonly [PromptMessageRole, string][];
29
+ constructor(model: string | null, reasoningEffort: ReasoningEffort | null, responseSchema: Record<string, unknown> | null, faceName: string,
30
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
31
+ tools: readonly string[] | null, messages: readonly [PromptMessageRole, string][]);
32
+ }
33
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAE7F,+IAA+I;AAC/I,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,qBAAqB,KACvB,OAAO,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAElG,qBAAa,cAAc;aAEP,KAAK,EAAE,MAAM,GAAG,IAAI;aACpB,eAAe,EAAE,eAAe,GAAG,IAAI;aACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;aAC9C,QAAQ,EAAE,MAAM;IAChC,oFAAoF;aACpE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;aAC/B,QAAQ,EAAE,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC,EAAE;gBANhD,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,eAAe,EAAE,eAAe,GAAG,IAAI,EACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC9C,QAAQ,EAAE,MAAM;IAChC,oFAAoF;IACpE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EAC/B,QAAQ,EAAE,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC,EAAE;CAEnE"}
package/dist/bundle.js ADDED
@@ -0,0 +1,19 @@
1
+ export class RenderedPrompt {
2
+ model;
3
+ reasoningEffort;
4
+ responseSchema;
5
+ faceName;
6
+ tools;
7
+ messages;
8
+ constructor(model, reasoningEffort, responseSchema, faceName,
9
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
10
+ tools, messages) {
11
+ this.model = model;
12
+ this.reasoningEffort = reasoningEffort;
13
+ this.responseSchema = responseSchema;
14
+ this.faceName = faceName;
15
+ this.tools = tools;
16
+ this.messages = messages;
17
+ }
18
+ }
19
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,cAAc;IAEP;IACA;IACA;IACA;IAEA;IACA;IAPlB,YACkB,KAAoB,EACpB,eAAuC,EACvC,cAA8C,EAC9C,QAAgB;IAChC,oFAAoF;IACpE,KAA+B,EAC/B,QAAgD;QANhD,UAAK,GAAL,KAAK,CAAe;QACpB,oBAAe,GAAf,eAAe,CAAwB;QACvC,mBAAc,GAAd,cAAc,CAAgC;QAC9C,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,UAAK,GAAL,KAAK,CAA0B;QAC/B,aAAQ,GAAR,QAAQ,CAAwC;IAC/D,CAAC;CACL"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `ext/prompt` — `.prompt` require pretreats to a scheme lambda over
3
+ * `dotprompt/run`. The pretreat is the prelude procedure `ext/prompt/resolve`.
4
+ * CALLABLE RULE: never a JS function through `jsToScheme`.
5
+ *
6
+ * A ProgrammaticJob parents an omitted-spec AgentCallJob (AskAgentSpec worker,
7
+ * schema on the Call, ReACT until respond). Any other job keeps an isolated
8
+ * CompletionExpectation (classifier, compact).
9
+ */
10
+ import { EnvCapability } from "@inhuman.tools/arrival";
11
+ import { Job } from "@inhuman.tools/plexus-expectations";
12
+ import { z } from "zod";
13
+ import { type PromptCompleteRequest } from "./bundle.js";
14
+ export declare const promptCapability: EnvCapability<{
15
+ job: z.ZodOptional<z.ZodCustom<Job, Job>>;
16
+ connectionId: z.ZodOptional<z.ZodString>;
17
+ model: z.ZodOptional<z.ZodString>;
18
+ /** Session/judge model. `model` is reserved by some exec hosts. */
19
+ completionModel: z.ZodOptional<z.ZodString>;
20
+ complete: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodType<PromptCompleteRequest, unknown, z.core.$ZodTypeInternals<PromptCompleteRequest, unknown>>], z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | null>, z.ZodType<Promise<{
21
+ readonly text: string;
22
+ readonly thought?: string;
23
+ readonly thoughtKind?: string;
24
+ }>, unknown, z.core.$ZodTypeInternals<Promise<{
25
+ readonly text: string;
26
+ readonly thought?: string;
27
+ readonly thoughtKind?: string;
28
+ }>, unknown>>>>;
29
+ readonly: z.ZodOptional<z.ZodBoolean>;
30
+ }, Record<string, never>>;
31
+ //# sourceMappingURL=capability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAA0B,MAAM,wBAAwB,CAAC;AAc/E,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AAMzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,aAAa,CAAC;AAiBzE,eAAO,MAAM,gBAAgB;;;;IAMzB,mEAAmE;;;uBAK5B,MAAM;2BAAqB,MAAM;+BAAyB,MAAM;;uBAAhE,MAAM;2BAAqB,MAAM;+BAAyB,MAAM;;;yBA8QzG,CAAC"}
@@ -0,0 +1,262 @@
1
+ /**
2
+ * `ext/prompt` — `.prompt` require pretreats to a scheme lambda over
3
+ * `dotprompt/run`. The pretreat is the prelude procedure `ext/prompt/resolve`.
4
+ * CALLABLE RULE: never a JS function through `jsToScheme`.
5
+ *
6
+ * A ProgrammaticJob parents an omitted-spec AgentCallJob (AskAgentSpec worker,
7
+ * schema on the Call, ReACT until respond). Any other job keeps an isolated
8
+ * CompletionExpectation (classifier, compact).
9
+ */
10
+ import { EnvCapability, toJS } from "@inhuman.tools/arrival";
11
+ import { arrivalHandlebarsCapability, compileTemplate, runCompiledTemplate, } from "@inhuman.tools/arrival-modules/handlebars";
12
+ import { AgentCallJob, CompletionExpectation, CompletionJob, ProgrammaticJob, PromptMessage, } from "@inhuman.tools/harness-model";
13
+ import { Job } from "@inhuman.tools/plexus-expectations";
14
+ import { ConnectionMiss } from "@inhuman.tools/plexus-expectations/driver";
15
+ import { picoschema } from "dotprompt";
16
+ import { when } from "mobx";
17
+ import invariant from "tiny-invariant";
18
+ import { parse as parseYaml } from "yaml";
19
+ import { z } from "zod";
20
+ import { RenderedPrompt } from "./bundle.js";
21
+ import { ParsedPrompt, REASONING_EFFORTS } from "./parse.js";
22
+ const isPlainRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
23
+ const reasoningEffort = z.enum(REASONING_EFFORTS, {
24
+ error: ".prompt: reasoningEffort must be none, minimal, low, medium, high, xhigh, or max",
25
+ });
26
+ const promptMeta = z.object({
27
+ model: z.string().optional(),
28
+ reasoningEffort: reasoningEffort.optional(),
29
+ });
30
+ const AGENT_ASK = "agent__ask";
31
+ export const promptCapability = EnvCapability.define("ext/prompt", {
32
+ deps: [arrivalHandlebarsCapability],
33
+ configuration: {
34
+ job: z.instanceof(Job).optional(),
35
+ connectionId: z.string().optional(),
36
+ model: z.string().optional(),
37
+ /** Session/judge model. `model` is reserved by some exec hosts. */
38
+ completionModel: z.string().optional(),
39
+ complete: z
40
+ .function()
41
+ .optional(),
42
+ readonly: z.boolean().optional(),
43
+ },
44
+ symbols: (symbol, sz) => ({
45
+ "dotprompt/parse": symbol.rosetta `dotprompt/parse: parses a .prompt file into a ParsedPrompt`({ input: [sz.string, sz.string], output: [sz.box.pipe(z.instanceof(ParsedPrompt))] }, async function (contents, path) {
46
+ // Every call re-parses. A source cache is the first place to look if prompt require shows up in a profile.
47
+ const fenced = contents.match(/^---\n([\s\S]*?)\n---\n?/);
48
+ const parsedFm = fenced === null ? {} : (parseYaml(fenced[1]) ?? {});
49
+ invariant(isPlainRecord(parsedFm), ".prompt: frontmatter must be a YAML map");
50
+ const body = fenced === null ? contents : contents.slice(fenced[0].length);
51
+ const modelRaw = parsedFm.model ?? null;
52
+ invariant(modelRaw === null || typeof modelRaw === "string", ".prompt: frontmatter `model:` must be a model name string or omitted");
53
+ const model = modelRaw === "" ? null : modelRaw;
54
+ for (const key of ["agent", "mcp", "fallbackModels"]) {
55
+ invariant(!Object.hasOwn(parsedFm, key) || parsedFm[key] == null, () => `.prompt: "${path}" frontmatter \`${key}:\` is not supported`);
56
+ }
57
+ const named = typeof parsedFm.name === "string" ? parsedFm.name.trim() : "";
58
+ const modeRaw = parsedFm.mode;
59
+ const mode = modeRaw ?? "chat";
60
+ invariant(mode === "instruct" || mode === "chat", () => `.prompt: "${path}" frontmatter \`mode:\` must be "instruct" or "chat", got ${JSON.stringify(modeRaw)}`);
61
+ const compiled = await picoschema(parsedFm.output);
62
+ const responseSchemaJson = compiled === null ? null : JSON.stringify(compiled);
63
+ const effortRaw = parsedFm.reasoningEffort;
64
+ const effort = effortRaw == null ? null : reasoningEffort.parse(effortRaw);
65
+ const base = path.replaceAll("\\", "/").split("/").pop() ?? path;
66
+ const stem = base.replace(/\.prompt$/i, "");
67
+ const toolsRaw = parsedFm.tools;
68
+ let tools;
69
+ if (toolsRaw === undefined || toolsRaw === null) {
70
+ tools = null;
71
+ }
72
+ else {
73
+ invariant(Array.isArray(toolsRaw), () => `.prompt: "${path}" frontmatter \`tools:\` must be a list of tool names`);
74
+ tools = toolsRaw.map((item, index) => {
75
+ invariant(typeof item === "string" && item.trim() !== "", () => `.prompt: "${path}" tools[${String(index)}] must be a non-empty string`);
76
+ return item.trim();
77
+ });
78
+ }
79
+ // Role split is over the author source, before call-site interpolation: a rendered hole cannot forge a turn.
80
+ const sections = [];
81
+ const roleMarker = /\{\{\s*role\s+["']([a-zA-Z]+)["']\s*\}\}/g;
82
+ let bodyStart = 0;
83
+ let role = null;
84
+ for (let mark = roleMarker.exec(body); mark !== null; mark = roleMarker.exec(body)) {
85
+ if (role === null) {
86
+ if (body.slice(0, mark.index).trim() !== "") {
87
+ throw new Error(`.prompt: text before the first {{role}} marker — a chat template must open with {{role "system|user|assistant"}}`);
88
+ }
89
+ }
90
+ else {
91
+ sections.push({ role, source: body.slice(bodyStart, mark.index).trim() });
92
+ }
93
+ const next = mark[1].toLowerCase();
94
+ invariant(next === "system" || next === "user" || next === "assistant", () => `.prompt: unknown role "${mark[1]}" — use system, user, or assistant`);
95
+ role = next;
96
+ bodyStart = roleMarker.lastIndex;
97
+ }
98
+ invariant(role !== null, `.prompt: no {{role "..."}} markers — a chat template needs at least one`);
99
+ sections.push({ role, source: body.slice(bodyStart).trim() });
100
+ return new ParsedPrompt(mode, model, effort, responseSchemaJson, named === "" ? (stem === "" || stem === "anonymous" ? "prompt" : stem) : named, tools, sections);
101
+ }),
102
+ "dotprompt/build-bundle": symbol.rosetta `dotprompt/build-bundle: renders a ParsedPrompt into a RenderedPrompt`({
103
+ input: [sz.box.pipe(z.instanceof(ParsedPrompt))],
104
+ inputRest: sz.dynamic,
105
+ output: [sz.box.pipe(z.instanceof(RenderedPrompt))],
106
+ provenance: "pipe",
107
+ }, function (spec, ...args) {
108
+ let pairs = args;
109
+ let positional;
110
+ if (pairs.length > 0) {
111
+ const head = String(pairs[0]);
112
+ if (!(head.startsWith(":") || head.startsWith("':"))) {
113
+ positional = pairs[0];
114
+ pairs = pairs.slice(1);
115
+ }
116
+ }
117
+ const folded = {};
118
+ if (pairs.length > 0) {
119
+ invariant(pairs.length % 2 === 0, "kwargs: needs an even number of trailing args (alternating :key value pairs)");
120
+ for (let i = 0; i < pairs.length; i += 2) {
121
+ folded[String(pairs[i]).replace(/^'?:/, "")] = toJS(pairs[i + 1]);
122
+ }
123
+ }
124
+ let inputs;
125
+ let meta;
126
+ if (positional !== undefined) {
127
+ const value = toJS(positional);
128
+ if (isPlainRecord(value) && Object.keys(folded).length === 0) {
129
+ const metaRaw = isPlainRecord(value.meta) ? value.meta : {};
130
+ const { meta: _meta, key: _key, ...rest } = value;
131
+ inputs = rest;
132
+ meta = promptMeta.parse(metaRaw);
133
+ }
134
+ else if (folded.evidence === undefined) {
135
+ folded.evidence = value;
136
+ }
137
+ }
138
+ if (inputs === undefined || meta === undefined) {
139
+ const metaRaw = isPlainRecord(folded.meta) ? folded.meta : {};
140
+ const { meta: _metaSlot, key: _keySlot, ...rest } = folded;
141
+ inputs = rest;
142
+ meta = promptMeta.parse(metaRaw);
143
+ }
144
+ const rendered = spec.sections.map((section) => [
145
+ section.role,
146
+ runCompiledTemplate(compileTemplate(section.source), [inputs]),
147
+ ]);
148
+ const model = [meta.model, spec.model].find((candidate) => typeof candidate === "string" && candidate !== "") ?? null;
149
+ return new RenderedPrompt(model, meta.reasoningEffort ?? spec.reasoningEffort, spec.responseSchemaJson, spec.faceName, spec.tools, spec.mode === "instruct" ? [["user", rendered.map(([, content]) => content).join("\n\n")]] : rendered);
150
+ }),
151
+ "dotprompt/run": symbol.rosetta `dotprompt/run: on a program, parents an omitted-spec AgentCallJob and waits; otherwise completes in isolation`({
152
+ input: [sz.box.pipe(z.instanceof(RenderedPrompt))],
153
+ output: [sz.dynamic],
154
+ provenance: "source",
155
+ requiresConfig: ["job"],
156
+ }, async function (bundle) {
157
+ const job = this.configuration.job;
158
+ const promptMessages = bundle.messages.map(([role, content]) => new PromptMessage({ role, content }));
159
+ if (job instanceof ProgrammaticJob) {
160
+ const rawId = job.toolCallId.trim();
161
+ const minted = new AgentCallJob({
162
+ toolCallId: `${rawId === "" ? "prompt" : rawId}:prompt:${job.children.length + 1}`,
163
+ name: AGENT_ASK,
164
+ argsJson: "{}",
165
+ voidLegal: false,
166
+ readonly: this.configuration.readonly === true,
167
+ responseSchemaJson: bundle.responseSchemaJson,
168
+ promptMessages,
169
+ faceName: bundle.faceName.trim(),
170
+ tools: bundle.tools ?? [],
171
+ inheritCallerTools: bundle.tools === null,
172
+ reasoningEffort: bundle.reasoningEffort,
173
+ });
174
+ job.registerJob(minted);
175
+ // when() rejects an already-aborted signal (WHEN_ABORTED) before it reads the predicate.
176
+ const signal = this.runCtx.signal;
177
+ if (!(minted.completed || minted.cancelled)) {
178
+ if (signal === undefined)
179
+ await when(() => minted.completed || minted.cancelled);
180
+ else
181
+ await when(() => minted.completed || minted.cancelled, { signal });
182
+ }
183
+ invariant(!minted.cancelled, "dotprompt/run: ask cancelled");
184
+ invariant(minted.outcomeSnap != null, () => minted.outcomeJson ?? "ask failed");
185
+ invariant(minted.outcomeSnap.ok !== false, () => minted.outcomeSnap?.text?.trim() || minted.outcomeSnap?.code || "ask failed");
186
+ if (bundle.responseSchemaJson != null) {
187
+ const raw = "value" in minted.outcomeSnap
188
+ ? minted.outcomeSnap.value
189
+ : typeof minted.outcomeSnap.text === "string"
190
+ ? JSON.parse(minted.outcomeSnap.text)
191
+ : undefined;
192
+ invariant(raw !== undefined, "dotprompt/run: structured ask returned no value");
193
+ return structuredClone(raw);
194
+ }
195
+ else {
196
+ return minted.outcomeSnap.text ?? minted.outcomeSnap.value ?? "";
197
+ }
198
+ }
199
+ const connectionId = this.configuration.connectionId;
200
+ invariant(typeof connectionId === "string" && connectionId !== "", "dotprompt/run: connectionId is required");
201
+ // Scheme `apply` runs build-bundle under apply's call context, so the host model is read here.
202
+ const model = [bundle.model, this.configuration.completionModel, this.configuration.model].find((candidate) => typeof candidate === "string" && candidate !== "") ?? null;
203
+ invariant(model != null, "dotprompt/run: model is required");
204
+ const completion = new CompletionExpectation({
205
+ connectionId,
206
+ model,
207
+ responseSchemaJson: bundle.responseSchemaJson,
208
+ completionMode: "isolated",
209
+ promptMessages,
210
+ reasoningEffort: bundle.reasoningEffort,
211
+ });
212
+ const cell = new CompletionJob({ expectation: completion, tail: job });
213
+ job.registerJob(cell);
214
+ const complete = this.configuration.complete;
215
+ const signal = this.runCtx.signal;
216
+ try {
217
+ if (typeof complete === "function") {
218
+ await complete({
219
+ connectionId,
220
+ model,
221
+ promptText: completion.userPrompt,
222
+ responseSchemaJson: bundle.responseSchemaJson ?? undefined,
223
+ signal,
224
+ round: completion,
225
+ });
226
+ }
227
+ else if (signal !== undefined) {
228
+ await when(() => completion.isDone, { signal });
229
+ }
230
+ else {
231
+ await completion;
232
+ }
233
+ }
234
+ catch (error) {
235
+ // todo move completion processing into other layer (need to think)
236
+ // job should abstract the retries, thus if connection fails, we should not retry
237
+ if (typeof complete === "function" && error instanceof ConnectionMiss) {
238
+ await completion;
239
+ }
240
+ else if (signal?.aborted === true && !completion.isDone) {
241
+ const reason = signal.reason instanceof Error ? signal.reason.message : "classifier aborted";
242
+ if (completion.failReason == null)
243
+ completion.failReason = reason;
244
+ completion.fail("cancel", "terminate", "null");
245
+ }
246
+ else {
247
+ throw error;
248
+ }
249
+ }
250
+ invariant(completion.outcome === "successful", () => completion.failReason == null ? (completion.endDetail ?? "completion failed") : completion.failReason);
251
+ return bundle.responseSchemaJson != null ? JSON.parse(completion.responseText) : completion.responseText;
252
+ }),
253
+ }),
254
+ prelude: `(define (ext/prompt/resolve contents)
255
+ (let ((spec (dotprompt/parse (if (bytevector? contents) (utf8->string contents) contents)
256
+ "anonymous.prompt")))
257
+ (lambda (arg . rest)
258
+ ;; todo inline dotprompt/build-bundle in favor of dotprompt/run args
259
+ (dotprompt/run (apply dotprompt/build-bundle spec arg rest)))))
260
+ (require/register-extension ".prompt" ext/prompt/resolve)`,
261
+ });
262
+ //# sourceMappingURL=capability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAoB,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EACL,2BAA2B,EAC3B,eAAe,EACf,mBAAmB,GACpB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,aAAa,GAEd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,C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,oBAAoB,CAAC;oBAC7F,IAAI,UAAU,CAAC,UAAU,IAAI,IAAI;wBAAE,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC;oBAClE,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;gBACjD,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YACD,SAAS,CAAC,UAAU,CAAC,OAAO,KAAK,YAAY,EAAE,GAAG,EAAE,CAClD,UAAU,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CACtG,CAAC;YACF,OAAO,MAAM,CAAC,kBAAkB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;QAC3G,CAAC,CACF;KACJ,CAAC;IACF,OAAO,EAAE;;;;;;0DAM+C;CACzD,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
2
+ import { RenderedPrompt } from "./bundle.js";
3
+ export declare function renderPrompt(spec: ParsedPrompt, args: readonly unknown[]): RenderedPrompt;
4
+ /** Both prompt hosts install this prelude. Require parses once and closes over the spec. */
5
+ export declare const promptPrelude = "(define (ext/prompt/resolve contents)\n (let ((spec (dotprompt/parse (if (bytevector? contents) (utf8->string contents) contents)\n \"anonymous.prompt\")))\n ;; apply would run dotprompt/run under the lists capability's context.\n (lambda args\n (dotprompt/run spec args))))\n(require/register-extension \".prompt\" ext/prompt/resolve)";
6
+ //# sourceMappingURL=dotprompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotprompt.d.ts","sourceRoot":"","sources":["../src/dotprompt.ts"],"names":[],"mappings":"AAMA,OAAO,EAAiB,KAAK,YAAY,EAAyB,MAAM,yCAAyC,CAAC;AAKlH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO7C,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,cAAc,CAoDzF;AAED,4FAA4F;AAC5F,eAAO,MAAM,aAAa,8XAMgC,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Render both prompt hosts call, and the prelude they install.
3
+ * `dotprompt/parse` is `dotpromptCapability`.
4
+ */
5
+ import { toJS } from "@here.build/arrival";
6
+ import { compileTemplate, runCompiledTemplate } from "@here.build/arrival-modules/handlebars";
7
+ import { isPlainRecord, reasoningEffortSchema } from "@inhuman.tools/env-capability-dotprompt";
8
+ import invariant from "tiny-invariant";
9
+ import { z } from "zod";
10
+ import { RenderedPrompt } from "./bundle.js";
11
+ const promptMeta = z.object({
12
+ model: z.string().optional(),
13
+ reasoningEffort: reasoningEffortSchema.optional(),
14
+ });
15
+ export function renderPrompt(spec, args) {
16
+ let pairs = args;
17
+ let positional;
18
+ if (pairs.length > 0) {
19
+ const head = String(pairs[0]);
20
+ if (!(head.startsWith(":") || head.startsWith("':"))) {
21
+ positional = pairs[0];
22
+ pairs = pairs.slice(1);
23
+ }
24
+ }
25
+ const folded = {};
26
+ if (pairs.length > 0) {
27
+ invariant(pairs.length % 2 === 0, "kwargs: needs an even number of trailing args (alternating :key value pairs)");
28
+ for (let i = 0; i < pairs.length; i += 2) {
29
+ folded[String(pairs[i]).replace(/^'?:/, "")] = toJS(pairs[i + 1]);
30
+ }
31
+ }
32
+ let inputs;
33
+ let meta;
34
+ if (positional !== undefined) {
35
+ const value = toJS(positional);
36
+ if (isPlainRecord(value) && Object.keys(folded).length === 0) {
37
+ const metaRaw = isPlainRecord(value.meta) ? value.meta : {};
38
+ const { meta: _meta, key: _key, ...rest } = value;
39
+ inputs = rest;
40
+ meta = promptMeta.parse(metaRaw);
41
+ }
42
+ else if (folded.evidence === undefined) {
43
+ folded.evidence = value;
44
+ }
45
+ }
46
+ if (inputs === undefined || meta === undefined) {
47
+ const metaRaw = isPlainRecord(folded.meta) ? folded.meta : {};
48
+ const { meta: _metaSlot, key: _keySlot, ...rest } = folded;
49
+ inputs = rest;
50
+ meta = promptMeta.parse(metaRaw);
51
+ }
52
+ const rendered = spec.sections.map((section) => [
53
+ section.role,
54
+ runCompiledTemplate(compileTemplate(section.source), [inputs]),
55
+ ]);
56
+ const model = [meta.model, spec.model].find((candidate) => typeof candidate === "string" && candidate !== "") ?? null;
57
+ return new RenderedPrompt(model, meta.reasoningEffort ?? spec.reasoningEffort, spec.responseSchema, spec.faceName, spec.tools, spec.mode === "instruct" ? [["user", rendered.map(([, content]) => content).join("\n\n")]] : rendered);
58
+ }
59
+ /** Both prompt hosts install this prelude. Require parses once and closes over the spec. */
60
+ export const promptPrelude = `(define (ext/prompt/resolve contents)
61
+ (let ((spec (dotprompt/parse (if (bytevector? contents) (utf8->string contents) contents)
62
+ "anonymous.prompt")))
63
+ ;; apply would run dotprompt/run under the lists capability's context.
64
+ (lambda args
65
+ (dotprompt/run spec args))))
66
+ (require/register-extension ".prompt" ext/prompt/resolve)`;
67
+ //# sourceMappingURL=dotprompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotprompt.js","sourceRoot":"","sources":["../src/dotprompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAoB,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAqB,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAElH,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,UAAU,GAAG,CAAC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IACH,MAAM,KAAK,GACT,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAC3B,CAAC,SAAS,EAAuB,EAAE,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,EAAE,CACtF,IAAI,IAAI,CAAC;IACZ,OAAO,IAAI,cAAc,CACvB,KAAK,EACL,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,EAC5C,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CACtG,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;0DAM6B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { type PromptComplete, RenderedPrompt } from "./bundle.js";
2
+ export { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
3
+ export { promptIsolatedCapability } from "./run-isolated.js";
4
+ export { promptProgramCapability } from "./run-program.js";
5
+ //# 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,KAAK,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { RenderedPrompt } from "./bundle.js";
2
+ export { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
3
+ export { promptIsolatedCapability } from "./run-isolated.js";
4
+ export { promptProgramCapability } from "./run-program.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Parsed `.prompt` file. Frontmatter `output:` is lowered to JSON Schema by
3
+ * `picoschema` from the `dotprompt` package and stored as `responseSchema`.
4
+ * JSON text is produced where a job or completion request is written.
5
+ * Own fields remain readable through Arrival's object membrane.
6
+ */
7
+ import type { PromptMessageRole } from "@inhuman.tools/harness-model";
8
+ export declare const REASONING_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
9
+ export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
10
+ export type PromptSection = {
11
+ readonly role: PromptMessageRole;
12
+ readonly source: string;
13
+ };
14
+ export declare class ParsedPrompt {
15
+ readonly mode: "instruct" | "chat";
16
+ readonly model: string | null;
17
+ readonly reasoningEffort: ReasoningEffort | null;
18
+ /** Frontmatter key is `output:`. Null returns text; a schema returns parsed JSON. */
19
+ readonly responseSchema: Record<string, unknown> | null;
20
+ readonly faceName: string;
21
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
22
+ readonly tools: readonly string[] | null;
23
+ readonly sections: readonly PromptSection[];
24
+ constructor(mode: "instruct" | "chat", model: string | null, reasoningEffort: ReasoningEffort | null,
25
+ /** Frontmatter key is `output:`. Null returns text; a schema returns parsed JSON. */
26
+ responseSchema: Record<string, unknown> | null, faceName: string,
27
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
28
+ tools: readonly string[] | null, sections: readonly PromptSection[]);
29
+ }
30
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,iBAAiB,uEAAwE,CAAC;AACvG,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,qBAAa,YAAY;aAEL,IAAI,EAAE,UAAU,GAAG,MAAM;aACzB,KAAK,EAAE,MAAM,GAAG,IAAI;aACpB,eAAe,EAAE,eAAe,GAAG,IAAI;IACvD,qFAAqF;aACrE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;aAC9C,QAAQ,EAAE,MAAM;IAChC,oFAAoF;aACpE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;aAC/B,QAAQ,EAAE,SAAS,aAAa,EAAE;gBARlC,IAAI,EAAE,UAAU,GAAG,MAAM,EACzB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,eAAe,EAAE,eAAe,GAAG,IAAI;IACvD,qFAAqF;IACrE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC9C,QAAQ,EAAE,MAAM;IAChC,oFAAoF;IACpE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EAC/B,QAAQ,EAAE,SAAS,aAAa,EAAE;CAErD"}
package/dist/parse.js ADDED
@@ -0,0 +1,24 @@
1
+ export const REASONING_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
2
+ export class ParsedPrompt {
3
+ mode;
4
+ model;
5
+ reasoningEffort;
6
+ responseSchema;
7
+ faceName;
8
+ tools;
9
+ sections;
10
+ constructor(mode, model, reasoningEffort,
11
+ /** Frontmatter key is `output:`. Null returns text; a schema returns parsed JSON. */
12
+ responseSchema, faceName,
13
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
14
+ tools, sections) {
15
+ this.mode = mode;
16
+ this.model = model;
17
+ this.reasoningEffort = reasoningEffort;
18
+ this.responseSchema = responseSchema;
19
+ this.faceName = faceName;
20
+ this.tools = tools;
21
+ this.sections = sections;
22
+ }
23
+ }
24
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC;AAQvG,MAAM,OAAO,YAAY;IAEL;IACA;IACA;IAEA;IACA;IAEA;IACA;IATlB,YACkB,IAAyB,EACzB,KAAoB,EACpB,eAAuC;IACvD,qFAAqF;IACrE,cAA8C,EAC9C,QAAgB;IAChC,oFAAoF;IACpE,KAA+B,EAC/B,QAAkC;QARlC,SAAI,GAAJ,IAAI,CAAqB;QACzB,UAAK,GAAL,KAAK,CAAe;QACpB,oBAAe,GAAf,eAAe,CAAwB;QAEvC,mBAAc,GAAd,cAAc,CAAgC;QAC9C,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,UAAK,GAAL,KAAK,CAA0B;QAC/B,aAAQ,GAAR,QAAQ,CAA0B;IACjD,CAAC;CACL"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Isolated host for `.prompt`. `dotprompt/run` performs one completion
3
+ * on the configured job (compact, classifier).
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { Job } from "@inhuman.tools/plexus-expectations";
7
+ import { z } from "zod";
8
+ export declare const promptIsolatedCapability: EnvCapability<{
9
+ job: z.ZodCustom<Job<unknown, unknown>, Job<unknown, unknown>>;
10
+ connectionId: z.ZodString;
11
+ model: z.ZodOptional<z.ZodString>;
12
+ /** Session/judge model. `model` is reserved by some exec hosts. */
13
+ completionModel: z.ZodOptional<z.ZodString>;
14
+ }, Record<string, never>>;
15
+ //# sourceMappingURL=run-isolated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-isolated.d.ts","sourceRoot":"","sources":["../src/run-isolated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,wBAAwB;;;;IAUjC,mEAAmE;;yBAqCrE,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Isolated host for `.prompt`. `dotprompt/run` performs one completion
3
+ * on the configured job (compact, classifier).
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { arrivalLoaderCapability } from "@here.build/arrival-modules";
7
+ import { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
8
+ import { CompletionExpectation, CompletionJob, ProgrammaticJob, PromptMessage } from "@inhuman.tools/harness-model";
9
+ import { Job } from "@inhuman.tools/plexus-expectations";
10
+ import invariant from "tiny-invariant";
11
+ import { z } from "zod";
12
+ import { promptPrelude, renderPrompt } from "./dotprompt.js";
13
+ export const promptIsolatedCapability = EnvCapability.define("ext/prompt/isolated", {
14
+ deps: [dotpromptCapability, arrivalLoaderCapability],
15
+ configuration: {
16
+ job: z.instanceof(Job).refine((job) => !(job instanceof ProgrammaticJob), {
17
+ error: "dotprompt/run: a program uses promptProgramCapability",
18
+ }),
19
+ connectionId: z
20
+ .string({ error: "dotprompt/run: connectionId is required" })
21
+ .refine((value) => value !== "", { error: "dotprompt/run: connectionId is required" }),
22
+ model: z.string().optional(),
23
+ /** Session/judge model. `model` is reserved by some exec hosts. */
24
+ completionModel: z.string().optional(),
25
+ },
26
+ symbols: (symbol, sz) => ({
27
+ "dotprompt/run": symbol.rosetta `dotprompt/run: completes the rendered prompt in isolation`({
28
+ input: [sz.box.pipe(z.instanceof(ParsedPrompt)), sz.list(sz.dynamic)],
29
+ output: [sz.dynamic],
30
+ provenance: "source",
31
+ requiresConfig: ["job"],
32
+ }, async function (spec, args) {
33
+ const bundle = renderPrompt(spec, args);
34
+ // Render overlays :meta, then the file model. The host model is appended here.
35
+ const model = [bundle.model, this.configuration.completionModel, this.configuration.model].find((candidate) => typeof candidate === "string" && candidate !== "") ?? null;
36
+ invariant(model != null, "dotprompt/run: model is required");
37
+ // The session orchestrator drives the CompletionJob. Await reads its result.
38
+ return await this.configuration.job.registerJob(new CompletionJob({
39
+ expectation: new CompletionExpectation({
40
+ connectionId: this.configuration.connectionId,
41
+ model,
42
+ responseSchema: bundle.responseSchema,
43
+ completionMode: "isolated",
44
+ promptMessages: bundle.messages.map(([role, content]) => new PromptMessage({ role, content })),
45
+ reasoningEffort: bundle.reasoningEffort,
46
+ }),
47
+ turnTail: this.configuration.job,
48
+ }));
49
+ }),
50
+ }),
51
+ prelude: promptPrelude,
52
+ });
53
+ //# sourceMappingURL=run-isolated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-isolated.js","sourceRoot":"","sources":["../src/run-isolated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,mBAA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-0,0 +1,12 @@
1
+ /**
2
+ * Program host for `.prompt`. `dotprompt/run` parents an omitted-spec
3
+ * AgentCallJob on the ProgrammaticJob and waits for the worker.
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { ProgrammaticJob } from "@inhuman.tools/harness-model";
7
+ import { z } from "zod";
8
+ export declare const promptProgramCapability: EnvCapability<{
9
+ job: z.ZodCustom<ProgrammaticJob, ProgrammaticJob>;
10
+ readonly: z.ZodDefault<z.ZodBoolean>;
11
+ }, Record<string, never>>;
12
+ //# sourceMappingURL=run-program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-program.d.ts","sourceRoot":"","sources":["../src/run-program.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAML,eAAe,EAGhB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,uBAAuB;;;yBAsDlC,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Program host for `.prompt`. `dotprompt/run` parents an omitted-spec
3
+ * AgentCallJob on the ProgrammaticJob and waits for the worker.
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { arrivalLoaderCapability } from "@here.build/arrival-modules";
7
+ import { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
8
+ import { AgentCallJob, claimCrossing, crossingPending, crossingWindow, isReplaying, ProgrammaticJob, PromptMessage, takeCrossing, } from "@inhuman.tools/harness-model";
9
+ import { runInAction, when } from "mobx";
10
+ import { z } from "zod";
11
+ import { promptPrelude, renderPrompt } from "./dotprompt.js";
12
+ const AGENT_ASK = "agent__ask";
13
+ export const promptProgramCapability = EnvCapability.define("ext/prompt/program", {
14
+ deps: [dotpromptCapability, arrivalLoaderCapability],
15
+ configuration: {
16
+ job: z.instanceof(ProgrammaticJob),
17
+ readonly: z.boolean().default(false),
18
+ },
19
+ symbols: (symbol, sz) => ({
20
+ "dotprompt/run": symbol.rosetta `dotprompt/run: parents an omitted-spec AgentCallJob on the program and waits`({
21
+ input: [sz.box.pipe(z.instanceof(ParsedPrompt)), sz.list(sz.dynamic)],
22
+ output: [sz.dynamic],
23
+ provenance: "source",
24
+ requiresConfig: ["job"],
25
+ }, async function (spec, args) {
26
+ const bundle = renderPrompt(spec, args);
27
+ const job = this.configuration.job;
28
+ const emission = this.runCtx.emission;
29
+ const path = job.trackMatch && emission != null ? claimCrossing(emission, crossingWindow(this)) : "";
30
+ if (path !== "" && emission != null) {
31
+ let existing = takeCrossing(job, emission, path);
32
+ if (existing == null && isReplaying(emission)) {
33
+ if (!job.completed && !job.cancelled) {
34
+ const joined = when(() => job.completed || job.cancelled || crossingPending(job, emission, path));
35
+ try {
36
+ await joined;
37
+ }
38
+ finally {
39
+ joined.cancel();
40
+ }
41
+ }
42
+ existing = takeCrossing(job, emission, path);
43
+ if (existing == null)
44
+ throw new Error("replay: no recorded dotprompt/run");
45
+ }
46
+ if (existing != null)
47
+ return await existing;
48
+ }
49
+ const minted = new AgentCallJob({
50
+ toolCallId: `${job.toolCallId}:prompt:${job.children.length + 1}`,
51
+ name: AGENT_ASK,
52
+ argsJson: "{}",
53
+ voidLegal: false,
54
+ readonly: this.configuration.readonly === true,
55
+ responseSchema: bundle.responseSchema,
56
+ promptMessages: bundle.messages.map(([role, content]) => new PromptMessage({ role, content })),
57
+ faceName: bundle.faceName.trim(),
58
+ tools: bundle.tools ?? [],
59
+ inheritCallerTools: bundle.tools === null,
60
+ reasoningEffort: bundle.reasoningEffort,
61
+ });
62
+ if (path !== "")
63
+ runInAction(() => (minted.track = path));
64
+ return await job.registerJob(minted);
65
+ }),
66
+ }),
67
+ prelude: promptPrelude,
68
+ });
69
+ //# sourceMappingURL=run-program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-program.js","sourceRoot":"","sources":["../src/run-program.ts"],"names":[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AAM,GAAG,IAAI,YAAY,CAAC;gBAC9B,UAAU,EAAE,GAAG,GAAG,CAAC,UAAU,WAAW,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjE,IAAI,EAAE,SAAS;gBACf,QAAQ,EAAE,IAAI;gBACd,SAAS,EAAE,KAAK;gBAChB,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC,QAAQ,KAAK,IAAI;gBAC9C,cAAc,EAAE,MAAM,CAAC,cAAc;gBACrC,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC9F,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAChC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE;gBACzB,kBAAkB,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI;gBACzC,eAAe,EAAE,MAAM,CAAC,eAAe;aACxC,CAAC,CAAC;YACH,IAAI,IAAI,KAAK,EAAE;gBAAE,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;YAC1D,OAAO,MAAM,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC,CACF;KACF,CAAC;IACF,OAAO,EAAE,aAAa;CACvB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@inhuman.tools/env-capability-module-prompt",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Arrival ext/prompt: (require \"x.prompt\") pretreats to a scheme lambda; a ProgrammaticJob parents an omitted-spec agent ask.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "!**/__tests__"
19
+ ],
20
+ "dependencies": {
21
+ "@here.build/arrival": "^0.10.2",
22
+ "@here.build/arrival-modules": "^0.10.0",
23
+ "handlebars": "^4.7.9",
24
+ "tiny-invariant": "^1.3.3",
25
+ "zod": "^4.4.3",
26
+ "@inhuman.tools/env-capability-dotprompt": "^0.1.0",
27
+ "@inhuman.tools/plexus-expectations": "^0.1.0",
28
+ "@inhuman.tools/harness-commons": "^0.1.0",
29
+ "@inhuman.tools/harness-model": "^0.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^24.0.0",
33
+ "dedent": "1.7.2",
34
+ "eslint": "9.39.2",
35
+ "mobx": "6.16.1",
36
+ "typescript": "6.0.2",
37
+ "vitest": "4.1.0",
38
+ "@-internal-/eslint-configs": "0.0.0"
39
+ },
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/here-build/inhuman-harness.git",
44
+ "directory": "packages/env-capability-module-prompt"
45
+ },
46
+ "peerDependencies": {
47
+ "mobx": "6.16.1"
48
+ },
49
+ "browserslist": [
50
+ "last 2 chrome versions",
51
+ "last 2 firefox versions",
52
+ "last 2 safari versions",
53
+ "ios_saf >= 16.4",
54
+ "node >= 22"
55
+ ],
56
+ "author": "Merkle Bonsai",
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "scripts": {
61
+ "build": "tsc -p tsconfig.build.json",
62
+ "lint": "eslint .",
63
+ "lint:fix": "eslint . --fix",
64
+ "test": "tsc -p tsconfig.json --noEmit && vitest run",
65
+ "typecheck": "tsc -p tsconfig.json --noEmit"
66
+ }
6
67
  }
package/src/bundle.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * One rendered `.prompt` call, and the host port for an isolated completion.
3
+ * A ProgrammaticJob parents an omitted-spec AgentCallJob instead of calling the port.
4
+ */
5
+ import type { ReasoningEffort } from "@inhuman.tools/env-capability-dotprompt";
6
+ import type { CompletionExpectation, PromptMessageRole } from "@inhuman.tools/harness-model";
7
+
8
+ /** Session/research intern port. Homed `round` is mutated in place. `responseSchemaJson` is the serialized schema, matching CompleteFields. */
9
+ export type PromptCompleteRequest = {
10
+ readonly connectionId: string;
11
+ readonly model: string;
12
+ readonly promptText?: string;
13
+ readonly responseSchemaJson?: string;
14
+ readonly signal?: AbortSignal;
15
+ readonly round: CompletionExpectation;
16
+ };
17
+
18
+ export type PromptComplete = (
19
+ req: PromptCompleteRequest,
20
+ ) => Promise<{ readonly text: string; readonly thought?: string; readonly thoughtKind?: string }>;
21
+
22
+ export class RenderedPrompt {
23
+ constructor(
24
+ public readonly model: string | null,
25
+ public readonly reasoningEffort: ReasoningEffort | null,
26
+ public readonly responseSchema: Record<string, unknown> | null,
27
+ public readonly faceName: string,
28
+ /** Null inherits the caller catalog; an empty list is an explicit empty overlay. */
29
+ public readonly tools: readonly string[] | null,
30
+ public readonly messages: readonly [PromptMessageRole, string][],
31
+ ) {}
32
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Render both prompt hosts call, and the prelude they install.
3
+ * `dotprompt/parse` is `dotpromptCapability`.
4
+ */
5
+ import { type SchemeValue, toJS } from "@here.build/arrival";
6
+ import { compileTemplate, runCompiledTemplate } from "@here.build/arrival-modules/handlebars";
7
+ import { isPlainRecord, type ParsedPrompt, reasoningEffortSchema } from "@inhuman.tools/env-capability-dotprompt";
8
+ import { type PromptMessageRole } from "@inhuman.tools/harness-model";
9
+ import invariant from "tiny-invariant";
10
+ import { z } from "zod";
11
+
12
+ import { RenderedPrompt } from "./bundle.js";
13
+
14
+ const promptMeta = z.object({
15
+ model: z.string().optional(),
16
+ reasoningEffort: reasoningEffortSchema.optional(),
17
+ });
18
+
19
+ export function renderPrompt(spec: ParsedPrompt, args: readonly unknown[]): RenderedPrompt {
20
+ let pairs = args;
21
+ let positional: unknown;
22
+ if (pairs.length > 0) {
23
+ const head = String(pairs[0]);
24
+ if (!(head.startsWith(":") || head.startsWith("':"))) {
25
+ positional = pairs[0];
26
+ pairs = pairs.slice(1);
27
+ }
28
+ }
29
+ const folded: Record<string, unknown> = {};
30
+ if (pairs.length > 0) {
31
+ invariant(pairs.length % 2 === 0, "kwargs: needs an even number of trailing args (alternating :key value pairs)");
32
+ for (let i = 0; i < pairs.length; i += 2) {
33
+ folded[String(pairs[i]).replace(/^'?:/, "")] = toJS(pairs[i + 1] as SchemeValue);
34
+ }
35
+ }
36
+ let inputs: Record<string, unknown> | undefined;
37
+ let meta: z.infer<typeof promptMeta> | undefined;
38
+ if (positional !== undefined) {
39
+ const value = toJS(positional as SchemeValue);
40
+ if (isPlainRecord(value) && Object.keys(folded).length === 0) {
41
+ const metaRaw = isPlainRecord(value.meta) ? value.meta : {};
42
+ const { meta: _meta, key: _key, ...rest } = value;
43
+ inputs = rest;
44
+ meta = promptMeta.parse(metaRaw);
45
+ } else if (folded.evidence === undefined) {
46
+ folded.evidence = value;
47
+ }
48
+ }
49
+ if (inputs === undefined || meta === undefined) {
50
+ const metaRaw = isPlainRecord(folded.meta) ? folded.meta : {};
51
+ const { meta: _metaSlot, key: _keySlot, ...rest } = folded;
52
+ inputs = rest;
53
+ meta = promptMeta.parse(metaRaw);
54
+ }
55
+ const rendered = spec.sections.map((section): [PromptMessageRole, string] => [
56
+ section.role,
57
+ runCompiledTemplate(compileTemplate(section.source), [inputs]),
58
+ ]);
59
+ const model =
60
+ [meta.model, spec.model].find(
61
+ (candidate): candidate is string => typeof candidate === "string" && candidate !== "",
62
+ ) ?? null;
63
+ return new RenderedPrompt(
64
+ model,
65
+ meta.reasoningEffort ?? spec.reasoningEffort,
66
+ spec.responseSchema,
67
+ spec.faceName,
68
+ spec.tools,
69
+ spec.mode === "instruct" ? [["user", rendered.map(([, content]) => content).join("\n\n")]] : rendered,
70
+ );
71
+ }
72
+
73
+ /** Both prompt hosts install this prelude. Require parses once and closes over the spec. */
74
+ export const promptPrelude = `(define (ext/prompt/resolve contents)
75
+ (let ((spec (dotprompt/parse (if (bytevector? contents) (utf8->string contents) contents)
76
+ "anonymous.prompt")))
77
+ ;; apply would run dotprompt/run under the lists capability's context.
78
+ (lambda args
79
+ (dotprompt/run spec args))))
80
+ (require/register-extension ".prompt" ext/prompt/resolve)`;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { type PromptComplete, RenderedPrompt } from "./bundle.js";
2
+ export { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
3
+ export { promptIsolatedCapability } from "./run-isolated.js";
4
+ export { promptProgramCapability } from "./run-program.js";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Isolated host for `.prompt`. `dotprompt/run` performs one completion
3
+ * on the configured job (compact, classifier).
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { arrivalLoaderCapability } from "@here.build/arrival-modules";
7
+ import { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
8
+ import { CompletionExpectation, CompletionJob, ProgrammaticJob, PromptMessage } from "@inhuman.tools/harness-model";
9
+ import { Job } from "@inhuman.tools/plexus-expectations";
10
+ import invariant from "tiny-invariant";
11
+ import { z } from "zod";
12
+
13
+ import { promptPrelude, renderPrompt } from "./dotprompt.js";
14
+
15
+ export const promptIsolatedCapability = EnvCapability.define("ext/prompt/isolated", {
16
+ deps: [dotpromptCapability, arrivalLoaderCapability],
17
+ configuration: {
18
+ job: z.instanceof(Job).refine((job) => !(job instanceof ProgrammaticJob), {
19
+ error: "dotprompt/run: a program uses promptProgramCapability",
20
+ }),
21
+ connectionId: z
22
+ .string({ error: "dotprompt/run: connectionId is required" })
23
+ .refine((value) => value !== "", { error: "dotprompt/run: connectionId is required" }),
24
+ model: z.string().optional(),
25
+ /** Session/judge model. `model` is reserved by some exec hosts. */
26
+ completionModel: z.string().optional(),
27
+ },
28
+ symbols: (symbol, sz) => ({
29
+ "dotprompt/run": symbol.rosetta`dotprompt/run: completes the rendered prompt in isolation`(
30
+ {
31
+ input: [sz.box.pipe(z.instanceof(ParsedPrompt)), sz.list(sz.dynamic)],
32
+ output: [sz.dynamic],
33
+ provenance: "source",
34
+ requiresConfig: ["job"],
35
+ },
36
+ async function (spec, args) {
37
+ const bundle = renderPrompt(spec, args);
38
+ // Render overlays :meta, then the file model. The host model is appended here.
39
+ const model =
40
+ [bundle.model, this.configuration.completionModel, this.configuration.model].find(
41
+ (candidate): candidate is string => typeof candidate === "string" && candidate !== "",
42
+ ) ?? null;
43
+ invariant(model != null, "dotprompt/run: model is required");
44
+ // The session orchestrator drives the CompletionJob. Await reads its result.
45
+ return await this.configuration.job.registerJob(
46
+ new CompletionJob({
47
+ expectation: new CompletionExpectation({
48
+ connectionId: this.configuration.connectionId,
49
+ model,
50
+ responseSchema: bundle.responseSchema,
51
+ completionMode: "isolated",
52
+ promptMessages: bundle.messages.map(([role, content]) => new PromptMessage({ role, content })),
53
+ reasoningEffort: bundle.reasoningEffort,
54
+ }),
55
+ turnTail: this.configuration.job,
56
+ }),
57
+ );
58
+ },
59
+ ),
60
+ }),
61
+ prelude: promptPrelude,
62
+ });
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Program host for `.prompt`. `dotprompt/run` parents an omitted-spec
3
+ * AgentCallJob on the ProgrammaticJob and waits for the worker.
4
+ */
5
+ import { EnvCapability } from "@here.build/arrival";
6
+ import { arrivalLoaderCapability } from "@here.build/arrival-modules";
7
+ import { dotpromptCapability, ParsedPrompt } from "@inhuman.tools/env-capability-dotprompt";
8
+ import {
9
+ AgentCallJob,
10
+ claimCrossing,
11
+ crossingPending,
12
+ crossingWindow,
13
+ isReplaying,
14
+ ProgrammaticJob,
15
+ PromptMessage,
16
+ takeCrossing,
17
+ } from "@inhuman.tools/harness-model";
18
+ import { runInAction, when } from "mobx";
19
+ import { z } from "zod";
20
+
21
+ import { promptPrelude, renderPrompt } from "./dotprompt.js";
22
+
23
+ const AGENT_ASK = "agent__ask";
24
+
25
+ export const promptProgramCapability = EnvCapability.define("ext/prompt/program", {
26
+ deps: [dotpromptCapability, arrivalLoaderCapability],
27
+ configuration: {
28
+ job: z.instanceof(ProgrammaticJob),
29
+ readonly: z.boolean().default(false),
30
+ },
31
+ symbols: (symbol, sz) => ({
32
+ "dotprompt/run": symbol.rosetta`dotprompt/run: parents an omitted-spec AgentCallJob on the program and waits`(
33
+ {
34
+ input: [sz.box.pipe(z.instanceof(ParsedPrompt)), sz.list(sz.dynamic)],
35
+ output: [sz.dynamic],
36
+ provenance: "source",
37
+ requiresConfig: ["job"],
38
+ },
39
+ async function (spec, args) {
40
+ const bundle = renderPrompt(spec, args);
41
+ const job = this.configuration.job;
42
+ const emission = this.runCtx.emission;
43
+ const path = job.trackMatch && emission != null ? claimCrossing(emission, crossingWindow(this)) : "";
44
+ if (path !== "" && emission != null) {
45
+ let existing = takeCrossing(job, emission, path);
46
+ if (existing == null && isReplaying(emission)) {
47
+ if (!job.completed && !job.cancelled) {
48
+ const joined = when(() => job.completed || job.cancelled || crossingPending(job, emission, path));
49
+ try {
50
+ await joined;
51
+ } finally {
52
+ joined.cancel();
53
+ }
54
+ }
55
+ existing = takeCrossing(job, emission, path);
56
+ if (existing == null) throw new Error("replay: no recorded dotprompt/run");
57
+ }
58
+ if (existing != null) return await existing;
59
+ }
60
+ const minted = new AgentCallJob({
61
+ toolCallId: `${job.toolCallId}:prompt:${job.children.length + 1}`,
62
+ name: AGENT_ASK,
63
+ argsJson: "{}",
64
+ voidLegal: false,
65
+ readonly: this.configuration.readonly === true,
66
+ responseSchema: bundle.responseSchema,
67
+ promptMessages: bundle.messages.map(([role, content]) => new PromptMessage({ role, content })),
68
+ faceName: bundle.faceName.trim(),
69
+ tools: bundle.tools ?? [],
70
+ inheritCallerTools: bundle.tools === null,
71
+ reasoningEffort: bundle.reasoningEffort,
72
+ });
73
+ if (path !== "") runInAction(() => (minted.track = path));
74
+ return await job.registerJob(minted);
75
+ },
76
+ ),
77
+ }),
78
+ prelude: promptPrelude,
79
+ });
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.