project-tiny-context-harness 0.6.2 → 0.7.1
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/LICENSE +21 -21
- package/README.md +342 -333
- package/assets/README.md +497 -487
- package/assets/README.zh-CN.md +266 -256
- package/assets/agents/.gitkeep +1 -1
- package/assets/agents/AGENTS_CORE.md +56 -56
- package/assets/context_templates/architecture.md +33 -33
- package/assets/context_templates/area.md +39 -39
- package/assets/context_templates/context.toml +30 -30
- package/assets/context_templates/deployment.md +35 -35
- package/assets/context_templates/global.md +55 -55
- package/assets/context_templates/product-surface-contract.md +63 -63
- package/assets/context_templates/verification.md +32 -32
- package/assets/github/.gitkeep +1 -1
- package/assets/github/harness.yml +41 -41
- package/assets/make/.gitkeep +1 -1
- package/assets/make/ty-context.mk +48 -48
- package/assets/skills/context_development_engineer/SKILL.md +90 -90
- package/assets/skills/context_full_project_export/SKILL.md +70 -70
- package/assets/skills/context_harness_upgrade/SKILL.md +60 -60
- package/assets/skills/context_product_plan/SKILL.md +77 -77
- package/assets/skills/context_surface_contract/SKILL.md +171 -171
- package/assets/skills/context_uiux_design/SKILL.md +99 -99
- package/assets/skills/long-task-workflow/SKILL.md +75 -71
- package/assets/skills/long-task-workflow/agents/openai.yaml +4 -4
- package/assets/skills/long-task-workflow/references/authority-lifecycle.md +53 -41
- package/assets/skills/long-task-workflow/references/contract-authoring.md +57 -43
- package/assets/skills/long-task-workflow/references/evidence-design.md +40 -32
- package/assets/skills/normal-long-task/SKILL.md +12 -12
- package/assets/skills/source-plan-authoring/SKILL.md +295 -295
- package/dist/commands/check-modularity.js +10 -10
- package/dist/commands/long-task-authoring.js +65 -65
- package/dist/commands/long-task-command-args.d.ts +3 -0
- package/dist/commands/long-task-command-args.js +20 -0
- package/dist/commands/long-task-revision.d.ts +1 -0
- package/dist/commands/long-task-revision.js +137 -0
- package/dist/commands/long-task.js +20 -120
- package/dist/lib/long-task-authority-revision-details.d.ts +2 -0
- package/dist/lib/long-task-authority-revision-details.js +10 -0
- package/dist/lib/long-task-authority-revision-diagnosis.d.ts +24 -0
- package/dist/lib/long-task-authority-revision-diagnosis.js +141 -0
- package/dist/lib/long-task-authority-revision-enforcement.d.ts +3 -1
- package/dist/lib/long-task-authority-revision-enforcement.js +17 -9
- package/dist/lib/long-task-authority-revision-summary.d.ts +11 -0
- package/dist/lib/long-task-authority-revision-summary.js +99 -0
- package/dist/lib/long-task-authority-revision-types.d.ts +44 -1
- package/dist/lib/long-task-authority-revision.js +9 -1
- package/dist/lib/long-task-delivery-compiler.d.ts +3 -0
- package/dist/lib/long-task-delivery-compiler.js +5 -2
- package/dist/lib/long-task-state.d.ts +3 -15
- package/dist/lib/long-task-status-v2.d.ts +2 -0
- package/dist/lib/long-task-status-v2.js +12 -2
- package/dist/lib/long-task-verifier-v2.d.ts +4 -0
- package/dist/lib/long-task-verifier-v2.js +1 -1
- package/migrations/README.md +8 -8
- package/package.json +5 -1
- package/source-mappings.yaml +25 -25
|
@@ -154,15 +154,15 @@ function parseLimit(value) {
|
|
|
154
154
|
return limit;
|
|
155
155
|
}
|
|
156
156
|
function helpText() {
|
|
157
|
-
return `ty-context check-modularity:
|
|
158
|
-
check-modularity --touched [--limit 300] [--fail-on-warning]
|
|
159
|
-
check-modularity --file <path> [--file <path> ...] [--limit 300] [--fail-on-warning]
|
|
160
|
-
check-modularity --base <ref> [--limit 300] [--fail-on-warning]
|
|
161
|
-
check-modularity --config-only
|
|
162
|
-
|
|
163
|
-
Audits physical lines, per-function statements and branch complexity, exports, state transitions and module responsibilities.
|
|
164
|
-
For --touched and --base, existing findings are reported but only new or worsened non-line complexity is a warning; physical lines remain a risk signal and new files are audited in full.
|
|
165
|
-
The default is warning-only; --fail-on-warning lets projects opt into CI enforcement.
|
|
166
|
-
Generated configs default to modularity.policy: strict_except_generated; omitted policy is treated as scoped_waivers for compatibility.
|
|
157
|
+
return `ty-context check-modularity:
|
|
158
|
+
check-modularity --touched [--limit 300] [--fail-on-warning]
|
|
159
|
+
check-modularity --file <path> [--file <path> ...] [--limit 300] [--fail-on-warning]
|
|
160
|
+
check-modularity --base <ref> [--limit 300] [--fail-on-warning]
|
|
161
|
+
check-modularity --config-only
|
|
162
|
+
|
|
163
|
+
Audits physical lines, per-function statements and branch complexity, exports, state transitions and module responsibilities.
|
|
164
|
+
For --touched and --base, existing findings are reported but only new or worsened non-line complexity is a warning; physical lines remain a risk signal and new files are audited in full.
|
|
165
|
+
The default is warning-only; --fail-on-warning lets projects opt into CI enforcement.
|
|
166
|
+
Generated configs default to modularity.policy: strict_except_generated; omitted policy is treated as scoped_waivers for compatibility.
|
|
167
167
|
Risks can be waived only through lifecycle-complete <harnessRoot>/config.yaml modularity.waivers when policy is scoped_waivers.`;
|
|
168
168
|
}
|
|
@@ -23,70 +23,70 @@ export function compactLongTaskTemplate() {
|
|
|
23
23
|
return template();
|
|
24
24
|
}
|
|
25
25
|
function template() {
|
|
26
|
-
return `schema_version: long-task-delivery-v2
|
|
27
|
-
task:
|
|
28
|
-
id: replace-me
|
|
29
|
-
title: Replace me
|
|
30
|
-
goal: Describe the complete observable delivery goal.
|
|
31
|
-
source_paths: [plans/replace-me.md]
|
|
32
|
-
context_refs: [project_context/areas/replace-me.md]
|
|
33
|
-
source_claims:
|
|
34
|
-
- key: replace-requirement
|
|
35
|
-
source_ref: plans/replace-me.md#replace-requirement
|
|
36
|
-
statement: Preserve one atomic source requirement.
|
|
37
|
-
disposition:
|
|
38
|
-
type: claim
|
|
39
|
-
refs: [replace-outcome.requirement.replace-requirement]
|
|
40
|
-
risk:
|
|
41
|
-
facts: {}
|
|
42
|
-
global: {}
|
|
43
|
-
outcomes:
|
|
44
|
-
- key: replace-outcome
|
|
45
|
-
title: Replace outcome
|
|
46
|
-
product:
|
|
47
|
-
observable_result: Describe what a user or system can observe.
|
|
48
|
-
owner:
|
|
49
|
-
label: replace-owner
|
|
50
|
-
context_refs: [project_context/areas/replace-me.md]
|
|
51
|
-
path_globs: ["src/**", "tests/**"]
|
|
52
|
-
requirements:
|
|
53
|
-
- key: replace-requirement
|
|
54
|
-
statement: Preserve one atomic source requirement.
|
|
55
|
-
required_proof_surfaces: [runtime_behavior]
|
|
56
|
-
technical:
|
|
57
|
-
expected_change_paths: ["src/**"]
|
|
58
|
-
bindings:
|
|
59
|
-
- key: replace-carrier
|
|
60
|
-
kind: file
|
|
61
|
-
target: src/replace-me.ts
|
|
62
|
-
carrier_paths: [src/replace-me.ts]
|
|
63
|
-
existence: planned
|
|
64
|
-
acceptance:
|
|
65
|
-
checks:
|
|
66
|
-
- key: replace-check
|
|
67
|
-
proof_surface: runtime_behavior
|
|
68
|
-
runner:
|
|
69
|
-
type: node_oracle
|
|
70
|
-
target: tests/replace-oracle.mjs
|
|
71
|
-
effect: read_only
|
|
72
|
-
verification_inputs: ["tests/replace-oracle.mjs"]
|
|
73
|
-
input_paths: [src/replace-me.ts]
|
|
74
|
-
expected_output_paths: [src/replace-me.ts]
|
|
75
|
-
positive_assertions:
|
|
76
|
-
- key: replace-success
|
|
77
|
-
criterion: The declared outcome and requirement are observable.
|
|
78
|
-
claims: [result, requirement.replace-requirement]
|
|
79
|
-
observation: result
|
|
80
|
-
operator: equals
|
|
81
|
-
expected: true
|
|
82
|
-
counterfactual_controls:
|
|
83
|
-
- key: remove-replace-carrier
|
|
84
|
-
binding_key: replace-carrier
|
|
85
|
-
claims: [result, requirement.replace-requirement]
|
|
86
|
-
check_key: replace-check
|
|
87
|
-
mutation:
|
|
88
|
-
type: remove_paths
|
|
89
|
-
paths: [src/replace-me.ts]
|
|
90
|
-
expected_assertion_failures: [replace-success]
|
|
26
|
+
return `schema_version: long-task-delivery-v2
|
|
27
|
+
task:
|
|
28
|
+
id: replace-me
|
|
29
|
+
title: Replace me
|
|
30
|
+
goal: Describe the complete observable delivery goal.
|
|
31
|
+
source_paths: [plans/replace-me.md]
|
|
32
|
+
context_refs: [project_context/areas/replace-me.md]
|
|
33
|
+
source_claims:
|
|
34
|
+
- key: replace-requirement
|
|
35
|
+
source_ref: plans/replace-me.md#replace-requirement
|
|
36
|
+
statement: Preserve one atomic source requirement.
|
|
37
|
+
disposition:
|
|
38
|
+
type: claim
|
|
39
|
+
refs: [replace-outcome.requirement.replace-requirement]
|
|
40
|
+
risk:
|
|
41
|
+
facts: {}
|
|
42
|
+
global: {}
|
|
43
|
+
outcomes:
|
|
44
|
+
- key: replace-outcome
|
|
45
|
+
title: Replace outcome
|
|
46
|
+
product:
|
|
47
|
+
observable_result: Describe what a user or system can observe.
|
|
48
|
+
owner:
|
|
49
|
+
label: replace-owner
|
|
50
|
+
context_refs: [project_context/areas/replace-me.md]
|
|
51
|
+
path_globs: ["src/**", "tests/**"]
|
|
52
|
+
requirements:
|
|
53
|
+
- key: replace-requirement
|
|
54
|
+
statement: Preserve one atomic source requirement.
|
|
55
|
+
required_proof_surfaces: [runtime_behavior]
|
|
56
|
+
technical:
|
|
57
|
+
expected_change_paths: ["src/**"]
|
|
58
|
+
bindings:
|
|
59
|
+
- key: replace-carrier
|
|
60
|
+
kind: file
|
|
61
|
+
target: src/replace-me.ts
|
|
62
|
+
carrier_paths: [src/replace-me.ts]
|
|
63
|
+
existence: planned
|
|
64
|
+
acceptance:
|
|
65
|
+
checks:
|
|
66
|
+
- key: replace-check
|
|
67
|
+
proof_surface: runtime_behavior
|
|
68
|
+
runner:
|
|
69
|
+
type: node_oracle
|
|
70
|
+
target: tests/replace-oracle.mjs
|
|
71
|
+
effect: read_only
|
|
72
|
+
verification_inputs: ["tests/replace-oracle.mjs"]
|
|
73
|
+
input_paths: [src/replace-me.ts]
|
|
74
|
+
expected_output_paths: [src/replace-me.ts]
|
|
75
|
+
positive_assertions:
|
|
76
|
+
- key: replace-success
|
|
77
|
+
criterion: The declared outcome and requirement are observable.
|
|
78
|
+
claims: [result, requirement.replace-requirement]
|
|
79
|
+
observation: result
|
|
80
|
+
operator: equals
|
|
81
|
+
expected: true
|
|
82
|
+
counterfactual_controls:
|
|
83
|
+
- key: remove-replace-carrier
|
|
84
|
+
binding_key: replace-carrier
|
|
85
|
+
claims: [result, requirement.replace-requirement]
|
|
86
|
+
check_key: replace-check
|
|
87
|
+
mutation:
|
|
88
|
+
type: remove_paths
|
|
89
|
+
paths: [src/replace-me.ts]
|
|
90
|
+
expected_assertion_failures: [replace-success]
|
|
91
91
|
`;
|
|
92
92
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function option(args, name) {
|
|
2
|
+
const indexes = args.flatMap((value, index) => value === name ? [index] : []);
|
|
3
|
+
if (indexes.length > 1)
|
|
4
|
+
throw new Error(`duplicate option: ${name}`);
|
|
5
|
+
if (!indexes.length)
|
|
6
|
+
return undefined;
|
|
7
|
+
const value = args[indexes[0] + 1];
|
|
8
|
+
if (!value || value.startsWith("--"))
|
|
9
|
+
throw new Error(`${name} requires a value`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
export function rejectOptions(args, allowed) {
|
|
13
|
+
for (let index = 0; index < args.length; index += 2)
|
|
14
|
+
if (!allowed.includes(args[index]) || !args[index + 1])
|
|
15
|
+
throw new Error(`Unknown or injected arguments: ${args.join(" ")}`);
|
|
16
|
+
}
|
|
17
|
+
export function rejectUnknown(actual, allowed) {
|
|
18
|
+
if (actual.join("\0") !== allowed.join("\0"))
|
|
19
|
+
throw new Error(`Unknown or injected arguments: ${actual.join(" ")}`);
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleLongTaskRevisionCommand(subcommand: string, workdir: string, args: string[]): Promise<boolean>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { diagnoseAuthorityRevision } from "../lib/long-task-authority-revision-diagnosis.js";
|
|
3
|
+
import { projectAuthorityRevisionDecision } from "../lib/long-task-authority-revision-summary.js";
|
|
4
|
+
import { canRetainProgressForSupportingContextRevision } from "../lib/long-task-context-authority.js";
|
|
5
|
+
import { compileDeliveryContract } from "../lib/long-task-delivery-compiler.js";
|
|
6
|
+
import { approvePendingAuthorityRevision, clearFinalReceipt, clearAuthorityRevision, commitActiveAuthority, invalidateDerivedProgress, loadActiveLongTaskAuthority, readPendingAuthorityRevision, stageCompiledDeliveryContract, } from "../lib/long-task-state.js";
|
|
7
|
+
import { repositoryRoot } from "../lib/long-task-workspace.js";
|
|
8
|
+
import { option, rejectOptions } from "./long-task-command-args.js";
|
|
9
|
+
export async function handleLongTaskRevisionCommand(subcommand, workdir, args) {
|
|
10
|
+
if (subcommand === "compile")
|
|
11
|
+
await compile(workdir, args);
|
|
12
|
+
else if (subcommand === "diagnose-revision")
|
|
13
|
+
await diagnoseRevision(workdir, args);
|
|
14
|
+
else if (subcommand === "approve-authority-revision")
|
|
15
|
+
await approveRevision(workdir, args);
|
|
16
|
+
else
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
async function compile(workdir, args) {
|
|
21
|
+
const revise = args.length === 1 && args[0] === "--revise";
|
|
22
|
+
if (args.length && !revise)
|
|
23
|
+
throw new Error(`Unknown or injected arguments: ${args.join(" ")}`);
|
|
24
|
+
const root = await repositoryRoot(process.cwd());
|
|
25
|
+
const loaded = await loadActiveLongTaskAuthority(root, {
|
|
26
|
+
migrate_legacy: true,
|
|
27
|
+
});
|
|
28
|
+
const previous = loaded.authority?.authority_snapshot ?? null;
|
|
29
|
+
if (loaded.authority && loaded.authority.workdir !== path.resolve(workdir))
|
|
30
|
+
throw new Error(`active_task_exists:${loaded.authority.workdir}`);
|
|
31
|
+
const revisionCapture = {
|
|
32
|
+
proposal: null,
|
|
33
|
+
};
|
|
34
|
+
const compiled = await compileForCommand(workdir, revise, previous, revisionCapture);
|
|
35
|
+
if (loaded.authority && loaded.authority.task_id !== compiled.task.id)
|
|
36
|
+
throw new Error(`active_task_exists:${loaded.authority.workdir}`);
|
|
37
|
+
const preserveProgress = previous !== null &&
|
|
38
|
+
canRetainProgressForSupportingContextRevision(previous, compiled);
|
|
39
|
+
const stagedCache = await stageCompiledDeliveryContract(compiled);
|
|
40
|
+
let authorityCommitted = false;
|
|
41
|
+
try {
|
|
42
|
+
await commitActiveAuthority({
|
|
43
|
+
candidate: compiled,
|
|
44
|
+
expected_previous_identity: loaded.authority?.active_authority_identity ?? null,
|
|
45
|
+
});
|
|
46
|
+
authorityCommitted = true;
|
|
47
|
+
try {
|
|
48
|
+
await stagedCache.publish();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
await stagedCache.discard();
|
|
52
|
+
throw new Error(`compiled_cache_projection_publish_failed:${message(error)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (!authorityCommitted)
|
|
57
|
+
await stagedCache.discard();
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
if (!previous || previous.compiled_identity !== compiled.compiled_identity) {
|
|
61
|
+
if (!preserveProgress)
|
|
62
|
+
await invalidateDerivedProgress(workdir);
|
|
63
|
+
await clearFinalReceipt(compiled.repository_root, workdir);
|
|
64
|
+
}
|
|
65
|
+
await clearAuthorityRevision(workdir);
|
|
66
|
+
console.log(JSON.stringify({
|
|
67
|
+
status: "compiled",
|
|
68
|
+
task_id: compiled.task.id,
|
|
69
|
+
compiled_identity: compiled.compiled_identity,
|
|
70
|
+
authority_revision: compiled.authority_revision,
|
|
71
|
+
effective_risk: compiled.effective_risk,
|
|
72
|
+
outcomes: compiled.outcomes.map((outcome) => outcome.key),
|
|
73
|
+
claim_coverage: compiled.claim_coverage,
|
|
74
|
+
progress_preserved: preserveProgress,
|
|
75
|
+
authority_revision_change: revisionCapture.proposal
|
|
76
|
+
? projectAuthorityRevisionDecision(revisionCapture.proposal)
|
|
77
|
+
: null,
|
|
78
|
+
execution_model_checkpoint: executionModelCheckpoint(previous === null),
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
async function compileForCommand(workdir, revise, previous, capture) {
|
|
82
|
+
try {
|
|
83
|
+
return await compileDeliveryContract(workdir, process.cwd(), {
|
|
84
|
+
revise,
|
|
85
|
+
previous_authority: previous,
|
|
86
|
+
on_authority_revision(value) {
|
|
87
|
+
capture.proposal = value;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (message(error).startsWith("authority_change_requires_user_decision:"))
|
|
93
|
+
await printPendingDecision(workdir, previous);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function printPendingDecision(workdir, previous) {
|
|
98
|
+
const pending = await readPendingAuthorityRevision(workdir);
|
|
99
|
+
if (!pending)
|
|
100
|
+
throw new Error("authority_revision_pending_state_missing");
|
|
101
|
+
console.log(JSON.stringify({
|
|
102
|
+
status: "authority_revision_pending",
|
|
103
|
+
acceptance_authorized: false,
|
|
104
|
+
active_compiled_identity: previous?.compiled_identity ?? null,
|
|
105
|
+
pending_authority_revision: projectAuthorityRevisionDecision(pending),
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
async function diagnoseRevision(workdir, args) {
|
|
109
|
+
const outcome = option(args, "--outcome");
|
|
110
|
+
const check = option(args, "--check");
|
|
111
|
+
rejectOptions(args, ["--outcome", "--check"]);
|
|
112
|
+
const result = await diagnoseAuthorityRevision(workdir, { outcome, check });
|
|
113
|
+
console.log(JSON.stringify(result));
|
|
114
|
+
if (result.findings.length)
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
}
|
|
117
|
+
async function approveRevision(workdir, args) {
|
|
118
|
+
const revision = option(args, "--revision");
|
|
119
|
+
rejectOptions(args, ["--revision"]);
|
|
120
|
+
if (!revision)
|
|
121
|
+
throw new Error("--revision requires a value");
|
|
122
|
+
await approvePendingAuthorityRevision(workdir, revision);
|
|
123
|
+
console.log(JSON.stringify({ status: "authority_revision_approved", revision }));
|
|
124
|
+
}
|
|
125
|
+
function executionModelCheckpoint(firstAuthorityLock) {
|
|
126
|
+
if (!firstAuthorityLock)
|
|
127
|
+
return { required: false };
|
|
128
|
+
return {
|
|
129
|
+
required: true,
|
|
130
|
+
phase: "post_authority_lock_pre_implementation",
|
|
131
|
+
options: ["continue_current_model", "switch_model_then_resume"],
|
|
132
|
+
message: "Authority Lock created. Pause before implementation and ask the user whether to continue with the current model or switch models, then resume this active Long-Task.",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function message(error) {
|
|
136
|
+
return error instanceof Error ? error.message : String(error);
|
|
137
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { canRetainProgressForSupportingContextRevision } from "../lib/long-task-context-authority.js";
|
|
3
|
-
import { compileDeliveryContract } from "../lib/long-task-delivery-compiler.js";
|
|
4
2
|
import { runDeliveryFinalGate } from "../lib/long-task-final-v2.js";
|
|
5
3
|
import { closeDeliveryTask, doctorDeliveryTask, readDeliveryStatus, resumeDeliveryTask, stopCheckDeliveryTask, } from "../lib/long-task-status-v2.js";
|
|
6
|
-
import { abandonLongTaskState,
|
|
4
|
+
import { abandonLongTaskState, forceClearCorruptActiveState, } from "../lib/long-task-state.js";
|
|
7
5
|
import { verifyDeliveryContract } from "../lib/long-task-verifier-v2.js";
|
|
8
6
|
import { repositoryRoot } from "../lib/long-task-workspace.js";
|
|
9
7
|
import { initializeLongTask, preflightLongTask, } from "./long-task-authoring.js";
|
|
8
|
+
import { option, rejectOptions, rejectUnknown, } from "./long-task-command-args.js";
|
|
10
9
|
import { explainLongTask } from "./long-task-explain.js";
|
|
10
|
+
import { handleLongTaskRevisionCommand } from "./long-task-revision.js";
|
|
11
11
|
export async function longTask(args) {
|
|
12
12
|
const subcommand = args[0] ?? "help";
|
|
13
13
|
if (subcommand === "help")
|
|
@@ -26,10 +26,8 @@ export async function longTask(args) {
|
|
|
26
26
|
rejectUnknown(args.slice(2), []);
|
|
27
27
|
return preflightLongTask(workdir);
|
|
28
28
|
}
|
|
29
|
-
if (subcommand
|
|
30
|
-
return
|
|
31
|
-
if (subcommand === "approve-authority-revision")
|
|
32
|
-
return approveRevision(workdir, args.slice(2));
|
|
29
|
+
if (await handleLongTaskRevisionCommand(subcommand, workdir, args.slice(2)))
|
|
30
|
+
return;
|
|
33
31
|
if (subcommand === "explain") {
|
|
34
32
|
rejectUnknown(args.slice(2), []);
|
|
35
33
|
return explainLongTask(workdir);
|
|
@@ -91,85 +89,6 @@ export async function longTask(args) {
|
|
|
91
89
|
}
|
|
92
90
|
throw new Error(`Unknown long-task subcommand: ${subcommand}`);
|
|
93
91
|
}
|
|
94
|
-
async function compile(workdir, args) {
|
|
95
|
-
const revise = args.length === 1 && args[0] === "--revise";
|
|
96
|
-
if (args.length && !revise)
|
|
97
|
-
throw new Error(`Unknown or injected arguments: ${args.join(" ")}`);
|
|
98
|
-
const root = await repositoryRoot(process.cwd());
|
|
99
|
-
const loaded = await loadActiveLongTaskAuthority(root, {
|
|
100
|
-
migrate_legacy: true,
|
|
101
|
-
});
|
|
102
|
-
const previous = loaded.authority?.authority_snapshot ?? null;
|
|
103
|
-
if (loaded.authority && loaded.authority.workdir !== path.resolve(workdir))
|
|
104
|
-
throw new Error(`active_task_exists:${loaded.authority.workdir}`);
|
|
105
|
-
const compiled = await compileDeliveryContract(workdir, process.cwd(), {
|
|
106
|
-
revise,
|
|
107
|
-
previous_authority: previous,
|
|
108
|
-
});
|
|
109
|
-
if (loaded.authority && loaded.authority.task_id !== compiled.task.id)
|
|
110
|
-
throw new Error(`active_task_exists:${loaded.authority.workdir}`);
|
|
111
|
-
const preserveProgress = previous !== null &&
|
|
112
|
-
canRetainProgressForSupportingContextRevision(previous, compiled);
|
|
113
|
-
const stagedCache = await stageCompiledDeliveryContract(compiled);
|
|
114
|
-
let authorityCommitted = false;
|
|
115
|
-
try {
|
|
116
|
-
await commitActiveAuthority({
|
|
117
|
-
candidate: compiled,
|
|
118
|
-
expected_previous_identity: loaded.authority?.active_authority_identity ?? null,
|
|
119
|
-
});
|
|
120
|
-
authorityCommitted = true;
|
|
121
|
-
try {
|
|
122
|
-
await stagedCache.publish();
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
await stagedCache.discard();
|
|
126
|
-
throw new Error(`compiled_cache_projection_publish_failed:${message(error)}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
if (!authorityCommitted)
|
|
131
|
-
await stagedCache.discard();
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
if (!previous || previous.compiled_identity !== compiled.compiled_identity) {
|
|
135
|
-
if (!preserveProgress)
|
|
136
|
-
await invalidateDerivedProgress(workdir);
|
|
137
|
-
await clearFinalReceipt(compiled.repository_root, workdir);
|
|
138
|
-
}
|
|
139
|
-
await clearAuthorityRevision(workdir);
|
|
140
|
-
console.log(JSON.stringify({
|
|
141
|
-
status: "compiled",
|
|
142
|
-
task_id: compiled.task.id,
|
|
143
|
-
compiled_identity: compiled.compiled_identity,
|
|
144
|
-
authority_revision: compiled.authority_revision,
|
|
145
|
-
effective_risk: compiled.effective_risk,
|
|
146
|
-
outcomes: compiled.outcomes.map((outcome) => outcome.key),
|
|
147
|
-
claim_coverage: compiled.claim_coverage,
|
|
148
|
-
progress_preserved: preserveProgress,
|
|
149
|
-
execution_model_checkpoint: executionModelCheckpoint(previous === null),
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
function executionModelCheckpoint(firstAuthorityLock) {
|
|
153
|
-
if (!firstAuthorityLock)
|
|
154
|
-
return { required: false };
|
|
155
|
-
return {
|
|
156
|
-
required: true,
|
|
157
|
-
phase: "post_authority_lock_pre_implementation",
|
|
158
|
-
options: ["continue_current_model", "switch_model_then_resume"],
|
|
159
|
-
message: "Authority Lock created. Pause before implementation and ask the user whether to continue with the current model or switch models, then resume this active Long-Task.",
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function message(error) {
|
|
163
|
-
return error instanceof Error ? error.message : String(error);
|
|
164
|
-
}
|
|
165
|
-
async function approveRevision(workdir, args) {
|
|
166
|
-
const revision = option(args, "--revision");
|
|
167
|
-
rejectOptions(args, ["--revision"]);
|
|
168
|
-
if (!revision)
|
|
169
|
-
throw new Error("--revision requires a value");
|
|
170
|
-
await approvePendingAuthorityRevision(workdir, revision);
|
|
171
|
-
console.log(JSON.stringify({ status: "authority_revision_approved", revision }));
|
|
172
|
-
}
|
|
173
92
|
async function verify(workdir, args) {
|
|
174
93
|
const outcome = option(args, "--outcome");
|
|
175
94
|
const check = option(args, "--check");
|
|
@@ -187,40 +106,21 @@ async function finalGate(workdir, args) {
|
|
|
187
106
|
result.workflow_status !== "machine_accepted_external_pending")
|
|
188
107
|
process.exitCode = 1;
|
|
189
108
|
}
|
|
190
|
-
function option(args, name) {
|
|
191
|
-
const indexes = args.flatMap((value, index) => value === name ? [index] : []);
|
|
192
|
-
if (indexes.length > 1)
|
|
193
|
-
throw new Error(`duplicate option: ${name}`);
|
|
194
|
-
if (!indexes.length)
|
|
195
|
-
return undefined;
|
|
196
|
-
const value = args[indexes[0] + 1];
|
|
197
|
-
if (!value || value.startsWith("--"))
|
|
198
|
-
throw new Error(`${name} requires a value`);
|
|
199
|
-
return value;
|
|
200
|
-
}
|
|
201
|
-
function rejectOptions(args, allowed) {
|
|
202
|
-
for (let index = 0; index < args.length; index += 2)
|
|
203
|
-
if (!allowed.includes(args[index]) || !args[index + 1])
|
|
204
|
-
throw new Error(`Unknown or injected arguments: ${args.join(" ")}`);
|
|
205
|
-
}
|
|
206
|
-
function rejectUnknown(actual, allowed) {
|
|
207
|
-
if (actual.join("\0") !== allowed.join("\0"))
|
|
208
|
-
throw new Error(`Unknown or injected arguments: ${actual.join(" ")}`);
|
|
209
|
-
}
|
|
210
109
|
function help() {
|
|
211
|
-
console.log(`ty-context long-task commands:
|
|
212
|
-
init <workdir>
|
|
213
|
-
preflight <workdir>
|
|
214
|
-
compile <workdir>
|
|
215
|
-
compile <workdir> --revise
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
110
|
+
console.log(`ty-context long-task commands:
|
|
111
|
+
init <workdir>
|
|
112
|
+
preflight <workdir>
|
|
113
|
+
compile <workdir>
|
|
114
|
+
compile <workdir> --revise
|
|
115
|
+
diagnose-revision <workdir> [--outcome <key>] [--check <key>]
|
|
116
|
+
approve-authority-revision <workdir> --revision <sha>
|
|
117
|
+
explain <workdir>
|
|
118
|
+
verify <workdir> [--outcome <key>] [--check <key>]
|
|
119
|
+
status <workdir>
|
|
120
|
+
resume <workdir>
|
|
121
|
+
doctor <workdir>
|
|
122
|
+
final-gate <workdir>
|
|
123
|
+
stop-check <workdir> [--message <text>]
|
|
124
|
+
close <workdir>
|
|
225
125
|
abandon <workdir> [--force-corrupt-state]`);
|
|
226
126
|
}
|
|
@@ -2,6 +2,8 @@ import type { CompiledCheckV2, CompiledDeliveryContractV2, CompiledOutcomeV2, De
|
|
|
2
2
|
export declare function checkIndex(globalChecks: CompiledCheckV2[], outcomes: CompiledOutcomeV2[]): Map<string, CompiledCheckV2>;
|
|
3
3
|
export declare function changedRunnerFields(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
4
4
|
export declare function removedOrReplacedVerificationInputs(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
5
|
+
export declare function addedVerificationInputs(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
6
|
+
export declare function addedInputPaths(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
5
7
|
export declare function removedOrNarrowedInputPaths(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
6
8
|
export declare function removedOrWeakenedExpectedOutputPaths(identity: string, before: CompiledCheckV2, after: CompiledCheckV2): string[];
|
|
7
9
|
export declare function sourceClaimReductions(beforeClaims: SourceClaimV2[], afterClaims: SourceClaimV2[]): string[];
|
|
@@ -25,6 +25,16 @@ export function removedOrReplacedVerificationInputs(identity, before, after) {
|
|
|
25
25
|
.filter(([file, hash]) => after.verification_input_hashes[file] !== hash)
|
|
26
26
|
.map(([file]) => `${identity}:${file}`);
|
|
27
27
|
}
|
|
28
|
+
export function addedVerificationInputs(identity, before, after) {
|
|
29
|
+
return Object.keys(after.verification_input_hashes)
|
|
30
|
+
.filter((file) => before.verification_input_hashes[file] === undefined)
|
|
31
|
+
.map((file) => `${identity}:${file}`);
|
|
32
|
+
}
|
|
33
|
+
export function addedInputPaths(identity, before, after) {
|
|
34
|
+
return after.input_paths
|
|
35
|
+
.filter((pattern) => !before.input_paths.includes(pattern))
|
|
36
|
+
.map((pattern) => `${identity}:${pattern}`);
|
|
37
|
+
}
|
|
28
38
|
export function removedOrNarrowedInputPaths(identity, before, after) {
|
|
29
39
|
return before.input_paths
|
|
30
40
|
.filter((oldPattern) => !after.input_paths.some((newPattern) => proveRepositoryPatternSubset(oldPattern, newPattern).status ===
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CheckExecutionResultV2, LongTaskFindingV2 } from "./long-task-delivery-types.js";
|
|
2
|
+
import type { AuthorityRevisionDecisionV2 } from "./long-task-authority-revision-types.js";
|
|
3
|
+
export interface AuthorityRevisionDiagnosisV2 {
|
|
4
|
+
schema_version: "long-task-authority-revision-diagnosis-v2";
|
|
5
|
+
status: "no_authority_change" | "monotonic_revision_available" | "scope_candidate_exercised" | "scope_candidate_previewed" | "protected_change_previewed" | "candidate_stale";
|
|
6
|
+
active_compiled_identity: string;
|
|
7
|
+
candidate_compiled_identity: string;
|
|
8
|
+
revision: AuthorityRevisionDecisionV2 | null;
|
|
9
|
+
acceptance_authorized: false;
|
|
10
|
+
progress_written: false;
|
|
11
|
+
pending_revision_written: false;
|
|
12
|
+
diagnostics_executed: boolean;
|
|
13
|
+
selected_outcome: string | null;
|
|
14
|
+
selected_check: string | null;
|
|
15
|
+
skipped_candidate_checks: string[];
|
|
16
|
+
snapshot_sha256: string | null;
|
|
17
|
+
check_results: CheckExecutionResultV2[];
|
|
18
|
+
findings: LongTaskFindingV2[];
|
|
19
|
+
completed_at: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function diagnoseAuthorityRevision(workdirInput: string, selection?: {
|
|
22
|
+
outcome?: string;
|
|
23
|
+
check?: string;
|
|
24
|
+
}): Promise<AuthorityRevisionDiagnosisV2>;
|