loopforge 3.7.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +171 -157
- package/dist/audit.d.ts +53 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +106 -22
- package/dist/audit.js.map +1 -1
- package/dist/canonical-state.d.ts +75 -69
- package/dist/canonical-state.d.ts.map +1 -1
- package/dist/canonical-state.js +276 -168
- package/dist/canonical-state.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +111 -12
- package/dist/cli.js.map +1 -1
- package/dist/cognitive-facts.d.ts +13 -0
- package/dist/cognitive-facts.d.ts.map +1 -1
- package/dist/cognitive-facts.js +30 -16
- package/dist/cognitive-facts.js.map +1 -1
- package/dist/cognitive-governance.d.ts +30 -6
- package/dist/cognitive-governance.d.ts.map +1 -1
- package/dist/cognitive-governance.js +74 -18
- package/dist/cognitive-governance.js.map +1 -1
- package/dist/committed-round.d.ts +109 -24
- package/dist/committed-round.d.ts.map +1 -1
- package/dist/committed-round.js +235 -52
- package/dist/committed-round.js.map +1 -1
- package/dist/contract-items.d.ts +55 -0
- package/dist/contract-items.d.ts.map +1 -0
- package/dist/contract-items.js +180 -0
- package/dist/contract-items.js.map +1 -0
- package/dist/enforcement-gate.d.ts +43 -20
- package/dist/enforcement-gate.d.ts.map +1 -1
- package/dist/enforcement-gate.js +269 -378
- package/dist/enforcement-gate.js.map +1 -1
- package/dist/engine.d.ts +11 -6
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +102 -67
- package/dist/engine.js.map +1 -1
- package/dist/evidence-claims.d.ts +4 -4
- package/dist/evidence-claims.d.ts.map +1 -1
- package/dist/evidence-claims.js +16 -14
- package/dist/evidence-claims.js.map +1 -1
- package/dist/evidence-provider.d.ts +91 -90
- package/dist/evidence-provider.d.ts.map +1 -1
- package/dist/evidence-provider.js +349 -160
- package/dist/evidence-provider.js.map +1 -1
- package/dist/explain.d.ts +76 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +127 -0
- package/dist/explain.js.map +1 -0
- package/dist/generate-schema.js +250 -53
- package/dist/generate-schema.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/loop-compiler.d.ts +41 -40
- package/dist/loop-compiler.d.ts.map +1 -1
- package/dist/loop-compiler.js +275 -515
- package/dist/loop-compiler.js.map +1 -1
- package/dist/loop-extras-parser.d.ts +0 -1
- package/dist/loop-extras-parser.d.ts.map +1 -1
- package/dist/loop-extras-parser.js +0 -4
- package/dist/loop-extras-parser.js.map +1 -1
- package/dist/loop-projection.d.ts.map +1 -1
- package/dist/loop-projection.js +3 -1
- package/dist/loop-projection.js.map +1 -1
- package/dist/mcp/round-lifecycle.d.ts +40 -21
- package/dist/mcp/round-lifecycle.d.ts.map +1 -1
- package/dist/mcp/round-lifecycle.js +173 -120
- package/dist/mcp/round-lifecycle.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +63 -10
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts +53 -7
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +240 -139
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/submission-boundary.d.ts +89 -0
- package/dist/mcp/submission-boundary.d.ts.map +1 -0
- package/dist/mcp/submission-boundary.js +203 -0
- package/dist/mcp/submission-boundary.js.map +1 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +377 -125
- package/dist/mcp/tools.js.map +1 -1
- package/dist/policy-metrics.js +2 -2
- package/dist/policy-metrics.js.map +1 -1
- package/dist/policy.d.ts +65 -95
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +151 -39
- package/dist/policy.js.map +1 -1
- package/dist/prompt-assembler.d.ts +7 -33
- package/dist/prompt-assembler.d.ts.map +1 -1
- package/dist/prompt-assembler.js +313 -473
- package/dist/prompt-assembler.js.map +1 -1
- package/dist/prompt-policy.d.ts +1 -4
- package/dist/prompt-policy.d.ts.map +1 -1
- package/dist/prompt-policy.js +6 -7
- package/dist/prompt-policy.js.map +1 -1
- package/dist/protocol.d.ts +411 -168
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +23 -69
- package/dist/protocol.js.map +1 -1
- package/dist/replay.js +2 -2
- package/dist/replay.js.map +1 -1
- package/dist/round-contract.d.ts +69 -57
- package/dist/round-contract.d.ts.map +1 -1
- package/dist/round-contract.js +104 -64
- package/dist/round-contract.js.map +1 -1
- package/dist/round-coordinator.d.ts +55 -16
- package/dist/round-coordinator.d.ts.map +1 -1
- package/dist/round-coordinator.js +179 -57
- package/dist/round-coordinator.js.map +1 -1
- package/dist/round-driver.d.ts +7 -5
- package/dist/round-driver.d.ts.map +1 -1
- package/dist/round-driver.js +2 -1
- package/dist/round-driver.js.map +1 -1
- package/dist/round-facts.d.ts +96 -0
- package/dist/round-facts.d.ts.map +1 -0
- package/dist/round-facts.js +216 -0
- package/dist/round-facts.js.map +1 -0
- package/dist/round-transaction.d.ts +23 -9
- package/dist/round-transaction.d.ts.map +1 -1
- package/dist/round-transaction.js +99 -22
- package/dist/round-transaction.js.map +1 -1
- package/dist/self-eval.d.ts +127 -11
- package/dist/self-eval.d.ts.map +1 -1
- package/dist/self-eval.js +517 -36
- package/dist/self-eval.js.map +1 -1
- package/dist/subgoal-state.d.ts +77 -0
- package/dist/subgoal-state.d.ts.map +1 -0
- package/dist/subgoal-state.js +198 -0
- package/dist/subgoal-state.js.map +1 -0
- package/dist/token-utils.d.ts +52 -19
- package/dist/token-utils.d.ts.map +1 -1
- package/dist/token-utils.js +83 -72
- package/dist/token-utils.js.map +1 -1
- package/dist/verification-gate.d.ts +27 -46
- package/dist/verification-gate.d.ts.map +1 -1
- package/dist/verification-gate.js +308 -557
- package/dist/verification-gate.js.map +1 -1
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +9 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +17 -0
- package/dist/workspace.js.map +1 -1
- package/loop_policy.json +17 -25
- package/package.json +7 -7
- package/skills/perception/SKILL.md +266 -64
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** The runtime's submission boundary — every check a submission must pass
|
|
2
|
+
* before a round may advance.
|
|
3
|
+
*
|
|
4
|
+
* v3.8.1: it lives here, not in the MCP tool handler. `SessionManager` is the
|
|
5
|
+
* runtime's public entry point (`index.ts` exports it) and `RoundLifecycle`
|
|
6
|
+
* is internal, so a boundary in the transport meant a library caller, a
|
|
7
|
+
* future CLI command, or any direct `mgr.advance()` got NONE of it. The
|
|
8
|
+
* handler now only maps the result onto its tool envelope.
|
|
9
|
+
*
|
|
10
|
+
* The placement is also what makes the ordering invariants hold. AGENTS.md:
|
|
11
|
+
* an invalid evaluation is handled BEFORE `RoundLifecycle.advance()` and
|
|
12
|
+
* "must not save session state, write the Vault, run verification or
|
|
13
|
+
* enforcement gates, increment rejection state, or record metrics". So it
|
|
14
|
+
* runs before the session queue and before the lease heartbeat — renewing a
|
|
15
|
+
* lease writes the session document, which would be a durable effect of a
|
|
16
|
+
* payload that was never accepted. It is judged before the session is even
|
|
17
|
+
* resolved, because a malformed evaluation is a payload defect whatever the
|
|
18
|
+
* session's state, and answering `session_not_found` for it would send the
|
|
19
|
+
* agent after the wrong problem.
|
|
20
|
+
*
|
|
21
|
+
* This module also owns the compile context the boundary reads, because the
|
|
22
|
+
* sub-goal reference space IS the compiled set the prompt carried — the
|
|
23
|
+
* session's own projection reads the same function, so the two cannot
|
|
24
|
+
* disagree about it.
|
|
25
|
+
*/
|
|
26
|
+
import type { LoopStore } from "../loop-store.js";
|
|
27
|
+
import type { LoopForgeResponse, SubGoal } from "../protocol.js";
|
|
28
|
+
import { LoopForgeEngine } from "../engine.js";
|
|
29
|
+
import type { ActiveContractView } from "../round-contract.js";
|
|
30
|
+
import { buildSelfEvaluation } from "../self-eval.js";
|
|
31
|
+
import type { AdvanceResult } from "./round-lifecycle.js";
|
|
32
|
+
/** What `compileSessionContext` needs from a session. Structural, so both the
|
|
33
|
+
* session manager and the boundary can pass their own view of it. */
|
|
34
|
+
export interface CompileContextSession {
|
|
35
|
+
loopId: string;
|
|
36
|
+
task: string;
|
|
37
|
+
maxRounds: number;
|
|
38
|
+
currentRound: number;
|
|
39
|
+
lastCompileResponse?: LoopForgeResponse | null;
|
|
40
|
+
roundSnapshot?: {
|
|
41
|
+
roundId: string;
|
|
42
|
+
} | null;
|
|
43
|
+
engine: LoopForgeEngine;
|
|
44
|
+
}
|
|
45
|
+
/** The compile response this round's prompt came from.
|
|
46
|
+
*
|
|
47
|
+
* Cached-when-fresh (the artifact's deterministic roundId guards against
|
|
48
|
+
* stale reuse), recompiled otherwise with `persistLineage: false` so it never
|
|
49
|
+
* writes the Vault, and null when it cannot be observed. Callers fail OPEN:
|
|
50
|
+
* an unobservable reference space must not become a rejection. */
|
|
51
|
+
export declare function compileSessionContext(session: CompileContextSession): LoopForgeResponse | null;
|
|
52
|
+
/** The sub-goal set an agent may legitimately reference: the compiled set the
|
|
53
|
+
* prompt carried, PLUS this submission's own `emerged_subtasks` — a sub-goal
|
|
54
|
+
* may be created and referenced (or transitioned) in one round. Null when it
|
|
55
|
+
* cannot be observed. */
|
|
56
|
+
export declare function knownSubGoalsFor(session: CompileContextSession, emerged: string[]): SubGoal[] | null;
|
|
57
|
+
/** The ACTIVE Round Contract governing a session's next round — ONE
|
|
58
|
+
* derivation, shared by the session's public view and the boundary. */
|
|
59
|
+
export declare function activeContractOf(store: LoopStore, session: {
|
|
60
|
+
loopId: string;
|
|
61
|
+
currentRound: number;
|
|
62
|
+
}): ActiveContractView | null;
|
|
63
|
+
/** The boundary's outcome. `submissionError` is shaped for `AdvanceResult` so
|
|
64
|
+
* a caller maps it straight onto its error envelope. */
|
|
65
|
+
export type SubmissionBoundary = {
|
|
66
|
+
ok: true;
|
|
67
|
+
evaluation: ReturnType<typeof buildSelfEvaluation>;
|
|
68
|
+
} | {
|
|
69
|
+
ok: false;
|
|
70
|
+
stopDetail: string;
|
|
71
|
+
submissionError: NonNullable<AdvanceResult["submissionError"]>;
|
|
72
|
+
};
|
|
73
|
+
/** THE submission boundary. Five checks, in this order, all of them before
|
|
74
|
+
* anything durable happens.
|
|
75
|
+
*
|
|
76
|
+
* Two are STRUCTURAL boundaries that REJECT rather than normalize:
|
|
77
|
+
* `subgoal_updates` (machine-processable state transitions) and the Round
|
|
78
|
+
* Contract declaration together with its item claims. Everything else about
|
|
79
|
+
* an evaluation is normalized leniently by `buildSelfEvaluation` instead of
|
|
80
|
+
* rejecting a round over a reporting detail — that split is deliberate and is
|
|
81
|
+
* the whole of the strict/lenient contract.
|
|
82
|
+
*
|
|
83
|
+
* The reference spaces (active item ids, known sub-goal ids) are facts about
|
|
84
|
+
* the loop, not properties of the payload, so each is `null` — fail open,
|
|
85
|
+
* shape checks still strict — when it cannot be observed. An unobserved
|
|
86
|
+
* session is different from a session with no active contract: the latter is
|
|
87
|
+
* an observed EMPTY space and an item claim in it is false. */
|
|
88
|
+
export declare function validateSubmission(store: LoopStore, session: CompileContextSession | undefined, submission: unknown): SubmissionBoundary;
|
|
89
|
+
//# sourceMappingURL=submission-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submission-boundary.d.ts","sourceRoot":"","sources":["../../src/mcp/submission-boundary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,kBAAkB,CAAC;AAE9D,OAAO,KAAK,EAAoB,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/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E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,qBAAqB,GAAG,SAAS,EAC1C,UAAU,EAAE,OAAO,GAClB,kBAAkB,CA0EpB"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** The runtime's submission boundary — every check a submission must pass
|
|
2
|
+
* before a round may advance.
|
|
3
|
+
*
|
|
4
|
+
* v3.8.1: it lives here, not in the MCP tool handler. `SessionManager` is the
|
|
5
|
+
* runtime's public entry point (`index.ts` exports it) and `RoundLifecycle`
|
|
6
|
+
* is internal, so a boundary in the transport meant a library caller, a
|
|
7
|
+
* future CLI command, or any direct `mgr.advance()` got NONE of it. The
|
|
8
|
+
* handler now only maps the result onto its tool envelope.
|
|
9
|
+
*
|
|
10
|
+
* The placement is also what makes the ordering invariants hold. AGENTS.md:
|
|
11
|
+
* an invalid evaluation is handled BEFORE `RoundLifecycle.advance()` and
|
|
12
|
+
* "must not save session state, write the Vault, run verification or
|
|
13
|
+
* enforcement gates, increment rejection state, or record metrics". So it
|
|
14
|
+
* runs before the session queue and before the lease heartbeat — renewing a
|
|
15
|
+
* lease writes the session document, which would be a durable effect of a
|
|
16
|
+
* payload that was never accepted. It is judged before the session is even
|
|
17
|
+
* resolved, because a malformed evaluation is a payload defect whatever the
|
|
18
|
+
* session's state, and answering `session_not_found` for it would send the
|
|
19
|
+
* agent after the wrong problem.
|
|
20
|
+
*
|
|
21
|
+
* This module also owns the compile context the boundary reads, because the
|
|
22
|
+
* sub-goal reference space IS the compiled set the prompt carried — the
|
|
23
|
+
* session's own projection reads the same function, so the two cannot
|
|
24
|
+
* disagree about it.
|
|
25
|
+
*/
|
|
26
|
+
import { queryLoopEntries } from "../loop-store.js";
|
|
27
|
+
import { Mode } from "../protocol.js";
|
|
28
|
+
import { deriveActiveRoundContract } from "../round-contract.js";
|
|
29
|
+
import { derivationRounds } from "../committed-round.js";
|
|
30
|
+
import { boundedEmergedSubtasks, buildSelfEvaluation, parseSubGoalUpdates, validateContractShape, validateCoreSelfEvaluation, validateSubGoalUpdatesShape, } from "../self-eval.js";
|
|
31
|
+
import { deriveEmergedItems, validateSubGoalUpdates } from "../subgoal-state.js";
|
|
32
|
+
import { isConfiguredCommand } from "../policy.js";
|
|
33
|
+
import { scopeEntryDetail } from "../workspace.js";
|
|
34
|
+
import { isRecord } from "../token-utils.js";
|
|
35
|
+
/** The compile response this round's prompt came from.
|
|
36
|
+
*
|
|
37
|
+
* Cached-when-fresh (the artifact's deterministic roundId guards against
|
|
38
|
+
* stale reuse), recompiled otherwise with `persistLineage: false` so it never
|
|
39
|
+
* writes the Vault, and null when it cannot be observed. Callers fail OPEN:
|
|
40
|
+
* an unobservable reference space must not become a rejection. */
|
|
41
|
+
export function compileSessionContext(session) {
|
|
42
|
+
const cached = session.lastCompileResponse;
|
|
43
|
+
const expectedRoundId = session.roundSnapshot?.roundId
|
|
44
|
+
?? `loop:${session.loopId}:round:${session.currentRound}`;
|
|
45
|
+
if (cached?.prompt_artifact && cached.prompt_artifact.roundId === expectedRoundId) {
|
|
46
|
+
return cached;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const request = {
|
|
50
|
+
task: session.task,
|
|
51
|
+
mode: Mode.LOOP_COMPILE,
|
|
52
|
+
feedback: null,
|
|
53
|
+
skill_name: null,
|
|
54
|
+
task_id: null,
|
|
55
|
+
loop_id: session.loopId,
|
|
56
|
+
round: session.currentRound,
|
|
57
|
+
max_rounds: session.maxRounds,
|
|
58
|
+
verification_flags: [],
|
|
59
|
+
};
|
|
60
|
+
const compiled = session.engine.invokeLoopCompile(request, undefined, { persistLineage: false });
|
|
61
|
+
return compiled.response ?? null;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null; // projection / boundary degrades gracefully
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** The sub-goal set an agent may legitimately reference: the compiled set the
|
|
68
|
+
* prompt carried, PLUS this submission's own `emerged_subtasks` — a sub-goal
|
|
69
|
+
* may be created and referenced (or transitioned) in one round. Null when it
|
|
70
|
+
* cannot be observed. */
|
|
71
|
+
export function knownSubGoalsFor(session, emerged) {
|
|
72
|
+
const response = compileSessionContext(session);
|
|
73
|
+
if (!response?.sub_goals)
|
|
74
|
+
return null;
|
|
75
|
+
const known = [...response.sub_goals];
|
|
76
|
+
for (const item of deriveEmergedItems(session.loopId, session.currentRound, emerged)) {
|
|
77
|
+
if (!known.some((subGoal) => subGoal.id === item.id)) {
|
|
78
|
+
known.push({
|
|
79
|
+
id: item.id,
|
|
80
|
+
description: item.description,
|
|
81
|
+
status: "pending",
|
|
82
|
+
declared_at_round: session.currentRound,
|
|
83
|
+
status_changed_at_round: session.currentRound,
|
|
84
|
+
priority: known.length,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return known;
|
|
89
|
+
}
|
|
90
|
+
/** The ACTIVE Round Contract governing a session's next round — ONE
|
|
91
|
+
* derivation, shared by the session's public view and the boundary. */
|
|
92
|
+
export function activeContractOf(store, session) {
|
|
93
|
+
const prefix = `loop:${session.loopId}:`;
|
|
94
|
+
const entries = [
|
|
95
|
+
...queryLoopEntries(store, session.loopId, { prefix }),
|
|
96
|
+
...queryLoopEntries(store, session.loopId, { prefix, feedbackOnly: true }),
|
|
97
|
+
];
|
|
98
|
+
return deriveActiveRoundContract(derivationRounds(entries, session.currentRound));
|
|
99
|
+
}
|
|
100
|
+
const EVALUATION_REQUIRED = "A structured evaluation object is required. Resubmit the same roundId " +
|
|
101
|
+
"with success, output_summary, constraint_violations, and should_continue.";
|
|
102
|
+
/** THE submission boundary. Five checks, in this order, all of them before
|
|
103
|
+
* anything durable happens.
|
|
104
|
+
*
|
|
105
|
+
* Two are STRUCTURAL boundaries that REJECT rather than normalize:
|
|
106
|
+
* `subgoal_updates` (machine-processable state transitions) and the Round
|
|
107
|
+
* Contract declaration together with its item claims. Everything else about
|
|
108
|
+
* an evaluation is normalized leniently by `buildSelfEvaluation` instead of
|
|
109
|
+
* rejecting a round over a reporting detail — that split is deliberate and is
|
|
110
|
+
* the whole of the strict/lenient contract.
|
|
111
|
+
*
|
|
112
|
+
* The reference spaces (active item ids, known sub-goal ids) are facts about
|
|
113
|
+
* the loop, not properties of the payload, so each is `null` — fail open,
|
|
114
|
+
* shape checks still strict — when it cannot be observed. An unobserved
|
|
115
|
+
* session is different from a session with no active contract: the latter is
|
|
116
|
+
* an observed EMPTY space and an item claim in it is false. */
|
|
117
|
+
export function validateSubmission(store, session, submission) {
|
|
118
|
+
if (!isRecord(submission)) {
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
stopDetail: EVALUATION_REQUIRED,
|
|
122
|
+
submissionError: {
|
|
123
|
+
code: "evaluation_invalid",
|
|
124
|
+
details: {
|
|
125
|
+
missing: ["evaluation"],
|
|
126
|
+
invalid: [{ field: "evaluation", expected: "object" }],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const core = validateCoreSelfEvaluation(submission);
|
|
132
|
+
if (core.missing.length > 0 || core.invalid.length > 0) {
|
|
133
|
+
return {
|
|
134
|
+
ok: false,
|
|
135
|
+
stopDetail: EVALUATION_REQUIRED,
|
|
136
|
+
submissionError: { code: "evaluation_invalid", details: { ...core } },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// The emerged set is part of BOTH referential spaces below. It goes through
|
|
140
|
+
// the SAME normalization the committed evaluation uses: the sub-goal ids are
|
|
141
|
+
// derived by ORDINAL over this list, so bounding it differently here let the
|
|
142
|
+
// boundary accept a transition to a sub-goal the prompt never carried.
|
|
143
|
+
const emerged = boundedEmergedSubtasks(submission.emerged_subtasks);
|
|
144
|
+
const subgoalShapeErrors = validateSubGoalUpdatesShape(submission);
|
|
145
|
+
if (subgoalShapeErrors.length > 0) {
|
|
146
|
+
return {
|
|
147
|
+
ok: false,
|
|
148
|
+
stopDetail: "subgoal_updates is malformed. Fix the entries and resubmit the same roundId.",
|
|
149
|
+
submissionError: {
|
|
150
|
+
code: "evaluation_invalid",
|
|
151
|
+
details: { missing: [], invalid: [], subgoal_errors: subgoalShapeErrors },
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const known = session ? knownSubGoalsFor(session, emerged) : null;
|
|
156
|
+
const updates = parseSubGoalUpdates(submission.subgoal_updates);
|
|
157
|
+
if (updates.length > 0 && known) {
|
|
158
|
+
const referentialErrors = validateSubGoalUpdates(known, updates).map((error) => ({
|
|
159
|
+
field: "subgoal_updates",
|
|
160
|
+
reason: error.reason,
|
|
161
|
+
detail: `${error.reason.replace(/_/g, " ")}: ${error.id}`,
|
|
162
|
+
}));
|
|
163
|
+
if (referentialErrors.length > 0) {
|
|
164
|
+
return {
|
|
165
|
+
ok: false,
|
|
166
|
+
stopDetail: "subgoal_updates references a sub-goal this loop does not have, a " +
|
|
167
|
+
"terminal one, or an illegal transition. Fix the entries and " +
|
|
168
|
+
"resubmit the same roundId.",
|
|
169
|
+
submissionError: {
|
|
170
|
+
code: "evaluation_invalid",
|
|
171
|
+
details: { missing: [], invalid: [], subgoal_errors: referentialErrors },
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const contractErrors = contractShapeErrors(store, session, submission, known);
|
|
177
|
+
if (contractErrors.length > 0) {
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
stopDetail: "The Round Contract declaration or its item claims are malformed. " +
|
|
181
|
+
"Fix them and resubmit the same roundId.",
|
|
182
|
+
submissionError: {
|
|
183
|
+
code: "contract_invalid",
|
|
184
|
+
details: { missing: [], invalid: [], contract_errors: contractErrors },
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return { ok: true, evaluation: buildSelfEvaluation(submission) };
|
|
189
|
+
}
|
|
190
|
+
function contractShapeErrors(store, session, submission, knownSubGoals) {
|
|
191
|
+
const active = session ? activeContractOf(store, session) : null;
|
|
192
|
+
return validateContractShape(submission, {
|
|
193
|
+
activeItemIds: session
|
|
194
|
+
? new Set((active?.items ?? []).map((item) => item.id))
|
|
195
|
+
: null,
|
|
196
|
+
knownSubGoalIds: knownSubGoals
|
|
197
|
+
? new Set(knownSubGoals.map((subGoal) => subGoal.id))
|
|
198
|
+
: null,
|
|
199
|
+
isConfiguredCommand,
|
|
200
|
+
checkScopeEntry: scopeEntryDetail,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=submission-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submission-boundary.js","sourceRoot":"","sources":["../../src/mcp/submission-boundary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAe7C;;;;;mEAKmE;AACnE,MAAM,UAAU,qBAAqB,CACnC,OAA8B;IAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAC3C,MAAM,eAAe,GAAG,OAAO,CAAC,aAAa,EAAE,OAAO;WACjD,Q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AAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,OAAO,qBAAqB,CAAC,UAAU,EAAE;QACvC,aAAa,EAAE,OAAO;YACpB,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvD,CAAC,CAAC,IAAI;QACR,eAAe,EAAE,aAAa;YAC5B,CAAC,CAAC,IAAI,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACrD,CAAC,CAAC,IAAI;QACR,mBAAmB;QACnB,eAAe,EAAE,gBAAgB;KAClC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/mcp/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,cAAc,CAAC;AAshB/D,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA4B1C;;;qEAGqE;AACrE,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAuF1D,CAAC;AAgDF,6EAA6E;AAC7E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOtB,CAAC;AAEJ,qBAAa,wBAAyB,SAAQ,KAA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