@pi-unipi/background-tasks 2.6.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/README.md +87 -0
- package/extensions/anthropic-attribution.ts +1 -0
- package/extensions/delegate-child.ts +1 -0
- package/extensions/fusion-child.ts +1 -0
- package/package.json +40 -0
- package/src/__tests__/anthropic-attribution.test.ts +195 -0
- package/src/__tests__/config.test.ts +137 -0
- package/src/__tests__/core.test.ts +493 -0
- package/src/__tests__/delegate-artifacts.test.ts +528 -0
- package/src/__tests__/delegate-budget.test.ts +456 -0
- package/src/__tests__/delegate-launch.test.ts +676 -0
- package/src/__tests__/delegate-result-package.test.ts +350 -0
- package/src/__tests__/delegate-seed.test.ts +392 -0
- package/src/__tests__/durable-fs.test.ts +559 -0
- package/src/__tests__/extension-api.test.ts +579 -0
- package/src/__tests__/fusion-artifacts.test.ts +1039 -0
- package/src/__tests__/fusion-budget.test.ts +1356 -0
- package/src/__tests__/fusion-claude-cache.test.ts +320 -0
- package/src/__tests__/fusion-config.test.ts +335 -0
- package/src/__tests__/fusion-context-prompts.test.ts +670 -0
- package/src/__tests__/fusion-evaluation.test.ts +315 -0
- package/src/__tests__/fusion-extraction-equivalence.test.ts +58 -0
- package/src/__tests__/fusion-golden-bytes.test.ts +35 -0
- package/src/__tests__/fusion-high-cardinality.test.ts +192 -0
- package/src/__tests__/fusion-model-selector.test.ts +205 -0
- package/src/__tests__/fusion-orchestrator.test.ts +1194 -0
- package/src/__tests__/fusion-rpc.test.ts +369 -0
- package/src/__tests__/fusion-sdk.test.ts +1226 -0
- package/src/__tests__/fusion-v5-core.test.ts +219 -0
- package/src/__tests__/fusion-validate-orchestrator.test.ts +240 -0
- package/src/__tests__/fusion-web-fetch.test.ts +485 -0
- package/src/__tests__/fusion-workflows.test.ts +59 -0
- package/src/__tests__/helpers/delegate-deterministic-seed.ts +109 -0
- package/src/__tests__/helpers/delegate-seed-subprocess.ts +10 -0
- package/src/__tests__/helpers/fusion-canonical-subprocess.ts +21 -0
- package/src/__tests__/helpers/fusion-canonical.ts +140 -0
- package/src/__tests__/helpers/fusion-fake-pi.ts +279 -0
- package/src/__tests__/helpers/fusion-golden-corpus.ts +500 -0
- package/src/__tests__/helpers/fusion-high-cardinality.ts +140 -0
- package/src/__tests__/helpers/normalize.ts +22 -0
- package/src/__tests__/helpers/pi-hook-contract-evidence.json +18 -0
- package/src/__tests__/pi-launch.test.ts +202 -0
- package/src/__tests__/registry.test.ts +1580 -0
- package/src/__tests__/scripted-provider/delegate-ambient-provider.test.ts +130 -0
- package/src/__tests__/scripted-provider/delegate-child-guard.test.ts +631 -0
- package/src/__tests__/scripted-provider/delegate-guard-provider.ts +403 -0
- package/src/__tests__/scripted-provider/follow-up.test.ts +448 -0
- package/src/__tests__/scripted-provider/fusion-output-recovery.test.ts +132 -0
- package/src/__tests__/scripted-provider/fusion-reason.test.ts +310 -0
- package/src/__tests__/scripted-provider/fusion-runtime-guard.test.ts +163 -0
- package/src/__tests__/scripted-provider/hook-contract-provider.ts +179 -0
- package/src/__tests__/scripted-provider/hook-probe-a.ts +3 -0
- package/src/__tests__/scripted-provider/hook-probe-b.ts +3 -0
- package/src/__tests__/scripted-provider/hook-probe-extension.ts +126 -0
- package/src/__tests__/scripted-provider/output-recovery-provider.ts +153 -0
- package/src/__tests__/scripted-provider/pi-hook-contract-evidence.json +18 -0
- package/src/__tests__/scripted-provider/pi-hook-contract.test.ts +477 -0
- package/src/__tests__/scripted-provider/runtime-guard-probe.ts +28 -0
- package/src/__tests__/scripted-provider/runtime-guard-provider.ts +49 -0
- package/src/__tests__/scripted-provider/scripted-provider-extension.ts +408 -0
- package/src/__tests__/task-manager.test.ts +479 -0
- package/src/__tests__/windows-taskkill.test.ts +161 -0
- package/src/anthropic-attribution-path.ts +21 -0
- package/src/anthropic-attribution.ts +1983 -0
- package/src/attested-pi-run.ts +612 -0
- package/src/child-process.ts +55 -0
- package/src/common.ts +8 -0
- package/src/config.ts +292 -0
- package/src/context-parent-snapshot.ts +142 -0
- package/src/context-token-budget.ts +903 -0
- package/src/context-visible-conversation-v2.ts +551 -0
- package/src/delegate/artifacts.ts +487 -0
- package/src/delegate/budget.ts +415 -0
- package/src/delegate/hook-contract-evidence.json +18 -0
- package/src/delegate/hook-contract.ts +154 -0
- package/src/delegate/launch.ts +497 -0
- package/src/delegate/result-package.ts +459 -0
- package/src/delegate/runner.ts +449 -0
- package/src/delegate/seed.ts +423 -0
- package/src/delegate/types.ts +323 -0
- package/src/delegate-child-extension.ts +978 -0
- package/src/delegate-extension.ts +806 -0
- package/src/durable-fs.ts +386 -0
- package/src/extension-api.ts +548 -0
- package/src/fixtures/delegate-context-incident.json +17 -0
- package/src/fixtures/fusion-golden-bytes.json +310 -0
- package/src/fixtures/fusion-validate-golden-bytes.json +282 -0
- package/src/fusion/artifacts.ts +967 -0
- package/src/fusion/budget.ts +1162 -0
- package/src/fusion/child-protocol.ts +305 -0
- package/src/fusion/claude-cache.ts +207 -0
- package/src/fusion/clean-context.ts +91 -0
- package/src/fusion/config.ts +449 -0
- package/src/fusion/context.ts +265 -0
- package/src/fusion/evaluation.ts +800 -0
- package/src/fusion/orchestrator.ts +1288 -0
- package/src/fusion/output-contract.ts +34 -0
- package/src/fusion/pi-child.ts +2373 -0
- package/src/fusion/prompts.ts +345 -0
- package/src/fusion/result-package.ts +959 -0
- package/src/fusion/source-policy.ts +257 -0
- package/src/fusion/types.ts +1139 -0
- package/src/fusion/web-fetch.ts +1060 -0
- package/src/fusion/workflows.ts +184 -0
- package/src/fusion-child-extension.ts +1052 -0
- package/src/fusion-extension.ts +1293 -0
- package/src/index.ts +295 -0
- package/src/pi-launch.ts +225 -0
- package/src/registry.ts +2424 -0
- package/src/settings-overlay.ts +208 -0
- package/src/task-manager.ts +774 -0
- package/src/tools.ts +530 -0
- package/src/turndown.d.ts +15 -0
- package/src/types.ts +963 -0
- package/src/ui/fusion-model-selector.ts +322 -0
- package/src/windows-taskkill.ts +250 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FUSION_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
3
|
+
FUSION_EVALUATOR_SYSTEM_PROMPT,
|
|
4
|
+
FUSION_MERGER_SYSTEM_PROMPT,
|
|
5
|
+
FUSION_VALIDATE_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
6
|
+
FUSION_VALIDATE_EVALUATOR_SYSTEM_PROMPT,
|
|
7
|
+
FUSION_VALIDATE_MERGER_SYSTEM_PROMPT,
|
|
8
|
+
fusionCandidateSystemPrompt,
|
|
9
|
+
fusionValidateCandidateSystemPrompt,
|
|
10
|
+
} from './prompts.js';
|
|
11
|
+
import {
|
|
12
|
+
FUSION_INSPECT_TOOLS,
|
|
13
|
+
FUSION_NO_TOOLS_CAPABILITY,
|
|
14
|
+
FUSION_RESEARCH_TOOLS,
|
|
15
|
+
FUSION_VALIDATE_CAPABILITY,
|
|
16
|
+
FusionError,
|
|
17
|
+
type FusionCapability,
|
|
18
|
+
type FusionContextKind,
|
|
19
|
+
type FusionPublicWorkflowName,
|
|
20
|
+
type FusionWorkflowId,
|
|
21
|
+
} from './types.js';
|
|
22
|
+
|
|
23
|
+
export const FUSION_REASON_TOOL_NAME = 'fusion_reason' as const;
|
|
24
|
+
export const FUSION_INVESTIGATE_TOOL_NAME = 'fusion_investigate' as const;
|
|
25
|
+
export const FUSION_RESEARCH_TOOL_NAME = 'fusion_research' as const;
|
|
26
|
+
export const FUSION_VALIDATE_TOOL_NAME = 'fusion_validate' as const;
|
|
27
|
+
|
|
28
|
+
/** @deprecated v4 recursion-denylist compatibility only; do not register new public APIs with this name. */
|
|
29
|
+
export const FUSION_BRAINSTORM_TOOL_NAME = 'fusion_brainstorm' as const;
|
|
30
|
+
|
|
31
|
+
export interface FusionWorkflowProfile {
|
|
32
|
+
readonly id: FusionWorkflowId;
|
|
33
|
+
readonly publicName: FusionPublicWorkflowName;
|
|
34
|
+
readonly toolName: FusionPublicWorkflowName;
|
|
35
|
+
/** Human-readable run-id prefix, e.g. `reason-<hex>`. */
|
|
36
|
+
readonly runIdPrefix: `${FusionWorkflowId}-`;
|
|
37
|
+
readonly contextKind: FusionContextKind;
|
|
38
|
+
readonly candidateCapability: FusionCapability;
|
|
39
|
+
readonly candidateTools: readonly string[];
|
|
40
|
+
readonly evaluatorCapability: typeof FUSION_NO_TOOLS_CAPABILITY;
|
|
41
|
+
readonly evaluatorTools: readonly [];
|
|
42
|
+
readonly mergeCapability: typeof FUSION_NO_TOOLS_CAPABILITY;
|
|
43
|
+
readonly mergeTools: readonly [];
|
|
44
|
+
readonly candidateSystemPrompt: (capability: FusionCapability) => string;
|
|
45
|
+
readonly evaluatorSystemPrompt: string;
|
|
46
|
+
readonly evaluationRepairSystemPrompt: string;
|
|
47
|
+
readonly mergerSystemPrompt: string;
|
|
48
|
+
readonly label: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function freezeProfile(profile: FusionWorkflowProfile): FusionWorkflowProfile {
|
|
52
|
+
const empty = Object.freeze([]) as readonly [];
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
...profile,
|
|
55
|
+
candidateTools: Object.freeze([...profile.candidateTools]),
|
|
56
|
+
evaluatorTools: empty,
|
|
57
|
+
mergeTools: empty,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const FUSION_REASON_WORKFLOW = freezeProfile({
|
|
62
|
+
id: 'reason',
|
|
63
|
+
publicName: FUSION_REASON_TOOL_NAME,
|
|
64
|
+
toolName: FUSION_REASON_TOOL_NAME,
|
|
65
|
+
runIdPrefix: 'reason-',
|
|
66
|
+
contextKind: 'session_projection',
|
|
67
|
+
candidateCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
68
|
+
candidateTools: [],
|
|
69
|
+
evaluatorCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
70
|
+
evaluatorTools: [],
|
|
71
|
+
mergeCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
72
|
+
mergeTools: [],
|
|
73
|
+
candidateSystemPrompt: fusionCandidateSystemPrompt,
|
|
74
|
+
evaluatorSystemPrompt: FUSION_EVALUATOR_SYSTEM_PROMPT,
|
|
75
|
+
evaluationRepairSystemPrompt: FUSION_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
76
|
+
mergerSystemPrompt: FUSION_MERGER_SYSTEM_PROMPT,
|
|
77
|
+
label: 'fusion reason',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const FUSION_INVESTIGATE_WORKFLOW = freezeProfile({
|
|
81
|
+
id: 'investigate',
|
|
82
|
+
publicName: FUSION_INVESTIGATE_TOOL_NAME,
|
|
83
|
+
toolName: FUSION_INVESTIGATE_TOOL_NAME,
|
|
84
|
+
runIdPrefix: 'investigate-',
|
|
85
|
+
contextKind: 'clean_task',
|
|
86
|
+
candidateCapability: 'inspect',
|
|
87
|
+
candidateTools: FUSION_INSPECT_TOOLS,
|
|
88
|
+
evaluatorCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
89
|
+
evaluatorTools: [],
|
|
90
|
+
mergeCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
91
|
+
mergeTools: [],
|
|
92
|
+
candidateSystemPrompt: fusionCandidateSystemPrompt,
|
|
93
|
+
evaluatorSystemPrompt: FUSION_EVALUATOR_SYSTEM_PROMPT,
|
|
94
|
+
evaluationRepairSystemPrompt: FUSION_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
95
|
+
mergerSystemPrompt: FUSION_MERGER_SYSTEM_PROMPT,
|
|
96
|
+
label: 'fusion investigate',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const FUSION_RESEARCH_WORKFLOW = freezeProfile({
|
|
100
|
+
id: 'research',
|
|
101
|
+
publicName: FUSION_RESEARCH_TOOL_NAME,
|
|
102
|
+
toolName: FUSION_RESEARCH_TOOL_NAME,
|
|
103
|
+
runIdPrefix: 'research-',
|
|
104
|
+
contextKind: 'clean_task',
|
|
105
|
+
candidateCapability: 'research',
|
|
106
|
+
candidateTools: FUSION_RESEARCH_TOOLS,
|
|
107
|
+
evaluatorCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
108
|
+
evaluatorTools: [],
|
|
109
|
+
mergeCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
110
|
+
mergeTools: [],
|
|
111
|
+
candidateSystemPrompt: fusionCandidateSystemPrompt,
|
|
112
|
+
evaluatorSystemPrompt: FUSION_EVALUATOR_SYSTEM_PROMPT,
|
|
113
|
+
evaluationRepairSystemPrompt: FUSION_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
114
|
+
mergerSystemPrompt: FUSION_MERGER_SYSTEM_PROMPT,
|
|
115
|
+
label: 'fusion research',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const FUSION_VALIDATE_WORKFLOW = freezeProfile({
|
|
119
|
+
id: 'validate',
|
|
120
|
+
publicName: FUSION_VALIDATE_TOOL_NAME,
|
|
121
|
+
toolName: FUSION_VALIDATE_TOOL_NAME,
|
|
122
|
+
runIdPrefix: 'validate-',
|
|
123
|
+
contextKind: 'clean_task',
|
|
124
|
+
candidateCapability: FUSION_VALIDATE_CAPABILITY,
|
|
125
|
+
candidateTools: FUSION_INSPECT_TOOLS,
|
|
126
|
+
evaluatorCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
127
|
+
evaluatorTools: [],
|
|
128
|
+
mergeCapability: FUSION_NO_TOOLS_CAPABILITY,
|
|
129
|
+
mergeTools: [],
|
|
130
|
+
candidateSystemPrompt: fusionValidateCandidateSystemPrompt,
|
|
131
|
+
evaluatorSystemPrompt: FUSION_VALIDATE_EVALUATOR_SYSTEM_PROMPT,
|
|
132
|
+
evaluationRepairSystemPrompt: FUSION_VALIDATE_EVALUATION_REPAIR_SYSTEM_PROMPT,
|
|
133
|
+
mergerSystemPrompt: FUSION_VALIDATE_MERGER_SYSTEM_PROMPT,
|
|
134
|
+
label: 'fusion validate',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const PROFILES_BY_ID: Readonly<Record<FusionWorkflowId, FusionWorkflowProfile>> = Object.freeze({
|
|
138
|
+
reason: FUSION_REASON_WORKFLOW,
|
|
139
|
+
investigate: FUSION_INVESTIGATE_WORKFLOW,
|
|
140
|
+
research: FUSION_RESEARCH_WORKFLOW,
|
|
141
|
+
validate: FUSION_VALIDATE_WORKFLOW,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
export const FUSION_WORKFLOW_PROFILES = Object.freeze([
|
|
145
|
+
FUSION_REASON_WORKFLOW,
|
|
146
|
+
FUSION_INVESTIGATE_WORKFLOW,
|
|
147
|
+
FUSION_RESEARCH_WORKFLOW,
|
|
148
|
+
FUSION_VALIDATE_WORKFLOW,
|
|
149
|
+
] as const);
|
|
150
|
+
|
|
151
|
+
export function fusionWorkflowProfile(id: FusionWorkflowId): FusionWorkflowProfile {
|
|
152
|
+
const profile = PROFILES_BY_ID[id];
|
|
153
|
+
if (profile === undefined) {
|
|
154
|
+
throw new FusionError(`unknown fusion workflow ${String(id)}`, {
|
|
155
|
+
code: 'orchestration_failed',
|
|
156
|
+
childCreated: false,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return profile;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function assertWorkflowCapability(
|
|
163
|
+
profile: FusionWorkflowProfile,
|
|
164
|
+
requested: FusionCapability | undefined,
|
|
165
|
+
): FusionCapability {
|
|
166
|
+
if (requested !== undefined && requested !== profile.candidateCapability) {
|
|
167
|
+
throw new FusionError(
|
|
168
|
+
`fusion workflow ${profile.id} always runs candidates with the ${profile.candidateCapability} capability; received ${String(requested)}`,
|
|
169
|
+
{ code: 'orchestration_failed', childCreated: false },
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return profile.candidateCapability;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** @deprecated v4 artifact/testing alias. The retired public tool is never registered. */
|
|
176
|
+
export const FUSION_BRAINSTORM_WORKFLOW = FUSION_REASON_WORKFLOW;
|
|
177
|
+
|
|
178
|
+
export const FUSION_REASON = FUSION_REASON_WORKFLOW;
|
|
179
|
+
export const FUSION_INVESTIGATE = FUSION_INVESTIGATE_WORKFLOW;
|
|
180
|
+
export const FUSION_RESEARCH = FUSION_RESEARCH_WORKFLOW;
|
|
181
|
+
export const FUSION_VALIDATE = FUSION_VALIDATE_WORKFLOW;
|
|
182
|
+
|
|
183
|
+
/** @deprecated v5 workflows do not default; retained for old imports. */
|
|
184
|
+
export const resolveWorkflowCapability = assertWorkflowCapability;
|