@ngockhoale/ukit 3.4.74 → 3.4.76
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/CHANGELOG.md +110 -95
- package/manifests/platform.full.yaml +15 -0
- package/package.json +14 -4
- package/src/cli/commands/markerStore.js +15 -0
- package/src/cli/index.js +7 -0
- package/src/core/markerStoreMigration.js +122 -0
- package/template_project/.claude/hooks/completion-gate.sh +10 -1
- package/template_project/.claude/hooks/handoff-resume.sh +9 -0
- package/template_project/.claude/hooks/owner-stop-gate.mjs +41 -0
- package/template_project/.claude/hooks/skill-router.sh +262 -28
- package/template_project/.claude/settings.json +11 -1
- package/template_project/.claude/ukit/index/publication-intent.mjs +144 -18
- package/template_project/.claude/ukit/index/route-task.mjs +91 -9
- package/template_project/.claude/ukit/runtime/cron-operation-adapter.mjs +11 -4
- package/template_project/.claude/ukit/runtime/execution-ledger.mjs +369 -29
- package/template_project/.claude/ukit/runtime/operation-evidence.mjs +9 -0
- package/template_project/.claude/ukit/runtime/resumable-run.mjs +33 -11
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +161 -32
- package/template_project/.omp/hooks/pre/ukit-bridge.js +552 -4
- package/scripts/bug/triage.mjs +0 -76
- package/scripts/dev/worktree-preflight.mjs +0 -166
- package/scripts/docs/render-instructions.mjs +0 -66
- package/scripts/index/build-index.mjs +0 -102
- package/scripts/index/query-index.mjs +0 -128
- package/scripts/index/refresh-index.mjs +0 -195
- package/scripts/install/sync-installed-mirror.mjs +0 -263
- package/scripts/measure-decision-gateway.mjs +0 -306
- package/scripts/probe/codex-capability-probe.mjs +0 -169
- package/scripts/skill/audit-skill.mjs +0 -68
- package/scripts/test/run-handoff-isolated.mjs +0 -178
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Canonical task semantics; intent never grants authorization or proves completion.
|
|
2
2
|
import crypto from 'node:crypto';
|
|
3
|
-
export const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:
|
|
3
|
+
export const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:d54a8c14f321c1eeba4832e4461cd6d0c2231b2f7a80932ac3129f1e8dd792f9';
|
|
4
4
|
|
|
5
5
|
export function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
|
|
6
6
|
return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
|
|
@@ -10,7 +10,7 @@ export function semanticContractIdentity({ promptText = '', targetFile = '', tas
|
|
|
10
10
|
const semanticContractShape = (contract) => JSON.stringify([
|
|
11
11
|
contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null,
|
|
12
12
|
contract?.configurationScope ?? null, contract?.releasePolicy ?? null, contract?.conditionalObligations ?? null,
|
|
13
|
-
contract?.reportArtifact ?? null, contract?.verificationOnly === true, contract?.statusReport === true,
|
|
13
|
+
contract?.reportArtifact ?? null, contract?.verificationOnly === true, contract?.statusReport === true, contract?.stateVerification === true, contract?.stateAction === true, contract?.stateConditionalStop === true, (contract?.stateTargets || []).join(','),
|
|
14
14
|
[...(contract?.completionEvidence || [])].sort(),
|
|
15
15
|
]);
|
|
16
16
|
export function compareSemanticContracts({ stored, fresh, previousIdentity, identity }) {
|
|
@@ -44,8 +44,8 @@ export function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstan
|
|
|
44
44
|
const text = foldIntent(raw);
|
|
45
45
|
const quoted = Boolean(marker || fence || /^\s*>/.test(raw));
|
|
46
46
|
const context = quoted ? 'quotation' : description && bullet ? 'description' : 'instruction';
|
|
47
|
-
const polarity = /\b(?:do not|don't|never|must not|no|khong|chua
|
|
48
|
-
const condition = text.match(/\b(?:if|neu|only if|only when)\b[^,;.\n]*/)?.[0] || null;
|
|
47
|
+
const polarity = /\b(?:do not|don't|never|must not|no|khong|chua|prohibited|forbidden|banned)\b/.test(text) || /đừng/i.test(raw) ? 'prohibited' : 'affirmative';
|
|
48
|
+
const condition = text.match(/\b(?:if|neu|sau khi|only if|only when|only after|only once)\b[^,;.\n]*/)?.[0] || null;
|
|
49
49
|
spans.push({ start: offset + part.index, end: offset + part.index + raw.length, raw,
|
|
50
50
|
context, polarity, condition, activation: condition ? 'pending' : context !== 'instruction' || polarity === 'prohibited' ? 'inactive' : 'eligible' });
|
|
51
51
|
}
|
|
@@ -65,10 +65,26 @@ export function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstan
|
|
|
65
65
|
const nativeReleasePolicy = classifySemanticText({ promptText: original, targetFile }).releasePolicy;
|
|
66
66
|
const deferredSpans = new Set(spans.filter(span => span.context === 'instruction'
|
|
67
67
|
&& span.polarity === 'affirmative' && span.condition
|
|
68
|
-
&& /^(?:[-*+•\d.)\s]*)(?:if|neu|only if|only when)\b/.test(foldIntent(span.raw))
|
|
68
|
+
&& /^(?:[-*+•\d.)\s]*)(?:if|neu|only if|only when|only after|only once)\b/.test(foldIntent(span.raw))
|
|
69
69
|
&& !nativeReleasePolicy && !VERIFICATION_GOAL.test(foldIntent(original))
|
|
70
70
|
&& !defectRepairBranches(foldIntent(span.raw)).length
|
|
71
71
|
&& ordersPublicationText(foldIntent(span.raw).replace(/^[^,]*,\s*/, ''))));
|
|
72
|
+
spans.forEach((span, index) => {
|
|
73
|
+
const folded = foldIntent(span.raw);
|
|
74
|
+
if (span.context === 'instruction' && span.polarity === 'affirmative' && span.condition
|
|
75
|
+
&& /\b(?:phat hanh|xuat ban)\s+npm\b/.test(folded)
|
|
76
|
+
&& /\b(?:neu|sau khi)\b/.test(span.condition) && !nativeReleasePolicy) deferredSpans.add(span);
|
|
77
|
+
const verb = folded.match(CONDITIONAL_RUNTIME_VERB);
|
|
78
|
+
const cond = span.condition ? folded.indexOf(span.condition) : -1;
|
|
79
|
+
if (!verb || cond < 0 || span.context !== 'instruction' || span.polarity !== 'affirmative' || nativeReleasePolicy
|
|
80
|
+
|| CONDITIONAL_RUNTIME_EXCLUDED.test(folded)) return;
|
|
81
|
+
const governed = verb.index >= cond || /^(?:only\s+(?:if|when)|unless)\b/.test(span.condition);
|
|
82
|
+
if (!NEED_OR_FAILURE_CONDITION.test(span.condition)) return;
|
|
83
|
+
const leadsVerification = VERIFICATION_LEAD.test(folded.slice(0, cond)) && cond > 0
|
|
84
|
+
|| spans.slice(0, index).some(prior => prior.context === 'instruction' && prior.polarity === 'affirmative'
|
|
85
|
+
&& !prior.condition && VERIFICATION_LEAD.test(foldIntent(prior.raw)));
|
|
86
|
+
if (governed && leadsVerification) deferredSpans.add(span);
|
|
87
|
+
});
|
|
72
88
|
// An explicit alternative links both consequences. Keep the unconditional
|
|
73
89
|
// review prefix, but do not require a repair before its review has found one.
|
|
74
90
|
const alternatives = spans.filter(span => span.condition?.startsWith('otherwise:'));
|
|
@@ -86,8 +102,12 @@ export function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstan
|
|
|
86
102
|
if (span.context === 'quotation' || span.context === 'description' || approvalPending || deferredSpans.has(span) || evidenceStatement) {
|
|
87
103
|
// Retain the prefix before a comma-introduced postfix repair condition.
|
|
88
104
|
// Leading conditions and otherwise consequences are masked in full.
|
|
89
|
-
const
|
|
90
|
-
|
|
105
|
+
const folded = foldIntent(span.raw);
|
|
106
|
+
const coordinatedRelease = folded.match(/\b(?:va|roi)\s+(?:phat hanh|xuat ban)\s+npm\b/);
|
|
107
|
+
const prefix = deferredSpans.has(span) && !/^(?:\s*)(?:if|neu|only if|only when|only after|only once|otherwise)\b/.test(folded)
|
|
108
|
+
? coordinatedRelease && /\b(?:neu|sau khi)\b/.test(span.condition || '')
|
|
109
|
+
? span.raw.slice(0, coordinatedRelease.index)
|
|
110
|
+
: span.raw.match(/^[^,]*,/)?.[0] || '' : '';
|
|
91
111
|
const masked = prefix + span.raw.slice(prefix.length).replace(/[^\r\n]/g, ' ');
|
|
92
112
|
semanticInput = semanticInput.slice(0, span.start) + masked + semanticInput.slice(span.end);
|
|
93
113
|
}
|
|
@@ -127,8 +147,14 @@ export function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstan
|
|
|
127
147
|
}
|
|
128
148
|
return { engineVersion: SEMANTIC_ENGINE_VERSION, identity: { taskInstanceId, sessionId }, original, spans, actions, semantic };
|
|
129
149
|
}
|
|
150
|
+
const NEED_OR_FAILURE_CONDITION = /\b(?:needed|necessary|required|requires?|broken|fails?|failed|failing|failure|down|unhealthy|stale|missing|wrong|errors?|crash\w*|unavailable|not\s+(?:working|healthy|running|live|ok)|neu\s+(?:can|loi|hong|that bai|thieu|sai|chet)|khi\s+can|loi)\b|^unless\s+(?:healthy|ok|working|running|live)\b/;
|
|
151
|
+
const CONDITIONAL_RUNTIME_VERB = /\b(?:redeploy|deploy|restart|khoi dong lai|trien khai)\b/;
|
|
152
|
+
const CONDITIONAL_RUNTIME_EXCLUDED = /\b(?:publish|phat hanh|commit|push|tag|git|implement|fix|edit|modify|sua)\b/;
|
|
153
|
+
const VERIFICATION_LEAD = /^[-*+\u2022>\d.)\s]*(?:(?:please|hay|vui long|now|also|first)\s+)*(?:verify|check|confirm|validate|inspect|kiem tra|xac nhan)\b/;
|
|
154
|
+
const PAST_RELEASE_SOURCE = 'release(?:\\s+\\S+)?\\s+(?:(?:(?:was|were|is|are|has been|have been|had been|just been)(?:\\s+already)?|already)\\s+(?:published|shipped|released|on npm|live|deployed|out)|da\\s+(?:publish|phat hanh|release|deploy))\\b';
|
|
155
|
+
const PAST_RELEASE_ITEM = new RegExp(`^(?:(?:please|just|now|also)\\s+)*${PAST_RELEASE_SOURCE}`);
|
|
130
156
|
const PUBLISH_ORDER_NEGATOR = /\b(?:do not|don't|dont|never|without|not yet|no|not|avoid|skip|exclud\w*|forbid\w*|prohibit\w*|khong|chua)\b|--dry-run/;
|
|
131
|
-
const PUBLISH_ORDER_IMPERATIVE = /^(?:please\s+|just\s+|now\s+|also\s+)*(?:run|do|execute|perform|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/;
|
|
157
|
+
const PUBLISH_ORDER_IMPERATIVE = /^(?:please\s+|just\s+|now\s+|also\s+)*(?:run|do|execute|perform|thuc hien|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/;
|
|
132
158
|
const PUBLISH_ORDER_HEADER = /prohibit|forbidden|out of scope|non-goal|scope control/;
|
|
133
159
|
function defectRepairBranches(text) {
|
|
134
160
|
return [...text.matchAll(/(?:^|\n|\.\s+)[ \t]*(?:[-*]|\d+[.)])?\s*((?:neu\s+(?:gap|phat hien|tim thay|co)|if\b)[^.!?]*(?:\.(?!\w)|$))/g)]
|
|
@@ -248,10 +274,11 @@ function ordersPublicationText(promptText = '') {
|
|
|
248
274
|
if (PUBLISH_ORDER_NEGATOR.test(item)) negated = true;
|
|
249
275
|
else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
|
|
250
276
|
const commandItem = item.replace(/^(?:please|just|now|also|then)\s+/, '');
|
|
251
|
-
const publication = /\bnpm\s+publish\b/.test(commandItem) && /^(?:npm\s+publish|run|do|execute|perform|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/.test(commandItem);
|
|
252
|
-
const releaseOrder = /^(?:please\s+|just\s+|now\s+|also\s+)*(?:release|ship|publish)\s+(?!instructions?\b|obligations?\b|policies\b|boundary\b|safety\b|progress\b|candidate\s+review\b|readiness\b|verifier\b|verification\b|evidence\b|policy\b|intent\b|notes\b|terminology\b)\S/.test(item);
|
|
277
|
+
const publication = /\bnpm\s+publish\b/.test(commandItem) && /^(?:npm\s+publish|run|do|execute|perform|thuc hien|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/.test(commandItem);
|
|
278
|
+
const releaseOrder = !PAST_RELEASE_ITEM.test(item) && /^(?:please\s+|just\s+|now\s+|also\s+)*(?:release|ship|publish)\s+(?!instructions?\b|obligations?\b|policies\b|boundary\b|safety\b|progress\b|candidate\s+review\b|readiness\b|verifier\b|verification\b|evidence\b|policy\b|intent\b|notes\b|terminology\b)\S/.test(item);
|
|
253
279
|
const politeItem = item.replace(/^(?:(?:please|just|now|also|then|vui long|hay)\s+)+/, '');
|
|
254
|
-
const viPublish = /^(?:(?:su dung
|
|
280
|
+
const viPublish = /^(?:(?:su dung(?: lenh)?|phat hanh bang)\s+`?npm\s+publish\b|(?:dua|phat hanh|xuat ban|deploy|day)\b(?:[^.;\n]|\.(?=\d)){0,60}\b(?:len|to|vao)\s+npm\b)/.test(politeItem)
|
|
281
|
+
|| /^(?:(?:sua|kiem thu|hoan tat)\b[^.;\n]*\b(?:va|roi)\s+|(?:va|roi)\s+)(?:phat hanh|xuat ban)\s+npm\b/.test(politeItem);
|
|
255
282
|
if (!negated && (releaseOrder || viPublish || (publication && (
|
|
256
283
|
(/^npm\s+publish\b/.test(politeItem) && (/^(?:[\s*•-]|\d+[.)])*(?:(?:please|just|now|also)\s+)*(?:npm\s+publish|run|execute|perform|commit|push|tag)\b/.test(hard.trim()) || /\bcontinue the release workflow:/.test(hard))) || PUBLISH_ORDER_IMPERATIVE.test(item)
|
|
257
284
|
|| /\b(?:chay|run)\s+`?npm\s+publish\b/.test(item)
|
|
@@ -263,7 +290,7 @@ function ordersPublicationText(promptText = '') {
|
|
|
263
290
|
return ordered;
|
|
264
291
|
}
|
|
265
292
|
|
|
266
|
-
const NOT_A_SERVICE = new Set(['it', 'this', 'that', 'them', 'the', 'all', 'everything', 'service', 'services', 'again', 'now', 'to', 'and', 'then']);
|
|
293
|
+
const NOT_A_SERVICE = new Set(['only', 'if', 'unless', 'needed', 'necessary', 'unneeded', 'neu', 'khi', 'can', 'thiet', 'lai', 'len', 'vao', 'tren', 'di', 'nhe', 'nua', 'it', 'this', 'that', 'them', 'the', 'all', 'everything', 'service', 'services', 'again', 'now', 'to', 'and', 'then']);
|
|
267
294
|
function nativeOperationGoal(domain, actionable, text) {
|
|
268
295
|
const goal = { domain, target: null, desiredState: 'verified', completionSemantics: 'execute-and-verify', requiredTargets: [] };
|
|
269
296
|
const clauses = actionable.join(' . ');
|
|
@@ -315,16 +342,24 @@ function neutralizeNonOrders(text) {
|
|
|
315
342
|
return source.replace(noVerbList(), ' ')
|
|
316
343
|
.replace(/\brelease-(?:publication|verification)\b|\brelease\s+(?:instructions?|authorization|obligations?|policies|readiness)\b/g, 'publication topic')
|
|
317
344
|
.replace(/\brelease\s+(?:safety|verification\s+plan)\b/g, 'publication topic')
|
|
345
|
+
.replace(new RegExp(`(^|[\\n.;]\\s*)(?:(?:please|just|now|also)\\s+)*${PAST_RELEASE_SOURCE}[^.;\\n]*`, 'g'), '$1publication topic')
|
|
318
346
|
.replace(/^[ \t]*[-*+•][ \t]*owner\s+yeu\s+cau\b[^\n]*/gm, ' ')
|
|
319
347
|
.replace(/^([ \t]*[-*+•][ \t]*)release\s+progress\s+reporter(?=[ \t]*(?:,|$))/gm, '$1progress reporter')
|
|
320
348
|
.replace(/^[ \t]*(?:[-*+\u2022]|\d+[.)])[ \t]*(?:negative|positive)\s+controls?\b[^\n]*(?:\n(?![ \t]*(?:[-*+\u2022]|\d+[.)])|[ \t]*\n)[^\n]*)*/gm, ' ')
|
|
321
349
|
.replace(/(?:^|(?<=[.;][ \t]))[^.;\n]*\b(?:khong\s+(?:cho\s+phep|duoc|lam)|(?:does|do|did|is|are)\s+not\s+(?:allow|permit|authori[sz]e)\w*|not\s+(?:allowed|permitted|authori[sz]ed)|prohibitions?|prohibited(?:\s+actions?)?|forbidden(?:\s+actions?)?|banned|must\s+not\s+do)\s*:[ \t]*(?:\n[ \t]*(?:[-*+\u2022]|\d+[.)])[^\n]*)+/gm, ' ')
|
|
322
350
|
.replace(new RegExp(`\\b(?:do\\s+not|don't|dont|must\\s+not|never|shall\\s+not)\\s+[^.;\\n]*?(?=\\s+(?:and|va)\\s+(?:${NON_ORDER_VERBS})\\b|\\s+(?:but|nhung|then|however)\\b|[.;\\n]|$)`, 'g'), ' ')
|
|
351
|
+
// Negated sufficiency ("git commit/tag/release chua du de ban giao", "a git commit is not enough /
|
|
352
|
+
// insufficient"): the negation sits AFTER the operation enumeration, so the khong/chua span strip
|
|
353
|
+
// below would remove only the predicate tail and leave the bare "git commit/tag/release" fragment
|
|
354
|
+
// standing as a phantom imperative. Consume the enumeration together with its negated predicate.
|
|
355
|
+
.replace(new RegExp(`\\b(?:(?:git|npm)\\s+)?(?:commit|push|tag|release|deploy(?:ment)?|redeploy|restart|publish|phat\\s+hanh|trien\\s+khai)(?:\\s*/\\s*(?:commit|push|tag|release|deploy(?:ment)?|redeploy|restart|publish|phat\\s+hanh|trien\\s+khai))*\\s+(?:(?:(?:is|are|was|were)\\s+)?(?:not\\s+(?:enough|sufficient)|insufficient)\\b|(?:(?:tuyet\\s+doi\\s+)?khong|chua)\\b)[^.;\\n]*`, 'g'), ' ')
|
|
323
356
|
.replace(new RegExp(`\\b(?:(?:tuyet\\s+doi\\s+)?khong|chua)\\s+[^.;\\n]*?(?=\\s+(?:nhung|tuy nhien)\\b|[.;\\n]|$)`, 'g'), ' ')
|
|
324
357
|
.replace(/"[^"\n]*\s[^"\n]*"|`[^`\n]*\s[^`\n]*`|\u201c[^\u201d\n]*\u201d/g, ' ')
|
|
325
358
|
.replace(/\b(?:uu tien|prefer(?:red)?)\s+(?:a\s+|an\s+)?(?:configuration|config|cau hinh)\s+(?:change|changes|update|thay doi)\b/g, ' ')
|
|
326
359
|
.replace(/\b(?:neu\s+(?:chi\s+)?(?:phai|can|thieu|khong du|bang chung chua du)(?![^.;\n]*\b(?:restart|deploy|xoa|delete|remove|cancel)\b)|if\s+(?:needed|necessary|required|evidence is insufficient))\b[^.;\n]*/g, ' ')
|
|
327
360
|
.replace(/[^.;\n]*\b(?:nao|gi|sao|the nao|bao nhieu)\b[^.;\n]*\?/g, ' ')
|
|
361
|
+
.replace(/\b(?:truoc khi|before)\s+(?:quay lai|tro lai|returning|going back|you (?:go|return)|we (?:go|return))\b[^.;\n]*/g, ' ')
|
|
362
|
+
.replace(/\b(?:cua|do|tu)\s+chinh\b|\bchinh\s+(?:cac|nhung|phien|no|minh|toi|ban than)\b/g, ' ')
|
|
328
363
|
.replace(/\bchinh\s+(?:xac|sach)\b|\b(?:phuong an|cach|de xuat|ban)\s+(?:sua|fix)\b|\b(?:diem|cho|muc|phan)\s+(?:phai|can|nen)\s+(?:sua|fix)\b/g, ' ')
|
|
329
364
|
.replace(/\bwrite\s*\/\s*verification\b|\bverification\s*\/\s*write\b|\bwrite\s+(?:or|and)\s+verification\b/g, ' ')
|
|
330
365
|
.replace(/\bwrite\s+permission\b/g, 'permission')
|
|
@@ -342,7 +377,7 @@ function neutralizeNonOrders(text) {
|
|
|
342
377
|
});
|
|
343
378
|
}
|
|
344
379
|
|
|
345
|
-
const READ_ONLY_DECLARATION = /\breviewer\s*[,—:-]?\s+read[\s_-]*only\b|\bread[\s_-]*only(?:\s+\w+){0,3}?\s+(?:audit|investigation|review|analysis|inspection|inventory|task|request|session|pass|check|diagnos\w+|verification|forensics?|reports?)\b|(?:^|\n)[\s*#>_-]*read[\s_-]*only\s*[.:!—-]|\b(?:audit|investigation|review|analysis|inventory)[\s-]*only\b|[(,]\s*read[\s_-]*only\s*[).]|\bchi\s+(?:doc|audit|kiem tra|kiem ke|phan tich|dieu tra)\b|\bkhong\s+sua\b|\b(?:make|with)\s+no\s+(?:source\s+|code\s+|file\s+)?(?:changes|edits|modifications)\b|\b(?:do\s+not|don't|dont|never)\s+(?:\w+\s+){0,2}edits?\b/;
|
|
380
|
+
const READ_ONLY_DECLARATION = /\breviewer\s*[,—:-]?\s+read[\s_-]*only\b|\bread[\s_-]*only(?:\s+\w+){0,3}?\s+(?:audit|investigation|review|analysis|inspection|inventory|task|request|session|pass|check|diagnos\w+|verification|forensics?|reports?)\b|(?:^|\n)[\s*#>_-]*read[\s_-]*only\s*[.:!—-]|\b(?:audit|investigation|review|analysis|inventory)[\s-]*only\b|[(,]\s*read[\s_-]*only\s*[).]|\bchi\s+(?:doc|audit|kiem tra|kiem ke|phan tich|dieu tra)\b|\bkhong\s+sua\b(?=\s*(?:$|[.,;:!?)\n])|\s+(?:code|file|files|source|repo|repository|gi|bat|moi|them|lai|nua|du\s+an|tai\s+lieu|test|tests|mot|nao|ca|ledger|gate|receipts?|worklog)\b)|\b(?:make|with)\s+no\s+(?:source\s+|code\s+|file\s+)?(?:changes|edits|modifications)\b|\b(?:do\s+not|don't|dont|never)\s+(?:\w+\s+){0,2}edits?\b/;
|
|
346
381
|
const ORDER_VERBS = 'implement|fix|apply|refactor|modify|edit|write|update|add|create|build|install|deploy|redeploy|restart|push|commit|rename|remove|delete|replace|change|sua|viet|chinh|them|bo sung|tao|xoa|enable|disable|set|toggle|configure|migrate|upgrade|publish|release|trien khai|khoi dong lai|(?:run|execute)\\s+(?:git\\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)|(?:npm|yarn)\\s+publish)|git\\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)';
|
|
347
382
|
const IMPERATIVE_ORDER = new RegExp(`^(?:[-*+\\u2022>\\d.)\\s]*)(?:(?:please|hay|vui long|now|also|first|then)\\s+)*(?:${ORDER_VERBS})\\b\\s+\\S`);
|
|
348
383
|
const MODAL_ORDER = new RegExp(`\\b(?:please|hay|vui long|need to|needs to|must|should|want(?:\\s+you)? to|toi muon|can phai|yeu cau)\\s+(?:[\\w-]+\\s+){0,2}(?:${ORDER_VERBS})\\b`);
|
|
@@ -372,6 +407,13 @@ function declaredReadOnly(promptText, releasePolicy) {
|
|
|
372
407
|
|
|
373
408
|
const VERIFY_LEAD = /^(?:[-*+•>\d.)\s]*)(?:(?:please|hay|vui long|now|also|first|then)\s+)*(?:(?:keep|continue|tiep tuc)\s+)?(?:verify|re-?run|confirm|xac nhan|validate|double-?check|wait(?:ing)?|monitor|watch|cho(?=\s+(?:dung\s+)?(?:job|verifier|build|test|suite|gate|ci|run|task|ket qua|xong|output)\b))\b/;
|
|
374
409
|
const CHANGE_LEAD = /^(?:[-*+•>\d.)\s]*)(?:(?:please|hay|vui long|now|also|first|then)\s+)*(?:make|rebuild|redo|rewrite|restore|revert|correct|clean|patch|resolve|ensure|run(?!(?=[^.]*\b(?:tests?|suite|gate|checks?|lint|typecheck|pilot|smoke|e2e|verif\w*|vitest|jest|audit)\b)))\b/;
|
|
410
|
+
const BANS_TEST_RUNS = /\b(?:do not|don't|never|khong|dung)\s+(?:run|execute|chay)\s+(?:(?:any|more|additional|extra|them)\s+)*(?:tests?|checks?|verifications?)\b(?:\s+on\s+\w+)?/g;
|
|
411
|
+
const OWN_TARGET = /\b(?:yarn|npm|npx|pnpm|vitest|jest|pytest|node)\s+\S|\b(?:staging|ci|job|build|release(?!\s+notes?)|published|integration|e2e)\b/;
|
|
412
|
+
const bansTestRuns = (promptText) => {
|
|
413
|
+
const plain = String(promptText ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
414
|
+
const bans = plain.match(BANS_TEST_RUNS);
|
|
415
|
+
return !!bans && !bans.some((ban) => /\bon\s+\w+$/.test(ban)) && !OWN_TARGET.test(plain.replace(BANS_TEST_RUNS, ' '));
|
|
416
|
+
};
|
|
375
417
|
export function isVerificationOnlyRequest(promptText) {
|
|
376
418
|
const plain = String(promptText ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase()
|
|
377
419
|
.replace(/```[\s\S]*?```/g, ' ').replace(/^[ \t]*>.*$/gm, ' ');
|
|
@@ -395,6 +437,27 @@ function neutralizeBannedLists(text) {
|
|
|
395
437
|
});
|
|
396
438
|
}
|
|
397
439
|
|
|
440
|
+
const OWNER_CONTROL_HOOK_TEXT = /^\s*(?:UKit completion gate:|UKit handoff|\[ukit[-\w]*\]|<system-reminder|<task-notification)/i;
|
|
441
|
+
const OWNER_STOP_EN = /^(?:please\s+)?(?:stop|halt|pause|cancel|abort)(?:\s+(?:all|everything|execution|executing|work|working|now|immediately|here|this|the|current|session|run|task|tasks|handoff|processing))*$/;
|
|
442
|
+
const OWNER_STOP_VI = /^(?:(?:tam\s+)?(?:dừng|ngừng)|(?:tạm\s+)?(?:dừng|ngừng)|hủy|huỷ|tam\s+dung|tam\s+ngung|ngung|dung\s+(?:lai|thuc\s+thi|ngay)|huy)(?:\s+(?:thực\s+thi|thuc\s+thi|phiên\s+này|phien\s+nay|phiên|phien|lại|lai|ngay|ngay\s+lập\s+tức|tất\s+cả|tat\s+ca|mọi\s+thứ|moi\s+thu|việc|viec|công\s+việc|cong\s+viec|run|handoff|session|task))*$/;
|
|
443
|
+
const OWNER_CONTROL_TASK_WORD = /\b(?:fix|implement|add|update|edit|write|create|deploy|redeploy|publish|commit|refactor|rewrite|install|sua|sửa|them|thêm|chay|chạy|cap nhat|cập nhật)\b|[\w-]+\/[\w.-]+/;
|
|
444
|
+
const OWNER_CONTROL_TASK_LEAD = /^(?:(?:and\s+)?then|also|afterwards?|after that|next|now|sau do|sau đó|roi|rồi|va|và)\b|^(?:please\s+)?(?:fix|implement|add|update|edit|write|create|run|deploy|redeploy|publish|commit|push|refactor|rewrite|install|build|sua|sửa|them|thêm|chay|chạy|trien khai|triển khai|cap nhat|cập nhật)\b/;
|
|
445
|
+
export function classifyOwnerControl(promptText = '') {
|
|
446
|
+
const raw = String(promptText ?? '').normalize('NFC').trim();
|
|
447
|
+
if (!raw || OWNER_CONTROL_HOOK_TEXT.test(raw)) return { kind: null };
|
|
448
|
+
const stripped = raw.replace(/^[\s*#_-]+/, '');
|
|
449
|
+
if (/^[>"'`\u201c\u2018]/.test(stripped)) return { kind: null };
|
|
450
|
+
const sentences = stripped.split(/[.!?\n]/);
|
|
451
|
+
const [lead, ...rest] = sentences[0].split(/[:;]/);
|
|
452
|
+
const first = lead.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
453
|
+
if (!first || first.length > 80) return { kind: null };
|
|
454
|
+
if (OWNER_CONTROL_TASK_WORD.test(rest.join(' ').toLowerCase())) return { kind: null };
|
|
455
|
+
if (!OWNER_STOP_EN.test(first) && !OWNER_STOP_VI.test(first)) return { kind: null };
|
|
456
|
+
const next = (sentences.slice(1).find((part) => part.trim()) || '').trim().toLowerCase();
|
|
457
|
+
if (OWNER_CONTROL_TASK_LEAD.test(next)) return { kind: null };
|
|
458
|
+
return { kind: 'stop' };
|
|
459
|
+
}
|
|
460
|
+
|
|
398
461
|
export function classifyTaskSemantics(input = {}) {
|
|
399
462
|
return analyzeTaskIntent(input).semantic;
|
|
400
463
|
}
|
|
@@ -409,7 +472,7 @@ const collapseInspectionSentences = (text) => text.replace(INSPECTION_SENTENCE,
|
|
|
409
472
|
|
|
410
473
|
function actionableClauses(promptText) {
|
|
411
474
|
const text = neutralizeBannedLists(neutralizeNonOrders(collapseInspectionSentences(String(promptText).normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[đĐ]/g, 'd').toLowerCase())));
|
|
412
|
-
const clauses = text.split(/\s*(?:[;\n,]|\.(?:\s+|$)|\band\b|\bthen\b|\bva\b)\s*/);
|
|
475
|
+
const clauses = text.split(/\s*(?:[;\n,]|\.(?:\s+|$)|\band\b|\bthen\b|\bva\b|\broi\b(?=\s+(?:redeploy|deploy|restart|khoi dong lai|trien khai)\b))\s*/);
|
|
413
476
|
const actionable = clauses.map((clause) => clause.split(/\bwithout\b/)[0]).filter((clause) => !/\b(?:do not|don't|never|khong)\b|^[\s*+•>\d.)-]*(?:(?:vui long|xin|hay|please)\s+)*dung\b/.test(clause)
|
|
414
477
|
&& !/^[\s*+•>\d.)-]*(?:(?:please|just|hay|vui long|now|also)\s+)*(?:audit|inspect|review|analyze|analyse|explain|read|kiem tra|phan tich)\b/.test(clause)
|
|
415
478
|
// A fragment led by a subordinator continues the previous clause's predicate ("…, including source
|
|
@@ -424,7 +487,69 @@ export function ordersAdditiveChange(promptText = '') {
|
|
|
424
487
|
return actionableClauses(publicationScope(promptText).text).actionable.some((clause) => ADDITIVE_ORDER_LEAD.test(clause));
|
|
425
488
|
}
|
|
426
489
|
|
|
427
|
-
|
|
490
|
+
const STATE_OBJECT = /\b(?:shells?|jobs?|process(?:es)?|pids?|agents?|subagents?|wakeups?|tien trinh|tac vu nen|background (?:tasks?|work)|crons?)\b/;
|
|
491
|
+
const STATE_LEAD = /\b(?:check|inspect|list|stop|cancel|kill|terminate|revoke|reclaim|kiem tra|liet ke|xac dinh|huy|thu hoi|ket thuc)\b/;
|
|
492
|
+
const STATE_ACTION = /\b(?:stop|cancel|kill|terminate|revoke|reclaim|dung|huy|thu hoi|ket thuc)\b/;
|
|
493
|
+
function statePlain(promptText) {
|
|
494
|
+
return String(promptText).normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[\u0111\u0110]/g, 'd').toLowerCase()
|
|
495
|
+
.replace(/```[\s\S]*?```/g, ' ').replace(/^[ \t]*>.*$/gm, ' ');
|
|
496
|
+
}
|
|
497
|
+
export function isStateOperationRequest(promptText = '') {
|
|
498
|
+
const plain = statePlain(promptText);
|
|
499
|
+
if (!/\b(?:running|still|live|background|wakeups?|pids?|hung|stuck|orphan\w*|leftover|reclaim|chay|nen|treo|con sot|\d+\s+(?:shells?|jobs?|agents?|subagents?|process(?:es)?)|(?:job|task|shell|agent)\s+(?:id\s+)?[a-z0-9]*\d[a-z0-9]{5,})\b/.test(plain)) return false;
|
|
500
|
+
return plain.split(/[;!?\n]+|[.:](?=\s|$)/).some((clause) => {
|
|
501
|
+
const lead = clause.match(STATE_LEAD);
|
|
502
|
+
if (!lead) return false;
|
|
503
|
+
// A clause whose verb is negated ("khong tu kill process", "do not stop the job") states a boundary, not an
|
|
504
|
+
// order to inspect or stop state. Only a negator BEFORE the verb counts: "stop X; do not ..." stays an order.
|
|
505
|
+
if (/\b(?:khong|do not|don't|never|not)\b/.test(clause.slice(0, lead.index))) return false;
|
|
506
|
+
const after = clause.slice(lead.index + lead[0].length);
|
|
507
|
+
const near = after.match(/^(?:\s+[\p{L}\p{N}_-]+){0,5}?\s+/u);
|
|
508
|
+
const window = after.split(/\s+/).slice(0, 7).join(' ');
|
|
509
|
+
return near !== null && STATE_OBJECT.test(window);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export function stateOperationShape(promptText = '') {
|
|
514
|
+
const plain = statePlain(promptText);
|
|
515
|
+
const unquoted = plain.replace(/`[^`\n]*`|"[^"\n]*"|\u201c[^\u201d\n]*\u201d/g, ' ');
|
|
516
|
+
const targets = [...new Set((unquoted.match(/(?<![\w-])[a-z]*\d[a-z0-9]{7,}\b/g) || []).filter((id) => /[a-z]/.test(id)))].slice(0, 8);
|
|
517
|
+
let conditional = false;
|
|
518
|
+
let gated = false;
|
|
519
|
+
const action = plain.split(/[;!?\n]+|[.:](?=\s|$)|,\s*/).some((raw) => {
|
|
520
|
+
const clause = raw.replace(/^[\s*\-\d.)]+/, '').trim();
|
|
521
|
+
if (!clause) return false;
|
|
522
|
+
const conditionLead = /^(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause);
|
|
523
|
+
if (!conditionLead && /\b(?:khong|do not|don't|never|not)\b/.test(clause)) return false;
|
|
524
|
+
if (/\b(?:cho phep|allow(?:ed|s)?|permit(?:ted)?|authori[sz]ed?|you may|may stop|duoc phep)\b/.test(clause)) { gated = false; return false; }
|
|
525
|
+
const head = clause.split(/\s+/).slice(0, 3).join(' ');
|
|
526
|
+
if (/\b(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause)) {
|
|
527
|
+
const leadsWithCondition = /^(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause);
|
|
528
|
+
const preCondition = leadsWithCondition ? '' : clause.split(/\b(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/)[0].trim();
|
|
529
|
+
if (preCondition && /\b(?:and|va|then|roi)\s+(?:stop|cancel|kill|terminate|revoke|reclaim|dung|huy|thu hoi|ket thuc)\b/.test(preCondition)) { conditional = true; return false; }
|
|
530
|
+
const consequent = leadsWithCondition ? (/\s(?:then|thi)\s/.test(clause) ? clause.split(/\s(?:then|thi)\s/).pop() : '') : clause;
|
|
531
|
+
if (STATE_ACTION.test(consequent.split(/\s+/).slice(0, 3).join(' '))) { conditional = true; return false; }
|
|
532
|
+
gated = leadsWithCondition && !STATE_ACTION.test(consequent);
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
const wasGated = gated;
|
|
536
|
+
gated = false;
|
|
537
|
+
const stops = (wasGated ? STATE_ACTION.test(clause) : STATE_ACTION.test(head)) && (wasGated || STATE_OBJECT.test(clause));
|
|
538
|
+
if (stops && wasGated) { conditional = true; return false; }
|
|
539
|
+
return stops;
|
|
540
|
+
});
|
|
541
|
+
return { action, conditional: conditional && !action, targets };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function classifySemanticText(input = {}) {
|
|
545
|
+
const semantic = classifySemanticCore(input);
|
|
546
|
+
if (semantic.taskKind !== 'READ_ONLY' || semantic.conditionalObligations || semantic.publication || !isStateOperationRequest(input.promptText)) return semantic;
|
|
547
|
+
const { verificationOnly: _verification, statusReport: _status, ...rest } = semantic;
|
|
548
|
+
const shape = stateOperationShape(input.promptText);
|
|
549
|
+
return { ...rest, stateVerification: true, ...(shape.action ? { stateAction: true } : shape.conditional ? { stateConditionalStop: true } : {}), ...(shape.targets.length ? { stateTargets: shape.targets } : {}) };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
428
553
|
promptText = publicationScope(promptText).text;
|
|
429
554
|
const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
430
555
|
const preflight = releaseText.match(/\b(?:yarn\s+release:verify|npm\s+run\s+release:verify)\b/)?.[0];
|
|
@@ -435,13 +560,13 @@ function classifySemanticText({ promptText = '', targetFile = '' } = {}) {
|
|
|
435
560
|
if (ordersPublicationText(promptText)) {
|
|
436
561
|
const implementation = hasExplicitOrder(clauses.filter((clause) => !/\b(?:release|publish)\b/.test(clause)));
|
|
437
562
|
const remaining = clauses.filter((clause) => !ordersPublicationText(clause) && !/\b(?:release|publish)\b/.test(clause)).join('; ');
|
|
438
|
-
const base = remaining.trim() ?
|
|
563
|
+
const base = remaining.trim() ? classifySemanticCore({ promptText: remaining, targetFile }) : {};
|
|
439
564
|
delete base.verificationOnly;
|
|
440
565
|
delete base.statusReport;
|
|
441
566
|
return { ...base, taskKind: implementation ? 'MIXED' : 'OPERATIONAL', publication: true, ...(releasePolicy ? { releasePolicy } : {}) };
|
|
442
567
|
}
|
|
443
568
|
if (!/[a-z0-9]/.test(text)) return { taskKind: 'READ_ONLY' };
|
|
444
|
-
if (declaredReadOnly(promptText, releasePolicy)) return { taskKind: 'READ_ONLY', ...(isVerificationOnlyRequest(promptText) ? { verificationOnly: true } : {}) };
|
|
569
|
+
if (declaredReadOnly(promptText, releasePolicy)) return { taskKind: 'READ_ONLY', ...(isVerificationOnlyRequest(promptText) && !bansTestRuns(promptText) ? { verificationOnly: true } : {}) };
|
|
445
570
|
const sourceOrder = actionable.some((clause) => /\b(?:implement|fix(?:es)?|apply|refactor|modify|edit|write|update|sua|viet|chinh)\b/.test(clause)
|
|
446
571
|
&& /\b(?:source|code|logic|scheduler|implementation|ma nguon)\b|\.[cm]?[jt]sx?\b/.test(clause));
|
|
447
572
|
const codeChangeVerb = actionable.some((clause) => !/^(?:run\s+|execute\s+)?git\s+/.test(clause) && /\b(?:implement|fix(?:es)?|apply|refactor|modify|edit|write|update|sua|viet|chinh)\b/.test(clause));
|
|
@@ -480,7 +605,7 @@ function classifySemanticText({ promptText = '', targetFile = '' } = {}) {
|
|
|
480
605
|
&& !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause));
|
|
481
606
|
const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime') : null;
|
|
482
607
|
const operation = Boolean(nativeDomain);
|
|
483
|
-
if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', verificationOnly: true };
|
|
608
|
+
if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', ...(bansTestRuns(promptText) ? {} : { verificationOnly: true }) };
|
|
484
609
|
const CONFIG_CHANGE_REPORT_CLAUSE = /\b(?:da|has|have|had|already)\s+(?:doi|thay doi|changed?|updated?)\b|\b(?:nao|gi|which|what|report|bao cao)\b[^.;]*?\b(?:doi|thay doi|changed?|updated?)\b/;
|
|
485
610
|
const CONFIG_MUTATION_VERB = /\b(?:set|change|toggle|enable|disable|switch|turn|configure|modify|update|edit|doi(?!\s+chieu\b)|bat(?!\s+dau\b)|tat(?!\s+ca\b)|chinh)\b/;
|
|
486
611
|
const CONFIG_NOUN = /\b(?:configuration|config|toggle|cau hinh)\b/;
|
|
@@ -533,6 +658,7 @@ export function applyTaskSemantics(contract, semantic) {
|
|
|
533
658
|
return { ...(contract || {}), ...semantic,
|
|
534
659
|
completionEvidence: semantic.taskKind === 'DOCUMENTATION_OUTPUT' ? ['report-artifact'] : operationOnly ? ['operation-verification']
|
|
535
660
|
: semantic.taskKind === 'MIXED' ? [...new Set([...evidence, 'write-evidence', 'operation-verification'])]
|
|
661
|
+
: semantic.taskKind === 'READ_ONLY' && semantic.stateVerification ? ['state-verification']
|
|
536
662
|
: semantic.taskKind === 'READ_ONLY' && semantic.statusReport ? []
|
|
537
663
|
: semantic.taskKind === 'READ_ONLY' ? (semantic.verificationOnly ? ['verification-evidence'] : ['impact-evidence'])
|
|
538
664
|
// A routed contract owns the debt; an unrouted (informational/null) turn carries none, because
|
|
@@ -1284,6 +1284,38 @@ export function isGuidanceOnlySupplementText(text) {
|
|
|
1284
1284
|
return true;
|
|
1285
1285
|
}
|
|
1286
1286
|
|
|
1287
|
+
// A linkage phrase re-anchored to a NAMED scope ("keep this work on the X") names X as the
|
|
1288
|
+
// NOTE's topic, not necessarily the open task's. X is FOREIGN unless EVERY content word of X
|
|
1289
|
+
// matches the task's own explicit prompt. Scope reading is deterministic, not semantic: the
|
|
1290
|
+
// phrase may contain slashes, ampersands, dotted FILE names (punctuation followed by an
|
|
1291
|
+
// alphanumeric stays inside the scope, so "package.json" is one name, never truncated to
|
|
1292
|
+
// "package") and quoted or parenthesized parts (parentheticals are asides and are stripped);
|
|
1293
|
+
// it ends at punctuation, a NEWLINE or end of text. Words of 2-3 chars (API, CLI, MCP) count
|
|
1294
|
+
// by EXACT equality; longer words match only as prefix + bound morphology suffix
|
|
1295
|
+
// ("deployment" ~ "deploy"), so a prefix share alone never binds ("contractor" is not
|
|
1296
|
+
// "contract", "production backlog" is not "deploy to production"). Quantifier and temporal
|
|
1297
|
+
// fragments (only/just/also/for now/...) are never scope words. All this preserves the P0
|
|
1298
|
+
// isolation: receipt/backlog reading never inherits a deploy order. No stored prompt never
|
|
1299
|
+
// blocks.
|
|
1300
|
+
export function guidanceReanchorsForeignScope(promptText, storedPrompt) {
|
|
1301
|
+
const match = String(promptText ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/đ/g, 'd').toLowerCase()
|
|
1302
|
+
.match(/\b(?:this|current)\s+(?:work|task|change|one)\s+(?:on|for|about|regarding|within|inside)\s+(?:the\s+|this\s+|our\s+)?([a-z0-9][a-z0-9 .\/_()&'-]*?)(?=[!?:;,]|\.(?![a-z0-9])|\r|\n|$)/);
|
|
1303
|
+
if (!match) return false;
|
|
1304
|
+
const prior = String(storedPrompt ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/đ/g, 'd').toLowerCase();
|
|
1305
|
+
if (!prior) return false;
|
|
1306
|
+
const scopeWords = match[1].replace(/[()]/g, ' ').replace(/\.(?![a-z0-9])/g, ' ').split(/[^a-z0-9]+/).filter((w) => w.length >= 2
|
|
1307
|
+
&& !['work', 'task', 'this', 'that', 'scope', 'current', 'focus', 'focused', 'change', 'note', 'plan', 'only', 'just', 'also', 'too', 'still', 'again', 'first', 'next', 'then', 'now', 'later', 'the', 'and', 'for', 'our', 'its', 'with', 'into', 'from', 'of', 'to', 'in', 'on', 'at', 'by', 'or'].includes(w));
|
|
1308
|
+
if (scopeWords.length === 0) return false;
|
|
1309
|
+
const priorWords = prior.split(/[^a-z0-9]+/).filter((w) => w.length >= 2);
|
|
1310
|
+
const wordMatches = (w) => priorWords.some((p) => {
|
|
1311
|
+
if (p === w) return true;
|
|
1312
|
+
if (w.length < 4 || p.length < 4) return false;
|
|
1313
|
+
const [short, long] = w.length <= p.length ? [w, p] : [p, w];
|
|
1314
|
+
return long.startsWith(short) && ['s', 'es', 'ed', 'ing', 'ment', 'ments', 'ion', 'ions', 'ly', 'er', 'ers', 'ation', 'ations'].includes(long.slice(short.length));
|
|
1315
|
+
});
|
|
1316
|
+
return !scopeWords.every(wordMatches);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1287
1319
|
export function reuseOrMintTaskInstanceId({ previousState = {}, promptText = '', commandText = '', targetFile = null, explicitId = null, continuingTask = false } = {}) {
|
|
1288
1320
|
const explicit = typeof explicitId === 'string' ? explicitId.trim() : '';
|
|
1289
1321
|
if (explicit && TASK_INSTANCE_ID_SHAPE.test(explicit)) return { id: explicit, origin: null };
|
|
@@ -1301,6 +1333,7 @@ export function reuseOrMintTaskInstanceId({ previousState = {}, promptText = '',
|
|
|
1301
1333
|
const guidanceOnly = !targetFile && !commandText
|
|
1302
1334
|
&& Boolean(stored) && Boolean(previousState?.routeSummary?.executionContract?.taskKind)
|
|
1303
1335
|
&& isGuidanceOnlySupplementText(promptText)
|
|
1336
|
+
&& !guidanceReanchorsForeignScope(promptText, stored)
|
|
1304
1337
|
&& Array.isArray(previousState?.routeSummary?.executionContract?.completionEvidence)
|
|
1305
1338
|
&& previousState.routeSummary.executionContract.completionEvidence.length > 0
|
|
1306
1339
|
&& previousState?.routeSummary?.continuationState?.required !== false;
|
|
@@ -1412,11 +1445,14 @@ async function main() {
|
|
|
1412
1445
|
const guidanceRefresh = Boolean(guidanceReuse) && Boolean(lastPrompt);
|
|
1413
1446
|
if (continuingTask || guidanceRefresh) promptText = lastPrompt;
|
|
1414
1447
|
const carryGuidanceState = (state) => {
|
|
1448
|
+
if (sessionId && previousState.ownerControl?.kind === 'stop' && previousState.ownerControl.sessionId === sessionId) {
|
|
1449
|
+
state.ownerControl = previousState.ownerControl;
|
|
1450
|
+
}
|
|
1415
1451
|
if (!guidanceRefresh || state.taskInstanceId !== previousState.taskInstanceId) return state;
|
|
1416
1452
|
state.requestKey = previousState.requestKey;
|
|
1417
1453
|
state.routingContext = { ...previousState.routingContext };
|
|
1418
1454
|
state.routeSummary ||= {};
|
|
1419
|
-
for (const key of ['executionContract', 'expectedSourceFiles', 'completionState', 'continuationState', 'executionMode']) {
|
|
1455
|
+
for (const key of ['executionContract', 'expectedSourceFiles', 'expectedSourceProvenance', 'completionState', 'continuationState', 'executionMode']) {
|
|
1420
1456
|
if (previousState.routeSummary[key] !== undefined) state.routeSummary[key] = previousState.routeSummary[key];
|
|
1421
1457
|
else delete state.routeSummary[key];
|
|
1422
1458
|
}
|
|
@@ -4150,7 +4186,41 @@ export async function applyRoleAdviceConsult({
|
|
|
4150
4186
|
}
|
|
4151
4187
|
|
|
4152
4188
|
|
|
4153
|
-
|
|
4189
|
+
const PROMPT_FILE_TOKEN_RE = /[\w@.~+-]+(?:\/[\w@.~+-]+)*\.[A-Za-z][\w]{0,9}\b/g;
|
|
4190
|
+
const PROMPT_DIR_TOKEN_RE = /[\w@.~+-]+(?:\/[\w@.~+-]+)*\/(?![\w@.~+-])|[\w@.~+-]+(?:\/[\w@.~+-]+)+(?![\w@.~+/-])/g;
|
|
4191
|
+
function promptNamesFile(promptTokens, filePath, promptDirs = []) {
|
|
4192
|
+
const file = String(filePath).replace(/\\/g, '/').replace(/^\.\//, '').toLowerCase();
|
|
4193
|
+
const base = file.split('/').pop();
|
|
4194
|
+
if (promptDirs.some((dir) => file.startsWith(`${dir}/`) || file.includes(`/${dir}/`))) return true;
|
|
4195
|
+
return promptTokens.some((token) => token === file
|
|
4196
|
+
|| (token.includes('/') && file.endsWith(`/${token}`))
|
|
4197
|
+
|| (token.includes('/') && token.endsWith(`/${file}`))
|
|
4198
|
+
|| token === base);
|
|
4199
|
+
}
|
|
4200
|
+
const DOCS_HOUSEKEEPING_PROMPT = /\b(?:docs?|documentation|readme|changelog|worklog|archive|archiving|status\s+(?:file|doc|update)|plans?|commit|tai\s*lieu|tài\s*liệu|luu\s*tru|lưu\s*trữ)\b/i;
|
|
4201
|
+
const CODE_CHANGE_PROMPT = /\b(?:fix|bug|implement|refactor|rewrite|add\s+(?:a\s+|an\s+|the\s+)?(?:function|feature|option|test|endpoint|handler|support)|patch|crash|error|regression|sua\s+loi|sửa\s+lỗi|them\s+tinh\s+nang|thêm\s+tính\s+năng)\b/i;
|
|
4202
|
+
export function deriveExpectedSourceProvenance({ promptText = '', targetFile = null, primaryTargets = [], relatedTests = [] } = {}) {
|
|
4203
|
+
const valid = (list) => (Array.isArray(list) ? list : []).filter((f) => typeof f === 'string' && f.trim());
|
|
4204
|
+
const promptTokens = String(promptText ?? '').replace(/\\/g, '/').toLowerCase()
|
|
4205
|
+
.match(PROMPT_FILE_TOKEN_RE)?.map((t) => t.replace(/^\.\//, '')) ?? [];
|
|
4206
|
+
const promptDirs = (String(promptText ?? '').replace(/\\/g, '/').toLowerCase().match(PROMPT_DIR_TOKEN_RE) ?? [])
|
|
4207
|
+
.map((d) => d.replace(/^\.\//, '').replace(/\/+$/, '')).filter((d) => d && !/\.[a-z][\w]{0,9}$/.test(d));
|
|
4208
|
+
const primaries = valid(primaryTargets);
|
|
4209
|
+
const tests = valid(relatedTests);
|
|
4210
|
+
const target = typeof targetFile === 'string' && targetFile.trim() ? targetFile : null;
|
|
4211
|
+
const named = (f) => promptNamesFile(promptTokens, f, promptDirs);
|
|
4212
|
+
const anchored = Boolean(target) || [...primaries, ...tests].some(named);
|
|
4213
|
+
const advisory = DOCS_HOUSEKEEPING_PROMPT.test(String(promptText ?? '')) && !CODE_CHANGE_PROMPT.test(String(promptText ?? ''));
|
|
4214
|
+
const entries = [];
|
|
4215
|
+
if (target) entries.push({ file: target, source: 'target' });
|
|
4216
|
+
for (const f of primaries) entries.push({ file: f, source: named(f) ? 'prompt' : target ? 'target' : anchored || advisory ? 'index-guess' : 'index-primary' });
|
|
4217
|
+
for (const f of tests) entries.push({ file: f, source: !anchored ? (advisory ? 'index-guess' : 'index-primary') : named(f) ? 'prompt' : 'related-test' });
|
|
4218
|
+
const seen = new Set();
|
|
4219
|
+
const expectedSourceProvenance = entries.filter((e) => (seen.has(e.file) ? false : seen.add(e.file))).slice(0, 8);
|
|
4220
|
+
return { expectedSourceFiles: expectedSourceProvenance.map((e) => e.file), expectedSourceProvenance };
|
|
4221
|
+
}
|
|
4222
|
+
|
|
4223
|
+
export function buildRouteSummary({
|
|
4154
4224
|
activeSkills = [],
|
|
4155
4225
|
routingContext = {},
|
|
4156
4226
|
contextRecommendation = null,
|
|
@@ -4180,11 +4250,12 @@ function buildRouteSummary({
|
|
|
4180
4250
|
// files, so carry the full resolver list (target + primaryTargets + relatedTests), bounded
|
|
4181
4251
|
// for compact route state. Absent when the route has no indexed context — the ledger then
|
|
4182
4252
|
// falls back to its legacy any-read behaviour.
|
|
4183
|
-
const expectedSourceFiles =
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4253
|
+
const { expectedSourceFiles, expectedSourceProvenance } = deriveExpectedSourceProvenance({
|
|
4254
|
+
promptText: routingContext.lastExplicitUserPromptText || routingContext.promptText,
|
|
4255
|
+
targetFile: routingContext.targetFile,
|
|
4256
|
+
primaryTargets: preview.primaryTargets,
|
|
4257
|
+
relatedTests: preview.relatedTests,
|
|
4258
|
+
});
|
|
4188
4259
|
const primaryCommands = unique(verificationRecommendation?.commands ?? []);
|
|
4189
4260
|
const fallbackCommands = unique(verificationRecommendation?.fallbackCommands ?? []);
|
|
4190
4261
|
const preferredOrder = unique(
|
|
@@ -4365,7 +4436,7 @@ function buildRouteSummary({
|
|
|
4365
4436
|
continuationState,
|
|
4366
4437
|
autonomyLevel,
|
|
4367
4438
|
continuousExecution,
|
|
4368
|
-
...(expectedSourceFiles.length > 0 ? { expectedSourceFiles } : {}),
|
|
4439
|
+
...(expectedSourceFiles.length > 0 ? { expectedSourceFiles, expectedSourceProvenance } : {}),
|
|
4369
4440
|
intentMode: routingContext.intentMode ?? null,
|
|
4370
4441
|
handoffFile,
|
|
4371
4442
|
delegateHint: delegationRecommendation?.hint ?? null,
|
|
@@ -6152,6 +6223,7 @@ export function compactRouteSummary(routeSummary = null) {
|
|
|
6152
6223
|
// to legacy any-read behaviour.
|
|
6153
6224
|
...(Array.isArray(routeSummary.expectedSourceFiles) && routeSummary.expectedSourceFiles.length > 0 ? {
|
|
6154
6225
|
expectedSourceFiles: routeSummary.expectedSourceFiles,
|
|
6226
|
+
...(Array.isArray(routeSummary.expectedSourceProvenance) ? { expectedSourceProvenance: routeSummary.expectedSourceProvenance } : {}),
|
|
6155
6227
|
} : {}),
|
|
6156
6228
|
nextActionType: routeSummary.nextActionType ?? null,
|
|
6157
6229
|
nextActionCommand: routeSummary.nextActionCommand ?? null,
|
|
@@ -6438,7 +6510,17 @@ export async function persistSharedRouteState(filePath, state, { expectedRouteBy
|
|
|
6438
6510
|
// This is a persistence revision, not handoff ownership or generation.
|
|
6439
6511
|
// Stamp every publication so an A → B → A route cannot recreate its old bytes.
|
|
6440
6512
|
const published = sidecar ? { ...state, routePersistenceRevision: crypto.randomUUID() } : state;
|
|
6441
|
-
|
|
6513
|
+
// The pending marker is the only record of this session while the publication is in flight, so it must carry
|
|
6514
|
+
// the owner STOP. A standing STOP on the committed sidecar survives an interrupted publication unless the new
|
|
6515
|
+
// publication itself carries a control. Fail-closed: a stranded marker keeps the STOP, never drops it.
|
|
6516
|
+
const committedControl = (() => {
|
|
6517
|
+
try {
|
|
6518
|
+
const committed = current === null ? null : JSON.parse(current);
|
|
6519
|
+
return committed?.ownerControl?.kind === 'stop' && committed.sessionId === owner ? committed.ownerControl : null;
|
|
6520
|
+
} catch { return null; }
|
|
6521
|
+
})();
|
|
6522
|
+
const markerControl = state.ownerControl ?? committedControl;
|
|
6523
|
+
if (sidecar) await writeJsonAtomic(sidecar, { sessionId: owner, taskInstanceId: state.taskInstanceId, routeGeneration: state.routeGeneration, routePersistenceRevision: published.routePersistenceRevision, routePublicationIncomplete: true, ...(markerControl ? { ownerControl: markerControl } : {}) });
|
|
6442
6524
|
// The sidecar lock is held, so no other route writer can publish meanwhile. When the shared write
|
|
6443
6525
|
// did not happen (lock busy/failed) and the shared slot is provably unchanged, restore the previous
|
|
6444
6526
|
// committed sidecar instead of stranding a pending marker over a still-valid route.
|
|
@@ -193,7 +193,7 @@ export function bashOperationReceipt(rawCommand, response, transportSuccess, goa
|
|
|
193
193
|
// the registry actually printed a semver. Agent prose is never evidence; the completion gate compares the
|
|
194
194
|
// recorded version with package.json and live Git state before it treats a release as published.
|
|
195
195
|
const NPM_PUBLISH = /^npm\s+publish(?:\s|$)/;
|
|
196
|
-
const NPM_VIEW = /^npm\s+view\s+(\S+?)(
|
|
196
|
+
const NPM_VIEW = /^npm\s+view\s+(\S+?)(?:@(\S+))?\s+(version|dist\.shasum)(?:\s+--prefer-online)?(?:\s+2>&1)?\s*$/;
|
|
197
197
|
const SEMVER_LINE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
198
198
|
export function releaseReceipt(rawCommand, response, transportSuccess) {
|
|
199
199
|
if (typeof rawCommand !== 'string') return null;
|
|
@@ -211,13 +211,17 @@ export function releaseReceipt(rawCommand, response, transportSuccess) {
|
|
|
211
211
|
const view = seg.match(NPM_VIEW);
|
|
212
212
|
if (view) {
|
|
213
213
|
const text = responseText(response);
|
|
214
|
+
if (view[3] !== 'version') {
|
|
215
|
+
const sha = /^[a-f0-9]{40}$/.test(text) && SEMVER_LINE.test(view[2] || '') && text;
|
|
216
|
+
return { type: 'view', success: ok && !!sha, version: view[2], integrity: sha, package: view[1] };
|
|
217
|
+
}
|
|
214
218
|
const version = SEMVER_LINE.test(text) ? text : null;
|
|
215
219
|
return { type: 'view', success: ok && version !== null, version, package: view[1] };
|
|
216
220
|
}
|
|
217
221
|
return null;
|
|
218
222
|
}
|
|
219
223
|
|
|
220
|
-
export function releaseOperationReceipt(command, response, transportSuccess, { sessionId, harness } = {}) {
|
|
224
|
+
export function releaseOperationReceipt(command, response, transportSuccess, { sessionId, harness, candidate } = {}) {
|
|
221
225
|
const found = releaseReceipt(command, response, transportSuccess);
|
|
222
226
|
if (!found) return null;
|
|
223
227
|
const scope = typeof sessionId === 'string' && sessionId.trim() ? `session:${sessionId.trim()}` : null;
|
|
@@ -225,9 +229,12 @@ export function releaseOperationReceipt(command, response, transportSuccess, { s
|
|
|
225
229
|
const base = { kind: 'operation', success: ok, transportSuccess: transportSuccess === true, harness };
|
|
226
230
|
if (found.type === 'publish') {
|
|
227
231
|
const state = found.package && found.version ? `published:${found.package}@${found.version}` : 'unproven';
|
|
228
|
-
|
|
232
|
+
const shasum = responseText(response).match(/(?:^|\n)npm notice shasum:\s+([a-f0-9]{40})\s*(?:\n|$)/)?.[1];
|
|
233
|
+
return { ...base, operation: { domain: 'release', role: 'mutation', scope, target: 'npm-publish', state,
|
|
234
|
+
...(/^[a-f0-9]{40,64}$/.test(candidate || '') ? { candidate } : {}), ...(shasum ? { integrity: shasum } : {}) } };
|
|
229
235
|
}
|
|
230
236
|
const state = ok && `published:${found.package}@${found.version}`.length <= 200
|
|
231
237
|
? `published:${found.package}@${found.version}` : 'unproven';
|
|
232
|
-
return { ...base, operation: { domain: 'release', role: 'state', scope, target: null, state, complete: ok && state !== 'unproven'
|
|
238
|
+
return { ...base, operation: { domain: 'release', role: 'state', scope, target: null, state, complete: ok && state !== 'unproven',
|
|
239
|
+
...(found.integrity ? { integrity: found.integrity, integrityFor: `${found.package}@${found.version}` } : {}) } };
|
|
233
240
|
}
|