@ngockhoale/ukit 3.4.74 → 3.4.75
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 +4 -0
- package/manifests/platform.full.yaml +15 -0
- package/package.json +4 -1
- package/template_project/.claude/hooks/completion-gate.sh +10 -1
- package/template_project/.claude/hooks/handoff-resume.sh +9 -0
- package/template_project/.claude/hooks/owner-stop-gate.mjs +41 -0
- package/template_project/.claude/hooks/skill-router.sh +177 -16
- package/template_project/.claude/settings.json +11 -1
- package/template_project/.claude/ukit/index/publication-intent.mjs +122 -12
- package/template_project/.claude/ukit/index/route-task.mjs +47 -8
- package/template_project/.claude/ukit/runtime/cron-operation-adapter.mjs +11 -4
- package/template_project/.claude/ukit/runtime/execution-ledger.mjs +369 -29
- package/template_project/.claude/ukit/runtime/operation-evidence.mjs +9 -0
- package/template_project/.claude/ukit/runtime/resumable-run.mjs +33 -11
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +158 -32
- package/template_project/.omp/hooks/pre/ukit-bridge.js +138 -3
- package/scripts/dev/worktree-preflight.mjs +0 -166
- package/scripts/measure-decision-gateway.mjs +0 -306
- package/scripts/probe/codex-capability-probe.mjs +0 -169
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to UKit are documented here.
|
|
4
4
|
|
|
5
|
+
## 3.4.75 - 2026-11-01
|
|
6
|
+
|
|
7
|
+
- Publish receipts bind to artifact integrity.
|
|
8
|
+
|
|
5
9
|
## 3.4.74 - 2026-10-30
|
|
6
10
|
|
|
7
11
|
**Route publication protocol, handoff ownership authority and explicit legacy adoption; no live-host certification beyond the isolated native OMP A/B/C acceptance recorded in `docs/STATUS.md`.**
|
|
@@ -1226,6 +1226,7 @@ items:
|
|
|
1226
1226
|
- hook-block-dangerous
|
|
1227
1227
|
- hook-handoff-model-guard
|
|
1228
1228
|
- hook-delegation-gate-module
|
|
1229
|
+
- hook-owner-stop-gate-module
|
|
1229
1230
|
- hook-auto-prune-bash
|
|
1230
1231
|
- hook-project-important
|
|
1231
1232
|
# Env block is post-merged by applyGatewayResilienceEnv (TASK-011) to add managed
|
|
@@ -1426,6 +1427,20 @@ items:
|
|
|
1426
1427
|
packs:
|
|
1427
1428
|
- core
|
|
1428
1429
|
|
|
1430
|
+
# Owner STOP gate: in-proc PreToolUse catch-all (`.*`) step; denies every NEW tool/spawn start for a stopped session
|
|
1431
|
+
# and its delegated children. Reads route state through ukit-runtime-scripts (execution-ledger.mjs).
|
|
1432
|
+
- id: hook-owner-stop-gate-module
|
|
1433
|
+
type: hook
|
|
1434
|
+
sourceTemplate: .claude/hooks/owner-stop-gate.mjs
|
|
1435
|
+
targetPath: .claude/hooks/owner-stop-gate.mjs
|
|
1436
|
+
requires:
|
|
1437
|
+
- ukit-runtime-scripts
|
|
1438
|
+
mergeStrategy: overwrite_with_backup
|
|
1439
|
+
variables: []
|
|
1440
|
+
enabledByDefault: true
|
|
1441
|
+
packs:
|
|
1442
|
+
- core
|
|
1443
|
+
|
|
1429
1444
|
# P0 delegation enforcement: in-proc PreToolUse chain step (Edit|Write, MultiEdit, Bash). Claude Code
|
|
1430
1445
|
# only (agent_id main/worker identity); reads route state + ledger from ukit-runtime-scripts.
|
|
1431
1446
|
- id: hook-delegation-gate-module
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngockhoale/ukit",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.75",
|
|
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",
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"scripts/",
|
|
33
33
|
"!scripts/dev/benchmark-verification-currency.mjs",
|
|
34
34
|
"!scripts/dev/capture-omp-stall.mjs",
|
|
35
|
+
"!scripts/dev/worktree-preflight.mjs",
|
|
36
|
+
"!scripts/measure-decision-gateway.mjs",
|
|
37
|
+
"!scripts/probe/codex-capability-probe.mjs",
|
|
35
38
|
"!scripts/install/generate-semantic-engine.mjs",
|
|
36
39
|
"!scripts/release/progress-reporter.mjs",
|
|
37
40
|
"!scripts/release/publish-guard-core.mjs",
|
|
@@ -85,7 +85,9 @@ fi
|
|
|
85
85
|
# (coordinator deadline + margin); a forced kill lands on the existing crash-streak
|
|
86
86
|
# path (non-zero STATUS) so the outcome is announced, never silently released.
|
|
87
87
|
__ukit_coord_out="$(mktemp "${TMPDIR:-/tmp}/ukit-coord-out.XXXXXX")"
|
|
88
|
-
|
|
88
|
+
__ukit_coord_err="$(mktemp "${TMPDIR:-/tmp}/ukit-coord-err.XXXXXX" 2>/dev/null)" || __ukit_coord_err=/dev/null
|
|
89
|
+
__ukit_coord_t0=$SECONDS
|
|
90
|
+
printf '%s' "$INPUT" | UKIT_HARNESS="${UKIT_HARNESS:-claude-code}" UKIT_HOOK_DEADLINE_MS="${UKIT_HOOK_DEADLINE_MS:-3000}" node "$SCRIPT" --evaluate-stop > "$__ukit_coord_out" 2>"$__ukit_coord_err" &
|
|
89
91
|
__ukit_coord_pid=$!
|
|
90
92
|
__ukit_coord_ms="${UKIT_HOOK_DEADLINE_MS:-3000}"
|
|
91
93
|
case "$__ukit_coord_ms" in ''|*[!0-9]*) __ukit_coord_ms=3000 ;; esac
|
|
@@ -99,6 +101,13 @@ kill "$__ukit_killer_pid" 2>/dev/null
|
|
|
99
101
|
wait "$__ukit_killer_pid" 2>/dev/null
|
|
100
102
|
OUTPUT="$(cat "$__ukit_coord_out" 2>/dev/null)"
|
|
101
103
|
rm -f "$__ukit_coord_out"
|
|
104
|
+
# Bounded diagnostic for a crashed coordinator (status>128 = killed by signal N-128, e.g. 137 = the deadline killer's SIGKILL).
|
|
105
|
+
# Written to a private cache file only; never part of the decision text (the reason stays fixed and redacted).
|
|
106
|
+
if [ "$STATUS" -ne 0 ]; then
|
|
107
|
+
mkdir -p "$PROJECT_ROOT/.ukit/storage/cache" 2>/dev/null
|
|
108
|
+
{ printf 'status=%s elapsed_s=%s deadline_ms=%s\n' "$STATUS" "$((SECONDS - __ukit_coord_t0))" "${__ukit_coord_ms}"; head -c 400 "$__ukit_coord_err" 2>/dev/null; printf '\n'; } > "$PROJECT_ROOT/.ukit/storage/cache/completion-gate-crash.last" 2>/dev/null
|
|
109
|
+
fi
|
|
110
|
+
[ "$__ukit_coord_err" = /dev/null ] || rm -f "$__ukit_coord_err"
|
|
102
111
|
|
|
103
112
|
if [ "$STATUS" -ne 0 ]; then
|
|
104
113
|
# BUG-C22-05: a PERSISTENT coordinator crash must not block every Stop forever.
|
|
@@ -280,6 +280,15 @@ function boundedTaskScopeLines(all, runCycle, currentTask) {
|
|
|
280
280
|
process.exit(0);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
try {
|
|
284
|
+
const ledger = await import(pathToFileURL(runtimePath).href);
|
|
285
|
+
const routeState = await ledger.readRouteState(projectRoot, payload);
|
|
286
|
+
if (ledger.ownerStopActive(routeState, payload)) {
|
|
287
|
+
process.stdout.write('UKit note: an owner STOP is standing for this session; handoff run not resumed. Cursor untouched. Only a new owner request resumes work.\n');
|
|
288
|
+
process.exit(0);
|
|
289
|
+
}
|
|
290
|
+
} catch {}
|
|
291
|
+
|
|
283
292
|
// Transcript intent cannot establish ownership of a cursor. Resolve the current
|
|
284
293
|
// session's durable binding before either injecting a resume or lifting a pause.
|
|
285
294
|
let ownership;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// owner-stop-gate.mjs — PreToolUse chain step (in-proc `runHook(ctx)`), wired on the catch-all `.*` matcher.
|
|
2
|
+
//
|
|
3
|
+
// While an owner STOP stands on a session (route state `ownerControl.kind === 'stop'`), NO new tool, shell command,
|
|
4
|
+
// edit, MCP call or subagent may start for that session or for a subagent it delegated. Matching is by the shared
|
|
5
|
+
// dispatch point (every tool name), not a tool list, so a new or renamed tool cannot slip past it.
|
|
6
|
+
//
|
|
7
|
+
// Scope, stated honestly:
|
|
8
|
+
// * It prevents NEW starts. It cannot cancel an operation that is already running — that is the host's `session_stop`.
|
|
9
|
+
// * Session-bound: an independent session in the same repo has its own route record and is never affected.
|
|
10
|
+
// * The STOP never expires; only a genuine owner prompt (the router) lifts it. Quoted/hook-shaped text cannot.
|
|
11
|
+
// * Denying is terminal for the call and creates no continuation: the Stop lanes already release on a standing STOP.
|
|
12
|
+
// * Codex exposes no hook surface, so nothing here runs there (advisory-only engine; see manifests/hostCapabilities.yaml).
|
|
13
|
+
// Fail-open on an internal fault (a broken advisory step must not wedge the session); the omp bridge applies the same
|
|
14
|
+
// check in-process at its own `tool_call` / `before_subagent_spawn` handlers.
|
|
15
|
+
|
|
16
|
+
import { ownerStopGovernsStart } from '../ukit/runtime/execution-ledger.mjs';
|
|
17
|
+
|
|
18
|
+
export const hookFailClosed = false;
|
|
19
|
+
|
|
20
|
+
export const OWNER_STOP_REASON = 'Owner STOP is in effect for this session: no new tool, shell command, edit or subagent may start until the owner sends a new request. Do not retry; report the stop and wait.';
|
|
21
|
+
|
|
22
|
+
export async function runHook(ctx) {
|
|
23
|
+
try {
|
|
24
|
+
const payload = ctx?.payload || {};
|
|
25
|
+
const env = ctx?.env || {};
|
|
26
|
+
// Bounded by the chain runner's per-step deadline (ctx.deadlineMs); a slow read fails open rather than wedge the call.
|
|
27
|
+
const deadlineMs = Number(ctx?.deadlineMs) > 0 ? Number(ctx.deadlineMs) : 4000;
|
|
28
|
+
const root = env.CLAUDE_PROJECT_DIR || ctx?.projectRoot || process.cwd();
|
|
29
|
+
const ids = [payload.session_id, payload.sessionId, payload.ukit_parent_session_id];
|
|
30
|
+
const stopped = await Promise.race([ownerStopGovernsStart(root, ids), new Promise((resolve) => setTimeout(() => resolve(false), Math.max(500, deadlineMs - 500)).unref())]);
|
|
31
|
+
if (!stopped) return { code: 0, stdout: '', stderr: '' };
|
|
32
|
+
const inChain = Boolean(env.UKIT_HOOK_CHAIN_RUNNER);
|
|
33
|
+
return {
|
|
34
|
+
code: inChain ? 2 : 0,
|
|
35
|
+
stdout: `${JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: OWNER_STOP_REASON } })}\n`,
|
|
36
|
+
stderr: `BLOCKED: ${OWNER_STOP_REASON}\n`,
|
|
37
|
+
};
|
|
38
|
+
} catch {
|
|
39
|
+
return { code: 0, stdout: '', stderr: '' };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -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=f574f585962b045968832191d0a086cb6625965b80b751a893e663fba12b085d
|
|
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:d2c70fa8c68d50f31917ee7befd16f6df36a441a2aae79a0de879f5b0a09edf1';
|
|
207
207
|
|
|
208
208
|
function semanticContractIdentity({ promptText = '', targetFile = '', taskInstanceId = null } = {}) {
|
|
209
209
|
return { taskInstanceId, targetFile, engineVersion: SEMANTIC_ENGINE_VERSION,
|
|
@@ -213,7 +213,7 @@ function semanticContractIdentity({ promptText = '', targetFile = '', taskInstan
|
|
|
213
213
|
const semanticContractShape = (contract) => JSON.stringify([
|
|
214
214
|
contract?.taskKind, contract?.publication === true, contract?.operationGoal ?? null,
|
|
215
215
|
contract?.configurationScope ?? null, contract?.releasePolicy ?? null, contract?.conditionalObligations ?? null,
|
|
216
|
-
contract?.reportArtifact ?? null, contract?.verificationOnly === true, contract?.statusReport === true,
|
|
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(),
|
|
218
218
|
]);
|
|
219
219
|
function compareSemanticContracts({ stored, fresh, previousIdentity, identity }) {
|
|
@@ -248,7 +248,7 @@ function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstanceId =
|
|
|
248
248
|
const quoted = Boolean(marker || fence || /^\s*>/.test(raw));
|
|
249
249
|
const context = quoted ? 'quotation' : description && bullet ? 'description' : 'instruction';
|
|
250
250
|
const polarity = /\b(?:do not|don't|never|must not|no|khong|chua)\b|đừng/i.test(raw) || /\b(?:prohibited|forbidden|banned)\b/.test(text) ? 'prohibited' : 'affirmative';
|
|
251
|
-
const condition = text.match(/\b(?:if|neu|only if|only when)\b[^,;.\n]*/)?.[0] || null;
|
|
251
|
+
const condition = text.match(/\b(?:if|neu|only if|only when|only after|only once)\b[^,;.\n]*/)?.[0] || null;
|
|
252
252
|
spans.push({ start: offset + part.index, end: offset + part.index + raw.length, raw,
|
|
253
253
|
context, polarity, condition, activation: condition ? 'pending' : context !== 'instruction' || polarity === 'prohibited' ? 'inactive' : 'eligible' });
|
|
254
254
|
}
|
|
@@ -268,10 +268,23 @@ function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstanceId =
|
|
|
268
268
|
const nativeReleasePolicy = classifySemanticText({ promptText: original, targetFile }).releasePolicy;
|
|
269
269
|
const deferredSpans = new Set(spans.filter(span => span.context === 'instruction'
|
|
270
270
|
&& span.polarity === 'affirmative' && span.condition
|
|
271
|
-
&& /^(?:[-*+•\d.)\s]*)(?:if|neu|only if|only when)\b/.test(foldIntent(span.raw))
|
|
271
|
+
&& /^(?:[-*+•\d.)\s]*)(?:if|neu|only if|only when|only after|only once)\b/.test(foldIntent(span.raw))
|
|
272
272
|
&& !nativeReleasePolicy && !VERIFICATION_GOAL.test(foldIntent(original))
|
|
273
273
|
&& !defectRepairBranches(foldIntent(span.raw)).length
|
|
274
274
|
&& ordersPublicationText(foldIntent(span.raw).replace(/^[^,]*,\s*/, ''))));
|
|
275
|
+
spans.forEach((span, index) => {
|
|
276
|
+
const folded = foldIntent(span.raw);
|
|
277
|
+
const verb = folded.match(CONDITIONAL_RUNTIME_VERB);
|
|
278
|
+
const cond = span.condition ? folded.indexOf(span.condition) : -1;
|
|
279
|
+
if (!verb || cond < 0 || span.context !== 'instruction' || span.polarity !== 'affirmative' || nativeReleasePolicy
|
|
280
|
+
|| CONDITIONAL_RUNTIME_EXCLUDED.test(folded)) return;
|
|
281
|
+
const governed = verb.index >= cond || /^(?:only\s+(?:if|when)|unless)\b/.test(span.condition);
|
|
282
|
+
if (!NEED_OR_FAILURE_CONDITION.test(span.condition)) return;
|
|
283
|
+
const leadsVerification = VERIFICATION_LEAD.test(folded.slice(0, cond)) && cond > 0
|
|
284
|
+
|| spans.slice(0, index).some(prior => prior.context === 'instruction' && prior.polarity === 'affirmative'
|
|
285
|
+
&& !prior.condition && VERIFICATION_LEAD.test(foldIntent(prior.raw)));
|
|
286
|
+
if (governed && leadsVerification) deferredSpans.add(span);
|
|
287
|
+
});
|
|
275
288
|
// An explicit alternative links both consequences. Keep the unconditional
|
|
276
289
|
// review prefix, but do not require a repair before its review has found one.
|
|
277
290
|
const alternatives = spans.filter(span => span.condition?.startsWith('otherwise:'));
|
|
@@ -289,7 +302,7 @@ function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstanceId =
|
|
|
289
302
|
if (span.context === 'quotation' || span.context === 'description' || approvalPending || deferredSpans.has(span) || evidenceStatement) {
|
|
290
303
|
// Retain the prefix before a comma-introduced postfix repair condition.
|
|
291
304
|
// Leading conditions and otherwise consequences are masked in full.
|
|
292
|
-
const prefix = deferredSpans.has(span) && !/^(?:\s*)(?:if|neu|only if|only when|otherwise)\b/.test(foldIntent(span.raw))
|
|
305
|
+
const prefix = deferredSpans.has(span) && !/^(?:\s*)(?:if|neu|only if|only when|only after|only once|otherwise)\b/.test(foldIntent(span.raw))
|
|
293
306
|
? span.raw.match(/^[^,]*,/)?.[0] || '' : '';
|
|
294
307
|
const masked = prefix + span.raw.slice(prefix.length).replace(/[^\r\n]/g, ' ');
|
|
295
308
|
semanticInput = semanticInput.slice(0, span.start) + masked + semanticInput.slice(span.end);
|
|
@@ -330,6 +343,12 @@ function analyzeTaskIntent({ promptText = '', targetFile = '', taskInstanceId =
|
|
|
330
343
|
}
|
|
331
344
|
return { engineVersion: SEMANTIC_ENGINE_VERSION, identity: { taskInstanceId, sessionId }, original, spans, actions, semantic };
|
|
332
345
|
}
|
|
346
|
+
const NEED_OR_FAILURE_CONDITION = /\b(?:needed|necessary|required|requires?|broken|fails?|failed|failing|failure|down|unhealthy|stale|missing|wrong|errors?|crash\w*|unavailable|not\s+(?:working|healthy|running|live|ok)|neu\s+(?:can|loi|hong|that bai|thieu|sai|chet)|khi\s+can|loi)\b|^unless\s+(?:healthy|ok|working|running|live)\b/;
|
|
347
|
+
const CONDITIONAL_RUNTIME_VERB = /\b(?:redeploy|deploy|restart|khoi dong lai|trien khai)\b/;
|
|
348
|
+
const CONDITIONAL_RUNTIME_EXCLUDED = /\b(?:publish|phat hanh|commit|push|tag|git|implement|fix|edit|modify|sua)\b/;
|
|
349
|
+
const VERIFICATION_LEAD = /^[-*+\u2022>\d.)\s]*(?:(?:please|hay|vui long|now|also|first)\s+)*(?:verify|check|confirm|validate|inspect|kiem tra|xac nhan)\b/;
|
|
350
|
+
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';
|
|
351
|
+
const PAST_RELEASE_ITEM = new RegExp(`^(?:(?:please|just|now|also)\\s+)*${PAST_RELEASE_SOURCE}`);
|
|
333
352
|
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/;
|
|
334
353
|
const PUBLISH_ORDER_IMPERATIVE = /^(?:please\s+|just\s+|now\s+|also\s+)*(?:run|do|execute|perform|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/;
|
|
335
354
|
const PUBLISH_ORDER_HEADER = /prohibit|forbidden|out of scope|non-goal|scope control/;
|
|
@@ -452,7 +471,7 @@ function ordersPublicationText(promptText = '') {
|
|
|
452
471
|
else if (/^(?:please\s+|now\s+|also\s+)*(?:run|execute|perform|chay)\s+\S/.test(item)) negated = false;
|
|
453
472
|
const commandItem = item.replace(/^(?:please|just|now|also|then)\s+/, '');
|
|
454
473
|
const publication = /\bnpm\s+publish\b/.test(commandItem) && /^(?:npm\s+publish|run|do|execute|perform|go|ship|publish|release|push|tag|commit|verify|make|cut|chay)\b/.test(commandItem);
|
|
455
|
-
const releaseOrder = /^(?:please\s+|just\s+|now\s+|also\s+)*(?:release|ship|publish)\s+(?!instructions?\b|obligations?\b|policies\b|boundary\b|safety\b|progress\b|candidate\s+review\b|readiness\b|verifier\b|verification\b|evidence\b|policy\b|intent\b|notes\b|terminology\b)\S/.test(item);
|
|
474
|
+
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);
|
|
456
475
|
const politeItem = item.replace(/^(?:(?:please|just|now|also|then|vui long|hay)\s+)+/, '');
|
|
457
476
|
const viPublish = /^(?:(?:su dung|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);
|
|
458
477
|
if (!negated && (releaseOrder || viPublish || (publication && (
|
|
@@ -466,7 +485,7 @@ function ordersPublicationText(promptText = '') {
|
|
|
466
485
|
return ordered;
|
|
467
486
|
}
|
|
468
487
|
|
|
469
|
-
const NOT_A_SERVICE = new Set(['it', 'this', 'that', 'them', 'the', 'all', 'everything', 'service', 'services', 'again', 'now', 'to', 'and', 'then']);
|
|
488
|
+
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']);
|
|
470
489
|
function nativeOperationGoal(domain, actionable, text) {
|
|
471
490
|
const goal = { domain, target: null, desiredState: 'verified', completionSemantics: 'execute-and-verify', requiredTargets: [] };
|
|
472
491
|
const clauses = actionable.join(' . ');
|
|
@@ -518,6 +537,7 @@ function neutralizeNonOrders(text) {
|
|
|
518
537
|
return source.replace(noVerbList(), ' ')
|
|
519
538
|
.replace(/\brelease-(?:publication|verification)\b|\brelease\s+(?:instructions?|authorization|obligations?|policies|readiness)\b/g, 'publication topic')
|
|
520
539
|
.replace(/\brelease\s+(?:safety|verification\s+plan)\b/g, 'publication topic')
|
|
540
|
+
.replace(new RegExp(`(^|[\\n.;]\\s*)(?:(?:please|just|now|also)\\s+)*${PAST_RELEASE_SOURCE}[^.;\\n]*`, 'g'), '$1publication topic')
|
|
521
541
|
.replace(/^[ \t]*[-*+•][ \t]*owner\s+yeu\s+cau\b[^\n]*/gm, ' ')
|
|
522
542
|
.replace(/^([ \t]*[-*+•][ \t]*)release\s+progress\s+reporter(?=[ \t]*(?:,|$))/gm, '$1progress reporter')
|
|
523
543
|
.replace(/^[ \t]*(?:[-*+\u2022]|\d+[.)])[ \t]*(?:negative|positive)\s+controls?\b[^\n]*(?:\n(?![ \t]*(?:[-*+\u2022]|\d+[.)])|[ \t]*\n)[^\n]*)*/gm, ' ')
|
|
@@ -528,6 +548,8 @@ function neutralizeNonOrders(text) {
|
|
|
528
548
|
.replace(/\b(?:uu tien|prefer(?:red)?)\s+(?:a\s+|an\s+)?(?:configuration|config|cau hinh)\s+(?:change|changes|update|thay doi)\b/g, ' ')
|
|
529
549
|
.replace(/\b(?:neu\s+(?:chi\s+)?(?:phai|can|thieu|khong du|bang chung chua du)(?![^.;\n]*\b(?:restart|deploy|xoa|delete|remove|cancel)\b)|if\s+(?:needed|necessary|required|evidence is insufficient))\b[^.;\n]*/g, ' ')
|
|
530
550
|
.replace(/[^.;\n]*\b(?:nao|gi|sao|the nao|bao nhieu)\b[^.;\n]*\?/g, ' ')
|
|
551
|
+
.replace(/\b(?:truoc khi|before)\s+(?:quay lai|tro lai|returning|going back|you (?:go|return)|we (?:go|return))\b[^.;\n]*/g, ' ')
|
|
552
|
+
.replace(/\b(?:cua|do|tu)\s+chinh\b|\bchinh\s+(?:cac|nhung|phien|no|minh|toi|ban than)\b/g, ' ')
|
|
531
553
|
.replace(/\bchinh\s+(?:xac|sach)\b|\b(?:phuong an|cach|de xuat|ban)\s+(?:sua|fix)\b|\b(?:diem|cho|muc|phan)\s+(?:phai|can|nen)\s+(?:sua|fix)\b/g, ' ')
|
|
532
554
|
.replace(/\bwrite\s*\/\s*verification\b|\bverification\s*\/\s*write\b|\bwrite\s+(?:or|and)\s+verification\b/g, ' ')
|
|
533
555
|
.replace(/\bwrite\s+permission\b/g, 'permission')
|
|
@@ -575,6 +597,13 @@ function declaredReadOnly(promptText, releasePolicy) {
|
|
|
575
597
|
|
|
576
598
|
const VERIFY_LEAD = /^(?:[-*+•>\d.)\s]*)(?:(?:please|hay|vui long|now|also|first|then)\s+)*(?:(?:keep|continue|tiep tuc)\s+)?(?:verify|re-?run|confirm|xac nhan|validate|double-?check|wait(?:ing)?|monitor|watch|cho(?=\s+(?:dung\s+)?(?:job|verifier|build|test|suite|gate|ci|run|task|ket qua|xong|output)\b))\b/;
|
|
577
599
|
const CHANGE_LEAD = /^(?:[-*+•>\d.)\s]*)(?:(?:please|hay|vui long|now|also|first|then)\s+)*(?:make|rebuild|redo|rewrite|restore|revert|correct|clean|patch|resolve|ensure|run(?!(?=[^.]*\b(?:tests?|suite|gate|checks?|lint|typecheck|pilot|smoke|e2e|verif\w*|vitest|jest|audit)\b)))\b/;
|
|
600
|
+
const BANS_TEST_RUNS = /\b(?:do not|don't|never|khong|dung)\s+(?:run|execute|chay)\s+(?:(?:any|more|additional|extra|them)\s+)*(?:tests?|checks?|verifications?)\b(?:\s+on\s+\w+)?/g;
|
|
601
|
+
const OWN_TARGET = /\b(?:yarn|npm|npx|pnpm|vitest|jest|pytest|node)\s+\S|\b(?:staging|ci|job|build|release(?!\s+notes?)|published|integration|e2e)\b/;
|
|
602
|
+
const bansTestRuns = (promptText) => {
|
|
603
|
+
const plain = String(promptText ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
604
|
+
const bans = plain.match(BANS_TEST_RUNS);
|
|
605
|
+
return !!bans && !bans.some((ban) => /\bon\s+\w+$/.test(ban)) && !OWN_TARGET.test(plain.replace(BANS_TEST_RUNS, ' '));
|
|
606
|
+
};
|
|
578
607
|
function isVerificationOnlyRequest(promptText) {
|
|
579
608
|
const plain = String(promptText ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase()
|
|
580
609
|
.replace(/```[\s\S]*?```/g, ' ').replace(/^[ \t]*>.*$/gm, ' ');
|
|
@@ -598,6 +627,27 @@ function neutralizeBannedLists(text) {
|
|
|
598
627
|
});
|
|
599
628
|
}
|
|
600
629
|
|
|
630
|
+
const OWNER_CONTROL_HOOK_TEXT = /^\s*(?:UKit completion gate:|UKit handoff|\[ukit[-\w]*\]|<system-reminder|<task-notification)/i;
|
|
631
|
+
const OWNER_STOP_EN = /^(?:please\s+)?(?:stop|halt|pause|cancel|abort)(?:\s+(?:all|everything|execution|executing|work|working|now|immediately|here|this|the|current|session|run|task|tasks|handoff|processing))*$/;
|
|
632
|
+
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))*$/;
|
|
633
|
+
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.-]+/;
|
|
634
|
+
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/;
|
|
635
|
+
function classifyOwnerControl(promptText = '') {
|
|
636
|
+
const raw = String(promptText ?? '').normalize('NFC').trim();
|
|
637
|
+
if (!raw || OWNER_CONTROL_HOOK_TEXT.test(raw)) return { kind: null };
|
|
638
|
+
const stripped = raw.replace(/^[\s*#_-]+/, '');
|
|
639
|
+
if (/^[>"'`\u201c\u2018]/.test(stripped)) return { kind: null };
|
|
640
|
+
const sentences = stripped.split(/[.!?\n]/);
|
|
641
|
+
const [lead, ...rest] = sentences[0].split(/[:;]/);
|
|
642
|
+
const first = lead.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
643
|
+
if (!first || first.length > 80) return { kind: null };
|
|
644
|
+
if (OWNER_CONTROL_TASK_WORD.test(rest.join(' ').toLowerCase())) return { kind: null };
|
|
645
|
+
if (!OWNER_STOP_EN.test(first) && !OWNER_STOP_VI.test(first)) return { kind: null };
|
|
646
|
+
const next = (sentences.slice(1).find((part) => part.trim()) || '').trim().toLowerCase();
|
|
647
|
+
if (OWNER_CONTROL_TASK_LEAD.test(next)) return { kind: null };
|
|
648
|
+
return { kind: 'stop' };
|
|
649
|
+
}
|
|
650
|
+
|
|
601
651
|
function classifyTaskSemantics(input = {}) {
|
|
602
652
|
return analyzeTaskIntent(input).semantic;
|
|
603
653
|
}
|
|
@@ -612,7 +662,7 @@ const collapseInspectionSentences = (text) => text.replace(INSPECTION_SENTENCE,
|
|
|
612
662
|
|
|
613
663
|
function actionableClauses(promptText) {
|
|
614
664
|
const text = neutralizeBannedLists(neutralizeNonOrders(collapseInspectionSentences(String(promptText).normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[đĐ]/g, 'd').toLowerCase())));
|
|
615
|
-
const clauses = text.split(/\s*(?:[;\n,]|\.(?:\s+|$)|\band\b|\bthen\b|\bva\b)\s*/);
|
|
665
|
+
const clauses = text.split(/\s*(?:[;\n,]|\.(?:\s+|$)|\band\b|\bthen\b|\bva\b|\broi\b(?=\s+(?:redeploy|deploy|restart|khoi dong lai|trien khai)\b))\s*/);
|
|
616
666
|
const actionable = clauses.map((clause) => clause.split(/\bwithout\b/)[0]).filter((clause) => !/\b(?:do not|don't|never|khong)\b|^[\s*+•>\d.)-]*(?:(?:vui long|xin|hay|please)\s+)*dung\b/.test(clause)
|
|
617
667
|
&& !/^[\s*+•>\d.)-]*(?:(?:please|just|hay|vui long|now|also)\s+)*(?:audit|inspect|review|analyze|analyse|explain|read|kiem tra|phan tich)\b/.test(clause)
|
|
618
668
|
// A fragment led by a subordinator continues the previous clause's predicate ("…, including source
|
|
@@ -627,7 +677,66 @@ function ordersAdditiveChange(promptText = '') {
|
|
|
627
677
|
return actionableClauses(publicationScope(promptText).text).actionable.some((clause) => ADDITIVE_ORDER_LEAD.test(clause));
|
|
628
678
|
}
|
|
629
679
|
|
|
630
|
-
|
|
680
|
+
const STATE_OBJECT = /\b(?:shells?|jobs?|process(?:es)?|pids?|agents?|subagents?|wakeups?|tien trinh|tac vu nen|background (?:tasks?|work)|crons?)\b/;
|
|
681
|
+
const STATE_LEAD = /\b(?:check|inspect|list|stop|cancel|kill|terminate|revoke|reclaim|kiem tra|liet ke|xac dinh|huy|thu hoi|ket thuc)\b/;
|
|
682
|
+
const STATE_ACTION = /\b(?:stop|cancel|kill|terminate|revoke|reclaim|dung|huy|thu hoi|ket thuc)\b/;
|
|
683
|
+
function statePlain(promptText) {
|
|
684
|
+
return String(promptText).normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[\u0111\u0110]/g, 'd').toLowerCase()
|
|
685
|
+
.replace(/```[\s\S]*?```/g, ' ').replace(/^[ \t]*>.*$/gm, ' ');
|
|
686
|
+
}
|
|
687
|
+
function isStateOperationRequest(promptText = '') {
|
|
688
|
+
const plain = statePlain(promptText);
|
|
689
|
+
if (!/\b(?:running|still|live|background|wakeups?|pids?|hung|stuck|orphan\w*|leftover|reclaim|chay|nen|treo|con sot|\d+\s+(?:shells?|jobs?|agents?|subagents?|process(?:es)?)|(?:job|task|shell|agent)\s+(?:id\s+)?[a-z0-9]*\d[a-z0-9]{5,})\b/.test(plain)) return false;
|
|
690
|
+
return plain.split(/[;!?\n]+|[.:](?=\s|$)/).some((clause) => {
|
|
691
|
+
const lead = clause.match(STATE_LEAD);
|
|
692
|
+
if (!lead) return false;
|
|
693
|
+
const after = clause.slice(lead.index + lead[0].length);
|
|
694
|
+
const near = after.match(/^(?:\s+[\p{L}\p{N}_-]+){0,5}?\s+/u);
|
|
695
|
+
const window = after.split(/\s+/).slice(0, 7).join(' ');
|
|
696
|
+
return near !== null && STATE_OBJECT.test(window);
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function stateOperationShape(promptText = '') {
|
|
701
|
+
const plain = statePlain(promptText);
|
|
702
|
+
const unquoted = plain.replace(/`[^`\n]*`|"[^"\n]*"|\u201c[^\u201d\n]*\u201d/g, ' ');
|
|
703
|
+
const targets = [...new Set((unquoted.match(/(?<![\w-])[a-z]*\d[a-z0-9]{7,}\b/g) || []).filter((id) => /[a-z]/.test(id)))].slice(0, 8);
|
|
704
|
+
let conditional = false;
|
|
705
|
+
let gated = false;
|
|
706
|
+
const action = plain.split(/[;!?\n]+|[.:](?=\s|$)|,\s*/).some((raw) => {
|
|
707
|
+
const clause = raw.replace(/^[\s*\-\d.)]+/, '').trim();
|
|
708
|
+
if (!clause) return false;
|
|
709
|
+
const conditionLead = /^(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause);
|
|
710
|
+
if (!conditionLead && /\b(?:khong|do not|don't|never|not)\b/.test(clause)) return false;
|
|
711
|
+
if (/\b(?:cho phep|allow(?:ed|s)?|permit(?:ted)?|authori[sz]ed?|you may|may stop|duoc phep)\b/.test(clause)) { gated = false; return false; }
|
|
712
|
+
const head = clause.split(/\s+/).slice(0, 3).join(' ');
|
|
713
|
+
if (/\b(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause)) {
|
|
714
|
+
const leadsWithCondition = /^(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/.test(clause);
|
|
715
|
+
const preCondition = leadsWithCondition ? '' : clause.split(/\b(?:if|when|unless|neu|khi|truoc khi|sau khi)\b/)[0].trim();
|
|
716
|
+
if (preCondition && /\b(?:and|va|then|roi)\s+(?:stop|cancel|kill|terminate|revoke|reclaim|dung|huy|thu hoi|ket thuc)\b/.test(preCondition)) { conditional = true; return false; }
|
|
717
|
+
const consequent = leadsWithCondition ? (/\s(?:then|thi)\s/.test(clause) ? clause.split(/\s(?:then|thi)\s/).pop() : '') : clause;
|
|
718
|
+
if (STATE_ACTION.test(consequent.split(/\s+/).slice(0, 3).join(' '))) { conditional = true; return false; }
|
|
719
|
+
gated = leadsWithCondition && !STATE_ACTION.test(consequent);
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
const wasGated = gated;
|
|
723
|
+
gated = false;
|
|
724
|
+
const stops = (wasGated ? STATE_ACTION.test(clause) : STATE_ACTION.test(head)) && (wasGated || STATE_OBJECT.test(clause));
|
|
725
|
+
if (stops && wasGated) { conditional = true; return false; }
|
|
726
|
+
return stops;
|
|
727
|
+
});
|
|
728
|
+
return { action, conditional: conditional && !action, targets };
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function classifySemanticText(input = {}) {
|
|
732
|
+
const semantic = classifySemanticCore(input);
|
|
733
|
+
if (semantic.taskKind !== 'READ_ONLY' || semantic.conditionalObligations || semantic.publication || !isStateOperationRequest(input.promptText)) return semantic;
|
|
734
|
+
const { verificationOnly: _verification, statusReport: _status, ...rest } = semantic;
|
|
735
|
+
const shape = stateOperationShape(input.promptText);
|
|
736
|
+
return { ...rest, stateVerification: true, ...(shape.action ? { stateAction: true } : shape.conditional ? { stateConditionalStop: true } : {}), ...(shape.targets.length ? { stateTargets: shape.targets } : {}) };
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function classifySemanticCore({ promptText = '', targetFile = '' } = {}) {
|
|
631
740
|
promptText = publicationScope(promptText).text;
|
|
632
741
|
const releaseText = String(promptText).normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/[đĐ]/g, 'd').toLowerCase();
|
|
633
742
|
const preflight = releaseText.match(/\b(?:yarn\s+release:verify|npm\s+run\s+release:verify)\b/)?.[0];
|
|
@@ -638,13 +747,13 @@ function classifySemanticText({ promptText = '', targetFile = '' } = {}) {
|
|
|
638
747
|
if (ordersPublicationText(promptText)) {
|
|
639
748
|
const implementation = hasExplicitOrder(clauses.filter((clause) => !/\b(?:release|publish)\b/.test(clause)));
|
|
640
749
|
const remaining = clauses.filter((clause) => !ordersPublicationText(clause) && !/\b(?:release|publish)\b/.test(clause)).join('; ');
|
|
641
|
-
const base = remaining.trim() ?
|
|
750
|
+
const base = remaining.trim() ? classifySemanticCore({ promptText: remaining, targetFile }) : {};
|
|
642
751
|
delete base.verificationOnly;
|
|
643
752
|
delete base.statusReport;
|
|
644
753
|
return { ...base, taskKind: implementation ? 'MIXED' : 'OPERATIONAL', publication: true, ...(releasePolicy ? { releasePolicy } : {}) };
|
|
645
754
|
}
|
|
646
755
|
if (!/[a-z0-9]/.test(text)) return { taskKind: 'READ_ONLY' };
|
|
647
|
-
if (declaredReadOnly(promptText, releasePolicy)) return { taskKind: 'READ_ONLY', ...(isVerificationOnlyRequest(promptText) ? { verificationOnly: true } : {}) };
|
|
756
|
+
if (declaredReadOnly(promptText, releasePolicy)) return { taskKind: 'READ_ONLY', ...(isVerificationOnlyRequest(promptText) && !bansTestRuns(promptText) ? { verificationOnly: true } : {}) };
|
|
648
757
|
const sourceOrder = actionable.some((clause) => /\b(?:implement|fix(?:es)?|apply|refactor|modify|edit|write|update|sua|viet|chinh)\b/.test(clause)
|
|
649
758
|
&& /\b(?:source|code|logic|scheduler|implementation|ma nguon)\b|\.[cm]?[jt]sx?\b/.test(clause));
|
|
650
759
|
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));
|
|
@@ -683,7 +792,7 @@ function classifySemanticText({ promptText = '', targetFile = '' } = {}) {
|
|
|
683
792
|
&& !/\.[cm]?[jt]sx?\b/.test(clause) && !/\bgit\b/.test(clause));
|
|
684
793
|
const nativeDomain = cronOperation ? 'scheduled-job' : gitOperation !== runtimeOperation ? (gitOperation ? 'git-integrity' : 'service-runtime') : null;
|
|
685
794
|
const operation = Boolean(nativeDomain);
|
|
686
|
-
if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', verificationOnly: true };
|
|
795
|
+
if (!releasePolicy && !operation && isVerificationOnlyRequest(promptText)) return { taskKind: 'READ_ONLY', ...(bansTestRuns(promptText) ? {} : { verificationOnly: true }) };
|
|
687
796
|
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/;
|
|
688
797
|
const CONFIG_MUTATION_VERB = /\b(?:set|change|toggle|enable|disable|switch|turn|configure|modify|update|edit|doi(?!\s+chieu\b)|bat(?!\s+dau\b)|tat(?!\s+ca\b)|chinh)\b/;
|
|
689
798
|
const CONFIG_NOUN = /\b(?:configuration|config|toggle|cau hinh)\b/;
|
|
@@ -736,6 +845,7 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
736
845
|
return { ...(contract || {}), ...semantic,
|
|
737
846
|
completionEvidence: semantic.taskKind === 'DOCUMENTATION_OUTPUT' ? ['report-artifact'] : operationOnly ? ['operation-verification']
|
|
738
847
|
: semantic.taskKind === 'MIXED' ? [...new Set([...evidence, 'write-evidence', 'operation-verification'])]
|
|
848
|
+
: semantic.taskKind === 'READ_ONLY' && semantic.stateVerification ? ['state-verification']
|
|
739
849
|
: semantic.taskKind === 'READ_ONLY' && semantic.statusReport ? []
|
|
740
850
|
: semantic.taskKind === 'READ_ONLY' ? (semantic.verificationOnly ? ['verification-evidence'] : ['impact-evidence'])
|
|
741
851
|
// A routed contract owns the debt; an unrouted (informational/null) turn carries none, because
|
|
@@ -959,6 +1069,9 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
959
1069
|
return tierLaneModule;
|
|
960
1070
|
}
|
|
961
1071
|
function writeTierLaneLines(summary, taskId) {
|
|
1072
|
+
if (summary?.playbookId === 'bug-fix') {
|
|
1073
|
+
process.stdout.write('[ukit-skill-router] Bug-fix evidence (include in any worker prompt): before editing, run the failing repro once and keep its failing result; after the fix re-run that same command and keep the passing result; state the root cause with UKIT_EVIDENCE="class=root-cause;claim=<mechanism>" on a Bash call. A worker\'s own runs count for this task only through its host-linked session.\n');
|
|
1074
|
+
}
|
|
962
1075
|
const lane = summary?.tierLane;
|
|
963
1076
|
if (!lane?.instruction) {
|
|
964
1077
|
return;
|
|
@@ -4094,6 +4207,7 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4094
4207
|
const compactState = { ...sharedState };
|
|
4095
4208
|
delete compactState.source;
|
|
4096
4209
|
delete compactState.ts;
|
|
4210
|
+
delete compactState.ownerControl; // STOP is per-session state, never a cached route fact
|
|
4097
4211
|
return compactState;
|
|
4098
4212
|
}
|
|
4099
4213
|
|
|
@@ -4186,6 +4300,9 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4186
4300
|
persisted.routingContext.mutationOrder = previous.routingContext.mutationOrder;
|
|
4187
4301
|
}
|
|
4188
4302
|
}
|
|
4303
|
+
// The STOP marker lives until the next genuine owner prompt re-routes (no TTL).
|
|
4304
|
+
if (ownerControlTurn) persisted.ownerControl = { kind: 'stop', sessionId, ts: Date.now() };
|
|
4305
|
+
else if (previous.ownerControl?.kind === 'stop' && (payload.tool_name || systemOriginTurn || !extractPrompt(payload).trim())) persisted.ownerControl = previous.ownerControl;
|
|
4189
4306
|
if (continuingTask && !persisted.suspendedContract && previous.suspendedContract) {
|
|
4190
4307
|
persisted.suspendedContract = previous.suspendedContract;
|
|
4191
4308
|
}
|
|
@@ -4195,7 +4312,7 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4195
4312
|
persisted.routeSummary ||= {};
|
|
4196
4313
|
persisted.routeSummary.executionContract = previous.routeSummary.executionContract;
|
|
4197
4314
|
persisted.contractOrigin = 'carried-system';
|
|
4198
|
-
for (const key of ['expectedSourceFiles', 'completionState', 'continuationState', 'executionMode']) {
|
|
4315
|
+
for (const key of ['expectedSourceFiles', 'expectedSourceProvenance', 'completionState', 'continuationState', 'executionMode']) {
|
|
4199
4316
|
if (previous.routeSummary[key] !== undefined) persisted.routeSummary[key] = previous.routeSummary[key];
|
|
4200
4317
|
else delete persisted.routeSummary[key];
|
|
4201
4318
|
}
|
|
@@ -4319,7 +4436,7 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4319
4436
|
persisted.requestKey = previous.requestKey;
|
|
4320
4437
|
persisted.routingContext = { ...previous.routingContext };
|
|
4321
4438
|
persisted.routeSummary ||= {};
|
|
4322
|
-
for (const key of ['executionContract', 'expectedSourceFiles', 'completionState', 'continuationState', 'executionMode']) {
|
|
4439
|
+
for (const key of ['executionContract', 'expectedSourceFiles', 'expectedSourceProvenance', 'completionState', 'continuationState', 'executionMode']) {
|
|
4323
4440
|
if (previous.routeSummary[key] !== undefined) persisted.routeSummary[key] = previous.routeSummary[key];
|
|
4324
4441
|
else delete persisted.routeSummary[key];
|
|
4325
4442
|
}
|
|
@@ -4451,9 +4568,13 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4451
4568
|
} catch { boundGateContinuation = false; }
|
|
4452
4569
|
}
|
|
4453
4570
|
}
|
|
4571
|
+
const ownerControlTurn = Boolean(sessionId && promptOrigin !== 'system' && !boundGateContinuation && !payload.tool_name
|
|
4572
|
+
&& (classifyOwnerControl(extractPrompt(payload)).kind === 'stop'
|
|
4573
|
+
|| (payload.ukit_harness === 'omp' && payload.ukit_owner_input === 'contains-stop')));
|
|
4454
4574
|
const systemOriginTurn = (() => {
|
|
4455
4575
|
const promptTrim = extractPrompt(payload).trim();
|
|
4456
4576
|
if (!promptTrim) return false;
|
|
4577
|
+
if (ownerControlTurn && previous.taskInstanceId) return true;
|
|
4457
4578
|
if (/^This session is being continued from a previous conversation/i.test(promptTrim)) return true;
|
|
4458
4579
|
// Bridge-owned metadata only (ukit-bridge.js maps the host's session-stop-continuation
|
|
4459
4580
|
// attribution); an arbitrary prompt prefix proves nothing and is never trusted here.
|
|
@@ -4638,7 +4759,18 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4638
4759
|
const handoffExpansion = payload.hook_event_name === 'UserPromptExpansion'
|
|
4639
4760
|
&& payload.expansion_type === 'slash_command'
|
|
4640
4761
|
&& /^(?:ukit:)?handoff-fullstack$/.test(String(payload.command_name || ''));
|
|
4641
|
-
const
|
|
4762
|
+
const ownerResumeTurn = (() => {
|
|
4763
|
+
if (previous.ownerControl?.kind !== 'stop' || previous.ownerControl.sessionId !== sessionId || !sessionId || !previous.taskInstanceId
|
|
4764
|
+
|| payload.tool_name || promptOrigin === 'system' || ownerControlTurn) return false;
|
|
4765
|
+
const fold = (text) => String(text ?? '').normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/\u0111/gi, 'd').toLowerCase();
|
|
4766
|
+
const body = fold(extractPrompt(payload)).trim();
|
|
4767
|
+
if (!/^(?:continue|resume|keep going|proceed|tiep tuc|lam tiep)\s*[:,\u2013\u2014-]\s*\S/.test(body)) return false;
|
|
4768
|
+
const targets = (text) => new Set(fold(text).match(/[\w.-]+\/[\w./-]+|[\w-]+\.[a-z][a-z0-9]{0,7}\b/g) || []);
|
|
4769
|
+
const wanted = targets(body);
|
|
4770
|
+
const owned = targets(previous.routingContext?.lastExplicitUserPromptText);
|
|
4771
|
+
return wanted.size > 0 && [...wanted].every((target) => owned.has(target));
|
|
4772
|
+
})();
|
|
4773
|
+
const continuingTask = Boolean(previous.taskInstanceId && (payload.tool_name || handoffExpansion || continuationPrompt || ownerResumeTurn || systemOriginTurn || guidanceTurn));
|
|
4642
4774
|
let taskInstanceId = continuingTask
|
|
4643
4775
|
? previous.taskInstanceId
|
|
4644
4776
|
: `task-${crypto.randomBytes(16).toString("hex")}`;
|
|
@@ -4648,6 +4780,34 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
4648
4780
|
// not reroute or overwrite the current task as if they were user prompts.
|
|
4649
4781
|
if (payload.tool_name === 'Skill' && !handoffSkill) process.exit(0);
|
|
4650
4782
|
let handoffRunId = continuingTask ? previous.handoffRunId : null;
|
|
4783
|
+
const HOOK_SHAPED_PROMPT = /^\s*(?:UKit completion gate:|UKit handoff|\[ukit-[\w-]+\]|\[ukit\]\s)/;
|
|
4784
|
+
if (previous.ownerControl?.kind === 'stop' && !payload.tool_name && (!extractPrompt(payload).trim() || HOOK_SHAPED_PROMPT.test(extractPrompt(payload)))) process.exit(0);
|
|
4785
|
+
if (previous.ownerControl?.kind === 'stop' && !payload.tool_name && payload.ukit_harness === 'omp'
|
|
4786
|
+
&& (payload.ukit_owner_input === 'before-stop' || payload.ukit_owner_input === 'unproven') && extractPrompt(payload).trim()) process.exit(0);
|
|
4787
|
+
if (!payload.tool_name && !systemOriginTurn) {
|
|
4788
|
+
const hookText = extractPrompt(payload);
|
|
4789
|
+
let inertHook = /^\s*\[ukit-[\w-]+\]/.test(hookText);
|
|
4790
|
+
if (!inertHook && /^UKit completion gate:/.test(hookText.trim())) {
|
|
4791
|
+
try {
|
|
4792
|
+
inertHook = (await import(pathToFileURL(path.join(projectRoot, '.claude', 'ukit', 'runtime', 'execution-ledger.mjs')).href)).isCompletionGateContinuationText(hookText);
|
|
4793
|
+
} catch { inertHook = true; }
|
|
4794
|
+
}
|
|
4795
|
+
if (inertHook) process.exit(0);
|
|
4796
|
+
}
|
|
4797
|
+
if (ownerControlTurn) {
|
|
4798
|
+
const priorPrompt = previous.routingContext?.lastExplicitUserPromptText || '';
|
|
4799
|
+
await ensureDir(statePath);
|
|
4800
|
+
await persistRouteState(JSON.stringify({
|
|
4801
|
+
...(sessionId ? { sessionId } : {}),
|
|
4802
|
+
ts: Date.now(),
|
|
4803
|
+
source: 'skill-router-owner-control',
|
|
4804
|
+
activeSkills: [],
|
|
4805
|
+
routingContext: compactRoutingContext({ promptText: '', lastExplicitUserPromptText: priorPrompt, commandText: '', targetFile: '', contextIntent: '', taskType: '', mutationOrder: typeof previous.routingContext?.mutationOrder === 'boolean' ? previous.routingContext.mutationOrder : null, planOnly: null }),
|
|
4806
|
+
...(previous.routeSummary ? { routeSummary: previous.routeSummary } : {}),
|
|
4807
|
+
...(previous.requestKey ? { requestKey: previous.requestKey } : {}),
|
|
4808
|
+
}));
|
|
4809
|
+
process.exit(0);
|
|
4810
|
+
}
|
|
4651
4811
|
const denyHandoff = (reason) => {
|
|
4652
4812
|
const message = `UKit handoff resume BLOCKED: ${reason}; cursor untouched.`;
|
|
4653
4813
|
process.stdout.write(JSON.stringify(handoffExpansion
|
|
@@ -5185,6 +5345,7 @@ function applyTaskSemantics(contract, semantic) {
|
|
|
5185
5345
|
ts: now,
|
|
5186
5346
|
requestKey,
|
|
5187
5347
|
routeSummary: rescuedRouteSummary,
|
|
5348
|
+
ownerControl: undefined,
|
|
5188
5349
|
};
|
|
5189
5350
|
reusedState.fingerprint = buildRouteStateFingerprint(reusedState);
|
|
5190
5351
|
|
|
@@ -59,6 +59,16 @@
|
|
|
59
59
|
},
|
|
60
60
|
"hooks": {
|
|
61
61
|
"PreToolUse": [
|
|
62
|
+
{
|
|
63
|
+
"matcher": ".*",
|
|
64
|
+
"hooks": [
|
|
65
|
+
{
|
|
66
|
+
"type": "command",
|
|
67
|
+
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/ukit/runtime/hook-chain-runner.mjs\" --emit-verdict - \"$CLAUDE_PROJECT_DIR/.claude/hooks/owner-stop-gate.mjs\":5",
|
|
68
|
+
"timeout": 15
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
62
72
|
{
|
|
63
73
|
"matcher": "Read|Grep|Glob",
|
|
64
74
|
"hooks": [
|
|
@@ -112,7 +122,7 @@
|
|
|
112
122
|
],
|
|
113
123
|
"PostToolUse": [
|
|
114
124
|
{
|
|
115
|
-
"matcher": "CronDelete|CronList",
|
|
125
|
+
"matcher": "CronDelete|CronList|TaskStop|TaskOutput",
|
|
116
126
|
"hooks": [
|
|
117
127
|
{
|
|
118
128
|
"type": "command",
|