@ngockhoale/ukit 3.5.6 → 3.5.8
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 +28 -0
- package/package.json +1 -1
- package/src/core/applyPlan.js +12 -0
- package/src/core/diffPlan.js +4 -3
- package/src/core/managedTemplateMerge.js +99 -14
- package/src/index/languageTools.js +5 -2
- package/src/index/playbookRegistry.js +6 -1
- package/src/index/semanticLane.js +9 -1
- package/src/index/taskRouting.js +49 -3
- package/template_project/.claude/hooks/skill-router.sh +362 -11
- package/template_project/.claude/ukit/index/lib/index-core.mjs +5 -2
- package/template_project/.claude/ukit/index/lib/semantic-lane.mjs +9 -1
- package/template_project/.claude/ukit/index/playbook-registry.mjs +6 -1
- package/template_project/.claude/ukit/index/publication-intent.mjs +159 -1
- package/template_project/.claude/ukit/index/route-task.mjs +63 -7
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +12 -1
|
@@ -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:02b15877348961e92a6d682beeb94b0dde7e116fb2b2ba9b5c419147772732f8';
|
|
4
4
|
|
|
5
5
|
export function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
|
|
6
6
|
return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
|
|
@@ -23,7 +23,24 @@ export function compareSemanticContracts({ stored, fresh, previousIdentity, iden
|
|
|
23
23
|
}
|
|
24
24
|
const foldIntent = (text) => String(text).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
25
25
|
|
|
26
|
+
// The analysers are pure functions of their arguments but one hook run asks the same question about the same
|
|
27
|
+
// prompt dozens of times. Memoise per exact input (bounded, insertion-order eviction) and hand every caller its
|
|
28
|
+
// own structuredClone, so no caller can mutate the cache or another caller's result.
|
|
29
|
+
const SEMANTIC_MEMO_LIMIT = 16;
|
|
30
|
+
const memoCloned = (cache, key, compute) => {
|
|
31
|
+
const hit = cache.get(key);
|
|
32
|
+
if (hit !== undefined) return structuredClone(hit);
|
|
33
|
+
const value = compute();
|
|
34
|
+
if (cache.size >= SEMANTIC_MEMO_LIMIT) cache.delete(cache.keys().next().value);
|
|
35
|
+
cache.set(key, structuredClone(value));
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
const analyzeMemo = new Map();
|
|
26
39
|
export function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstanceId = null, sessionId = null } = {}) {
|
|
40
|
+
return memoCloned(analyzeMemo, JSON.stringify([String(promptText), targetFile, taskInstanceId, sessionId]),
|
|
41
|
+
() => analyzeTaskIntentUncached({ promptText, targetFile, taskInstanceId, sessionId }));
|
|
42
|
+
}
|
|
43
|
+
function analyzeTaskIntentUncached({ promptText = '', targetFile = '', taskInstanceId = null, sessionId = null } = {}) {
|
|
27
44
|
const original = String(promptText);
|
|
28
45
|
const spans = [];
|
|
29
46
|
let fence = null;
|
|
@@ -212,7 +229,11 @@ function classifyProhibitionItem(item, authorized, proper) {
|
|
|
212
229
|
return null;
|
|
213
230
|
}
|
|
214
231
|
|
|
232
|
+
const scopeMemo = new Map();
|
|
215
233
|
export function publicationScope(promptText = '') {
|
|
234
|
+
return memoCloned(scopeMemo, String(promptText), () => publicationScopeUncached(promptText));
|
|
235
|
+
}
|
|
236
|
+
function publicationScopeUncached(promptText = '') {
|
|
216
237
|
const plain = String(promptText).normalize('NFC')
|
|
217
238
|
.replace(/\bdùng\b/giu, 'su dung').replace(/đừng/giu, 'khong')
|
|
218
239
|
.replace(/(^|[\n;.]\s*)([ \t]*(?:[-*+•]|\d+[.)])?[ \t]*)dung(?=\s+(?:publish|release|npm|git|run|fix|sua)\b)/gi, '$1$2khong')
|
|
@@ -533,8 +554,139 @@ const OWNER_STOP_EN = /^(?:please\s+)?(?:stop|halt|pause|cancel|abort)(?:\s+(?:a
|
|
|
533
554
|
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))*$/;
|
|
534
555
|
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.-]+/;
|
|
535
556
|
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/;
|
|
557
|
+
// A STANDING POLICY states how the owner wants bugs handled in general ("luôn nhớ: có bug là phải fix ngay",
|
|
558
|
+
// "always remember: any bug must be fixed immediately, at its root cause"). It names no defect, so it owes no
|
|
559
|
+
// repro/root-cause contract. CLOSED GRAMMAR: the prompt is split into clauses and returns true ONLY if EVERY
|
|
560
|
+
// non-empty clause, whole and anchored (^...$), is one of the enumerated forms below, and at least one clause is
|
|
561
|
+
// a defect rule. No clause is skipped (only clauses of pure whitespace/punctuation are empty), no clause passes
|
|
562
|
+
// by "all its words are in a set", and no script is exempt: text in any alphabet that matches no form is an
|
|
563
|
+
// order. Any doubt returns false (a real bug order keeps its full evidence duty; a wrong release is the worse
|
|
564
|
+
// error). Global rejects first: concrete referent (path/identifier/quote/version/URL/exit code), a symptom
|
|
565
|
+
// statement, a deictic aimed at a present defect, no policy marker anywhere. The splitter (SP_CLAUSE_SPLIT)
|
|
566
|
+
// cuts on punctuation/newline ONLY and never contains a letter, so no connector word is dropped unjudged;
|
|
567
|
+
// "và" exists only inside form RC. Clause forms (judged on raw NFC text, accents exact, see below):
|
|
568
|
+
// F1 MARK a marker phrase alone ("luôn nhớ", "from now on", "nguyên tắc của tôi")
|
|
569
|
+
// R1 [MARK] (có|thấy|gặp|phát hiện) DEF (là|thì) [phải|luôn] FIX ADV*
|
|
570
|
+
// R2 [MARK] mọi DEF [là|đều] phải FIX ADV*
|
|
571
|
+
// R3 [MARK] (any|every|each|all) DEF (must|should|shall|needs to|has to|gets) [be] FIX ADV*
|
|
572
|
+
// R4 [MARK] bare-plural-DEF (must|should|shall|get) [be] FIX ADV*
|
|
573
|
+
// R5 [MARK] no DEF [luôn] [là (tiêu chí|nguyên tắc|quy tắc|quan điểm) [của tôi]] (nominal slogan)
|
|
574
|
+
// RC (R1|R2|R3|R4) và R6 (rule và purpose)
|
|
575
|
+
// R6 [phải] [tận root cause] để không (tái hiện|xảy ra|lặp lại) DEF nữa (purpose)
|
|
576
|
+
// F3 MARK [vẫn] là phải FIX ADV* (marker REQUIRED; no defect word, no scope word anywhere)
|
|
577
|
+
// F3p quan điểm của tôi [lần chạy này] vẫn là phải FIX ADV* (owner's exact opening)
|
|
578
|
+
// F4 fix [trên ukit] không phải chỉ để pass [thôi] [đâu] (negated purpose)
|
|
579
|
+
// F5 one fixed adverb phrase [nhé], or "nhé" alone ("ngay lập tức", "at its root cause", ...); reachable only after punctuation
|
|
580
|
+
// V1/V2/V3 three enumerated product-rationale sentences ("ukit là sản phẩm tôi sử dụng hỗ trợ rất nhiều sản phẩm khác" ...)
|
|
581
|
+
// ADV* is ONE closed whole-phrase adverb (SP_PHRASE: "ngay lập tức", "triệt để", "at its root cause", ...),
|
|
582
|
+
// optionally followed by "nhé"; never a run of loose words.
|
|
583
|
+
// ACCENTS ARE NEVER FOLDED BEFORE MATCHING. The grammar is written once, in canonical accented spelling; spw()
|
|
584
|
+
// compiles each Vietnamese word to an exact alternation of (its fully unaccented form | its ONE canonical
|
|
585
|
+
// spelling). So "lập" and "lắp"/"lấp"/"lặp", "để" and "đè"/"đẻ", "thấy" and "thay"/"thầy", "nữa" and "nửa" are
|
|
586
|
+
// different words: an accented token that is not the canonical spelling matches nothing. A token with no
|
|
587
|
+
// diacritic still stands for the canonical word (unaccented typing keeps working). English words are ASCII
|
|
588
|
+
// literals, so "FİXED" or "fíx" match nothing. SP_CANONICAL lists every accented word the grammar uses.
|
|
589
|
+
const SP_FOLD = (s) => s.normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/đ/g, 'd');
|
|
590
|
+
const SP_ACCENTED = new Set();
|
|
591
|
+
const spw = (token) => {
|
|
592
|
+
const t = token.normalize('NFC');
|
|
593
|
+
const f = SP_FOLD(t);
|
|
594
|
+
if (f === t) return t;
|
|
595
|
+
SP_ACCENTED.add(t);
|
|
596
|
+
return `(?:${f}|${t})`;
|
|
597
|
+
};
|
|
598
|
+
const sp = (phrase) => phrase.trim().split(/\s+/).map(spw).join('\\s+');
|
|
599
|
+
const spAny = (...phrases) => `(?:${phrases.map(sp).join('|')})`;
|
|
600
|
+
const SP_DEF = `(?:bugs?|${sp('lỗi')}|defects?|crash(?:es)?|errors?|exceptions?|broken|regressions?|failures?|failing|fails?)`;
|
|
601
|
+
const SP_DEF_PLURAL = `(?:bugs|${sp('lỗi')}|defects|crashes|errors|exceptions|regressions|failures)`;
|
|
602
|
+
const SP_FIXV = `(?:fix|fixed|fixes|fixing|${sp('sửa')}|${sp('khắc phục')}|${sp('xử lý')}|resolved?)`;
|
|
603
|
+
// Adverbs are a closed list of whole PHRASES, never a run of words: one primary phrase, then optionally "nhé".
|
|
604
|
+
const SP_PHRASE = spAny('ngay lập tức', 'ngay luôn', 'ngay', 'luôn', 'triệt để', 'tận gốc', 'hoàn toàn', 'tận root cause', 'tận root cáue',
|
|
605
|
+
'at its root cause', 'at the root cause', 'at its root', 'immediately', 'right away', 'at once', 'properly', 'fully', 'completely', 'thoroughly');
|
|
606
|
+
const SP_ADVRUN = `(?:\\s+${SP_PHRASE})?(?:\\s+${sp('nhé')})?`;
|
|
607
|
+
const SP_MARK = `(?:${spAny('luôn nhớ', 'luôn luôn', 'từ giờ', 'từ nay', 'nguyên tắc', 'tiêu chí', 'quy tắc', 'quan điểm',
|
|
608
|
+
'always remember', 'from now on', 'as a rule', 'my rule is', 'my policy is', 'my principle is')})(?:\\s+${sp('của tôi')})?`;
|
|
609
|
+
const SP_MARK_PFX = `(?:${SP_MARK}\\s+)?`;
|
|
610
|
+
// The enumerated clause forms (see the header comment). Every one is anchored at both ends. Connector words
|
|
611
|
+
// (và ...) exist ONLY inside the compound form RC below; the clause splitter never consumes a word.
|
|
612
|
+
const SP_R1 = `${SP_MARK_PFX}${spAny('có', 'thấy', 'gặp', 'phát hiện')}\\s+${SP_DEF}\\s+${spAny('là', 'thì')}\\s+(?:${spAny('phải', 'luôn')}\\s+)?${SP_FIXV}${SP_ADVRUN}`;
|
|
613
|
+
const SP_R2 = `${SP_MARK_PFX}${sp('mọi')}\\s+${SP_DEF}\\s+(?:${sp('là')}\\s+|${sp('đều')}\\s+)?${sp('phải')}\\s+${SP_FIXV}${SP_ADVRUN}`;
|
|
614
|
+
const SP_R3 = `${SP_MARK_PFX}(?:any|every|each|all)\\s+${SP_DEF}\\s+(?:must|should|shall|needs? to|has to|gets?)\\s+(?:be\\s+)?${SP_FIXV}${SP_ADVRUN}`;
|
|
615
|
+
const SP_R4 = `${SP_MARK_PFX}${SP_DEF_PLURAL}\\s+(?:must|should|shall|get)\\s+(?:be\\s+)?${SP_FIXV}${SP_ADVRUN}`;
|
|
616
|
+
const SP_R6 = `(?:${sp('phải')}\\s+)?(?:${spAny('tận root cause', 'tận root cáue')}\\s+)?${sp('để không')}\\s+${spAny('tái hiện', 'xảy ra', 'lặp lại')}\\s+${SP_DEF}\\s+${sp('nữa')}`;
|
|
617
|
+
const SP_CLAUSE_FORMS = [
|
|
618
|
+
new RegExp(`^${SP_MARK}$`), // F1
|
|
619
|
+
new RegExp(`^${SP_R1}$`), // R1
|
|
620
|
+
new RegExp(`^${SP_R2}$`), // R2
|
|
621
|
+
new RegExp(`^${SP_R3}$`), // R3
|
|
622
|
+
new RegExp(`^${SP_R4}$`), // R4
|
|
623
|
+
new RegExp(`^${SP_MARK_PFX}no\\s+${SP_DEF}(?:\\s+${sp('luôn')})?(?:\\s+${sp('là')}\\s+${spAny('tiêu chí', 'nguyên tắc', 'quy tắc', 'quan điểm')}(?:\\s+${sp('của tôi')})?)?$`), // R5
|
|
624
|
+
new RegExp(`^(?:${SP_R1}|${SP_R2}|${SP_R3}|${SP_R4})\\s+${sp('và')}\\s+${SP_R6}$`), // RC: rule và purpose (owner's P2)
|
|
625
|
+
new RegExp(`^${SP_R6}$`), // R6
|
|
626
|
+
new RegExp(`^${SP_MARK}\\s+(?:${sp('vẫn')}\\s+)?${sp('là phải')}\\s+${SP_FIXV}${SP_ADVRUN}$`), // F3 (marker required)
|
|
627
|
+
new RegExp(`^${sp('quan điểm của tôi')}(?:\\s+${sp('lần chạy này')})?\\s+${sp('vẫn là phải')}\\s+${SP_FIXV}${SP_ADVRUN}$`), // F3p
|
|
628
|
+
new RegExp(`^fix(?:\\s+${sp('trên ukit')})?\\s+${sp('không phải chỉ để')}\\s+pass(?:\\s+${sp('thôi')})?(?:\\s+${sp('đâu')})?$`), // F4
|
|
629
|
+
new RegExp(`^(?:${SP_PHRASE}(?:\\s+${sp('nhé')})?|${sp('nhé')})$`), // F5 (reachable only after punctuation)
|
|
630
|
+
new RegExp(`^${sp('ukit là sản phẩm tôi sử dụng hỗ trợ rất nhiều sản phẩm khác')}$`), // V1
|
|
631
|
+
new RegExp(`^${sp('ukit là sản phẩm quan trọng')}$`), // V2
|
|
632
|
+
new RegExp(`^${sp('ukit hỗ trợ rất nhiều sản phẩm khác')}$`), // V3
|
|
633
|
+
];
|
|
634
|
+
// Folded key -> canonical accented spelling(s). One spelling per word; a word with two legitimate tone
|
|
635
|
+
// placements would list both here and in the grammar.
|
|
636
|
+
export const SP_CANONICAL = {};
|
|
637
|
+
for (const w of [...SP_ACCENTED].sort()) (SP_CANONICAL[SP_FOLD(w)] ||= []).push(w);
|
|
638
|
+
// The splitter splits on punctuation/newline ONLY. It must never contain a letter: a word consumed by a
|
|
639
|
+
// splitter is discarded unjudged. (Asserted by a test.)
|
|
640
|
+
export const SP_CLAUSE_SPLIT = /[.!?;:\n,]+/;
|
|
641
|
+
// Forms that state a defect rule: at least one clause must be one of them (R1-R5 and RC).
|
|
642
|
+
const SP_RULE_FORM_COUNT = 7;
|
|
643
|
+
const STANDING_POLICY_MARKER = /\b(?:luon nho|luon luon|tu gio|tu nay|nguyen tac|tieu chi|quy tac|quan diem|always remember|from now on|as a rule|my (?:rule|policy|principle) is)\b/;
|
|
644
|
+
const STANDING_POLICY_CONCRETE = /[`"“”«»]|https?:\/\/|www\.|\b\w+\(\)|[\w.-]+\/[\w.-]+|\b[\w-]+\.(?:m?js|cjs|jsx?|tsx?|json|md|sh|py|ya?ml|css|html?|go|rs|java|rb|php|sql|toml|txt|lock|log)\b|\b[a-z]+[A-Z]\w*|\b\w+_\w+|\b\w*Error\b|\bE[A-Z]{3,}\b|\bv?\d+\.\d+|\bexit\s*(?:code|status)?\s*:?\s*-?\d+|\bstack\b|\b\d{3,}\b/;
|
|
645
|
+
const STANDING_POLICY_SYMPTOM = /\b(?:bi loi|khong chay|khong hoat dong|hong|treo|sai|van con|chua (?:duoc )?(?:fix|sua)|crash(?:es|ed)?|(?:does ?n[o']?t|won'?t|is ?n[o']?t) work|(?:is|are) broken|fail(?:s|ed|ing)?)\b/;
|
|
646
|
+
const STANDING_POLICY_DEICTIC_ANYWHERE = /\b(?:the above|above|vua roi|hien tai|current(?:ly)?|dang|failing|following|ben tren|o tren)\b/;
|
|
647
|
+
export function isStandingPolicyPrompt(promptText = '') {
|
|
648
|
+
const raw = String(promptText ?? '').trim();
|
|
649
|
+
if (!raw || raw.length > 800 || STANDING_POLICY_CONCRETE.test(raw)) return false;
|
|
650
|
+
// The global rejects (marker present, no symptom, no deictic) are deliberately lenient and run on a folded
|
|
651
|
+
// copy; the clause forms below run on the RAW lowercase NFC text, where accents are exact. Nothing but
|
|
652
|
+
// Latin combining marks and "đ" is ever removed from the folded copy, and the raw text is what is judged.
|
|
653
|
+
const text = raw.toLowerCase().normalize('NFC').replace(/\s+/g, ' ');
|
|
654
|
+
const folded = SP_FOLD(text);
|
|
655
|
+
if (!STANDING_POLICY_MARKER.test(folded) || STANDING_POLICY_DEICTIC_ANYWHERE.test(folded) || STANDING_POLICY_SYMPTOM.test(folded)) return false;
|
|
656
|
+
const clauses = text.split(SP_CLAUSE_SPLIT);
|
|
657
|
+
let ruleClauses = 0;
|
|
658
|
+
for (const clause of clauses) {
|
|
659
|
+
const norm = clause.replace(/\s+/g, ' ').trim();
|
|
660
|
+
// Only a clause that is empty after whitespace/ASCII punctuation is skipped. Anything else (a letter or
|
|
661
|
+
// digit of any script, an emoji, a symbol) must match an enumerated form, else the prompt is not a policy.
|
|
662
|
+
if (!norm.replace(/[\s!-/:-@[-`{-~]/g, '')) continue;
|
|
663
|
+
const form = SP_CLAUSE_FORMS.findIndex((re) => re.test(norm));
|
|
664
|
+
if (form < 0) return false;
|
|
665
|
+
if (form >= 1 && form < SP_RULE_FORM_COUNT) ruleClauses += 1;
|
|
666
|
+
}
|
|
667
|
+
return ruleClauses > 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// A host-delivered peer (teammate/subagent/other-session) message: optional banner line, one or more CLOSED
|
|
671
|
+
// peer blocks, then nothing or (banner required) the host's own single-paragraph trailer, recognised by its
|
|
672
|
+
// stable lead words. Owner words anywhere else make it an owner prompt. A host wording change falls back to
|
|
673
|
+
// "not a peer prompt" (old routing), never to dropping owner text. Mirrors the early-exit check in skill-router.sh.
|
|
674
|
+
export function isPeerMessagePrompt(promptText = '') {
|
|
675
|
+
const text = String(promptText ?? '').trim();
|
|
676
|
+
const banner = /^Another Claude session sent a message:[ \t]*\r?\n/i;
|
|
677
|
+
const bannered = banner.test(text);
|
|
678
|
+
let rest = text.replace(banner, '').trim();
|
|
679
|
+
const peerBlock = /^<(agent-message|teammate-message|cross-session-message)(?:\s[^>]*)?>[\s\S]*?<\/\1>\s*/;
|
|
680
|
+
let blocks = 0;
|
|
681
|
+
for (let m = peerBlock.exec(rest); m; m = peerBlock.exec(rest)) { rest = rest.slice(m[0].length); blocks += 1; }
|
|
682
|
+
const trailer = /^(?:This came from another Claude session|That .other Claude session. is an agent working inside this same session)[^\r\n]{0,1500}$/i;
|
|
683
|
+
return blocks > 0 && (rest === '' || (bannered && trailer.test(rest.trim())));
|
|
684
|
+
}
|
|
685
|
+
|
|
536
686
|
export function classifyOwnerControl(promptText = '') {
|
|
537
687
|
const raw = String(promptText ?? '').normalize('NFC').trim();
|
|
688
|
+
// Text shape is never provenance here: an envelope-first/banner-first text already yields kind null because
|
|
689
|
+
// OWNER_STOP_EN/VI are anchored on the first lead (proved 0 diffs vs the former isPeerMessagePrompt guard).
|
|
538
690
|
if (!raw || OWNER_CONTROL_HOOK_TEXT.test(raw)) return { kind: null };
|
|
539
691
|
const stripped = raw.replace(/^[\s*#_-]+/, '');
|
|
540
692
|
if (/^[>"'`\u201c\u2018]/.test(stripped)) return { kind: null };
|
|
@@ -726,7 +878,13 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
|
726
878
|
const cronOperation = actionable.some((clause) => /\b(?:delete|remove|cancel|xoa|huy|ensure|dam bao)\b/.test(clause)
|
|
727
879
|
&& /\bcron\b|scheduled\s+(?:cron\s+)?(?:task|job)|tac vu\s+(?:cron|dinh ky)/.test(clause))
|
|
728
880
|
&& (!codeChangeVerb || hasOperationId);
|
|
881
|
+
// Pure per clause and asked once by runtimeClause and once by gitClause for every clause; compute each clause once.
|
|
882
|
+
const operationNotOrderedMemo = new Map();
|
|
729
883
|
const operationNotOrdered = (clause) => {
|
|
884
|
+
if (!operationNotOrderedMemo.has(clause)) operationNotOrderedMemo.set(clause, operationNotOrderedUncached(clause));
|
|
885
|
+
return operationNotOrderedMemo.get(clause);
|
|
886
|
+
};
|
|
887
|
+
const operationNotOrderedUncached = (clause) => {
|
|
730
888
|
const OP = '(?:restart|redeploy|deploy(?:ment)?|trien khai|khoi dong lai|git\\s+push|push\\s+(?:to\\s+)?origin|commit|push)';
|
|
731
889
|
const BAN = '(?:bi\\s+(?:cam|chan)|forbidden|prohibited|banned|not\\s+allowed|not\\s+permitted|disallowed)';
|
|
732
890
|
if (/\b(?:was|were|previously|before|formerly|no\s+longer|even\s+though|although|though|now\s+allows?|now\s+permits?|owner\s+allows?|khong\s+bi|da\s+duoc\s+phep|except)\b/.test(clause)) return false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { classifyTaskSemantics, applyTaskSemantics } from './route-resolver.mjs';
|
|
3
|
-
import { semanticContractIdentity, ordersAdditiveChange } from './publication-intent.mjs';
|
|
3
|
+
import { semanticContractIdentity, ordersAdditiveChange, isStandingPolicyPrompt } from './publication-intent.mjs';
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
5
5
|
// `fsSync` aliases the SAME fs module — used ONLY by the process.on('exit')
|
|
6
6
|
// audit-sidecar fold below (event loop is gone; async cannot run) and by the
|
|
@@ -2113,6 +2113,15 @@ async function appendPerQuestionShadowReceipts({
|
|
|
2113
2113
|
* every failure degrades to a receipt with outcomeClass 'unavailable' —
|
|
2114
2114
|
* never throws, never blocks the route.
|
|
2115
2115
|
*/
|
|
2116
|
+
// A spawnSync that hit its `timeout` was killed (error.code ETIMEDOUT, signal
|
|
2117
|
+
// SIGTERM): the adapter started but ran past its deadline. Label it with the
|
|
2118
|
+
// decision plane's own timeout code ('deadline-exceeded', same as client.js /
|
|
2119
|
+
// unic-decision.mjs) instead of claiming it could not start. Everything else
|
|
2120
|
+
// (spawn error, non-zero exit, empty stdout) stays 'adapter-spawn-failed'.
|
|
2121
|
+
function spawnFailureCode(spawned) {
|
|
2122
|
+
return spawned?.error?.code === 'ETIMEDOUT' ? 'deadline-exceeded' : 'adapter-spawn-failed';
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2116
2125
|
export async function runRouteDecisionShadow({
|
|
2117
2126
|
rootDir = process.cwd(),
|
|
2118
2127
|
config = null,
|
|
@@ -2232,7 +2241,7 @@ export async function runRouteDecisionShadow({
|
|
|
2232
2241
|
if (spawned && !spawned.error && spawned.status === 0 && spawned.stdout) {
|
|
2233
2242
|
result = JSON.parse(spawned.stdout);
|
|
2234
2243
|
} else {
|
|
2235
|
-
result = { status: 'unavailable', fallbackCode:
|
|
2244
|
+
result = { status: 'unavailable', fallbackCode: spawnFailureCode(spawned) };
|
|
2236
2245
|
}
|
|
2237
2246
|
} catch {
|
|
2238
2247
|
result = { status: 'unavailable', fallbackCode: 'adapter-spawn-failed' };
|
|
@@ -2349,7 +2358,7 @@ async function askUnicDecisionBatch({
|
|
|
2349
2358
|
if (spawned && !spawned.error && spawned.status === 0 && spawned.stdout) {
|
|
2350
2359
|
return JSON.parse(spawned.stdout);
|
|
2351
2360
|
}
|
|
2352
|
-
return { status: 'unavailable', fallbackCode:
|
|
2361
|
+
return { status: 'unavailable', fallbackCode: spawnFailureCode(spawned), answers: [] };
|
|
2353
2362
|
} catch {
|
|
2354
2363
|
return { status: 'unavailable', fallbackCode: 'adapter-spawn-failed', answers: [] };
|
|
2355
2364
|
}
|
|
@@ -4694,7 +4703,9 @@ function isInformationalPrompt({
|
|
|
4694
4703
|
}
|
|
4695
4704
|
// C85-019: consult-shape also overrides the vocabulary vetoes — the
|
|
4696
4705
|
// mutation/debug/lỗi words are the question's SUBJECT, not the ask.
|
|
4697
|
-
|
|
4706
|
+
// chạy/tạo/cài are judged by the shared position rule (ambiguousVerbOrder), not by bare presence.
|
|
4707
|
+
const implementWords = /(?<![A-Za-z0-9_])(implement|apply|update|modify|add|create|ship|deliver|fix|refactor|remove|delete|rename|change|write|build|make|install|run|deploy|execute|sửa|thêm|xóa|đổi|thay thế|cập nhật|viết|build)(?![A-Za-z0-9_])/.test(softenEnglishNouns(raw))
|
|
4708
|
+
|| ambiguousVerbOrder(raw);
|
|
4698
4709
|
if (implementWords && !consultShape) return false;
|
|
4699
4710
|
const investigationWords = /\b(why|debug|triage|root cause|investigate|tại sao)\b/.test(raw);
|
|
4700
4711
|
if (investigationWords && !consultShape) return false;
|
|
@@ -4724,6 +4735,8 @@ function isInformationalPrompt({
|
|
|
4724
4735
|
// a bare "không biết…chưa" uncertainty is NOT an assertion and stays on the
|
|
4725
4736
|
// plain question path.
|
|
4726
4737
|
function hasAdvisoryOnlyAssertion({ promptText = '', commandText = '' } = {}) {
|
|
4738
|
+
// A standing owner policy about bugs in general is advisory: no defect is named, nothing to repro.
|
|
4739
|
+
if (!String(commandText || '').trim() && isStandingPolicyPrompt(promptText)) return true;
|
|
4727
4740
|
const folded = `${promptText ?? ''}\n${commandText ?? ''}`
|
|
4728
4741
|
.toLowerCase()
|
|
4729
4742
|
.normalize('NFD')
|
|
@@ -4890,7 +4903,51 @@ export function classifyAdvisorRequest({ promptText = '', commandText = '' } = {
|
|
|
4890
4903
|
// folding, so "Cái này là gì, tại sao…" is not read as an install order (3.4.81 telemetry audit).
|
|
4891
4904
|
function maskTonedNonVerbs(text = '') {
|
|
4892
4905
|
return String(text ?? '').normalize('NFC')
|
|
4893
|
-
.replace(/(?<![\p{L}\p{N}_])(?:cái|chính|việt|cháy|chảy|đợi|đời|đối|đội|đôi|đói|sữa|thèm)(?![\p{L}\p{N}_])/giu, ' _ ');
|
|
4906
|
+
.replace(/(?<![\p{L}\p{N}_])(?:cái|cải|cãi|chính|việt|cháy|chảy|đợi|đời|đối|đội|đôi|đói|sữa|thèm)(?![\p{L}\p{N}_])/giu, ' _ ');
|
|
4907
|
+
}
|
|
4908
|
+
// Position rule for the closed set of verbs that tone-fold onto an order verb but are ordinary
|
|
4909
|
+
// aspect/nominal words in progress talk: ch\u1ea1y (run / is running), t\u1ea1o (create / the creation of),
|
|
4910
|
+
// c\u1ea3i/c\u00e0i (improve / install). Input is folded (accent-free, lowercase) text. A verb is an ORDER when it
|
|
4911
|
+
// has an object or an imperative particle; it is NOT an order after a nominaliser/preposition/copula/
|
|
4912
|
+
// aspect marker (PREV = cua, viec, su, khi, dang) or when only a stative/degree complement follows
|
|
4913
|
+
// (co ve + lau, mai, hoai, cham, nhanh, xong, roi, duoc, qua, rat, hoi, ne, then end of clause or a conjunction).
|
|
4914
|
+
// Imperative particles (di, luon, ngay, giup, gium, ho, nhe) within 3 tokens always keep it an order.
|
|
4915
|
+
// Non-orders become " _ "; orders are untouched. English: a mutation word right after a determiner/possessive is
|
|
4916
|
+
// a noun ("the build"), unless a light verb stands before the determiner ("do the build", "finish that update").
|
|
4917
|
+
// Destructive verbs (x\u00f3a, delete, drop, reset) are deliberately not in this set.
|
|
4918
|
+
// Three copies (taskRouting.js, route-task.mjs, skill-router.sh) \u2014 keep them identical.
|
|
4919
|
+
function softenEnglishNouns(text = '') {
|
|
4920
|
+
return String(text).replace(/(?<!\b(?:do|does|doing|perform|finish|complete|handle|start|get|try)\s+)\b(the|a|an|any|this|that|these|those|my|our|your|its|their|his|her)\s+(?:implement|apply|update|modify|add|create|ship|deliver|fix|refactor|rename|change|write|build|make|install|run|deploy|execute|edit)\b/gi, '$1 _ ');
|
|
4921
|
+
}
|
|
4922
|
+
function softenAmbiguousVerbs(folded = '') {
|
|
4923
|
+
const PREV = new Set(['cua', 'viec', 'su', 'khi', 'dang']);
|
|
4924
|
+
const PARTICLE = new Set(['di', 'luon', 'ngay', 'giup', 'gium', 'ho', 'nhe']);
|
|
4925
|
+
const COMPLEMENT = new Set(['lau', 'mai', 'hoai', 'cham', 'nhanh', 'xong', 'roi', 'duoc', 'qua', 'rat', 'hoi', 'ne']);
|
|
4926
|
+
const CONJ = new Set(['ma', 'nhung', 'va', 'thi', 'hay', 'nen', 'khong', 'chua', 'but', 'and', 'so']);
|
|
4927
|
+
// Each occurrence is judged on its own (a clause can hold several: "tạo ra Ukit là cải tiến ...").
|
|
4928
|
+
// English: a mutation token right after a determiner/possessive is a noun ("the build", "my fix"), never an
|
|
4929
|
+
// order. Only that token is softened, so "run the build" / "fix the build" still order through the verb.
|
|
4930
|
+
// delete/remove are never softened.
|
|
4931
|
+
return softenEnglishNouns(folded).replace(/\b(chay|tao|cai)\b/g, (match, verb, offset, whole) => {
|
|
4932
|
+
const prev = whole.slice(0, offset).trimEnd().split(/\s+/).pop() || '';
|
|
4933
|
+
const tokens = (whole.slice(offset + match.length).split(/[.,;!?\n]/)[0] || '').split(/\s+/).filter(Boolean);
|
|
4934
|
+
if (tokens.slice(0, 3).some((token) => PARTICLE.has(token))) return match;
|
|
4935
|
+
if (PREV.has(prev)) return ' _ ';
|
|
4936
|
+
let index = 0;
|
|
4937
|
+
let consumed = 0;
|
|
4938
|
+
while (index < tokens.length) {
|
|
4939
|
+
if (tokens[index] === 'co' && tokens[index + 1] === 've') { index += 2; consumed += 1; continue; }
|
|
4940
|
+
if (COMPLEMENT.has(tokens[index])) { index += 1; consumed += 1; continue; }
|
|
4941
|
+
break;
|
|
4942
|
+
}
|
|
4943
|
+
if (consumed > 0 && (index >= tokens.length || CONJ.has(tokens[index]))) return ' _ ';
|
|
4944
|
+
return match;
|
|
4945
|
+
});
|
|
4946
|
+
}
|
|
4947
|
+
// The shared predicate: does any ambiguous verb in this text still stand as an order?
|
|
4948
|
+
function ambiguousVerbOrder(text = '') {
|
|
4949
|
+
const folded = maskTonedNonVerbs(text).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/\u0111/g, 'd');
|
|
4950
|
+
return /\b(?:chay|tao|cai)\b/.test(softenAmbiguousVerbs(folded));
|
|
4894
4951
|
}
|
|
4895
4952
|
function hasMutationOrder({ promptText = '', commandText = '' } = {}) {
|
|
4896
4953
|
const folded = `${maskTonedNonVerbs(promptText)}\n${commandText ?? ''}`
|
|
@@ -4898,7 +4955,7 @@ function hasMutationOrder({ promptText = '', commandText = '' } = {}) {
|
|
|
4898
4955
|
.normalize('NFD')
|
|
4899
4956
|
.replace(/[\u0300-\u036f]/g, '')
|
|
4900
4957
|
.replace(/\u0111/g, 'd');
|
|
4901
|
-
const trimmed = folded.trim();
|
|
4958
|
+
const trimmed = softenAmbiguousVerbs(folded.trim());
|
|
4902
4959
|
if (!trimmed) return false;
|
|
4903
4960
|
// C85-019c: clause strips must stop BEFORE a conjunction-joined imperative
|
|
4904
4961
|
// — "giữ nguyên header và sửa lỗi login" keeps 'và sửa lỗi' as a surviving
|
|
@@ -5066,7 +5123,6 @@ function deriveExecutionMode({
|
|
|
5066
5123
|
// an edit order, not a consultation). A leading interrogative overrides them:
|
|
5067
5124
|
// "Lam sao ma do duoc khi toi cai…?" asks HOW something is done, it does not order
|
|
5068
5125
|
// the action performed.
|
|
5069
|
-
const consultationImplementWords = /(?<![A-Za-z0-9_])(?:implement|apply|update|modify|add|create|ship|deliver|fix|refactor|remove|delete|rename|change|write|build|make|install|run|deploy|execute|sửa|thêm|tạo|xóa|đổi|thay thế|cập nhật|viết|chạy|cài)(?![A-Za-z0-9_])/.test(trimmedPromptText);
|
|
5070
5126
|
// C85-019: question shape + no surviving imperative = consult. The
|
|
5071
5127
|
// pre-C85-019 all-zero-scores clause consulted only when NOTHING in the
|
|
5072
5128
|
// prompt resembled work — impossible for a question about code. Replacing
|
|
@@ -26,6 +26,12 @@ import { withAsyncLock } from './async-lock.mjs';
|
|
|
26
26
|
// the SAME selector filters the completion and blocked predicates below. Sandbox
|
|
27
27
|
// runtimes that copy this file by an explicit sibling list must copy this module too.
|
|
28
28
|
import { selectTaskScope } from './handoff-task-scope.mjs';
|
|
29
|
+
// Peer-message recogniser: ONE shared implementation (index/publication-intent.mjs). Loaded fail-open — a runtime
|
|
30
|
+
// without that sibling degrades to "never a peer prompt" (old behaviour), it must not break the Stop hook import.
|
|
31
|
+
let isPeerMessagePrompt = () => false;
|
|
32
|
+
try {
|
|
33
|
+
({ isPeerMessagePrompt } = await import('../index/publication-intent.mjs'));
|
|
34
|
+
} catch { /* degrade: peer text then counts as user text, as before */ }
|
|
29
35
|
// PreToolUse block-breaker cause matching for stop reconciliation — advisory and
|
|
30
36
|
// fail-open: a missing/corrupt breaker module degrades to "no match" (a block then
|
|
31
37
|
// stays a block; nothing is released), never to a changed stop verdict.
|
|
@@ -2614,6 +2620,11 @@ const RESUME_COMMAND_TAG = /^<command-name>\/?(?:ukit:)?handoff-(?:fullstack|imp
|
|
|
2614
2620
|
|
|
2615
2621
|
function genuineUserText(entry) {
|
|
2616
2622
|
if (!entry || entry.type !== 'user' || entry.isSidechain === true || entry.isMeta === true) return null;
|
|
2623
|
+
// Host stamps beat text shape: a peer-stamped entry is never the owner; an entry the host stamped as human
|
|
2624
|
+
// (origin.kind 'human' / promptSource 'typed') is the owner even if the text looks like a peer envelope.
|
|
2625
|
+
// Only an UNSTAMPED entry falls back to the envelope-shape check below.
|
|
2626
|
+
if (entry.origin?.kind === 'peer' || entry.turnOrigin === 'peer') return null;
|
|
2627
|
+
const hostStampedHuman = entry.origin?.kind === 'human' || entry.promptSource === 'typed';
|
|
2617
2628
|
const msg = entry.message;
|
|
2618
2629
|
if (!msg || msg.role !== 'user') return null;
|
|
2619
2630
|
let text = '';
|
|
@@ -2629,7 +2640,7 @@ function genuineUserText(entry) {
|
|
|
2629
2640
|
return null;
|
|
2630
2641
|
}
|
|
2631
2642
|
text = text.trim();
|
|
2632
|
-
if (!text || SYNTHETIC_USER_PREFIX.test(text)) return null;
|
|
2643
|
+
if (!text || SYNTHETIC_USER_PREFIX.test(text) || (!hostStampedHuman && isPeerMessagePrompt(text))) return null;
|
|
2633
2644
|
return text;
|
|
2634
2645
|
}
|
|
2635
2646
|
|