@agenticprimitives/orchestration 0.0.0-alpha.1 → 0.0.0-alpha.3
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/dist/admission.d.ts +87 -0
- package/dist/admission.d.ts.map +1 -0
- package/dist/admission.js +193 -0
- package/dist/admission.js.map +1 -0
- package/dist/artifacts.d.ts +137 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +232 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/authority.d.ts +431 -0
- package/dist/authority.d.ts.map +1 -0
- package/dist/authority.js +2 -0
- package/dist/authority.js.map +1 -0
- package/dist/durable.d.ts +44 -0
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +15 -0
- package/dist/durable.js.map +1 -0
- package/dist/flow-trace.d.ts +105 -0
- package/dist/flow-trace.d.ts.map +1 -0
- package/dist/flow-trace.js +60 -0
- package/dist/flow-trace.js.map +1 -0
- package/dist/index.d.ts +20 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +165 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +33 -0
- package/dist/input.js.map +1 -0
- package/dist/loop.d.ts +115 -3
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +656 -30
- package/dist/loop.js.map +1 -1
- package/dist/metrics.d.ts +35 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +98 -0
- package/dist/metrics.js.map +1 -0
- package/dist/planner-wire.d.ts +11 -0
- package/dist/planner-wire.d.ts.map +1 -0
- package/dist/planner-wire.js +53 -0
- package/dist/planner-wire.js.map +1 -0
- package/dist/planner.d.ts +33 -0
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js.map +1 -1
- package/dist/record.d.ts +161 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +72 -0
- package/dist/record.js.map +1 -0
- package/dist/spans.d.ts +200 -0
- package/dist/spans.d.ts.map +1 -0
- package/dist/spans.js +522 -0
- package/dist/spans.js.map +1 -0
- package/dist/tool-invoker.d.ts +7 -0
- package/dist/tool-invoker.d.ts.map +1 -1
- package/dist/trace-context.d.ts +26 -0
- package/dist/trace-context.d.ts.map +1 -0
- package/dist/trace-context.js +59 -0
- package/dist/trace-context.js.map +1 -0
- package/dist/types.d.ts +180 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Intent, Plan, ToolSpec } from './types.js';
|
|
2
|
+
/** Spec 367 §4 — the violation codes. Each names the field at fault and the recovery it allows. */
|
|
3
|
+
export type AdmissionCode = 'REQUIRED_ROLE_UNRESOLVED' | 'RESOURCE_SCOPE_MISMATCH' | 'CAPABILITY_UNAVAILABLE' | 'UNSUPPORTED_BINDING_SOURCE' | 'DEPENDENCY_NOT_SATISFIED' | 'OUTCOME_NOT_ESTABLISHED' | 'BRANCH_UNDECIDABLE' | 'QUESTION_NOT_ANSWERED' | 'EXTERNAL_EXECUTOR_ACT';
|
|
4
|
+
export interface AdmissionViolation {
|
|
5
|
+
code: AdmissionCode;
|
|
6
|
+
/** The sentence a planner is re-planned with, and a person is refused with. */
|
|
7
|
+
message: string;
|
|
8
|
+
stepIndex?: number;
|
|
9
|
+
toolId?: string;
|
|
10
|
+
/** The argument or plan field at fault, when there is one. */
|
|
11
|
+
field?: string;
|
|
12
|
+
/** What may fix it: re-plan the means, ask the person, resolve the binding, or refuse. */
|
|
13
|
+
recovery: 'replan' | 'ask' | 'resolve' | 'refuse';
|
|
14
|
+
}
|
|
15
|
+
export type AdmissionVerdict = {
|
|
16
|
+
admitted: true;
|
|
17
|
+
} | {
|
|
18
|
+
admitted: false;
|
|
19
|
+
violations: AdmissionViolation[];
|
|
20
|
+
};
|
|
21
|
+
export interface AdmissionInput {
|
|
22
|
+
intent: Intent;
|
|
23
|
+
plan: Plan;
|
|
24
|
+
tools: ToolSpec[];
|
|
25
|
+
}
|
|
26
|
+
/** One rule. Pure over its input and whatever deps it closed over; returns the violations it found. */
|
|
27
|
+
export type AdmissionRule = (input: AdmissionInput) => Promise<AdmissionViolation[]> | AdmissionViolation[];
|
|
28
|
+
export interface PlanAdmission {
|
|
29
|
+
admit(input: AdmissionInput): Promise<AdmissionVerdict>;
|
|
30
|
+
}
|
|
31
|
+
/** Compose rules into the port. Every rule runs; the verdict carries every violation, so a re-plan is
|
|
32
|
+
* told everything at once rather than one thing per round. */
|
|
33
|
+
export declare function planAdmission(rules: readonly AdmissionRule[]): PlanAdmission;
|
|
34
|
+
/** Letters only — "Missio Nexus", "missio-nexus" and the label of `missionexus.org` are one word to a person. */
|
|
35
|
+
export declare const squash: (s: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* AN INSTRUCTION IS ANSWERED BY AN ACT. A tool that declares a capability declares the verbs that name it
|
|
38
|
+
* (`ToolSpec.verbs`). A sentence that OPENS with one of those verbs is an instruction, and a plan for it
|
|
39
|
+
* that contains no capability-bearing step is a read pretending to act — the plan that told a person
|
|
40
|
+
* "nothing was sent" about a payment they asked for. Which act is not judged here (a message and a
|
|
41
|
+
* payment both open with "send"); that a step ACTS is.
|
|
42
|
+
*/
|
|
43
|
+
/** What a tool ESTABLISHES (spec 367 §6), with the declared default: a read establishes who was meant; an act
|
|
44
|
+
* establishes its outcome unless its contract says it only submits. */
|
|
45
|
+
export declare function outcomeClassOf(t: ToolSpec): 'lookup' | 'submission' | 'authoritative';
|
|
46
|
+
export declare const instructionNeedsAct: AdmissionRule;
|
|
47
|
+
/** A step that consumes `{ $ref: name }` must follow a step that provides `ref: name` (spec 367 §4:
|
|
48
|
+
* typed unresolved dependencies — a later step may depend on an earlier one, never on nothing). */
|
|
49
|
+
export declare const dependenciesProvided: AdmissionRule;
|
|
50
|
+
/**
|
|
51
|
+
* Spec 370 P3 — a branch must be DECIDABLE and an edge must point BACKWARD. `when.ref` names a result an
|
|
52
|
+
* earlier step binds (`ref`); `after` names ids of earlier steps. A branch on a result nobody produces would
|
|
53
|
+
* be decided by absence — which is a guess dressed as a condition — and an edge to a later step is a cycle.
|
|
54
|
+
*/
|
|
55
|
+
export declare const branchesDecidable: AdmissionRule;
|
|
56
|
+
/**
|
|
57
|
+
* Spec 371 — THE QUESTION MUST BE ANSWERED BY THE READ THAT ANSWERS IT. A read declares the fact words a
|
|
58
|
+
* question uses to name what it establishes (`answers`: "balance", "how much"). When the sentence names
|
|
59
|
+
* such a fact and an exposed tool answers it, a plan without that tool is answering something else — a
|
|
60
|
+
* survey of receipts for a balance question. The rule reads declarations only, and it says which tool.
|
|
61
|
+
*/
|
|
62
|
+
export declare const questionAnsweredByRead: AdmissionRule;
|
|
63
|
+
/** A step naming a tool this agent does not expose. The loop refuses it anyway (`unknown_tool`); as a rule it
|
|
64
|
+
* lets an eval and a re-plan see WHICH capability was missing. */
|
|
65
|
+
export declare const capabilitiesAvailable: AdmissionRule;
|
|
66
|
+
/** A PLACEHOLDER IS NOT AN ARGUMENT. "<UNKNOWN>", "TBD", "n/a" inside a step is a value the person would be
|
|
67
|
+
* asked to sign over. Omit the argument and it is asked for; a placeholder is refused. */
|
|
68
|
+
export declare const noPlaceholders: AdmissionRule;
|
|
69
|
+
/**
|
|
70
|
+
* THE SUBJECT THE SENTENCE NAMES MUST BE IN THE STEP. A tool that declares a `subject` argument (spec 366)
|
|
71
|
+
* is answered by the agent that argument names. When the sentence contains the name of an agent the asker
|
|
72
|
+
* KNOWS — from their own links, supplied by the harness, never guessed from the directory — and the step
|
|
73
|
+
* leaves the subject empty, the step would run against the addressee's own records and answer for the
|
|
74
|
+
* wrong agent. That is the Missio Nexus incident, as a rule.
|
|
75
|
+
*/
|
|
76
|
+
export declare function subjectNamedInAsk(knownNames: (intent: Intent) => Promise<Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
agent: string;
|
|
79
|
+
}>>): AdmissionRule;
|
|
80
|
+
/**
|
|
81
|
+
* Spec 379 (appendix M4) — AN OUTSIDE AGENT MAY ANSWER, NEVER ACT. A step whose `executor` is outside this
|
|
82
|
+
* deployment (the caller says which — an https card URL, an address not served here) may run only a
|
|
83
|
+
* tool that exercises no capability: its answer is an observation. A value-moving or record-changing
|
|
84
|
+
* step aimed at an outside agent is refused at admission, before any planner or verifier spends anything.
|
|
85
|
+
*/
|
|
86
|
+
export declare function externalExecutorsReadOnly(isExternal: (executor: string) => boolean): AdmissionRule;
|
|
87
|
+
//# sourceMappingURL=admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../src/admission.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEzD,mGAAmG;AACnG,MAAM,MAAM,aAAa,GACrB,0BAA0B,GAC1B,yBAAyB,GACzB,wBAAwB,GACxB,4BAA4B,GAC5B,0BAA0B,GAC1B,yBAAyB,GACzB,oBAAoB,GACpB,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,aAAa,CAAC;IACpB,+EAA+E;IAC/E,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;CACnD;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAAC;AAE1G,MAAM,WAAW,cAAc;IAAG,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC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CAWlG"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/** Compose rules into the port. Every rule runs; the verdict carries every violation, so a re-plan is
|
|
2
|
+
* told everything at once rather than one thing per round. */
|
|
3
|
+
export function planAdmission(rules) {
|
|
4
|
+
return {
|
|
5
|
+
async admit(input) {
|
|
6
|
+
const violations = (await Promise.all(rules.map((r) => r(input)))).flat();
|
|
7
|
+
return violations.length ? { admitted: false, violations } : { admitted: true };
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const lc = (s) => s.trim().toLowerCase();
|
|
12
|
+
/** Letters only — "Missio Nexus", "missio-nexus" and the label of `missionexus.org` are one word to a person. */
|
|
13
|
+
export const squash = (s) => lc(s).replace(/[^a-z0-9]+/g, '');
|
|
14
|
+
/** The imperative opening of a sentence, with the polite wrappers stripped: "please send…", "can you pay…",
|
|
15
|
+
* "i want to create…" all open with the verb. A question ("who did I send money to") does not. */
|
|
16
|
+
function imperativeOf(goal) {
|
|
17
|
+
return lc(goal).replace(/^(please\s+|can you\s+|could you\s+|would you\s+|i want to\s+|i'd like to\s+|i would like to\s+|go ahead and\s+)+/, '');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* AN INSTRUCTION IS ANSWERED BY AN ACT. A tool that declares a capability declares the verbs that name it
|
|
21
|
+
* (`ToolSpec.verbs`). A sentence that OPENS with one of those verbs is an instruction, and a plan for it
|
|
22
|
+
* that contains no capability-bearing step is a read pretending to act — the plan that told a person
|
|
23
|
+
* "nothing was sent" about a payment they asked for. Which act is not judged here (a message and a
|
|
24
|
+
* payment both open with "send"); that a step ACTS is.
|
|
25
|
+
*/
|
|
26
|
+
/** What a tool ESTABLISHES (spec 367 §6), with the declared default: a read establishes who was meant; an act
|
|
27
|
+
* establishes its outcome unless its contract says it only submits. */
|
|
28
|
+
export function outcomeClassOf(t) {
|
|
29
|
+
return t.establishes ?? (t.capability ? 'authoritative' : 'lookup');
|
|
30
|
+
}
|
|
31
|
+
export const instructionNeedsAct = ({ intent, plan, tools }) => {
|
|
32
|
+
const opening = imperativeOf(intent.goal);
|
|
33
|
+
const acts = tools.filter((t) => t.capability && t.verbs?.length);
|
|
34
|
+
const claims = (t) => !!t.verbs?.some((v) => opening === lc(v) || opening.startsWith(`${lc(v)} `));
|
|
35
|
+
const named = acts.filter(claims);
|
|
36
|
+
if (!named.length)
|
|
37
|
+
return [];
|
|
38
|
+
const byId = new Map(tools.map((t) => [t.id, t]));
|
|
39
|
+
// A READ MAY CLAIM THE VERB TOO (spec 379): "ask the clock what time it is" opens with "ask", which an
|
|
40
|
+
// invitation act also claims. When a lookup in the plan declares that verb, the read IS what was
|
|
41
|
+
// instructed — consulting an outside agent — and the plan discharges the sentence by doing it.
|
|
42
|
+
if (plan.steps.some((s) => { const t = byId.get(s.toolId); return !!t && !t.capability && claims(t); }))
|
|
43
|
+
return [];
|
|
44
|
+
// The outcome rule (§6), not a "last tool" rule: a lookup may precede the act (who is "my daughter"), and
|
|
45
|
+
// a notification may follow it. What may not happen is a plan whose every step only ESTABLISHES WHO WAS
|
|
46
|
+
// MEANT — a lookup cannot discharge an instruction, however well it went.
|
|
47
|
+
const canDischarge = plan.steps.some((s) => { const t = byId.get(s.toolId); return !!t && outcomeClassOf(t) !== 'lookup'; });
|
|
48
|
+
if (canDischarge)
|
|
49
|
+
return [];
|
|
50
|
+
return [{
|
|
51
|
+
code: 'OUTCOME_NOT_ESTABLISHED', recovery: 'replan',
|
|
52
|
+
message: `"${intent.goal}" is an instruction (it opens with ${named.map((t) => `"${t.verbs[0]}"`).join(' / ')}) and every step in the plan only looks something up (${plan.steps.map((s) => s.toolId).join(', ') || 'nothing'}) — a lookup cannot establish that it was done. Plan the capability that performs it — ${named.map((t) => t.id).join(' or ')} — and pass the person's words as its arguments; it resolves who is meant itself.`,
|
|
53
|
+
}];
|
|
54
|
+
};
|
|
55
|
+
/** A step that consumes `{ $ref: name }` must follow a step that provides `ref: name` (spec 367 §4:
|
|
56
|
+
* typed unresolved dependencies — a later step may depend on an earlier one, never on nothing). */
|
|
57
|
+
export const dependenciesProvided = ({ plan }) => {
|
|
58
|
+
const out = [];
|
|
59
|
+
const provided = new Set();
|
|
60
|
+
plan.steps.forEach((s, i) => {
|
|
61
|
+
const refs = new Set();
|
|
62
|
+
const walk = (v) => {
|
|
63
|
+
if (!v || typeof v !== 'object')
|
|
64
|
+
return;
|
|
65
|
+
if (Array.isArray(v)) {
|
|
66
|
+
v.forEach(walk);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const o = v;
|
|
70
|
+
if (typeof o.$ref === 'string')
|
|
71
|
+
refs.add(o.$ref.split('.')[0]);
|
|
72
|
+
if (typeof o.$forEach === 'string')
|
|
73
|
+
refs.add(o.$forEach.split('.')[0]);
|
|
74
|
+
Object.values(o).forEach(walk);
|
|
75
|
+
};
|
|
76
|
+
walk(s.args);
|
|
77
|
+
// The fan-out form (spec 358 W4): `forEach: { ref: 'roster.members' }` names the enumerating step by ref.
|
|
78
|
+
const fe = s.forEach;
|
|
79
|
+
if (fe && typeof fe.ref === 'string')
|
|
80
|
+
refs.add(fe.ref.split('.')[0]);
|
|
81
|
+
for (const r of refs)
|
|
82
|
+
if (!provided.has(r))
|
|
83
|
+
out.push({ code: 'DEPENDENCY_NOT_SATISFIED', recovery: 'replan', stepIndex: i, toolId: s.toolId, field: r, message: `step ${i + 1} (${s.toolId}) uses "${r}" before any step provides it — order the step that produces "${r}" first, or drop the reference.` });
|
|
84
|
+
if (s.ref)
|
|
85
|
+
provided.add(s.ref);
|
|
86
|
+
});
|
|
87
|
+
return out;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Spec 370 P3 — a branch must be DECIDABLE and an edge must point BACKWARD. `when.ref` names a result an
|
|
91
|
+
* earlier step binds (`ref`); `after` names ids of earlier steps. A branch on a result nobody produces would
|
|
92
|
+
* be decided by absence — which is a guess dressed as a condition — and an edge to a later step is a cycle.
|
|
93
|
+
*/
|
|
94
|
+
export const branchesDecidable = ({ plan }) => {
|
|
95
|
+
const out = [];
|
|
96
|
+
const provided = new Set();
|
|
97
|
+
const ids = new Set();
|
|
98
|
+
plan.steps.forEach((s, i) => {
|
|
99
|
+
const w = s.when;
|
|
100
|
+
if (w && (typeof w.ref !== 'string' || !provided.has(w.ref.split('.')[0]))) {
|
|
101
|
+
out.push({ code: 'BRANCH_UNDECIDABLE', recovery: 'replan', stepIndex: i, toolId: s.toolId, field: 'when', message: `step ${i + 1} (${s.toolId}) branches on "${String(w.ref ?? '')}", which no earlier step produces — bind the producing step with $ref first, or drop the condition.` });
|
|
102
|
+
}
|
|
103
|
+
for (const id of s.after ?? []) {
|
|
104
|
+
if (typeof id !== 'string' || !ids.has(id))
|
|
105
|
+
out.push({ code: 'BRANCH_UNDECIDABLE', recovery: 'replan', stepIndex: i, toolId: s.toolId, field: 'after', message: `step ${i + 1} (${s.toolId}) waits for "${String(id)}", which is not an earlier step's id.` });
|
|
106
|
+
}
|
|
107
|
+
if (s.ref)
|
|
108
|
+
provided.add(s.ref);
|
|
109
|
+
ids.add(s.id ?? `s${i}`);
|
|
110
|
+
});
|
|
111
|
+
return out;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Spec 371 — THE QUESTION MUST BE ANSWERED BY THE READ THAT ANSWERS IT. A read declares the fact words a
|
|
115
|
+
* question uses to name what it establishes (`answers`: "balance", "how much"). When the sentence names
|
|
116
|
+
* such a fact and an exposed tool answers it, a plan without that tool is answering something else — a
|
|
117
|
+
* survey of receipts for a balance question. The rule reads declarations only, and it says which tool.
|
|
118
|
+
*/
|
|
119
|
+
export const questionAnsweredByRead = ({ intent, plan, tools }) => {
|
|
120
|
+
const goal = ` ${lc(intent.goal).replace(/[^a-z0-9]+/g, ' ')} `;
|
|
121
|
+
const out = [];
|
|
122
|
+
const inPlan = new Set(plan.steps.map((s) => s.toolId));
|
|
123
|
+
for (const t of tools) {
|
|
124
|
+
if (!t.answers?.length || inPlan.has(t.id))
|
|
125
|
+
continue;
|
|
126
|
+
const named = t.answers.find((w) => goal.includes(` ${lc(w).replace(/[^a-z0-9]+/g, ' ')} `));
|
|
127
|
+
if (!named)
|
|
128
|
+
continue;
|
|
129
|
+
out.push({ code: 'QUESTION_NOT_ANSWERED', recovery: 'replan', toolId: t.id, field: named, message: `the sentence asks about "${named}", which ${t.id} answers, and the plan does not use it — use ${t.id} for that, not a survey of other records.` });
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
/** A step naming a tool this agent does not expose. The loop refuses it anyway (`unknown_tool`); as a rule it
|
|
134
|
+
* lets an eval and a re-plan see WHICH capability was missing. */
|
|
135
|
+
export const capabilitiesAvailable = ({ plan, tools }) => {
|
|
136
|
+
const ids = new Set(tools.map((t) => t.id));
|
|
137
|
+
return plan.steps.flatMap((s, i) => ids.has(s.toolId) ? [] : [{ code: 'CAPABILITY_UNAVAILABLE', recovery: 'refuse', stepIndex: i, toolId: s.toolId, message: `step ${i + 1} names "${s.toolId}", which this agent does not offer — choose among: ${[...ids].join(', ')}.` }]);
|
|
138
|
+
};
|
|
139
|
+
/** A PLACEHOLDER IS NOT AN ARGUMENT. "<UNKNOWN>", "TBD", "n/a" inside a step is a value the person would be
|
|
140
|
+
* asked to sign over. Omit the argument and it is asked for; a placeholder is refused. */
|
|
141
|
+
export const noPlaceholders = ({ plan }) => plan.steps.flatMap((s, i) => Object.entries(s.args)
|
|
142
|
+
.filter(([, v]) => typeof v === 'string' && /^<.*>$|^(unknown|tbd|n\/a|null|undefined|placeholder)$/i.test(v.trim()))
|
|
143
|
+
.map(([k, v]) => ({ code: 'UNSUPPORTED_BINDING_SOURCE', recovery: 'ask', stepIndex: i, toolId: s.toolId, field: k, message: `step ${i + 1} (${s.toolId}) carries a placeholder for "${k}" (${String(v)}); omit an argument the sentence did not give, and it will be asked for.` })));
|
|
144
|
+
/**
|
|
145
|
+
* THE SUBJECT THE SENTENCE NAMES MUST BE IN THE STEP. A tool that declares a `subject` argument (spec 366)
|
|
146
|
+
* is answered by the agent that argument names. When the sentence contains the name of an agent the asker
|
|
147
|
+
* KNOWS — from their own links, supplied by the harness, never guessed from the directory — and the step
|
|
148
|
+
* leaves the subject empty, the step would run against the addressee's own records and answer for the
|
|
149
|
+
* wrong agent. That is the Missio Nexus incident, as a rule.
|
|
150
|
+
*/
|
|
151
|
+
export function subjectNamedInAsk(knownNames) {
|
|
152
|
+
return async ({ intent, plan, tools }) => {
|
|
153
|
+
const byId = new Map(tools.map((t) => [t.id, t]));
|
|
154
|
+
const candidates = plan.steps.map((s, i) => ({ s, i, tool: byId.get(s.toolId) }))
|
|
155
|
+
.filter(({ s, tool }) => tool?.subject && !String(s.args[tool.subject] ?? '').trim());
|
|
156
|
+
if (!candidates.length)
|
|
157
|
+
return [];
|
|
158
|
+
const goal = squash(intent.goal);
|
|
159
|
+
const names = (await knownNames(intent).catch(() => [])).filter((n) => n.name && !/^0x[0-9a-f]{40}$/i.test(n.name));
|
|
160
|
+
const named = names.filter((n) => {
|
|
161
|
+
const full = squash(n.name);
|
|
162
|
+
const label = squash(n.name.split('.')[0] ?? '');
|
|
163
|
+
return (full.length >= 4 && goal.includes(full)) || (label.length >= 4 && goal.includes(label));
|
|
164
|
+
});
|
|
165
|
+
if (!named.length)
|
|
166
|
+
return [];
|
|
167
|
+
return candidates.map(({ s, i, tool }) => ({
|
|
168
|
+
code: 'REQUIRED_ROLE_UNRESOLVED', recovery: 'resolve', stepIndex: i, toolId: s.toolId, field: tool.subject,
|
|
169
|
+
message: `the ask names ${named.map((n) => `"${n.name}"`).join(' / ')} and step ${i + 1} (${s.toolId}) names no ${tool.subject}; pass the name the person used as "${tool.subject}".`,
|
|
170
|
+
}));
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Spec 379 (appendix M4) — AN OUTSIDE AGENT MAY ANSWER, NEVER ACT. A step whose `executor` is outside this
|
|
175
|
+
* deployment (the caller says which — an https card URL, an address not served here) may run only a
|
|
176
|
+
* tool that exercises no capability: its answer is an observation. A value-moving or record-changing
|
|
177
|
+
* step aimed at an outside agent is refused at admission, before any planner or verifier spends anything.
|
|
178
|
+
*/
|
|
179
|
+
export function externalExecutorsReadOnly(isExternal) {
|
|
180
|
+
return ({ plan, tools }) => {
|
|
181
|
+
const out = [];
|
|
182
|
+
plan.steps.forEach((st, i) => {
|
|
183
|
+
const ex = st.executor;
|
|
184
|
+
if (typeof ex !== 'string' || !ex || !isExternal(ex))
|
|
185
|
+
return;
|
|
186
|
+
const tool = tools.find((t) => t.id === st.toolId);
|
|
187
|
+
if (tool?.capability)
|
|
188
|
+
out.push({ code: 'EXTERNAL_EXECUTOR_ACT', recovery: 'refuse', stepIndex: i, toolId: st.toolId, field: 'executor', message: `step ${i + 1} (${st.toolId}) exercises ${tool.capability.id} and names ${ex} to run it — an outside agent may answer a question, never perform an act; run the step here or drop it.` });
|
|
189
|
+
});
|
|
190
|
+
return out;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.js","sourceRoot":"","sources":["../src/admission.ts"],"names":[],"mappings":"AAkDA;+DAC+D;AAC/D,MAAM,UAAU,aAAa,CAAC,KAA+B;IAC3D,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,KAAK;YACf,MAAM,UAAU,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1E,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAClF,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,EAA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C,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAI,EAA6B,CAAC,QAAQ,CAAC;YACnD,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBAAE,OAAO;YAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC;YACnD,IAAI,IAAI,EAAE,UAAU;gBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,MAAM,eAAe,IAAI,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,0GAA0G,EAAE,CAAC,CAAC;QAC7U,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { StepObservation, PlanStep } from './types.js';
|
|
2
|
+
import type { RunResult } from './types.js';
|
|
3
|
+
export declare const ARTIFACT_REF_TYPE: "ap.artifact-ref.v1";
|
|
4
|
+
/** A result whose canonical JSON is longer than this is offloaded when a store is bound. A deployment setting. */
|
|
5
|
+
export declare const OFFLOAD_THRESHOLD_CHARS = 8000;
|
|
6
|
+
/** The most a summary may run to — a shape, never a body. */
|
|
7
|
+
export declare const SUMMARY_MAX_CHARS = 600;
|
|
8
|
+
/** The stand-in for an offloaded result: where the body is, what it is, and its shape. */
|
|
9
|
+
export interface ArtifactRefV1 {
|
|
10
|
+
$artifact: typeof ARTIFACT_REF_TYPE;
|
|
11
|
+
/** The agent whose vault holds it (the acting agent — the run's addressee). */
|
|
12
|
+
agent: string;
|
|
13
|
+
/** The vault record key: `run.artifact:<runRef>:<stepRef>`. */
|
|
14
|
+
recordType: string;
|
|
15
|
+
/** sha256 of the canonical JSON of the body — the same bytes the receipt's outputDigest commits to. */
|
|
16
|
+
digest: string;
|
|
17
|
+
bytes: number;
|
|
18
|
+
toolId: string;
|
|
19
|
+
summary: string;
|
|
20
|
+
/** The few top-level FACTS the run's record and spans read off a result (a chain tx hash, a routed step's
|
|
21
|
+
* `via`, a count) — kept on the reference so offloading a body loses no evidence. Names from a fixed list. */
|
|
22
|
+
retained?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** Top-level result keys retained on a reference: what the record, the spans and the graph cite. */
|
|
25
|
+
export declare const RETAINED_RESULT_KEYS: readonly ["txHash", "via", "count", "total", "ok", "outcome"];
|
|
26
|
+
/** The facts of a result whether it is whole or a reference — what a projection reads. */
|
|
27
|
+
export declare function resultFactsOf(result: unknown): Record<string, unknown> | undefined;
|
|
28
|
+
export declare const RUN_ARTIFACT_RECORD_PREFIX: "run.artifact:";
|
|
29
|
+
export declare const runArtifactRecordKey: (runRef: string, stepRef: string) => string;
|
|
30
|
+
/** The vault record an offloaded result becomes. */
|
|
31
|
+
export interface RunArtifactRecordV1 {
|
|
32
|
+
type: 'ap.run-artifact.v1';
|
|
33
|
+
runRef: string;
|
|
34
|
+
stepRef: string;
|
|
35
|
+
toolId: string;
|
|
36
|
+
digest: string;
|
|
37
|
+
bytes: number;
|
|
38
|
+
at: number;
|
|
39
|
+
result: unknown;
|
|
40
|
+
}
|
|
41
|
+
export declare function isArtifactRef(v: unknown): v is ArtifactRefV1;
|
|
42
|
+
/** Canonical JSON: keys sorted, bigints as strings — the same bytes the receipt digests. */
|
|
43
|
+
export declare const canonicalJson: (v: unknown) => string;
|
|
44
|
+
/**
|
|
45
|
+
* A DETERMINISTIC summary of a result: its kind and top-level shape, the length of every array, the
|
|
46
|
+
* first three items' title-like field, a count when the result declares one. Bounded, never a body,
|
|
47
|
+
* never a model's words. Two runs over the same result produce the same string.
|
|
48
|
+
*/
|
|
49
|
+
export declare function summarizeResult(result: unknown): string;
|
|
50
|
+
/** The port the app binds to the acting agent's vault door. Failures throw — an artifact that could not be
|
|
51
|
+
* written is a step whose result stays in the record whole, and the caller says so (never a silent drop). */
|
|
52
|
+
export interface ArtifactStore {
|
|
53
|
+
put(record: RunArtifactRecordV1, agent: string): Promise<{
|
|
54
|
+
ok: true;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
error: string;
|
|
58
|
+
}>;
|
|
59
|
+
get(ref: ArtifactRefV1): Promise<RunArtifactRecordV1 | null>;
|
|
60
|
+
}
|
|
61
|
+
export interface OffloadReport {
|
|
62
|
+
stepRef: string;
|
|
63
|
+
toolId: string;
|
|
64
|
+
bytes: number;
|
|
65
|
+
recordType: string;
|
|
66
|
+
ok: boolean;
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The record / checkpoint form of a run's observations: every result whose canonical JSON exceeds the
|
|
71
|
+
* threshold is written to the store and replaced by its reference. The receipts are untouched (their
|
|
72
|
+
* digests already commit to the full output). A write that fails leaves the result whole and is reported.
|
|
73
|
+
*/
|
|
74
|
+
export declare function offloadObservations(steps: ReadonlyArray<StepObservation>, opts: {
|
|
75
|
+
runRef: string;
|
|
76
|
+
agent: string;
|
|
77
|
+
store: ArtifactStore;
|
|
78
|
+
threshold?: number;
|
|
79
|
+
now?: number;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
steps: StepObservation[];
|
|
82
|
+
offloaded: OffloadReport[];
|
|
83
|
+
}>;
|
|
84
|
+
/** The record form of a whole RunResult (steps offloaded; everything else as it was). */
|
|
85
|
+
export declare function offloadRunResult<T extends Pick<RunResult, 'steps'>>(result: T, opts: Parameters<typeof offloadObservations>[1]): Promise<{
|
|
86
|
+
result: T;
|
|
87
|
+
offloaded: OffloadReport[];
|
|
88
|
+
}>;
|
|
89
|
+
/** The step references a plan's remaining steps reach through `$ref` (`{ $ref: 'name.path' }` — the name is
|
|
90
|
+
* the producing step's `ref` or `id`). */
|
|
91
|
+
export declare function refsReachedBy(steps: ReadonlyArray<PlanStep>): Set<string>;
|
|
92
|
+
/**
|
|
93
|
+
* The inverse, on a resume: a completed step whose result is a reference gets its body back from the store
|
|
94
|
+
* ONLY when a remaining step's `$ref` reaches it (by the step's `ref`, `id` or stepRef). A body nobody will
|
|
95
|
+
* read stays a reference. A missing artifact is an error the caller surfaces — a resume that guessed a
|
|
96
|
+
* result would be a resume that lied.
|
|
97
|
+
*/
|
|
98
|
+
export declare function rehydrateObservations<T extends {
|
|
99
|
+
stepRef: string;
|
|
100
|
+
result?: unknown;
|
|
101
|
+
}>(completed: ReadonlyArray<T>, plan: {
|
|
102
|
+
steps: ReadonlyArray<PlanStep>;
|
|
103
|
+
}, store: ArtifactStore): Promise<{
|
|
104
|
+
completed: T[];
|
|
105
|
+
rehydrated: string[];
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Spec 391 W2 — what a RE-PLAN sees of prior observations: a body over the threshold becomes its summary (a
|
|
109
|
+
* reference keeps its own). A planner deciding what comes next needs what a step was and how big, not 40 KB
|
|
110
|
+
* of it in the prompt.
|
|
111
|
+
*/
|
|
112
|
+
export declare function compactObservations(observations: ReadonlyArray<StepObservation>, threshold?: number): StepObservation[];
|
|
113
|
+
export interface EvidenceItemV1 {
|
|
114
|
+
tool: string;
|
|
115
|
+
result: unknown; /** A summary stood in for the body. */
|
|
116
|
+
summarized?: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface FittedEvidenceV1 {
|
|
119
|
+
items: EvidenceItemV1[];
|
|
120
|
+
/** Characters of the fitted evidence, and of the whole. */
|
|
121
|
+
chars: number;
|
|
122
|
+
of: number;
|
|
123
|
+
/** Every step whose body was replaced by its summary, in order — for the trace and the governor. */
|
|
124
|
+
dropped: Array<{
|
|
125
|
+
tool: string;
|
|
126
|
+
stepRef?: string;
|
|
127
|
+
bytes: number;
|
|
128
|
+
}>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The composer's evidence, FITTED to a budget instead of sliced: successful observations in order; a
|
|
132
|
+
* reference contributes its summary; a body that fits is kept whole; a body that would push the whole
|
|
133
|
+
* past the cap is replaced by its summary and recorded as dropped. The first item is always kept whole
|
|
134
|
+
* when it fits alone — an answer with no evidence is not an answer.
|
|
135
|
+
*/
|
|
136
|
+
export declare function fitEvidence(observations: ReadonlyArray<StepObservation>, cap: number): FittedEvidenceV1;
|
|
137
|
+
//# sourceMappingURL=artifacts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../src/artifacts.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,iBAAiB,EAAG,oBAA6B,CAAC;AAC/D,kHAAkH;AAClH,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAC7C,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,OAAO,iBAAiB,CAAC;IACpC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,uGAAuG;IACvG,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB;mHAC+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,+DAAgE,C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