@abelxiaoxing/cadence 1.2.0 → 1.2.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/package.json +1 -1
- package/src/control-contracts.ts +58 -0
- package/src/index.ts +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abelxiaoxing/cadence",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Four explicit Abel workflow prompts with stage-isolated design and diagnosis, durable resumable implementation, and three package-owned professional Agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/control-contracts.ts
CHANGED
|
@@ -74,6 +74,64 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
74
74
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
const CONTROL_TOOL_FIELDS = new Set([
|
|
78
|
+
"command",
|
|
79
|
+
"stage",
|
|
80
|
+
"change",
|
|
81
|
+
"operationId",
|
|
82
|
+
"deliveryRevision",
|
|
83
|
+
"receiptHash",
|
|
84
|
+
"routeId",
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const COMMAND_FIELDS: Readonly<
|
|
88
|
+
Record<ControlCommandName, ReadonlySet<string>>
|
|
89
|
+
> = Object.freeze({
|
|
90
|
+
start: new Set(["command", "stage", "change", "operationId"]),
|
|
91
|
+
status: new Set(["command", "stage", "change"]),
|
|
92
|
+
resume: new Set([
|
|
93
|
+
"command",
|
|
94
|
+
"stage",
|
|
95
|
+
"change",
|
|
96
|
+
"operationId",
|
|
97
|
+
"deliveryRevision",
|
|
98
|
+
"receiptHash",
|
|
99
|
+
]),
|
|
100
|
+
rebind: new Set(["command", "stage", "change", "operationId", "routeId"]),
|
|
101
|
+
cancel: new Set(["command", "stage", "change", "operationId"]),
|
|
102
|
+
discard: new Set(["command", "stage", "change", "operationId"]),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Adapts Pi/provider strict-schema padding to the closed command union.
|
|
107
|
+
* Known fields belonging to a different command are projected away, while
|
|
108
|
+
* unknown fields and fields owned by the selected command remain available to
|
|
109
|
+
* the strict validator and therefore cannot bypass its exact-key/type checks.
|
|
110
|
+
*/
|
|
111
|
+
export function canonicalizeControlCommandToolInput(value: unknown): unknown {
|
|
112
|
+
if (
|
|
113
|
+
!isRecord(value) ||
|
|
114
|
+
!(CONTROL_COMMANDS as readonly unknown[]).includes(value.command)
|
|
115
|
+
) {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
const command = value.command as ControlCommandName;
|
|
119
|
+
const allowed = COMMAND_FIELDS[command];
|
|
120
|
+
const canonical = Object.create(null) as Record<string, unknown>;
|
|
121
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
122
|
+
if (CONTROL_TOOL_FIELDS.has(key) && !allowed.has(key)) continue;
|
|
123
|
+
if (
|
|
124
|
+
command === "resume" &&
|
|
125
|
+
(key === "deliveryRevision" || key === "receiptHash") &&
|
|
126
|
+
(entry === null || entry === undefined)
|
|
127
|
+
) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
canonical[key] = entry;
|
|
131
|
+
}
|
|
132
|
+
return canonical;
|
|
133
|
+
}
|
|
134
|
+
|
|
77
135
|
function hasExactKeys(
|
|
78
136
|
value: Record<string, unknown>,
|
|
79
137
|
required: readonly string[],
|
package/src/index.ts
CHANGED
|
@@ -37,7 +37,10 @@ import {
|
|
|
37
37
|
type StructuredVerificationContract,
|
|
38
38
|
verificationSteps,
|
|
39
39
|
} from "./contracts.ts";
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
canonicalizeControlCommandToolInput,
|
|
42
|
+
validateControlCommand,
|
|
43
|
+
} from "./control-contracts.ts";
|
|
41
44
|
import {
|
|
42
45
|
assessDeliveryTraceability,
|
|
43
46
|
compileImplementPlan,
|
|
@@ -1841,7 +1844,7 @@ export function registerWorkflowControl(
|
|
|
1841
1844
|
receiptHash: { type: "string" },
|
|
1842
1845
|
routeId: { type: "string" },
|
|
1843
1846
|
},
|
|
1844
|
-
required: ["command", "stage"],
|
|
1847
|
+
required: ["command", "stage", "change"],
|
|
1845
1848
|
additionalProperties: false,
|
|
1846
1849
|
} as const;
|
|
1847
1850
|
const PACKET_PARAMETERS = {
|
|
@@ -1872,6 +1875,12 @@ export function registerWorkflowControl(
|
|
|
1872
1875
|
? "Private stage-bound Abel workflow control. Accepts durable Implement change commands."
|
|
1873
1876
|
: "Private stage-bound Abel packet control. Accepts bounded Design and Diagnose packet operations.",
|
|
1874
1877
|
executionMode: "parallel",
|
|
1878
|
+
...(kind === "command"
|
|
1879
|
+
? {
|
|
1880
|
+
prepareArguments: (args: unknown) =>
|
|
1881
|
+
canonicalizeControlCommandToolInput(args) as never,
|
|
1882
|
+
}
|
|
1883
|
+
: {}),
|
|
1875
1884
|
parameters:
|
|
1876
1885
|
kind === "command" ? CONTROL_COMMAND_PARAMETERS : PACKET_PARAMETERS,
|
|
1877
1886
|
async execute(
|
|
@@ -2004,7 +2013,9 @@ export function registerWorkflowControl(
|
|
|
2004
2013
|
...(usage === undefined ? {} : { usage }),
|
|
2005
2014
|
};
|
|
2006
2015
|
}
|
|
2007
|
-
const validation = validateControlCommand(
|
|
2016
|
+
const validation = validateControlCommand(
|
|
2017
|
+
canonicalizeControlCommandToolInput(params),
|
|
2018
|
+
);
|
|
2008
2019
|
if (!validation.ok) {
|
|
2009
2020
|
const error = new Error(validation.code);
|
|
2010
2021
|
error.name = "ControlCommandError";
|