@ngockhoale/ukit 3.4.76 → 3.4.78

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngockhoale/ukit",
3
- "version": "3.4.76",
3
+ "version": "3.4.78",
4
4
  "description": "Install/update an index-first AI workspace for Claude Code, OpenAI Codex and omp (Oh My Pi).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -201,9 +201,9 @@ const HOOK_DEADLINE_MS = Number.parseInt(process.env.UKIT_HOOK_DEADLINE_MS || ''
201
201
  setTimeout(() => process.exit(0), HOOK_DEADLINE_MS).unref();
202
202
 
203
203
  (async () => {
204
- // BEGIN GENERATED SEMANTIC ENGINE sha256=d125c6ef30c4bec1e3065148855cfd0b90c1af5acd90de2020de02607a4e0adf
204
+ // BEGIN GENERATED SEMANTIC ENGINE sha256=c04c341ecd5922273ac127ddd37adf9dccc6c3927f0149b96845bf991bff2014
205
205
  // Canonical task semantics; intent never grants authorization or proves completion.
206
- const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:d54a8c14f321c1eeba4832e4461cd6d0c2231b2f7a80932ac3129f1e8dd792f9';
206
+ const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:a489851b01e95788d8a3e0a080b80c04d8161c734b6c0ed5c9758a765f5bc0a4';
207
207
 
208
208
  function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
209
209
  return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
@@ -211,7 +211,7 @@ function semanticContractIdentity({ promptText = '', targetFile = '', taskInstan
211
211
  }
212
212
 
213
213
  const semanticContractShape = (contract) => JSON.stringify([
214
- contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null,
214
+ contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null, contract?.operationGoals ?? null,
215
215
  contract?.configurationScope ?? null, contract?.releasePolicy ?? null, contract?.conditionalObligations ?? null,
216
216
  contract?.reportArtifact ?? null, contract?.verificationOnly === true, contract?.statusReport === true, contract?.stateVerification === true, contract?.stateAction === true, contract?.stateConditionalStop === true, (contract?.stateTargets || []).join(','),
217
217
  [...(contract?.completionEvidence || [])].sort(),
@@ -355,7 +355,7 @@ const CONDITIONAL_RUNTIME_VERB = /\b(?:redeploy|deploy|restart|khoi dong lai|tri
355
355
  const CONDITIONAL_RUNTIME_EXCLUDED = /\b(?:publish|phat hanh|commit|push|tag|git|implement|fix|edit|modify|sua)\b/;
356
356
  const VERIFICATION_LEAD = /^[-*+\u2022>\d.)\s]*(?:(?:please|hay|vui long|now|also|first)\s+)*(?:verify|check|confirm|validate|inspect|kiem tra|xac nhan)\b/;
357
357
  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';
358
- const PAST_RELEASE_ITEM = new RegExp(`^(?:(?:please|just|now|also)\\s+)*${PAST_RELEASE_SOURCE}`);
358
+ const PAST_RELEASE_ITEM = new RegExp(`^(?:(?:please|just|now|also)\\s+)*(?:${PAST_RELEASE_SOURCE}|release(?:\\s+\\S+)?\\s+(?:(?:co the|may|might|could)\\b|da\\s+len\\b|(?:has|have)\\s+gone\\s+live\\b))`);
359
359
  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/;
360
360
  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/;
361
361
  const PUBLISH_ORDER_HEADER = /prohibit|forbidden|out of scope|non-goal|scope control/;
@@ -367,6 +367,54 @@ function defectRepairBranches(text) {
367
367
  && /\b(?:sua|fix|repair)\b/.test(branch));
368
368
  }
369
369
 
370
+ const REVOCATION_ITEM = /\b(?:thu hoi|revoke\w*|rescind\w*|withdraw\w*)\b[^.;\n]*\b(?:deploy|redeploy|publish|publication|release|trien khai|phat hanh)\b/;
371
+ // deploy words prohibit only as a direct ban ("do not deploy"), never as an object inside other prose.
372
+ const DIRECT_DEPLOY_BAN = /^(?:(?:please|hay|vui long)\s+)*(?:do not|don't|dont|never|khong|must not)\s+(?:npm\s+)?(?:re-?deploy|deploy|trien khai)\b/;
373
+ const GATE_QUOTE = /\b(?:prohibits? publication|publication blocked|ukit completion gate|ukit publication)\b|\b(?:bi bao|bao rang|reports?|reported|says?|said|message|thong bao)\b[^.;\n]*\b(?:prohibit\w*|blocked|chan|cam)\b/;
374
+ const GATE_ANCHOR = /\b(?:ukit|gates?|hooks?|logs?)\b|`/;
375
+ const CONTINUATION_NEGATION = /\b(?:do not|don't|dont|never|khong|chua)\s+(?:\w+\s+){0,2}?(?:dung|stop|end|finish|halt|ngung|ket thuc|quit|exit)\b/;
376
+ const PURPOSE_SCOPE = /\b(?:chi de|only to|just to|only for)\b/;
377
+ const CONDITION_LEAD = /\b(?:neu|if|khi|unless|in case|truong hop)\b/;
378
+ const NAME_STOP = new Set(['the', 'a', 'an', 'to', 'on', 'npm', 'if', 'khi', 'neu', 'again', 'now', 'production', 'prod', 'staging', 'artifact', 'image', 'build', 'candidate', 'lai', 'len', 'vao', 'nua', 'qua', 'via', 'tu', 'from', 'with', 'voi', 'any', 'moi', 'khac', 'other', 'another', 'nay', 'package', 'version', 'release', 'publish', 'sau', 'truoc', 'before', 'after', 'while', 'until', 'tren', 'cho', 'khong', 'not', 'and', 'or', 'anything', 'yet', 'this', 'that', 'today', 'packages', 'everything', 'nothing', 'something', 'it', 'them']);
379
+ function authorizedSubjects(promptText) {
380
+ const out = new Set();
381
+ const raw = String(promptText).normalize('NFC').replace(/đ/g, 'd').replace(/Đ/g, 'D').normalize('NFD').replace(/[̀-ͯ]/g, '');
382
+ for (const item of raw.split(/[;\n,]|\.\s+/)) {
383
+ if (PUBLISH_ORDER_NEGATOR.test(item.toLowerCase())) continue;
384
+ for (const m of item.matchAll(/\b(?:[Tt]rien khai|[Dd]eploy|[Rr]edeploy|[Rr]elease|[Pp]hat hanh|[Pp]ublish)\s+(?:the\s+)?([A-Z][A-Za-z0-9_-]{2,})/g)) {
385
+ const name = m[1].toLowerCase();
386
+ if (!NAME_STOP.has(name)) out.add(name);
387
+ }
388
+ }
389
+ return out;
390
+ }
391
+ // Returns null (fail closed: a direct in-scope prohibition) or a non-prohibiting verdict.
392
+ function properNames(promptText) {
393
+ const raw = String(promptText).normalize('NFC').replace(/đ/g, 'd').replace(/Đ/g, 'D').normalize('NFD').replace(/[̀-ͯ]/g, '');
394
+ const out = new Set();
395
+ for (const m of raw.matchAll(/(?<=[^\s.!?;:\n*#>\-\d)][ \t]+)([A-Z][A-Za-z0-9_-]{2,})\b/g)) out.add(m[1].toLowerCase());
396
+ return out;
397
+ }
398
+ const GATE_LEAD = /\b(?:bi bao|bao rang|reports?|reported|says?|said|shows?|showed|message|thong bao|log|logs|gate|gates|hook|hooks)\b/;
399
+ function classifyProhibitionItem(item, authorized, proper) {
400
+ const strongGate = /\b(?:prohibits? publication|publication blocked|ukit completion gate)\b/.test(item);
401
+ const quotedGate = GATE_QUOTE.test(item) && (item.includes('`') || GATE_LEAD.test(item)) && (strongGate || GATE_ANCHOR.test(item));
402
+ if (quotedGate) return { scope: 'quoted', conditional: false };
403
+ if (CONTINUATION_NEGATION.test(item)) {
404
+ // A continuation clause only neutralises itself; a publish ban in a sibling clause survives.
405
+ const rest = item.split(/\s*(?:,|\bva\b|\band\b)\s*/).filter((part) => !CONTINUATION_NEGATION.test(part)).join(' ');
406
+ if (!(PUBLISH_ORDER_NEGATOR.test(rest) && /\b(?:release|publish|publication|deploy)\b/.test(rest))) return { scope: 'continuation', conditional: false };
407
+ item = rest;
408
+ }
409
+ const neg = PUBLISH_ORDER_NEGATOR.exec(item);
410
+ const lead = CONDITION_LEAD.exec(item);
411
+ if (neg && lead && lead.index < neg.index) return { scope: 'workspace', conditional: true };
412
+ if (PURPOSE_SCOPE.test(item) || /\b(?:truoc khi|cho den khi|cho toi khi|until|before|while)\b/.test(item)) return { scope: 'workspace', conditional: true };
413
+ const target = item.match(/\b(?:npm\s+publish|publish|release|deploy|redeploy|trien khai|phat hanh)\s+(?:the\s+)?([a-z][a-z0-9_-]{2,})\b/)?.[1];
414
+ if (target && !NAME_STOP.has(target) && authorized.size && !authorized.has(target) && proper.has(target)) return { scope: 'other', conditional: false };
415
+ return null;
416
+ }
417
+
370
418
  function publicationScope(promptText = '') {
371
419
  const plain = String(promptText).normalize('NFC')
372
420
  .replace(/\bdùng\b/giu, 'su dung').replace(/đừng/giu, 'khong')
@@ -432,7 +480,9 @@ function publicationScope(promptText = '') {
432
480
  lines.push(line);
433
481
  }
434
482
  const text = lines.join('\n');
435
- let prohibited = false;
483
+ const authorized = authorizedSubjects(promptText);
484
+ const proper = properNames(promptText);
485
+ const prohibitions = [];
436
486
  let prohibitionBlock = false;
437
487
  for (const line of text.split('\n')) {
438
488
  if (!line.trim()) continue;
@@ -448,11 +498,18 @@ function publicationScope(promptText = '') {
448
498
  || /\b(?:publish|publication|release)\b[^,]*\b(?:must not|not yet)\b[^,]*\b(?:until|before|while)\b/.test(item)) continue;
449
499
  if (PUBLISH_ORDER_NEGATOR.test(item)) negated = true;
450
500
  else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
451
- if (negated && /\b(?:release|publish|publication)\b/.test(item)) prohibited = true;
501
+ const revoked = REVOCATION_ITEM.test(item);
502
+ if (!revoked && !(negated && (/\b(?:release|publish|publication)\b/.test(item) || DIRECT_DEPLOY_BAN.test(item)))) continue;
503
+ let verdict = revoked ? null : classifyProhibitionItem(item, authorized, proper);
504
+ if (!verdict && !revoked && !/\b(?:release|publish|publication)\b/.test(item)) verdict = { scope: 'deploy', conditional: false };
505
+ if (prohibitions.length < 20) prohibitions.push({ span: item.slice(0, 160), line: line.trim().slice(0, 160), ...(verdict || { scope: 'workspace', conditional: false }) });
452
506
  }
453
507
  }
454
508
  }
455
- return { text, prohibited };
509
+ // A deploy-only ban does not prohibit an ordered npm publication; it stands only when no publication is ordered.
510
+ const prohibited = prohibitions.some((entry) => entry.scope === 'workspace' && !entry.conditional)
511
+ || (prohibitions.some((entry) => entry.scope === 'deploy') && !ordersPublicationFromText(text));
512
+ return { text, prohibited, prohibitions };
456
513
  }
457
514
 
458
515
  function ordersPublication(promptText = '') {
@@ -460,7 +517,11 @@ function ordersPublication(promptText = '') {
460
517
  }
461
518
 
462
519
  function ordersPublicationText(promptText = '') {
463
- let active = collapseInspectionSentences(publicationScope(promptText).text).replace(/```[^]*?```|~~~[^]*?~~~/g, '')
520
+ return ordersPublicationFromText(publicationScope(promptText).text);
521
+ }
522
+
523
+ function ordersPublicationFromText(scopedText = '') {
524
+ let active = collapseInspectionSentences(scopedText).replace(/```[^]*?```|~~~[^]*?~~~/g, '')
464
525
  .replace(/^[ \t]*>.*$/gm, '').replace(/[“"][^”"\n]*[”"]|‘[^’\n]*’/g, '');
465
526
  for (const branch of defectRepairBranches(active)) active = active.replace(branch, '');
466
527
  let ordered = false;
@@ -478,7 +539,7 @@ function ordersPublicationText(promptText = '') {
478
539
  else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
479
540
  const commandItem = item.replace(/^(?:please|just|now|also|then)\s+/, '');
480
541
  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);
481
- 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);
542
+ 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|history\b|line\b|receipts?\b|lich\s+su\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);
482
543
  const politeItem = item.replace(/^(?:(?:please|just|now|also|then|vui long|hay)\s+)+/, '');
483
544
  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)
484
545
  || /^(?:(?:sua|kiem thu|hoan tat)\b[^.;\n]*\b(?:va|roi)\s+|(?:va|roi)\s+)(?:phat hanh|xuat ban)\s+npm\b/.test(politeItem);
@@ -493,8 +554,16 @@ function ordersPublicationText(promptText = '') {
493
554
  return ordered;
494
555
  }
495
556
 
496
- 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']);
497
- function nativeOperationGoal(domain, actionable, text) {
557
+ 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', 'artifact', 'artifacts', 'image', 'images', 'build', 'qua', 'via', 'through', 'bang', 'tu', 'from', 'voi', 'with', 'toi', 'da', 'nhung', 'moi', 'khac',
558
+ // Vietnamese function words typed without diacritics ("restart rieng X", "trien khai phu hop", "kiem chung").
559
+ 'phu', 'hop', 'rieng', 'kiem', 'chung', 'tra', 'chinh', 'cac', 'mot', 'cua', 'cho', 'de', 'va', 'roi', 'sau', 'duoc', 'theo', 'ngay', 'luon', 'xong', 'het', 'ca', 'thu', 'that', 'dung', 'cung', 'nay', 'do', 'lan', 'tiep', 'thanh', 'cong', 'ban', 'bao', 'gom']);
560
+ // A required service target must be a name the owner actually typed: a word whose diacritics were stripped
561
+ // ("phù" -> "phu", "riêng" -> "rieng") is prose, not a service no native command could ever name.
562
+ function typedToken(name, rawPrompt) {
563
+ if (typeof rawPrompt !== 'string' || !rawPrompt) return true;
564
+ return rawPrompt.toLowerCase().split(/[^\p{L}\p{N}_.-]+/u).some((token) => token === name || token.replace(/[.,:;]+$/, '') === name);
565
+ }
566
+ function nativeOperationGoal(domain, actionable, text, rawPrompt = '') {
498
567
  const goal = { domain, target: null, desiredState: 'verified', completionSemantics: 'execute-and-verify', requiredTargets: [] };
499
568
  const clauses = actionable.join(' . ');
500
569
  if (domain === 'git-integrity') {
@@ -510,9 +579,31 @@ function nativeOperationGoal(domain, actionable, text) {
510
579
  return goal;
511
580
  }
512
581
  const services = [...clauses.matchAll(/\b(?:restart|redeploy|deploy|khoi dong lai|trien khai)\s+(?:the\s+|lai\s+)?([a-z0-9][\w.-]*)/g)]
513
- .map((m) => m[1]).filter((name) => !NOT_A_SERVICE.has(name));
582
+ .map((m) => m[1]).filter((name) => !NOT_A_SERVICE.has(name) && !/^\d+(?:\.\d+)+/.test(name) && !/^[a-z0-9_-]+\.[a-z]{1,5}$/.test(name)
583
+ && name.length >= 2 && typedToken(name, rawPrompt));
514
584
  goal.requiredTargets = [...new Set(services)];
515
- const probePath = text.match(/(?:^|\s)(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/)?.[1] || null;
585
+ const deployScript = clauses.match(/\b(?:via|qua|through|bang)\s+(?:the\s+)?(?:\.\/|[\w./-]*\/)?([\w-]+\.sh)\b/)?.[1] || clauses.match(/(?:^|\s)(?:\.\/|[\w./-]*\/)?([\w-]+\.sh)\s+--deploy/)?.[1] || null;
586
+ // The owner-named deploy script is the single native mutation; project/service words around it are its
587
+ // subject, not separate commands, so they must not become targets no script invocation can ever name.
588
+ if (deployScript) {
589
+ goal.deployCommand = deployScript.slice(0, 64);
590
+ // Drop only the script's own subject: the name right after deploy/trien khai that sits before "via <script>".
591
+ const subject = clauses.match(/\b(?:redeploy|deploy|trien khai)\s+(?:the\s+)?([a-z0-9][\w.-]*)(?:\s+(?:production|prod|staging|artifact|image))*\s+(?:via|qua|through|bang)\s+(?:the\s+)?(?:\.\/|[\w./-]*\/)?[\w-]+\.sh\b/)?.[1];
592
+ goal.requiredTargets = goal.requiredTargets.filter((name) => name !== subject && !/^(?:production|prod|staging)$/.test(name));
593
+ }
594
+ const FS_PATH = /^\/(?:tmp|private|var|users|volumes|home|opt|etc)\b|\.[a-z0-9]{1,5}$/;
595
+ const urlPath = text.match(/\bhttps?:\/\/[^\s/]+(\/[a-z0-9_.\/-]*)/)?.[1];
596
+ const ctxPath = text.match(/\b(?:curl|get|endpoint|health|url)\b[^\n/]{0,20}\s(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/)?.[1];
597
+ // A bare absolute path names the probe only next to a probe word ("verify /v1/models returns 200"); a path in a
598
+ // filesystem context (backup dir, "nam o", folder) never does. Trailing sentence punctuation is not part of it.
599
+ const PROBE_WORD = /\b(?:curl|get|endpoint|health|url|returns?|http|status)\b/;
600
+ const FS_CONTEXT = /\b(?:backups?|nam o|located|thu muc|directory|folder|duoi|under)\b/;
601
+ const barePaths = [...text.matchAll(/(?:^|\s)(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/g)].filter((m) => {
602
+ const near = text.slice(Math.max(0, m.index - 40), m.index + m[0].length + 40);
603
+ return PROBE_WORD.test(near) && !FS_CONTEXT.test(near);
604
+ }).map((m) => m[1]);
605
+ const probePath = [urlPath, ctxPath, ...barePaths].map((candidate) => candidate?.replace(/[.,;:]+$/, ''))
606
+ .find((candidate) => candidate && !FS_PATH.test(candidate) && !FS_CONTEXT.test(candidate)) || null;
516
607
  const probeStatus = text.match(/\b(?:returns?|returning|responds?(?:\s+with)?|http|status(?:\s+code)?)\s+([1-5]\d\d)\b/)?.[1] || null;
517
608
  if (probePath || probeStatus) goal.probe = { path: probePath, status: probeStatus };
518
609
  return goal;
@@ -752,6 +843,10 @@ function classifySemanticText(input = {}) {
752
843
  return { ...rest, stateVerification: true, ...(shape.action ? { stateAction: true } : shape.conditional ? { stateConditionalStop: true } : {}), ...(shape.targets.length ? { stateTargets: shape.targets } : {}) };
753
844
  }
754
845
 
846
+ // Clauses that order a plain change keep a git+deploy prompt a code task; history/receipt bookkeeping does not.
847
+ const PLAIN_CHANGE_VERB = /\b(?:add|change|remove|delete|bump|rename|update|fix(?:es)?|edit|modify|implement|refactor|create|write|replace|set|toggle|enable|disable|upgrade|install|them|bo sung|xoa|(?<!thay )doi(?!\s+chieu)|sua|tao|viet|chinh|cap nhat)\b/;
848
+ const HISTORY_OBJECT = /\b(?:release(?:\s+history)?|lich su release|receipts?|worklog|ledger|status)\b/;
849
+ const AUTH_EXCLUSION = /\b(?:khong cap phep|not authori[sz]e\w*|does not authori[sz]e|khong duoc phep)\b[^.]*\./g;
755
850
  function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
756
851
  promptText = publicationScope(promptText).text;
757
852
  const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
@@ -802,11 +897,23 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
802
897
  }
803
898
  return total > 0 && banned === total;
804
899
  };
805
- const gitOperation = actionable.some((clause) => !operationNotOrdered(clause)
806
- && (GIT_ORDER_LEAD.test(clause) || /\bgit\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)\b|\bpush\s+(?:to\s+)?origin\b/.test(clause)));
807
- const runtimeOperation = actionable.some((clause) => !operationNotOrdered(clause) && /(?<!\b(?:process|crash|hard|soft|graceful|after|upon|during|across|following)\s)\b(?:restart|redeploy|deploy|khoi dong lai|trien khai\s+(?:len\s+)?(?:service|server|production|prod|staging|dich vu|may chu|moi truong))\b/.test(clause)
808
- && !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause));
809
- const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime') : null;
900
+ // A status/report wrap-up ("check X and Y results; then docs, commit, report") lists a bare `commit` as
901
+ // bookkeeping next to the report it closes; it is not an ordered history operation with a remote proof.
902
+ const statusWrapUp = /^[\s*+•>\d.)-]*(?:(?:please|hay|vui long)\s+)*(?:check|status|report|show|summari[sz]e|kiem tra|bao cao)\b/.test(actionable[0] || '')
903
+ && actionable.some((clause) => /^[\s*+•>\d.)-]*(?:report|bao cao)\s*$/.test(clause));
904
+ const runtimeClause = (clause) => !operationNotOrdered(clause) && /(?<!\b(?:process|crash|hard|soft|graceful|after|upon|during|across|following)\s)\b(?:restart|redeploy|deploy|khoi dong lai|trien khai\s+(?:len\s+)?(?:service|server|production|prod|staging|dich vu|may chu|moi truong))\b/.test(clause)
905
+ && !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause);
906
+ const runtimeOperation = actionable.some(runtimeClause);
907
+ // Only a PURE status wrap-up drops its bare commit; one that also orders a deploy keeps the git goal.
908
+ const bookkeepingCommit = (clause) => statusWrapUp && !runtimeOperation && /^[\s*+•>\d.)-]*commit\s*$/.test(clause);
909
+ const gitClause = (clause) => !operationNotOrdered(clause) && !bookkeepingCommit(clause)
910
+ && (GIT_ORDER_LEAD.test(clause) || /\bgit\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)\b|\bpush\s+(?:to\s+)?origin\b/.test(clause));
911
+ const gitOperation = actionable.some(gitClause);
912
+ // Commit/push AND a deploy with no source-change order are TWO independent native obligations: each keeps
913
+ // its own proof (git remote parity; deploy receipt + live check). Neither is folded into the other, and
914
+ // owner authorization wording never drops one of them.
915
+ const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime')
916
+ : gitOperation && runtimeOperation && !sourceOrder && !codeChangeVerb && actionable.every((clause) => !PLAIN_CHANGE_VERB.test(clause) || /^[\s*+•>\d.)-]*(?:chay|run|verify|kiem tra|check)\b/.test(clause) || (clause.length > 3 && (releaseText.match(AUTH_EXCLUSION) || []).some((span) => span.includes(clause))) || HISTORY_OBJECT.test(clause)) ? 'multi' : null;
810
917
  const operation = Boolean(nativeDomain);
811
918
  if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', ...(bansTestRuns(promptText) ? {} : { verificationOnly: true }) };
812
919
  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/;
@@ -840,8 +947,13 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
840
947
  const taskKind = operation ? (sourceOrder || codeChangeVerb ? 'MIXED' : 'OPERATIONAL')
841
948
  : config ? 'CONFIGURATION' : documentation ? 'DOCUMENTATION_OUTPUT' : readOnly ? 'READ_ONLY' : 'CODE_IMPLEMENTATION';
842
949
  const id = text.match(/\b[a-f0-9]{8}(?:[a-f0-9-]{0,28})\b/)?.[0] || null;
950
+ // Multi-operation: the goal ordered first is the primary `operationGoal`; `operationGoals` carries all of them.
951
+ const operationGoals = nativeDomain === 'multi'
952
+ ? (actionable.findIndex(gitClause) <= actionable.findIndex(runtimeClause) ? ['git-integrity', 'service-runtime'] : ['service-runtime', 'git-integrity'])
953
+ .map((domain) => nativeOperationGoal(domain, actionable, text, promptText)) : null;
843
954
  return { taskKind, ...(releasePolicy ? { releasePolicy } : {}), ...(documentation ? { reportArtifact } : {}), ...(taskKind === 'READ_ONLY' && statusReport ? { statusReport: true } : {}), ...(config ? { configurationScope: repository ? 'repository' : 'external' } : {}),
844
- ...(operation && nativeDomain !== 'scheduled-job' ? { operationGoal: nativeOperationGoal(nativeDomain, actionable, text) } : {}),
955
+ ...(operationGoals ? { operationGoal: operationGoals[0], operationGoals } : {}),
956
+ ...(operation && !operationGoals && nativeDomain !== 'scheduled-job' ? { operationGoal: nativeOperationGoal(nativeDomain, actionable, text, promptText) } : {}),
845
957
  ...(operation && nativeDomain === 'scheduled-job' ? { operationGoal: { domain: 'scheduled-job', target: id, desiredState: /\b(?:delete|remove|cancel|xoa|huy|absent|removed|deleted|no longer|khong con)\b/.test(actionable.join(' ')) ? 'absent' : 'present',
846
958
  completionSemantics: /\b(?:ensure|dam bao)\b/.test(text)
847
959
  || actionable.some((clause) => /\b(?:delete|remove|cancel|xoa|huy)\b/.test(clause)
@@ -4296,6 +4408,7 @@ function applyTaskSemantics(contract, semantic) {
4296
4408
  // The task identity is minted on a fresh owner prompt and retained only on
4297
4409
  // the router's continuation lineage. It is also the route generation.
4298
4410
  persisted.routeGeneration = taskInstanceId;
4411
+ if (predecessorLink) persisted.predecessor = predecessorLink; else delete persisted.predecessor;
4299
4412
  // Bounded audit metadata (short strings, additive): where this turn's task id and
4300
4413
  // contract came from — 'system' marks a synthetic continuation that resumed the
4301
4414
  // previous task instead of minting a fresh one. No consumer branches on these yet.
@@ -4629,6 +4742,43 @@ function applyTaskSemantics(contract, semantic) {
4629
4742
  peerDeliveryIds.add(at.delivery_id);
4630
4743
  }
4631
4744
  }
4745
+ // A /loop fire queued behind a busy turn is delivered only when that turn ends, so its
4746
+ // scheduled_task_fire record can sit behind the busy turn's assistant entries and beyond the
4747
+ // 128KB tail (BAGuide/UKit incident: 177KB, 7 minutes). Such a fire is still provenance while
4748
+ // it is UNCONSUMED: the host writes the meta user entry carrying scheduledFireId only after this
4749
+ // hook runs, so a fire whose id no later entry references has not been delivered yet. Same
4750
+ // session, same prompt-match rule as the current-turn path, bounded scan and age.
4751
+ const fireMatches = (entry) => {
4752
+ if (!(entry?.type === 'system' && entry.subtype === 'scheduled_task_fire' && sessionId && entry.sessionId === sessionId
4753
+ && typeof entry.taskId === 'string' && entry.taskId.trim() && typeof entry.prompt === 'string')) return false;
4754
+ const fired = entry.prompt.trim();
4755
+ const firedBase = fired.replace(/(?:\u2026|\.{3})+$/, '').trim();
4756
+ // Prefix match only for a CLIPPED fire (ellipsis, or at the host's ~200-char clip, which real fires
4757
+ // reach without an ellipsis); an unclipped fire plus owner-appended text is an owner prompt.
4758
+ const clipped = firedBase !== fired || entry.prompt.length >= 190;
4759
+ return Boolean(fired && (fired === promptTrim || (clipped && firedBase.length >= 40 && promptTrim.startsWith(firedBase))));
4760
+ };
4761
+ {
4762
+ const wideLen = Math.min(size, 8 * 1024 * 1024);
4763
+ const wide = wideLen > len ? Buffer.alloc(wideLen) : buf;
4764
+ if (wide !== buf) fs.readSync(fd, wide, 0, wideLen, size - wideLen);
4765
+ const consumedFireIds = new Set();
4766
+ let pendingFire = null;
4767
+ for (const l of wide.toString('utf8').split('\n')) {
4768
+ if (!l || !(l.includes('scheduled_task_fire') || l.includes('scheduledFireId'))) continue;
4769
+ let e; try { e = JSON.parse(l); } catch { continue; }
4770
+ if (typeof e?.scheduledFireId === 'string') consumedFireIds.add(e.scheduledFireId);
4771
+ if (fireMatches(e) && typeof e.uuid === 'string') pendingFire = e;
4772
+ }
4773
+ const fireAge = pendingFire ? Date.now() - Date.parse(pendingFire.timestamp || '') : NaN;
4774
+ if (pendingFire && !consumedFireIds.has(pendingFire.uuid) && Number.isFinite(fireAge) && fireAge >= 0 && fireAge <= 6 * 60 * 60 * 1000) {
4775
+ if (classifyTaskSemantics({ promptText: promptTrim }).taskKind === 'READ_ONLY') {
4776
+ coordinationTurn = true;
4777
+ return false;
4778
+ }
4779
+ return true;
4780
+ }
4781
+ }
4632
4782
  let deliveryCurrent = true;
4633
4783
  for (let i = lines.length - 1; i >= 0; i -= 1) {
4634
4784
  const line = lines[i];
@@ -4650,6 +4800,17 @@ function applyTaskSemantics(contract, semantic) {
4650
4800
  coordinationTurn = true;
4651
4801
  return false;
4652
4802
  }
4803
+ // Host-authored wakeup provenance that exists at hook time: the scheduled_task_fire system
4804
+ // entry (the meta user entry is written only AFTER this hook runs). Same session, a task id,
4805
+ // the current turn, and the prompt equal to - or a >=40 char truncated prefix of (the /loop
4806
+ // fire record clips to ~200 chars) - the typed prompt. A human typing the text leaves no fire.
4807
+ if (deliveryCurrent && fireMatches(entry)) {
4808
+ if (classifyTaskSemantics({ promptText: promptTrim }).taskKind === 'READ_ONLY') {
4809
+ coordinationTurn = true;
4810
+ return false;
4811
+ }
4812
+ return true;
4813
+ }
4653
4814
  if (entry.type !== 'user' || entry.isSidechain === true) continue;
4654
4815
  const content = entry.message?.content;
4655
4816
  const text = (typeof content === 'string' ? content
@@ -4844,6 +5005,18 @@ function applyTaskSemantics(contract, semantic) {
4844
5005
  return wanted.size > 0 && [...wanted].every((target) => owned.has(target));
4845
5006
  })();
4846
5007
  const continuingTask = Boolean(previous.taskInstanceId && (payload.tool_name || handoffExpansion || continuationPrompt || ownerResumeTurn || systemOriginTurn || guidanceTurn));
5008
+ // An owner prompt that explicitly resumes the previous checkpoint (names its background job id or commit)
5009
+ // still mints a fresh task id - the contract may legitimately differ (e.g. a new deploy authorization) -
5010
+ // but records a bounded single-hop predecessor link so the ledger can reconcile current evidence. A
5011
+ // genuinely new task has no such reference and gets no link.
5012
+ let predecessorLink = null;
5013
+ if (!continuingTask && sessionId && previous.taskInstanceId && String(previous.sessionId || '') === sessionId
5014
+ && !payload.tool_name && promptOrigin !== 'system' && previous.ownerControl?.kind !== 'stop') {
5015
+ try {
5016
+ const ledgerRuntime = await import(pathToFileURL(path.join(projectRoot, '.claude', 'ukit', 'runtime', 'execution-ledger.mjs')).href);
5017
+ predecessorLink = await ledgerRuntime.checkpointPredecessorLink(projectRoot, payload, extractPrompt(payload), previous);
5018
+ } catch { predecessorLink = null; }
5019
+ }
4847
5020
  let taskInstanceId = continuingTask
4848
5021
  ? previous.taskInstanceId
4849
5022
  : `task-${crypto.randomBytes(16).toString("hex")}`;
@@ -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:d54a8c14f321c1eeba4832e4461cd6d0c2231b2f7a80932ac3129f1e8dd792f9';
3
+ export const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:a489851b01e95788d8a3e0a080b80c04d8161c734b6c0ed5c9758a765f5bc0a4';
4
4
 
5
5
  export function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
6
6
  return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
@@ -8,7 +8,7 @@ export function semanticContractIdentity({ promptText = '', targetFile = '', tas
8
8
  }
9
9
 
10
10
  const semanticContractShape = (contract) => JSON.stringify([
11
- contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null,
11
+ contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null, contract?.operationGoals ?? null,
12
12
  contract?.configurationScope ?? null, contract?.releasePolicy ?? null, contract?.conditionalObligations ?? null,
13
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(),
@@ -152,7 +152,7 @@ const CONDITIONAL_RUNTIME_VERB = /\b(?:redeploy|deploy|restart|khoi dong lai|tri
152
152
  const CONDITIONAL_RUNTIME_EXCLUDED = /\b(?:publish|phat hanh|commit|push|tag|git|implement|fix|edit|modify|sua)\b/;
153
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
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}`);
155
+ const PAST_RELEASE_ITEM = new RegExp(`^(?:(?:please|just|now|also)\\s+)*(?:${PAST_RELEASE_SOURCE}|release(?:\\s+\\S+)?\\s+(?:(?:co the|may|might|could)\\b|da\\s+len\\b|(?:has|have)\\s+gone\\s+live\\b))`);
156
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/;
157
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/;
158
158
  const PUBLISH_ORDER_HEADER = /prohibit|forbidden|out of scope|non-goal|scope control/;
@@ -164,6 +164,54 @@ function defectRepairBranches(text) {
164
164
  && /\b(?:sua|fix|repair)\b/.test(branch));
165
165
  }
166
166
 
167
+ const REVOCATION_ITEM = /\b(?:thu hoi|revoke\w*|rescind\w*|withdraw\w*)\b[^.;\n]*\b(?:deploy|redeploy|publish|publication|release|trien khai|phat hanh)\b/;
168
+ // deploy words prohibit only as a direct ban ("do not deploy"), never as an object inside other prose.
169
+ const DIRECT_DEPLOY_BAN = /^(?:(?:please|hay|vui long)\s+)*(?:do not|don't|dont|never|khong|must not)\s+(?:npm\s+)?(?:re-?deploy|deploy|trien khai)\b/;
170
+ const GATE_QUOTE = /\b(?:prohibits? publication|publication blocked|ukit completion gate|ukit publication)\b|\b(?:bi bao|bao rang|reports?|reported|says?|said|message|thong bao)\b[^.;\n]*\b(?:prohibit\w*|blocked|chan|cam)\b/;
171
+ const GATE_ANCHOR = /\b(?:ukit|gates?|hooks?|logs?)\b|`/;
172
+ const CONTINUATION_NEGATION = /\b(?:do not|don't|dont|never|khong|chua)\s+(?:\w+\s+){0,2}?(?:dung|stop|end|finish|halt|ngung|ket thuc|quit|exit)\b/;
173
+ const PURPOSE_SCOPE = /\b(?:chi de|only to|just to|only for)\b/;
174
+ const CONDITION_LEAD = /\b(?:neu|if|khi|unless|in case|truong hop)\b/;
175
+ const NAME_STOP = new Set(['the', 'a', 'an', 'to', 'on', 'npm', 'if', 'khi', 'neu', 'again', 'now', 'production', 'prod', 'staging', 'artifact', 'image', 'build', 'candidate', 'lai', 'len', 'vao', 'nua', 'qua', 'via', 'tu', 'from', 'with', 'voi', 'any', 'moi', 'khac', 'other', 'another', 'nay', 'package', 'version', 'release', 'publish', 'sau', 'truoc', 'before', 'after', 'while', 'until', 'tren', 'cho', 'khong', 'not', 'and', 'or', 'anything', 'yet', 'this', 'that', 'today', 'packages', 'everything', 'nothing', 'something', 'it', 'them']);
176
+ function authorizedSubjects(promptText) {
177
+ const out = new Set();
178
+ const raw = String(promptText).normalize('NFC').replace(/đ/g, 'd').replace(/Đ/g, 'D').normalize('NFD').replace(/[̀-ͯ]/g, '');
179
+ for (const item of raw.split(/[;\n,]|\.\s+/)) {
180
+ if (PUBLISH_ORDER_NEGATOR.test(item.toLowerCase())) continue;
181
+ for (const m of item.matchAll(/\b(?:[Tt]rien khai|[Dd]eploy|[Rr]edeploy|[Rr]elease|[Pp]hat hanh|[Pp]ublish)\s+(?:the\s+)?([A-Z][A-Za-z0-9_-]{2,})/g)) {
182
+ const name = m[1].toLowerCase();
183
+ if (!NAME_STOP.has(name)) out.add(name);
184
+ }
185
+ }
186
+ return out;
187
+ }
188
+ // Returns null (fail closed: a direct in-scope prohibition) or a non-prohibiting verdict.
189
+ function properNames(promptText) {
190
+ const raw = String(promptText).normalize('NFC').replace(/đ/g, 'd').replace(/Đ/g, 'D').normalize('NFD').replace(/[̀-ͯ]/g, '');
191
+ const out = new Set();
192
+ for (const m of raw.matchAll(/(?<=[^\s.!?;:\n*#>\-\d)][ \t]+)([A-Z][A-Za-z0-9_-]{2,})\b/g)) out.add(m[1].toLowerCase());
193
+ return out;
194
+ }
195
+ const GATE_LEAD = /\b(?:bi bao|bao rang|reports?|reported|says?|said|shows?|showed|message|thong bao|log|logs|gate|gates|hook|hooks)\b/;
196
+ function classifyProhibitionItem(item, authorized, proper) {
197
+ const strongGate = /\b(?:prohibits? publication|publication blocked|ukit completion gate)\b/.test(item);
198
+ const quotedGate = GATE_QUOTE.test(item) && (item.includes('`') || GATE_LEAD.test(item)) && (strongGate || GATE_ANCHOR.test(item));
199
+ if (quotedGate) return { scope: 'quoted', conditional: false };
200
+ if (CONTINUATION_NEGATION.test(item)) {
201
+ // A continuation clause only neutralises itself; a publish ban in a sibling clause survives.
202
+ const rest = item.split(/\s*(?:,|\bva\b|\band\b)\s*/).filter((part) => !CONTINUATION_NEGATION.test(part)).join(' ');
203
+ if (!(PUBLISH_ORDER_NEGATOR.test(rest) && /\b(?:release|publish|publication|deploy)\b/.test(rest))) return { scope: 'continuation', conditional: false };
204
+ item = rest;
205
+ }
206
+ const neg = PUBLISH_ORDER_NEGATOR.exec(item);
207
+ const lead = CONDITION_LEAD.exec(item);
208
+ if (neg && lead && lead.index < neg.index) return { scope: 'workspace', conditional: true };
209
+ if (PURPOSE_SCOPE.test(item) || /\b(?:truoc khi|cho den khi|cho toi khi|until|before|while)\b/.test(item)) return { scope: 'workspace', conditional: true };
210
+ const target = item.match(/\b(?:npm\s+publish|publish|release|deploy|redeploy|trien khai|phat hanh)\s+(?:the\s+)?([a-z][a-z0-9_-]{2,})\b/)?.[1];
211
+ if (target && !NAME_STOP.has(target) && authorized.size && !authorized.has(target) && proper.has(target)) return { scope: 'other', conditional: false };
212
+ return null;
213
+ }
214
+
167
215
  export function publicationScope(promptText = '') {
168
216
  const plain = String(promptText).normalize('NFC')
169
217
  .replace(/\bdùng\b/giu, 'su dung').replace(/đừng/giu, 'khong')
@@ -229,7 +277,9 @@ export function publicationScope(promptText = '') {
229
277
  lines.push(line);
230
278
  }
231
279
  const text = lines.join('\n');
232
- let prohibited = false;
280
+ const authorized = authorizedSubjects(promptText);
281
+ const proper = properNames(promptText);
282
+ const prohibitions = [];
233
283
  let prohibitionBlock = false;
234
284
  for (const line of text.split('\n')) {
235
285
  if (!line.trim()) continue;
@@ -245,11 +295,18 @@ export function publicationScope(promptText = '') {
245
295
  || /\b(?:publish|publication|release)\b[^,]*\b(?:must not|not yet)\b[^,]*\b(?:until|before|while)\b/.test(item)) continue;
246
296
  if (PUBLISH_ORDER_NEGATOR.test(item)) negated = true;
247
297
  else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
248
- if (negated && /\b(?:release|publish|publication)\b/.test(item)) prohibited = true;
298
+ const revoked = REVOCATION_ITEM.test(item);
299
+ if (!revoked && !(negated && (/\b(?:release|publish|publication)\b/.test(item) || DIRECT_DEPLOY_BAN.test(item)))) continue;
300
+ let verdict = revoked ? null : classifyProhibitionItem(item, authorized, proper);
301
+ if (!verdict && !revoked && !/\b(?:release|publish|publication)\b/.test(item)) verdict = { scope: 'deploy', conditional: false };
302
+ if (prohibitions.length < 20) prohibitions.push({ span: item.slice(0, 160), line: line.trim().slice(0, 160), ...(verdict || { scope: 'workspace', conditional: false }) });
249
303
  }
250
304
  }
251
305
  }
252
- return { text, prohibited };
306
+ // A deploy-only ban does not prohibit an ordered npm publication; it stands only when no publication is ordered.
307
+ const prohibited = prohibitions.some((entry) => entry.scope === 'workspace' && !entry.conditional)
308
+ || (prohibitions.some((entry) => entry.scope === 'deploy') && !ordersPublicationFromText(text));
309
+ return { text, prohibited, prohibitions };
253
310
  }
254
311
 
255
312
  export function ordersPublication(promptText = '') {
@@ -257,7 +314,11 @@ export function ordersPublication(promptText = '') {
257
314
  }
258
315
 
259
316
  function ordersPublicationText(promptText = '') {
260
- let active = collapseInspectionSentences(publicationScope(promptText).text).replace(/```[^]*?```|~~~[^]*?~~~/g, '')
317
+ return ordersPublicationFromText(publicationScope(promptText).text);
318
+ }
319
+
320
+ function ordersPublicationFromText(scopedText = '') {
321
+ let active = collapseInspectionSentences(scopedText).replace(/```[^]*?```|~~~[^]*?~~~/g, '')
261
322
  .replace(/^[ \t]*>.*$/gm, '').replace(/[“"][^”"\n]*[”"]|‘[^’\n]*’/g, '');
262
323
  for (const branch of defectRepairBranches(active)) active = active.replace(branch, '');
263
324
  let ordered = false;
@@ -275,7 +336,7 @@ function ordersPublicationText(promptText = '') {
275
336
  else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
276
337
  const commandItem = item.replace(/^(?:please|just|now|also|then)\s+/, '');
277
338
  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);
339
+ 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|history\b|line\b|receipts?\b|lich\s+su\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);
279
340
  const politeItem = item.replace(/^(?:(?:please|just|now|also|then|vui long|hay)\s+)+/, '');
280
341
  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
342
  || /^(?:(?:sua|kiem thu|hoan tat)\b[^.;\n]*\b(?:va|roi)\s+|(?:va|roi)\s+)(?:phat hanh|xuat ban)\s+npm\b/.test(politeItem);
@@ -290,8 +351,16 @@ function ordersPublicationText(promptText = '') {
290
351
  return ordered;
291
352
  }
292
353
 
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']);
294
- function nativeOperationGoal(domain, actionable, text) {
354
+ 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', 'artifact', 'artifacts', 'image', 'images', 'build', 'qua', 'via', 'through', 'bang', 'tu', 'from', 'voi', 'with', 'toi', 'da', 'nhung', 'moi', 'khac',
355
+ // Vietnamese function words typed without diacritics ("restart rieng X", "trien khai phu hop", "kiem chung").
356
+ 'phu', 'hop', 'rieng', 'kiem', 'chung', 'tra', 'chinh', 'cac', 'mot', 'cua', 'cho', 'de', 'va', 'roi', 'sau', 'duoc', 'theo', 'ngay', 'luon', 'xong', 'het', 'ca', 'thu', 'that', 'dung', 'cung', 'nay', 'do', 'lan', 'tiep', 'thanh', 'cong', 'ban', 'bao', 'gom']);
357
+ // A required service target must be a name the owner actually typed: a word whose diacritics were stripped
358
+ // ("phù" -> "phu", "riêng" -> "rieng") is prose, not a service no native command could ever name.
359
+ function typedToken(name, rawPrompt) {
360
+ if (typeof rawPrompt !== 'string' || !rawPrompt) return true;
361
+ return rawPrompt.toLowerCase().split(/[^\p{L}\p{N}_.-]+/u).some((token) => token === name || token.replace(/[.,:;]+$/, '') === name);
362
+ }
363
+ function nativeOperationGoal(domain, actionable, text, rawPrompt = '') {
295
364
  const goal = { domain, target: null, desiredState: 'verified', completionSemantics: 'execute-and-verify', requiredTargets: [] };
296
365
  const clauses = actionable.join(' . ');
297
366
  if (domain === 'git-integrity') {
@@ -307,9 +376,31 @@ function nativeOperationGoal(domain, actionable, text) {
307
376
  return goal;
308
377
  }
309
378
  const services = [...clauses.matchAll(/\b(?:restart|redeploy|deploy|khoi dong lai|trien khai)\s+(?:the\s+|lai\s+)?([a-z0-9][\w.-]*)/g)]
310
- .map((m) => m[1]).filter((name) => !NOT_A_SERVICE.has(name));
379
+ .map((m) => m[1]).filter((name) => !NOT_A_SERVICE.has(name) && !/^\d+(?:\.\d+)+/.test(name) && !/^[a-z0-9_-]+\.[a-z]{1,5}$/.test(name)
380
+ && name.length >= 2 && typedToken(name, rawPrompt));
311
381
  goal.requiredTargets = [...new Set(services)];
312
- const probePath = text.match(/(?:^|\s)(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/)?.[1] || null;
382
+ const deployScript = clauses.match(/\b(?:via|qua|through|bang)\s+(?:the\s+)?(?:\.\/|[\w./-]*\/)?([\w-]+\.sh)\b/)?.[1] || clauses.match(/(?:^|\s)(?:\.\/|[\w./-]*\/)?([\w-]+\.sh)\s+--deploy/)?.[1] || null;
383
+ // The owner-named deploy script is the single native mutation; project/service words around it are its
384
+ // subject, not separate commands, so they must not become targets no script invocation can ever name.
385
+ if (deployScript) {
386
+ goal.deployCommand = deployScript.slice(0, 64);
387
+ // Drop only the script's own subject: the name right after deploy/trien khai that sits before "via <script>".
388
+ const subject = clauses.match(/\b(?:redeploy|deploy|trien khai)\s+(?:the\s+)?([a-z0-9][\w.-]*)(?:\s+(?:production|prod|staging|artifact|image))*\s+(?:via|qua|through|bang)\s+(?:the\s+)?(?:\.\/|[\w./-]*\/)?[\w-]+\.sh\b/)?.[1];
389
+ goal.requiredTargets = goal.requiredTargets.filter((name) => name !== subject && !/^(?:production|prod|staging)$/.test(name));
390
+ }
391
+ const FS_PATH = /^\/(?:tmp|private|var|users|volumes|home|opt|etc)\b|\.[a-z0-9]{1,5}$/;
392
+ const urlPath = text.match(/\bhttps?:\/\/[^\s/]+(\/[a-z0-9_.\/-]*)/)?.[1];
393
+ const ctxPath = text.match(/\b(?:curl|get|endpoint|health|url)\b[^\n/]{0,20}\s(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/)?.[1];
394
+ // A bare absolute path names the probe only next to a probe word ("verify /v1/models returns 200"); a path in a
395
+ // filesystem context (backup dir, "nam o", folder) never does. Trailing sentence punctuation is not part of it.
396
+ const PROBE_WORD = /\b(?:curl|get|endpoint|health|url|returns?|http|status)\b/;
397
+ const FS_CONTEXT = /\b(?:backups?|nam o|located|thu muc|directory|folder|duoi|under)\b/;
398
+ const barePaths = [...text.matchAll(/(?:^|\s)(\/[a-z0-9_.-]+(?:\/[a-z0-9_.-]+)*)/g)].filter((m) => {
399
+ const near = text.slice(Math.max(0, m.index - 40), m.index + m[0].length + 40);
400
+ return PROBE_WORD.test(near) && !FS_CONTEXT.test(near);
401
+ }).map((m) => m[1]);
402
+ const probePath = [urlPath, ctxPath, ...barePaths].map((candidate) => candidate?.replace(/[.,;:]+$/, ''))
403
+ .find((candidate) => candidate && !FS_PATH.test(candidate) && !FS_CONTEXT.test(candidate)) || null;
313
404
  const probeStatus = text.match(/\b(?:returns?|returning|responds?(?:\s+with)?|http|status(?:\s+code)?)\s+([1-5]\d\d)\b/)?.[1] || null;
314
405
  if (probePath || probeStatus) goal.probe = { path: probePath, status: probeStatus };
315
406
  return goal;
@@ -549,6 +640,10 @@ function classifySemanticText(input = {}) {
549
640
  return { ...rest, stateVerification: true, ...(shape.action ? { stateAction: true } : shape.conditional ? { stateConditionalStop: true } : {}), ...(shape.targets.length ? { stateTargets: shape.targets } : {}) };
550
641
  }
551
642
 
643
+ // Clauses that order a plain change keep a git+deploy prompt a code task; history/receipt bookkeeping does not.
644
+ const PLAIN_CHANGE_VERB = /\b(?:add|change|remove|delete|bump|rename|update|fix(?:es)?|edit|modify|implement|refactor|create|write|replace|set|toggle|enable|disable|upgrade|install|them|bo sung|xoa|(?<!thay )doi(?!\s+chieu)|sua|tao|viet|chinh|cap nhat)\b/;
645
+ const HISTORY_OBJECT = /\b(?:release(?:\s+history)?|lich su release|receipts?|worklog|ledger|status)\b/;
646
+ const AUTH_EXCLUSION = /\b(?:khong cap phep|not authori[sz]e\w*|does not authori[sz]e|khong duoc phep)\b[^.]*\./g;
552
647
  function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
553
648
  promptText = publicationScope(promptText).text;
554
649
  const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
@@ -599,11 +694,23 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
599
694
  }
600
695
  return total > 0 && banned === total;
601
696
  };
602
- const gitOperation = actionable.some((clause) => !operationNotOrdered(clause)
603
- && (GIT_ORDER_LEAD.test(clause) || /\bgit\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)\b|\bpush\s+(?:to\s+)?origin\b/.test(clause)));
604
- const runtimeOperation = actionable.some((clause) => !operationNotOrdered(clause) && /(?<!\b(?:process|crash|hard|soft|graceful|after|upon|during|across|following)\s)\b(?:restart|redeploy|deploy|khoi dong lai|trien khai\s+(?:len\s+)?(?:service|server|production|prod|staging|dich vu|may chu|moi truong))\b/.test(clause)
605
- && !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause));
606
- const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime') : null;
697
+ // A status/report wrap-up ("check X and Y results; then docs, commit, report") lists a bare `commit` as
698
+ // bookkeeping next to the report it closes; it is not an ordered history operation with a remote proof.
699
+ const statusWrapUp = /^[\s*+•>\d.)-]*(?:(?:please|hay|vui long)\s+)*(?:check|status|report|show|summari[sz]e|kiem tra|bao cao)\b/.test(actionable[0] || '')
700
+ && actionable.some((clause) => /^[\s*+•>\d.)-]*(?:report|bao cao)\s*$/.test(clause));
701
+ const runtimeClause = (clause) => !operationNotOrdered(clause) && /(?<!\b(?:process|crash|hard|soft|graceful|after|upon|during|across|following)\s)\b(?:restart|redeploy|deploy|khoi dong lai|trien khai\s+(?:len\s+)?(?:service|server|production|prod|staging|dich vu|may chu|moi truong))\b/.test(clause)
702
+ && !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause);
703
+ const runtimeOperation = actionable.some(runtimeClause);
704
+ // Only a PURE status wrap-up drops its bare commit; one that also orders a deploy keeps the git goal.
705
+ const bookkeepingCommit = (clause) => statusWrapUp && !runtimeOperation && /^[\s*+•>\d.)-]*commit\s*$/.test(clause);
706
+ const gitClause = (clause) => !operationNotOrdered(clause) && !bookkeepingCommit(clause)
707
+ && (GIT_ORDER_LEAD.test(clause) || /\bgit\s+(?:push|clean|commit|reset|rebase|merge|tag|stash|checkout|restore|cherry-pick)\b|\bpush\s+(?:to\s+)?origin\b/.test(clause));
708
+ const gitOperation = actionable.some(gitClause);
709
+ // Commit/push AND a deploy with no source-change order are TWO independent native obligations: each keeps
710
+ // its own proof (git remote parity; deploy receipt + live check). Neither is folded into the other, and
711
+ // owner authorization wording never drops one of them.
712
+ const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime')
713
+ : gitOperation && runtimeOperation && !sourceOrder && !codeChangeVerb && actionable.every((clause) => !PLAIN_CHANGE_VERB.test(clause) || /^[\s*+•>\d.)-]*(?:chay|run|verify|kiem tra|check)\b/.test(clause) || (clause.length > 3 && (releaseText.match(AUTH_EXCLUSION) || []).some((span) => span.includes(clause))) || HISTORY_OBJECT.test(clause)) ? 'multi' : null;
607
714
  const operation = Boolean(nativeDomain);
608
715
  if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', ...(bansTestRuns(promptText) ? {} : { verificationOnly: true }) };
609
716
  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/;
@@ -637,8 +744,13 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
637
744
  const taskKind = operation ? (sourceOrder || codeChangeVerb ? 'MIXED' : 'OPERATIONAL')
638
745
  : config ? 'CONFIGURATION' : documentation ? 'DOCUMENTATION_OUTPUT' : readOnly ? 'READ_ONLY' : 'CODE_IMPLEMENTATION';
639
746
  const id = text.match(/\b[a-f0-9]{8}(?:[a-f0-9-]{0,28})\b/)?.[0] || null;
747
+ // Multi-operation: the goal ordered first is the primary `operationGoal`; `operationGoals` carries all of them.
748
+ const operationGoals = nativeDomain === 'multi'
749
+ ? (actionable.findIndex(gitClause) <= actionable.findIndex(runtimeClause) ? ['git-integrity', 'service-runtime'] : ['service-runtime', 'git-integrity'])
750
+ .map((domain) => nativeOperationGoal(domain, actionable, text, promptText)) : null;
640
751
  return { taskKind, ...(releasePolicy ? { releasePolicy } : {}), ...(documentation ? { reportArtifact } : {}), ...(taskKind === 'READ_ONLY' && statusReport ? { statusReport: true } : {}), ...(config ? { configurationScope: repository ? 'repository' : 'external' } : {}),
641
- ...(operation && nativeDomain !== 'scheduled-job' ? { operationGoal: nativeOperationGoal(nativeDomain, actionable, text) } : {}),
752
+ ...(operationGoals ? { operationGoal: operationGoals[0], operationGoals } : {}),
753
+ ...(operation && !operationGoals && nativeDomain !== 'scheduled-job' ? { operationGoal: nativeOperationGoal(nativeDomain, actionable, text, promptText) } : {}),
642
754
  ...(operation && nativeDomain === 'scheduled-job' ? { operationGoal: { domain: 'scheduled-job', target: id, desiredState: /\b(?:delete|remove|cancel|xoa|huy|absent|removed|deleted|no longer|khong con)\b/.test(actionable.join(' ')) ? 'absent' : 'present',
643
755
  completionSemantics: /\b(?:ensure|dam bao)\b/.test(text)
644
756
  || actionable.some((clause) => /\b(?:delete|remove|cancel|xoa|huy)\b/.test(clause)