@ngockhoale/ukit 3.4.77 → 3.4.79
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 +12 -471
- package/manifests/documentation.yaml +12 -0
- package/package.json +1 -1
- package/template_project/.claude/commands/ukit/handoff-create.md +7 -0
- package/template_project/.claude/commands/ukit/handoff-fullstack.md +5 -0
- package/template_project/.claude/hooks/skill-router.sh +104 -21
- package/template_project/.claude/skills/advisor-plan/REFERENCE.md +2 -0
- package/template_project/.claude/ukit/index/publication-intent.mjs +61 -5
- package/template_project/.claude/ukit/runtime/resumable-run.mjs +12 -0
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +424 -26
- package/template_project/docs/AI_HANDOFF/queued/README.md +32 -0
|
@@ -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=
|
|
204
|
+
// BEGIN GENERATED SEMANTIC ENGINE sha256=db789c44db60937d51b7d9a4a9481264feb9f7152b88721bc973a16c4129f7fc
|
|
205
205
|
// Canonical task semantics; intent never grants authorization or proves completion.
|
|
206
|
-
const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:
|
|
206
|
+
const SEMANTIC_ENGINE_VERSION = 'round4-semantic-1:86afd8b71e068da6a63a85fcf003f79be262881f6c203fa44682853cf8acb4f7';
|
|
207
207
|
|
|
208
208
|
function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
|
|
209
209
|
return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
|
|
@@ -847,7 +847,11 @@ function classifySemanticText(input = {}) {
|
|
|
847
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
848
|
const HISTORY_OBJECT = /\b(?:release(?:\s+history)?|lich su release|receipts?|worklog|ledger|status)\b/;
|
|
849
849
|
const AUTH_EXCLUSION = /\b(?:khong cap phep|not authori[sz]e\w*|does not authori[sz]e|khong duoc phep)\b[^.]*\./g;
|
|
850
|
+
const NON_DOC_TARGET = /\b(?:tests?|code|source|ma nguon|functions?|ham|endpoints?|api|routes?|scripts?|database|db|schema|tables?|dockerfile|makefile|config(?:uration)?|cau hinh|environment|package|dependenc(?:y|ies)|publish|deploy|restart|run|chay|yarn|npm|pnpm|git|commit|push|build|install|helpers?|modules?|class(?:es)?|components?|hooks?|lint|handlers?|parsers?|bugs?|crash\w*|prs?|pull request|prod|production|staging|cron|process(?:es)?|server|service|users?|customers?)\b|[\w-]+\.(?!md\b|txt\b)[a-z][a-z0-9]{0,4}\b|(?:^|\s)\.?[\w-]+\/[\w./-]+/;
|
|
851
|
+
// Action verbs that, inside a docs clause, order something besides the docs edit ("update docs/x.md to fix ...").
|
|
852
|
+
const ACTION_VERB = /\b(?:implement|fix(?:es)?|apply|refactor|modify|add|build|make|remove|delete|rename|replace|change|set|bump|rewrite|correct|resolve|patch|optimi[sz]e|upgrade|merge|tag|upload|send|migrate|enable|disable|cancel|kill|reboot|rollback|roll out|go live|flip|verify|ship|launch|do|execute|proceed|handle|finish|complete|continue|go ahead|take care|wire|clean|sua|them|xoa|doi|bo sung|cai|lam|thuc hien|xu ly|tiep tuc|hoan thanh)\b/;
|
|
850
853
|
function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
854
|
+
const rawPrompt = String(promptText);
|
|
851
855
|
promptText = publicationScope(promptText).text;
|
|
852
856
|
const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
853
857
|
const preflight = releaseText.match(/\b(?:yarn\s+release:verify|npm\s+run\s+release:verify)\b/)?.[0];
|
|
@@ -868,9 +872,59 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
|
868
872
|
const sourceOrder = actionable.some((clause) => /\b(?:implement|fix(?:es)?|apply|refactor|modify|edit|write|update|sua|viet|chinh)\b/.test(clause)
|
|
869
873
|
&& /\b(?:source|code|logic|scheduler|implementation|ma nguon)\b|\.[cm]?[jt]sx?\b/.test(clause));
|
|
870
874
|
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));
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
875
|
+
const scopedArtifact = String(promptText).match(/(?:^|\s)((?:docs\/|reports\/)[A-Za-z0-9_./-]+\.(?:md|txt))(?=\s|[.,;:]|$)/)?.[1];
|
|
876
|
+
// The scoped text is lowercased; keep the prompt's own casing so the artifact resolves on case-sensitive disks.
|
|
877
|
+
const reportArtifact = scopedArtifact && ([...rawPrompt.matchAll(/(?:docs|reports)\/[A-Za-z0-9_./-]+\.(?:md|txt)/gi)]
|
|
878
|
+
.map((match) => match[0]).find((candidate) => candidate.toLowerCase() === scopedArtifact) || scopedArtifact);
|
|
879
|
+
// DOCUMENTATION_OUTPUT only when EVERY actionable clause is doc-only (whitelist, fail safe): a clause naming a
|
|
880
|
+
// docs/ or reports/ .md/.txt file may carry only doc wording beside it; a clause naming none may contain only
|
|
881
|
+
// connector/doc-noun words. Any other word (a verb, a code/config/release/operation target) keeps the code or
|
|
882
|
+
// operation contract.
|
|
883
|
+
const DOC_PATH = /(?:^|\s)(?:docs|reports)\/[a-z0-9_./-]+\.(?:md|txt)\b/g;
|
|
884
|
+
const DOC_WORD = /^(?:a|an|the|this|that|these|those|new|full|short|brief|detailed|current|updated|final|draft|clear|concise|for|of|in|into|on|to|at|from|with|about|as|by|please|just|also|only|now|then|it|its|our|my|same|section|sections|report|reports|analysis|document|documents|documentation|doc|docs|plan|plans|planning|guide|guides|notes|note|design|spec|readme|changelog|runbook|summary|overview|proposal|roadmap|checklist|describe|describing|explain|explaining|document|documenting|summari[sz]e|summari[sz]ing|cover|covering|list|listing|record|recording|outline|outlining|write|create|save|draft|update|edit|revise|refresh|amend|viet|tao|luu|soan|lap|cap|nhat|chinh|sua doi|tai|lieu|ke|hoach|bao|cao|phan|tich|huong|dan|ghi|chu|cho|ve|vao|trong|cua|va|mot|cac|nhung|ban|moi|day|du|chi|tiet|v?\d+(?:\.\d+)*|[^a-z0-9]+)$/;
|
|
885
|
+
// An ordering noun (release/migration/deployment/rollout/upgrade) is prose only as the modifier of a doc noun
|
|
886
|
+
// ("release notes", "migration guide"); bare, it is an order ("…and release", "write the migration").
|
|
887
|
+
const DOC_NOUN = '(?:notes?|guides?|plans?|docs?|documents?|documentation|reports?|summary|overview|checklist|runbook|tai lieu|ke hoach|huong dan|ghi chu|bao cao)';
|
|
888
|
+
const docWordList = (fragment) => fragment
|
|
889
|
+
.replace(new RegExp(`\\b(?:release|migration|deployment|rollout|upgrade|trien khai|complete|comprehensive|thorough|step-by-step)\\s+(?=${DOC_NOUN}\\b)`, 'g'), ' ')
|
|
890
|
+
.replace(/\b(tai lieu|ke hoach|huong dan|bao cao)\s+(?:trien khai|nang cap|phat hanh|di chuyen)\b/g, '$1')
|
|
891
|
+
.split(/\s+/).filter(Boolean).every((word) => DOC_WORD.test(word.replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, '')) || !/[a-z0-9]/.test(word));
|
|
892
|
+
const docWordsOnly = (fragment) => docWordList(fragment)
|
|
893
|
+
// A doc verb must name a doc noun: a bare "write"/"update" (its object neutralized, e.g. "write the fix") orders
|
|
894
|
+
// something unnamed and keeps the code contract.
|
|
895
|
+
&& (!/\b(?:write|create|save|draft|update|edit|revise|refresh|amend|viet|tao|luu|soan|lap|cap nhat|chinh)\b/.test(fragment)
|
|
896
|
+
|| /\b(?:reports?|analysis|documents?|documentation|docs?|plans?|planning|guides?|notes?|design|spec|readme|changelog|runbook|summary|overview|proposal|roadmap|checklist|tai lieu|ke hoach|bao cao|phan tich|huong dan|ghi chu)\b/.test(fragment));
|
|
897
|
+
// Free subject-matter prose is allowed only after a describe/explain lead ("to describe how to handle errors"),
|
|
898
|
+
// and only up to the next coordinator: whatever follows plus/once/as well as/parentheses/colon/dash must itself
|
|
899
|
+
// be doc words, so "describe X plus revert main" keeps the code contract.
|
|
900
|
+
const DESCRIBE_LEAD = /\b(?:describe|describing|explain|explaining|document|documenting|cover|covering|list|listing|summari[sz]e|summari[sz]ing|outline|outlining|record|recording|mo ta|giai thich)\b/;
|
|
901
|
+
const PROSE_BREAK = /\b(?:plus|as well as|along with|together with|once|after|before|also|first|afterwards|sau khi|truoc khi|dong thoi)\b|[()[\]{}&+:]|\s-\s/;
|
|
902
|
+
const INSPECTION_LEAD = /^[\s*+•>\d.)-]*(?:(?:please|just|hay|vui long|now|also|first)\s+)*(?:investigate|inspect|review|audit|analy[sz]e|check|debug|trace|look into|read|study|kiem tra|phan tich|dieu tra|tim hieu|xem)\b/;
|
|
903
|
+
const docOnly = actionable.length > 0 && actionable.every((clause) => {
|
|
904
|
+
const rest = clause.replace(DOC_PATH, ' ');
|
|
905
|
+
// A docs clause is whitelist-only (the path is its doc noun): every word before a describe/explain lead must be
|
|
906
|
+
// a doc word; after the lead, subject-matter prose is free up to the next coordinator, and each coordinated tail
|
|
907
|
+
// must again be doc words only ("update docs/x.md plus revert main", "…: revert main" keep the code contract).
|
|
908
|
+
if (rest !== clause) {
|
|
909
|
+
const lead = DESCRIBE_LEAD.exec(rest);
|
|
910
|
+
if (!lead) return docWordList(rest);
|
|
911
|
+
const [prose, ...tails] = rest.slice(lead.index).split(PROSE_BREAK);
|
|
912
|
+
return docWordList(rest.slice(0, lead.index)) && !NON_DOC_TARGET.test(prose) && tails.every((tail) => docWordList(tail));
|
|
913
|
+
}
|
|
914
|
+
// A read-only inspection clause ("investigate logs", "review the crash") feeds the report; it orders nothing.
|
|
915
|
+
// Every coordinated segment must itself be inspection-only or doc words only, so "investigate logs and write
|
|
916
|
+
// the fix" / "xem log roi cap nhat code" keep the code contract (write/update verbs are not in ACTION_VERB).
|
|
917
|
+
if (INSPECTION_LEAD.test(rest)) {
|
|
918
|
+
return rest.split(/\b(?:and|then|roi|va|sau do)\b|[,;:]/).every((segment) => (INSPECTION_LEAD.test(segment)
|
|
919
|
+
? !ACTION_VERB.test(segment) && !/\b(?:write|create|update|edit|modify|cap nhat|viet|tao)\b/.test(segment)
|
|
920
|
+
: docWordsOnly(segment)));
|
|
921
|
+
}
|
|
922
|
+
return docWordsOnly(rest);
|
|
923
|
+
});
|
|
924
|
+
const documentation = docOnly && !sourceOrder && reportArtifact
|
|
925
|
+
&& (actionable.some((clause) => clause.replace(DOC_PATH, ' ') !== clause && /\b(?:update|edit|modify|cap nhat|chinh)\b/.test(clause))
|
|
926
|
+
|| (actionable.some((clause) => /\b(?:write|create|save|viet|tao|luu|soan|lap)\b/.test(clause))
|
|
927
|
+
&& /\b(?:report|bao cao|analysis|phan tich|document(?:ation)?|tai lieu|ke hoach|plans?|guide|huong dan|notes|ghi chu|design|spec|readme|changelog|runbook)\b/.test(text.replace(/\S*\/\S*\.(?:md|txt)\b/g, ' '))));
|
|
874
928
|
const hasOperationId = /\b[a-f0-9]{8}(?:[a-f0-9-]{0,28})\b/.test(text);
|
|
875
929
|
const cronOperation = actionable.some((clause) => /\b(?:delete|remove|cancel|xoa|huy|ensure|dam bao)\b/.test(clause)
|
|
876
930
|
&& /\bcron\b|scheduled\s+(?:cron\s+)?(?:task|job)|tac vu\s+(?:cron|dinh ky)/.test(clause))
|
|
@@ -901,7 +955,9 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
|
901
955
|
// bookkeeping next to the report it closes; it is not an ordered history operation with a remote proof.
|
|
902
956
|
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
957
|
&& actionable.some((clause) => /^[\s*+•>\d.)-]*(?:report|bao cao)\s*$/.test(clause));
|
|
904
|
-
|
|
958
|
+
// File-path tokens name artifacts, not orders: "docs/plans/deploy.md" is not a deploy order.
|
|
959
|
+
const unpathed = (clause) => clause.replace(/[a-z0-9_.-]*\/[a-z0-9_./-]*|[a-z0-9_-]+\.(?:md|txt)\b/g, ' ');
|
|
960
|
+
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(unpathed(clause))
|
|
905
961
|
&& !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause);
|
|
906
962
|
const runtimeOperation = actionable.some(runtimeClause);
|
|
907
963
|
// Only a PURE status wrap-up drops its bare commit; one that also orders a deploy keeps the git goal.
|
|
@@ -4742,6 +4798,43 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4742
4798
|
peerDeliveryIds.add(at.delivery_id);
|
|
4743
4799
|
}
|
|
4744
4800
|
}
|
|
4801
|
+
// A /loop fire queued behind a busy turn is delivered only when that turn ends, so its
|
|
4802
|
+
// scheduled_task_fire record can sit behind the busy turn's assistant entries and beyond the
|
|
4803
|
+
// 128KB tail (BAGuide/UKit incident: 177KB, 7 minutes). Such a fire is still provenance while
|
|
4804
|
+
// it is UNCONSUMED: the host writes the meta user entry carrying scheduledFireId only after this
|
|
4805
|
+
// hook runs, so a fire whose id no later entry references has not been delivered yet. Same
|
|
4806
|
+
// session, same prompt-match rule as the current-turn path, bounded scan and age.
|
|
4807
|
+
const fireMatches = (entry) => {
|
|
4808
|
+
if (!(entry?.type === 'system' && entry.subtype === 'scheduled_task_fire' && sessionId && entry.sessionId === sessionId
|
|
4809
|
+
&& typeof entry.taskId === 'string' && entry.taskId.trim() && typeof entry.prompt === 'string')) return false;
|
|
4810
|
+
const fired = entry.prompt.trim();
|
|
4811
|
+
const firedBase = fired.replace(/(?:\u2026|\.{3})+$/, '').trim();
|
|
4812
|
+
// Prefix match only for a CLIPPED fire (ellipsis, or at the host's ~200-char clip, which real fires
|
|
4813
|
+
// reach without an ellipsis); an unclipped fire plus owner-appended text is an owner prompt.
|
|
4814
|
+
const clipped = firedBase !== fired || entry.prompt.length >= 190;
|
|
4815
|
+
return Boolean(fired && (fired === promptTrim || (clipped && firedBase.length >= 40 && promptTrim.startsWith(firedBase))));
|
|
4816
|
+
};
|
|
4817
|
+
{
|
|
4818
|
+
const wideLen = Math.min(size, 8 * 1024 * 1024);
|
|
4819
|
+
const wide = wideLen > len ? Buffer.alloc(wideLen) : buf;
|
|
4820
|
+
if (wide !== buf) fs.readSync(fd, wide, 0, wideLen, size - wideLen);
|
|
4821
|
+
const consumedFireIds = new Set();
|
|
4822
|
+
let pendingFire = null;
|
|
4823
|
+
for (const l of wide.toString('utf8').split('\n')) {
|
|
4824
|
+
if (!l || !(l.includes('scheduled_task_fire') || l.includes('scheduledFireId'))) continue;
|
|
4825
|
+
let e; try { e = JSON.parse(l); } catch { continue; }
|
|
4826
|
+
if (typeof e?.scheduledFireId === 'string') consumedFireIds.add(e.scheduledFireId);
|
|
4827
|
+
if (fireMatches(e) && typeof e.uuid === 'string') pendingFire = e;
|
|
4828
|
+
}
|
|
4829
|
+
const fireAge = pendingFire ? Date.now() - Date.parse(pendingFire.timestamp || '') : NaN;
|
|
4830
|
+
if (pendingFire && !consumedFireIds.has(pendingFire.uuid) && Number.isFinite(fireAge) && fireAge >= 0 && fireAge <= 6 * 60 * 60 * 1000) {
|
|
4831
|
+
if (classifyTaskSemantics({ promptText: promptTrim }).taskKind === 'READ_ONLY') {
|
|
4832
|
+
coordinationTurn = true;
|
|
4833
|
+
return false;
|
|
4834
|
+
}
|
|
4835
|
+
return true;
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4745
4838
|
let deliveryCurrent = true;
|
|
4746
4839
|
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
4747
4840
|
const line = lines[i];
|
|
@@ -4767,22 +4860,12 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4767
4860
|
// entry (the meta user entry is written only AFTER this hook runs). Same session, a task id,
|
|
4768
4861
|
// the current turn, and the prompt equal to - or a >=40 char truncated prefix of (the /loop
|
|
4769
4862
|
// fire record clips to ~200 chars) - the typed prompt. A human typing the text leaves no fire.
|
|
4770
|
-
if (deliveryCurrent && entry
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
const fired = entry.prompt.trim();
|
|
4775
|
-
const firedBase = fired.replace(/(?:\u2026|\.{3})+$/, '').trim();
|
|
4776
|
-
// Prefix match only for a CLIPPED fire (ellipsis, or at the host's ~200-char clip, which real fires
|
|
4777
|
-
// reach without an ellipsis); an unclipped fire plus owner-appended text is an owner prompt.
|
|
4778
|
-
const clipped = firedBase !== fired || entry.prompt.length >= 190;
|
|
4779
|
-
if (fired && (fired === promptTrim || (clipped && firedBase.length >= 40 && promptTrim.startsWith(firedBase)))) {
|
|
4780
|
-
if (classifyTaskSemantics({ promptText: promptTrim }).taskKind === 'READ_ONLY') {
|
|
4781
|
-
coordinationTurn = true;
|
|
4782
|
-
return false;
|
|
4783
|
-
}
|
|
4784
|
-
return true;
|
|
4863
|
+
if (deliveryCurrent && fireMatches(entry)) {
|
|
4864
|
+
if (classifyTaskSemantics({ promptText: promptTrim }).taskKind === 'READ_ONLY') {
|
|
4865
|
+
coordinationTurn = true;
|
|
4866
|
+
return false;
|
|
4785
4867
|
}
|
|
4868
|
+
return true;
|
|
4786
4869
|
}
|
|
4787
4870
|
if (entry.type !== 'user' || entry.isSidechain === true) continue;
|
|
4788
4871
|
const content = entry.message?.content;
|
|
@@ -80,6 +80,8 @@ Two queue kinds share the `queued/` lane and must not be confused:
|
|
|
80
80
|
- **Mandatory overflow** (`feasible`/`adapted` rows beyond the 10-task threshold): queued WITHOUT `QueueIntent` (no `Queue*` header line at all). Fullstack folds it into the cycle like a legacy blueprint; it is consumable work, never excluded.
|
|
81
81
|
- **Deliberate-future** (`deferred` rows only): carries the four `Queue*` lines above. Fullstack reports it as `Backlog: <slug>`, never folds it, and drains it only when the human names the slug.
|
|
82
82
|
|
|
83
|
+
- **Stale / superseded** (already delivered or replaced): `QueueIntent: superseded|stale` + `QueueSupersededBy: archive:cycle-NN[, …] | queue:<slug>`. Excluded only when the runtime proves the provenance (every task archived as delivered, or a live non-cyclic replacement); otherwise it fails closed and still counts.
|
|
84
|
+
|
|
83
85
|
A blueprint without the line keeps the legacy fold-in behaviour. The contract is documented in `docs/AI_HANDOFF/queued/README.md`.
|
|
84
86
|
|
|
85
87
|
**Mandatory overflow naming (default):** group overflow tasks by dependency chain (a task and everything it depends on that is also overflow form one group). Each group is one blueprint: `queued/<plan-slug>-overflow-<NN>/`, where `<plan-slug>` is the plan's slug and `<NN>` is the next unused two-digit index under that plan (scan existing `overflow-*` dirs, take max+1). Never reuse or overwrite an existing blueprint dir; on any collision append `-2`, `-3`, … to the directory name. Each blueprint's `HANDOFF.md` lists its R-IDs and task IDs.
|
|
@@ -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:86afd8b71e068da6a63a85fcf003f79be262881f6c203fa44682853cf8acb4f7';
|
|
4
4
|
|
|
5
5
|
export function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
|
|
6
6
|
return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
|
|
@@ -644,7 +644,11 @@ function classifySemanticText(input = {}) {
|
|
|
644
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
645
|
const HISTORY_OBJECT = /\b(?:release(?:\s+history)?|lich su release|receipts?|worklog|ledger|status)\b/;
|
|
646
646
|
const AUTH_EXCLUSION = /\b(?:khong cap phep|not authori[sz]e\w*|does not authori[sz]e|khong duoc phep)\b[^.]*\./g;
|
|
647
|
+
const NON_DOC_TARGET = /\b(?:tests?|code|source|ma nguon|functions?|ham|endpoints?|api|routes?|scripts?|database|db|schema|tables?|dockerfile|makefile|config(?:uration)?|cau hinh|environment|package|dependenc(?:y|ies)|publish|deploy|restart|run|chay|yarn|npm|pnpm|git|commit|push|build|install|helpers?|modules?|class(?:es)?|components?|hooks?|lint|handlers?|parsers?|bugs?|crash\w*|prs?|pull request|prod|production|staging|cron|process(?:es)?|server|service|users?|customers?)\b|[\w-]+\.(?!md\b|txt\b)[a-z][a-z0-9]{0,4}\b|(?:^|\s)\.?[\w-]+\/[\w./-]+/;
|
|
648
|
+
// Action verbs that, inside a docs clause, order something besides the docs edit ("update docs/x.md to fix ...").
|
|
649
|
+
const ACTION_VERB = /\b(?:implement|fix(?:es)?|apply|refactor|modify|add|build|make|remove|delete|rename|replace|change|set|bump|rewrite|correct|resolve|patch|optimi[sz]e|upgrade|merge|tag|upload|send|migrate|enable|disable|cancel|kill|reboot|rollback|roll out|go live|flip|verify|ship|launch|do|execute|proceed|handle|finish|complete|continue|go ahead|take care|wire|clean|sua|them|xoa|doi|bo sung|cai|lam|thuc hien|xu ly|tiep tuc|hoan thanh)\b/;
|
|
647
650
|
function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
651
|
+
const rawPrompt = String(promptText);
|
|
648
652
|
promptText = publicationScope(promptText).text;
|
|
649
653
|
const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
650
654
|
const preflight = releaseText.match(/\b(?:yarn\s+release:verify|npm\s+run\s+release:verify)\b/)?.[0];
|
|
@@ -665,9 +669,59 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
|
665
669
|
const sourceOrder = actionable.some((clause) => /\b(?:implement|fix(?:es)?|apply|refactor|modify|edit|write|update|sua|viet|chinh)\b/.test(clause)
|
|
666
670
|
&& /\b(?:source|code|logic|scheduler|implementation|ma nguon)\b|\.[cm]?[jt]sx?\b/.test(clause));
|
|
667
671
|
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));
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
|
|
672
|
+
const scopedArtifact = String(promptText).match(/(?:^|\s)((?:docs\/|reports\/)[A-Za-z0-9_./-]+\.(?:md|txt))(?=\s|[.,;:]|$)/)?.[1];
|
|
673
|
+
// The scoped text is lowercased; keep the prompt's own casing so the artifact resolves on case-sensitive disks.
|
|
674
|
+
const reportArtifact = scopedArtifact && ([...rawPrompt.matchAll(/(?:docs|reports)\/[A-Za-z0-9_./-]+\.(?:md|txt)/gi)]
|
|
675
|
+
.map((match) => match[0]).find((candidate) => candidate.toLowerCase() === scopedArtifact) || scopedArtifact);
|
|
676
|
+
// DOCUMENTATION_OUTPUT only when EVERY actionable clause is doc-only (whitelist, fail safe): a clause naming a
|
|
677
|
+
// docs/ or reports/ .md/.txt file may carry only doc wording beside it; a clause naming none may contain only
|
|
678
|
+
// connector/doc-noun words. Any other word (a verb, a code/config/release/operation target) keeps the code or
|
|
679
|
+
// operation contract.
|
|
680
|
+
const DOC_PATH = /(?:^|\s)(?:docs|reports)\/[a-z0-9_./-]+\.(?:md|txt)\b/g;
|
|
681
|
+
const DOC_WORD = /^(?:a|an|the|this|that|these|those|new|full|short|brief|detailed|current|updated|final|draft|clear|concise|for|of|in|into|on|to|at|from|with|about|as|by|please|just|also|only|now|then|it|its|our|my|same|section|sections|report|reports|analysis|document|documents|documentation|doc|docs|plan|plans|planning|guide|guides|notes|note|design|spec|readme|changelog|runbook|summary|overview|proposal|roadmap|checklist|describe|describing|explain|explaining|document|documenting|summari[sz]e|summari[sz]ing|cover|covering|list|listing|record|recording|outline|outlining|write|create|save|draft|update|edit|revise|refresh|amend|viet|tao|luu|soan|lap|cap|nhat|chinh|sua doi|tai|lieu|ke|hoach|bao|cao|phan|tich|huong|dan|ghi|chu|cho|ve|vao|trong|cua|va|mot|cac|nhung|ban|moi|day|du|chi|tiet|v?\d+(?:\.\d+)*|[^a-z0-9]+)$/;
|
|
682
|
+
// An ordering noun (release/migration/deployment/rollout/upgrade) is prose only as the modifier of a doc noun
|
|
683
|
+
// ("release notes", "migration guide"); bare, it is an order ("…and release", "write the migration").
|
|
684
|
+
const DOC_NOUN = '(?:notes?|guides?|plans?|docs?|documents?|documentation|reports?|summary|overview|checklist|runbook|tai lieu|ke hoach|huong dan|ghi chu|bao cao)';
|
|
685
|
+
const docWordList = (fragment) => fragment
|
|
686
|
+
.replace(new RegExp(`\\b(?:release|migration|deployment|rollout|upgrade|trien khai|complete|comprehensive|thorough|step-by-step)\\s+(?=${DOC_NOUN}\\b)`, 'g'), ' ')
|
|
687
|
+
.replace(/\b(tai lieu|ke hoach|huong dan|bao cao)\s+(?:trien khai|nang cap|phat hanh|di chuyen)\b/g, '$1')
|
|
688
|
+
.split(/\s+/).filter(Boolean).every((word) => DOC_WORD.test(word.replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, '')) || !/[a-z0-9]/.test(word));
|
|
689
|
+
const docWordsOnly = (fragment) => docWordList(fragment)
|
|
690
|
+
// A doc verb must name a doc noun: a bare "write"/"update" (its object neutralized, e.g. "write the fix") orders
|
|
691
|
+
// something unnamed and keeps the code contract.
|
|
692
|
+
&& (!/\b(?:write|create|save|draft|update|edit|revise|refresh|amend|viet|tao|luu|soan|lap|cap nhat|chinh)\b/.test(fragment)
|
|
693
|
+
|| /\b(?:reports?|analysis|documents?|documentation|docs?|plans?|planning|guides?|notes?|design|spec|readme|changelog|runbook|summary|overview|proposal|roadmap|checklist|tai lieu|ke hoach|bao cao|phan tich|huong dan|ghi chu)\b/.test(fragment));
|
|
694
|
+
// Free subject-matter prose is allowed only after a describe/explain lead ("to describe how to handle errors"),
|
|
695
|
+
// and only up to the next coordinator: whatever follows plus/once/as well as/parentheses/colon/dash must itself
|
|
696
|
+
// be doc words, so "describe X plus revert main" keeps the code contract.
|
|
697
|
+
const DESCRIBE_LEAD = /\b(?:describe|describing|explain|explaining|document|documenting|cover|covering|list|listing|summari[sz]e|summari[sz]ing|outline|outlining|record|recording|mo ta|giai thich)\b/;
|
|
698
|
+
const PROSE_BREAK = /\b(?:plus|as well as|along with|together with|once|after|before|also|first|afterwards|sau khi|truoc khi|dong thoi)\b|[()[\]{}&+:]|\s-\s/;
|
|
699
|
+
const INSPECTION_LEAD = /^[\s*+•>\d.)-]*(?:(?:please|just|hay|vui long|now|also|first)\s+)*(?:investigate|inspect|review|audit|analy[sz]e|check|debug|trace|look into|read|study|kiem tra|phan tich|dieu tra|tim hieu|xem)\b/;
|
|
700
|
+
const docOnly = actionable.length > 0 && actionable.every((clause) => {
|
|
701
|
+
const rest = clause.replace(DOC_PATH, ' ');
|
|
702
|
+
// A docs clause is whitelist-only (the path is its doc noun): every word before a describe/explain lead must be
|
|
703
|
+
// a doc word; after the lead, subject-matter prose is free up to the next coordinator, and each coordinated tail
|
|
704
|
+
// must again be doc words only ("update docs/x.md plus revert main", "…: revert main" keep the code contract).
|
|
705
|
+
if (rest !== clause) {
|
|
706
|
+
const lead = DESCRIBE_LEAD.exec(rest);
|
|
707
|
+
if (!lead) return docWordList(rest);
|
|
708
|
+
const [prose, ...tails] = rest.slice(lead.index).split(PROSE_BREAK);
|
|
709
|
+
return docWordList(rest.slice(0, lead.index)) && !NON_DOC_TARGET.test(prose) && tails.every((tail) => docWordList(tail));
|
|
710
|
+
}
|
|
711
|
+
// A read-only inspection clause ("investigate logs", "review the crash") feeds the report; it orders nothing.
|
|
712
|
+
// Every coordinated segment must itself be inspection-only or doc words only, so "investigate logs and write
|
|
713
|
+
// the fix" / "xem log roi cap nhat code" keep the code contract (write/update verbs are not in ACTION_VERB).
|
|
714
|
+
if (INSPECTION_LEAD.test(rest)) {
|
|
715
|
+
return rest.split(/\b(?:and|then|roi|va|sau do)\b|[,;:]/).every((segment) => (INSPECTION_LEAD.test(segment)
|
|
716
|
+
? !ACTION_VERB.test(segment) && !/\b(?:write|create|update|edit|modify|cap nhat|viet|tao)\b/.test(segment)
|
|
717
|
+
: docWordsOnly(segment)));
|
|
718
|
+
}
|
|
719
|
+
return docWordsOnly(rest);
|
|
720
|
+
});
|
|
721
|
+
const documentation = docOnly && !sourceOrder && reportArtifact
|
|
722
|
+
&& (actionable.some((clause) => clause.replace(DOC_PATH, ' ') !== clause && /\b(?:update|edit|modify|cap nhat|chinh)\b/.test(clause))
|
|
723
|
+
|| (actionable.some((clause) => /\b(?:write|create|save|viet|tao|luu|soan|lap)\b/.test(clause))
|
|
724
|
+
&& /\b(?:report|bao cao|analysis|phan tich|document(?:ation)?|tai lieu|ke hoach|plans?|guide|huong dan|notes|ghi chu|design|spec|readme|changelog|runbook)\b/.test(text.replace(/\S*\/\S*\.(?:md|txt)\b/g, ' '))));
|
|
671
725
|
const hasOperationId = /\b[a-f0-9]{8}(?:[a-f0-9-]{0,28})\b/.test(text);
|
|
672
726
|
const cronOperation = actionable.some((clause) => /\b(?:delete|remove|cancel|xoa|huy|ensure|dam bao)\b/.test(clause)
|
|
673
727
|
&& /\bcron\b|scheduled\s+(?:cron\s+)?(?:task|job)|tac vu\s+(?:cron|dinh ky)/.test(clause))
|
|
@@ -698,7 +752,9 @@ function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
|
698
752
|
// bookkeeping next to the report it closes; it is not an ordered history operation with a remote proof.
|
|
699
753
|
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
754
|
&& actionable.some((clause) => /^[\s*+•>\d.)-]*(?:report|bao cao)\s*$/.test(clause));
|
|
701
|
-
|
|
755
|
+
// File-path tokens name artifacts, not orders: "docs/plans/deploy.md" is not a deploy order.
|
|
756
|
+
const unpathed = (clause) => clause.replace(/[a-z0-9_.-]*\/[a-z0-9_./-]*|[a-z0-9_-]+\.(?:md|txt)\b/g, ' ');
|
|
757
|
+
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(unpathed(clause))
|
|
702
758
|
&& !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause);
|
|
703
759
|
const runtimeOperation = actionable.some(runtimeClause);
|
|
704
760
|
// Only a PURE status wrap-up drops its bare commit; one that also orders a deploy keeps the git goal.
|
|
@@ -1499,6 +1499,17 @@ async function main() {
|
|
|
1499
1499
|
if (!result.ok) process.exitCode = 3;
|
|
1500
1500
|
return;
|
|
1501
1501
|
}
|
|
1502
|
+
if (command === 'queue-status') {
|
|
1503
|
+
// Read-only queued/ lifecycle inventory (eligible / excluded / invalid) — the same classifier
|
|
1504
|
+
// the Stop gate uses. Lazy import: the coordinator is only needed for this command.
|
|
1505
|
+
const { classifyQueuedBlueprints, parseScopeQueue } = await import(new URL('./stop-coordinator.mjs', import.meta.url).href);
|
|
1506
|
+
const qflags = parseCliFlags([taskId, ...rest].filter((v) => v !== undefined));
|
|
1507
|
+
const scope = typeof qflags.scope === 'string' ? parseScopeQueue(qflags.scope) : null;
|
|
1508
|
+
const result = await classifyQueuedBlueprints(projectRoot, { scope });
|
|
1509
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
1510
|
+
if (!result.ok) process.exitCode = 3;
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1502
1513
|
if ((command === 'claim' || command === 'release') && taskId) {
|
|
1503
1514
|
// Main-agent participation in the existing claim registry (no second scheduler): the
|
|
1504
1515
|
// orchestrator that must run a task itself claims it first; the guard honours `main:<session>`.
|
|
@@ -1532,6 +1543,7 @@ async function main() {
|
|
|
1532
1543
|
process.stderr.write(
|
|
1533
1544
|
'usage: resumable-run.mjs read <projectRoot> <taskId> [--boundary <id>]\n'
|
|
1534
1545
|
+ ' resumable-run.mjs archive-cycle <projectRoot> <NN>\n'
|
|
1546
|
+
+ ' resumable-run.mjs queue-status <projectRoot> [--scope <slug,slug|none>]\n'
|
|
1535
1547
|
+ ' resumable-run.mjs claim|release <projectRoot> <taskId> --owner <main:session> [--cycle <NN>] [--generation <N>]\n'
|
|
1536
1548
|
+ ' resumable-run.mjs suspend <projectRoot> <taskId> [--boundary <id>] '
|
|
1537
1549
|
+ '[--phase <phase>] [--next <action>] [--completed <a,b,...>]\n',
|