progmune-runtime 2.1.0 → 2.1.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/README.md +172 -0
- package/dist/action-runtime.js +1 -0
- package/dist/audit.js +4 -0
- package/dist/branch-ledger.js +28 -0
- package/dist/deterministic-replay.js +6 -0
- package/dist/emitter.js +31 -0
- package/dist/execute.js +9 -0
- package/dist/extract-ir.js +48 -6
- package/dist/failure-collector.js +20 -0
- package/dist/failure-corpus.js +26 -0
- package/dist/feedback.js +4 -0
- package/dist/immune-reporter.js +1 -0
- package/dist/ir-utils.js +18 -0
- package/dist/ledger-registry.js +11 -0
- package/dist/llm.js +3 -0
- package/dist/memory-layer.js +3 -0
- package/dist/planner.js +109 -18
- package/dist/protocol-registry.js +7 -0
- package/dist/repair-proposal.js +10 -0
- package/dist/runtime-invariants.js +9 -0
- package/dist/runtime.js +1 -0
- package/dist/search-planner.js +1 -0
- package/dist/semantic-snapshot.js +2 -0
- package/dist/session-utils.js +19 -0
- package/dist/ssg-validator.js +8 -0
- package/dist/utils.js +2 -0
- package/dist/validator.js +2 -0
- package/package.json +1 -1
- package/readme.md +0 -829
package/dist/ssg-validator.js
CHANGED
|
@@ -98,6 +98,7 @@ function deepEqualSnapshots(a, b) {
|
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
100
|
// ── rebuildState: pure fold over ledger → per-namespace state snapshot ──
|
|
101
|
+
/** @requires LEDGER_DATA @produces STATE_SNAPSHOT */
|
|
101
102
|
function rebuildState(ledger, namespaceInitialStates = new Map([["_global", "INIT"]])) {
|
|
102
103
|
const stateMap = fromSnapshot({});
|
|
103
104
|
for (const [ns, initState] of namespaceInitialStates) {
|
|
@@ -131,6 +132,7 @@ function computeDelta(beforeSnap, afterSnap, namespace) {
|
|
|
131
132
|
return { acquired, invalidated };
|
|
132
133
|
}
|
|
133
134
|
// ── findFixPathStatic: BFS state graph search (extracted from class) ──
|
|
135
|
+
/** @requires CURRENT_STATES @produces FIX_PATH */
|
|
134
136
|
function findFixPathStatic(rules, namespace, current, targetPreStates) {
|
|
135
137
|
const nsFuncs = [];
|
|
136
138
|
for (const [fn, rule] of rules) {
|
|
@@ -184,6 +186,7 @@ function findFixPathStatic(rules, namespace, current, targetPreStates) {
|
|
|
184
186
|
return path;
|
|
185
187
|
}
|
|
186
188
|
// ── validateTransition: pure function, stateless ──
|
|
189
|
+
/** @requires TRANSITION_CONTEXT @produces VALIDATION_RESULT */
|
|
187
190
|
function validateTransition(ctx, candidateFunctionName, actionIndex, rules, namespaceInitialStates, ruleHash) {
|
|
188
191
|
const currentState = ctx.currentState;
|
|
189
192
|
const rule = rules.get(candidateFunctionName);
|
|
@@ -281,6 +284,7 @@ function validateTransition(ctx, candidateFunctionName, actionIndex, rules, name
|
|
|
281
284
|
return { valid: true, transition };
|
|
282
285
|
}
|
|
283
286
|
// ── checkLedgerConsistency: Invariant-0 + Invariant-1 over full ledger ──
|
|
287
|
+
/** @requires LEDGER_DATA @produces CONSISTENCY_RESULT */
|
|
284
288
|
function checkLedgerConsistency(ledger, namespaceInitialStates = new Map([["_global", "INIT"]])) {
|
|
285
289
|
const violations = [];
|
|
286
290
|
const running = fromSnapshot({});
|
|
@@ -348,6 +352,7 @@ function checkLedgerConsistency(ledger, namespaceInitialStates = new Map([["_glo
|
|
|
348
352
|
return { consistent: violations.length === 0, violations };
|
|
349
353
|
}
|
|
350
354
|
// ── hashRules: stable hash of rule set for constraint snapshot (P1) ──
|
|
355
|
+
/** @requires RULES @produces RULE_HASH */
|
|
351
356
|
function hashRules(rules) {
|
|
352
357
|
const sorted = [...rules.entries()]
|
|
353
358
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
@@ -361,6 +366,7 @@ function hashRules(rules) {
|
|
|
361
366
|
return crypto.createHash("sha256").update(JSON.stringify(sorted)).digest("hex").slice(0, 16);
|
|
362
367
|
}
|
|
363
368
|
/** Compute a deterministic SHA256 hash of an entire ledger (P1: Tamper-evident integrity). */
|
|
369
|
+
/** @requires LEDGER_DATA @produces LEDGER_HASH */
|
|
364
370
|
function hashLedger(ledger) {
|
|
365
371
|
const canonical = ledger.map(t => ({
|
|
366
372
|
actionIndex: t.actionIndex,
|
|
@@ -376,6 +382,7 @@ function hashLedger(ledger) {
|
|
|
376
382
|
return crypto.createHash("sha256").update(JSON.stringify(canonical)).digest("hex").slice(0, 16);
|
|
377
383
|
}
|
|
378
384
|
/** Compare two ledgers and identify structural differences. */
|
|
385
|
+
/** @requires TWO_LEDGERS @produces LEDGER_DIFF */
|
|
379
386
|
function diffLedgers(ledgerA, ledgerB) {
|
|
380
387
|
const hash = (t) => crypto.createHash("sha256").update(JSON.stringify({
|
|
381
388
|
i: t.actionIndex, f: t.function, n: t.namespace,
|
|
@@ -617,6 +624,7 @@ exports.StateMachineValidator = StateMachineValidator;
|
|
|
617
624
|
// Standalone presentation utilities (formerly static methods)
|
|
618
625
|
// ═══════════════════════════════════════════════════════════════
|
|
619
626
|
/** Format an SSG rejection as a human-readable multi-line string. */
|
|
627
|
+
/** @requires SSG_REJECTION @produces EXPLANATION */
|
|
620
628
|
function explainRejection(rejection) {
|
|
621
629
|
const nsLabel = rejection.namespace && rejection.namespace !== DEFAULT_NAMESPACE
|
|
622
630
|
? ` [namespace: ${rejection.namespace}]` : '';
|
package/dist/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.jaccardSimilarity = jaccardSimilarity;
|
|
4
4
|
exports.extractKeywords = extractKeywords;
|
|
5
5
|
// 计算两个字符串的简单 Jaccard 相似度(基于字符二元组)
|
|
6
|
+
/** @requires STRING_A @produces SIMILARITY_SCORE */
|
|
6
7
|
function jaccardSimilarity(a, b) {
|
|
7
8
|
const bigrams = (s) => {
|
|
8
9
|
const bgs = new Set();
|
|
@@ -17,6 +18,7 @@ function jaccardSimilarity(a, b) {
|
|
|
17
18
|
return intersection.size / (union.size || 1);
|
|
18
19
|
}
|
|
19
20
|
// 从意图中提取关键词
|
|
21
|
+
/** @requires TEXT @produces KEYWORDS */
|
|
20
22
|
function extractKeywords(intent) {
|
|
21
23
|
return intent.split(/[\s,。!?,]+/).filter(w => w.length > 1).map(w => w.toLowerCase());
|
|
22
24
|
}
|
package/dist/validator.js
CHANGED
|
@@ -150,6 +150,7 @@ function checkVariableFlow(actions) {
|
|
|
150
150
|
* 校验单个动作的合法性(函数存在、类型匹配、参数数量)。
|
|
151
151
|
* @protocol namespace=dev_pipeline pre_states=["IR_EXTRACTED"] post_states=["ACTION_VALIDATED"]
|
|
152
152
|
*/
|
|
153
|
+
/** @requires ACTION @produces VALIDATION_RESULT */
|
|
153
154
|
function validateAction(action, actionIndex) {
|
|
154
155
|
const functions = loadIR();
|
|
155
156
|
const errors = [];
|
|
@@ -229,6 +230,7 @@ function validateAction(action, actionIndex) {
|
|
|
229
230
|
* 批量校验动作序列 + 变量流向分析。
|
|
230
231
|
* @protocol namespace=dev_pipeline pre_states=["ACTION_VALIDATED"] post_states=["SEQUENCE_VALIDATED"] invalidate=["ACTION_VALIDATED"]
|
|
231
232
|
*/
|
|
233
|
+
/** @requires ACTIONS @produces VALIDATION_RESULT */
|
|
232
234
|
function validateActionSequence(actions) {
|
|
233
235
|
const errors = [];
|
|
234
236
|
const violations = [];
|