aptly 0.1.5 → 0.1.6
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/dist/src/automatic-hook.d.ts +17 -1
- package/dist/src/automatic-hook.js +24 -14
- package/dist/src/context-retry.d.ts +14 -0
- package/dist/src/context-retry.js +126 -24
- package/dist/src/context-sufficiency.d.ts +1 -0
- package/dist/src/context-sufficiency.js +24 -0
- package/dist/src/routing-observations.d.ts +23 -0
- package/dist/src/routing-observations.js +12 -1
- package/dist/src/server.js +11 -2
- package/dist/src/setup.js +26 -17
- package/dist/src/spawn-context.js +2 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/windows-private.d.ts +2 -1
- package/dist/src/windows-private.js +37 -20
- package/docs/SPAWN_CONTEXT.md +100 -1
- package/docs/guide/en.md +9 -0
- package/docs/guide/ja.md +9 -0
- package/docs/guide/ko.md +9 -0
- package/docs/guide/zh-CN.md +9 -0
- package/package.json +1 -1
|
@@ -37,6 +37,17 @@ export interface AutomaticHookObservation {
|
|
|
37
37
|
reason: string;
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
+
fresh_delegation?: {
|
|
41
|
+
outcome?: {
|
|
42
|
+
preparation_id: string;
|
|
43
|
+
profile_id: string;
|
|
44
|
+
};
|
|
45
|
+
last_attempt: {
|
|
46
|
+
status: string;
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
49
|
+
execution: 'not_observed';
|
|
50
|
+
};
|
|
40
51
|
}
|
|
41
52
|
export interface ContextRetrySeed {
|
|
42
53
|
request_id: string;
|
|
@@ -46,6 +57,7 @@ export interface ContextRetrySeed {
|
|
|
46
57
|
application_blocked?: string;
|
|
47
58
|
fill_model?: boolean;
|
|
48
59
|
fill_effort?: boolean;
|
|
60
|
+
fresh_eligible?: boolean;
|
|
49
61
|
}
|
|
50
62
|
export interface AutomaticHookResult {
|
|
51
63
|
output: HookOutput | {
|
|
@@ -78,6 +90,10 @@ export interface AutomaticHookOptions {
|
|
|
78
90
|
retry_id?: string;
|
|
79
91
|
reason?: string;
|
|
80
92
|
};
|
|
93
|
+
onBlockedAdvice?: (seed: ContextRetrySeed, current: () => string | undefined) => {
|
|
94
|
+
retry_id?: string;
|
|
95
|
+
reason?: string;
|
|
96
|
+
};
|
|
81
97
|
/** A caller may revoke the pending event; absence does not certify native dispatch. */
|
|
82
98
|
stillCurrent?: () => boolean | Promise<boolean>;
|
|
83
99
|
}
|
|
@@ -93,4 +109,4 @@ export declare function automaticCallIdentity(client: unknown, event: unknown):
|
|
|
93
109
|
export declare function automaticCallId(client: unknown, event: unknown): string | undefined;
|
|
94
110
|
export declare function initialHookObservation(client: unknown, event: unknown): AutomaticHookObservation;
|
|
95
111
|
/** Operator default selection only. No provenance_verified/evidence_verified host claim. */
|
|
96
|
-
export declare function automaticHook({ client, event, router, policyPath, signal, context, stillCurrent, onObservation, onNeedsContext }: AutomaticHookOptions): Promise<AutomaticHookResult>;
|
|
112
|
+
export declare function automaticHook({ client, event, router, policyPath, signal, context, stillCurrent, onObservation, onNeedsContext, onBlockedAdvice }: AutomaticHookOptions): Promise<AutomaticHookResult>;
|
|
@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto';
|
|
|
3
3
|
import { closeSync, openSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { isAbsolute, join } from 'node:path';
|
|
5
5
|
import { Router } from './core.js';
|
|
6
|
+
import { hasSufficientTaskText } from './context-sufficiency.js';
|
|
6
7
|
import { assertPrivateStatePath, readRegularFile } from './files.js';
|
|
7
8
|
import { hookInput, hookOutput, validatedHookProfile, profilePreservesChoices, effortKeys } from './hook.js';
|
|
8
9
|
import { digestToolInput } from './provenance.js';
|
|
@@ -125,7 +126,7 @@ function boundedSummary(call, maxBytes) {
|
|
|
125
126
|
return { summary };
|
|
126
127
|
}
|
|
127
128
|
const first = body.trim().split(/\r?\n\s*\r?\n/, 1)[0];
|
|
128
|
-
if (first
|
|
129
|
+
if (!hasSufficientTaskText(first) || (typeof label === 'string' && first.trim() === label.trim()))
|
|
129
130
|
return { reason: 'insufficient_context' };
|
|
130
131
|
const prefix = safeText(label, 512) ? `Task: ${label.trim()}\n` : '';
|
|
131
132
|
const budget = Math.min(4000, maxBytes) - Buffer.byteLength(prefix);
|
|
@@ -177,7 +178,7 @@ function bindCall(call, policy, policyFingerprint, catalog, contextDigest) {
|
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
/** Operator default selection only. No provenance_verified/evidence_verified host claim. */
|
|
180
|
-
export async function automaticHook({ client, event, router, policyPath, signal, context, stillCurrent, onObservation, onNeedsContext }) {
|
|
181
|
+
export async function automaticHook({ client, event, router, policyPath, signal, context, stillCurrent, onObservation, onNeedsContext, onBlockedAdvice }) {
|
|
181
182
|
const observation = initialHookObservation(client, event);
|
|
182
183
|
let activeMode;
|
|
183
184
|
const preserve = (reason, request_id) => {
|
|
@@ -214,18 +215,13 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
214
215
|
if (loaded.policy.mode === 'defaults' && router.policy.provider_id !== 'decisions')
|
|
215
216
|
return preserve('synthetic_provider');
|
|
216
217
|
activeMode = loaded.policy.mode;
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
return preserve(reason, request_id);
|
|
220
|
-
if (signal?.aborted)
|
|
221
|
-
return preserve('call_cancelled', request_id);
|
|
222
|
-
const currentPolicy = loadAutomaticHookPolicy(policyPath);
|
|
223
|
-
if (!currentPolicy.policy?.enabled || currentPolicy.fingerprint !== loaded.fingerprint)
|
|
224
|
-
return preserve('automatic_policy_changed', request_id);
|
|
218
|
+
const freshEligible = loaded.policy.mode === 'defaults' && call.client === 'codex' && (call.input.fork_turns === undefined || call.input.fork_turns === 'all') && Object.keys(call.input).every(key => ['task_name', 'message', 'fork_turns', 'model', 'reasoning_effort'].includes(key));
|
|
219
|
+
const reference = (request_id, issue) => {
|
|
225
220
|
const expectedContext = context?.();
|
|
226
|
-
|
|
221
|
+
return issue({ request_id, client: call.client, eligible_profile_ids: profiles.map(profile => profile.id),
|
|
227
222
|
policy_fingerprint: loaded.fingerprint, application_blocked: applicationConstraint(call) ?? undefined,
|
|
228
|
-
fill_model: !hasModel, fill_effort: !hasEffort
|
|
223
|
+
fill_model: !hasModel, fill_effort: !hasEffort,
|
|
224
|
+
...(freshEligible ? { fresh_eligible: true } : {}) }, () => {
|
|
229
225
|
const latest = context?.();
|
|
230
226
|
if (latest?.reason)
|
|
231
227
|
return latest.reason;
|
|
@@ -234,8 +230,18 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
234
230
|
const latestCall = readCall(client, event);
|
|
235
231
|
return latestCall?.payloadDigest === call.payloadDigest ? undefined : 'call_changed';
|
|
236
232
|
});
|
|
233
|
+
};
|
|
234
|
+
const needsContext = (reason, request_id) => {
|
|
235
|
+
if (!onNeedsContext)
|
|
236
|
+
return preserve(reason, request_id);
|
|
237
|
+
if (signal?.aborted)
|
|
238
|
+
return preserve('call_cancelled', request_id);
|
|
239
|
+
const currentPolicy = loadAutomaticHookPolicy(policyPath);
|
|
240
|
+
if (!currentPolicy.policy?.enabled || currentPolicy.fingerprint !== loaded.fingerprint)
|
|
241
|
+
return preserve('automatic_policy_changed', request_id);
|
|
242
|
+
const recovery = reference(request_id, onNeedsContext);
|
|
237
243
|
const instruction = recovery.retry_id
|
|
238
|
-
? `Call Aptly retry_spawn_recommendation with retry_id "${recovery.retry_id}" and a short description of task purpose, scope, expected output and complexity. Use context you already have; ask the user only for genuinely missing information. One supplementation is allowed. Do not decode the opaque body or invent native call IDs. A recommendation is advice only: preserve explicit choices, roles, permissions and history
|
|
244
|
+
? `Call Aptly retry_spawn_recommendation with retry_id "${recovery.retry_id}" and a short description of task purpose, scope, expected output and complexity. Use context you already have; ask the user only for genuinely missing information. One supplementation is allowed. Do not decode the opaque body or invent native call IDs. A recommendation is advice only: preserve all explicit user choices, roles, permissions and required history. Never rewrite the ORIGINAL invocation in place or resubmit it with changed history semantics to apply advice. If application is blocked, report that limitation. ${freshEligible ? 'A separate NEW invocation for the SAME independent task is supported ONLY through prepare_fresh_delegation if a later response offers it, under all of that response\'s conditions; do not invent a direct fresh call. This protocol does not change the original invocation or grant permissions.' : 'Do not create a fresh child to bypass this constraint.'} Do not spawn while the retry still needs context or is unavailable.`
|
|
239
245
|
: `Context recovery is unavailable (${recovery.reason ?? 'context_retry_unavailable'}). Report the limitation; do not repeat the spawn unchanged.`;
|
|
240
246
|
const feedback = `Aptly needs additional task context (${reason}). ${instruction}`;
|
|
241
247
|
return { output: { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: feedback,
|
|
@@ -340,7 +346,11 @@ export async function automaticHook({ client, event, router, policyPath, signal,
|
|
|
340
346
|
if (blocked) {
|
|
341
347
|
const kept = preserve(blocked, request_id);
|
|
342
348
|
const next = blocked === 'effort_argument_unsupported' ? 'The caller must review the native reasoning_effort argument spelling; Aptly never rewrites an explicit choice.' : 'Inherited model/effort updates are not verified for this host. Verify the host version and native contract before enabling them; task arguments cannot certify support. Aptly never changes history automatically.';
|
|
343
|
-
const
|
|
349
|
+
const fresh = blocked === 'inherited_context_application_unverified' && onBlockedAdvice ? reference(request_id, onBlockedAdvice) : undefined;
|
|
350
|
+
if (fresh?.retry_id)
|
|
351
|
+
kept.observation.retry_id = fresh.retry_id;
|
|
352
|
+
const continuation = fresh?.retry_id ? ` Only after the host reports this tool call blocked, if the task is independently declared, inherited history is not required by the user, and complete standalone instructions are available, prepare a SEPARATE fresh delegation with prepare_fresh_delegation using retry_id \"${fresh.retry_id}\". Never do this for required or unknown history, or unknown original execution.` : ' Do not create a fresh child merely to apply the recommendation.';
|
|
353
|
+
const message = `Aptly recommends ${profile.id}, but application is blocked (${blocked}). Original history and arguments are preserved; no child execution is observed. ${next} ${activeMode === 'defaults' ? 'Report this constraint and stop this ORIGINAL spawn.' : 'The host may still execute this original call under advisory policy; do not submit an additional call solely to apply the recommendation.'} Do not discard required history merely to apply the recommendation.${continuation}`;
|
|
344
354
|
kept.output = { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: message,
|
|
345
355
|
...(activeMode === 'defaults' ? { permissionDecision: 'deny', permissionDecisionReason: message } : {}) } };
|
|
346
356
|
kept.observation.status = activeMode === 'defaults' ? 'blocked' : 'preserved';
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ContextRetrySeed } from './automatic-hook.ts';
|
|
2
2
|
import type { Router } from './core.ts';
|
|
3
|
+
export interface FreshDeclaration {
|
|
4
|
+
independent_task: boolean;
|
|
5
|
+
same_task: boolean;
|
|
6
|
+
original_call_outcome: 'blocked' | 'executed' | 'unknown';
|
|
7
|
+
history_requirement: 'not_required' | 'required' | 'unknown';
|
|
8
|
+
standalone_context_complete: boolean;
|
|
9
|
+
}
|
|
3
10
|
/** One caller-supplied supplement, never an automatic native spawn or a retry chain. */
|
|
4
11
|
export declare class ContextRetries {
|
|
5
12
|
private entries;
|
|
@@ -7,9 +14,16 @@ export declare class ContextRetries {
|
|
|
7
14
|
private policyPath;
|
|
8
15
|
private now;
|
|
9
16
|
constructor(router: Router, policyPath: unknown, now?: () => number);
|
|
17
|
+
private current;
|
|
10
18
|
register(seed: ContextRetrySeed, current?: () => string | undefined): {
|
|
11
19
|
retry_id?: string;
|
|
12
20
|
reason?: string;
|
|
13
21
|
};
|
|
22
|
+
registerAdvice(seed: ContextRetrySeed, current?: () => string | undefined): {
|
|
23
|
+
retry_id?: string;
|
|
24
|
+
reason?: string;
|
|
25
|
+
};
|
|
14
26
|
retry(retry_id: string, description: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
27
|
+
/** Caller-declared independent work only; never rewrites or executes the blocked call. */
|
|
28
|
+
prepareFresh(retry_id: string, task_name: string, standalone_task: string, declaration: FreshDeclaration, signal?: AbortSignal): Record<string, unknown>;
|
|
15
29
|
}
|
|
@@ -3,6 +3,7 @@ import { closeSync, openSync, writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { loadAutomaticHookPolicy } from './automatic-hook.js';
|
|
5
5
|
import { assertPrivateStatePath, readRegularFile } from './files.js';
|
|
6
|
+
import { hasSufficientTaskText } from './context-sufficiency.js';
|
|
6
7
|
const hash = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
7
8
|
/** One caller-supplied supplement, never an automatic native spawn or a retry chain. */
|
|
8
9
|
export class ContextRetries {
|
|
@@ -11,6 +12,28 @@ export class ContextRetries {
|
|
|
11
12
|
policyPath;
|
|
12
13
|
now;
|
|
13
14
|
constructor(router, policyPath, now = Date.now) { this.router = router; this.policyPath = policyPath; this.now = now; }
|
|
15
|
+
current(entry, signal) {
|
|
16
|
+
if (entry.cancelled || signal?.aborted)
|
|
17
|
+
return 'context_retry_cancelled';
|
|
18
|
+
if (this.now() - entry.at >= 300_000)
|
|
19
|
+
return 'context_retry_expired';
|
|
20
|
+
try {
|
|
21
|
+
const changed = entry.current?.();
|
|
22
|
+
if (changed)
|
|
23
|
+
return changed;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return 'context_changed';
|
|
27
|
+
}
|
|
28
|
+
const loaded = loadAutomaticHookPolicy(this.policyPath);
|
|
29
|
+
if (!loaded.policy?.enabled)
|
|
30
|
+
return loaded.reason;
|
|
31
|
+
if (loaded.fingerprint !== entry.seed.policy_fingerprint)
|
|
32
|
+
return 'automatic_policy_changed';
|
|
33
|
+
if (hash(this.router.policy) !== entry.catalog)
|
|
34
|
+
return 'catalog_changed';
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
14
37
|
register(seed, current) {
|
|
15
38
|
try {
|
|
16
39
|
this.router.load();
|
|
@@ -30,40 +53,41 @@ export class ContextRetries {
|
|
|
30
53
|
this.entries.set(retry_id, { seed: structuredClone(seed), at: this.now(), catalog: hash(this.router.policy), current });
|
|
31
54
|
return { retry_id };
|
|
32
55
|
}
|
|
56
|
+
registerAdvice(seed, current) {
|
|
57
|
+
if (!seed.fresh_eligible || seed.application_blocked !== 'inherited_context_application_unverified')
|
|
58
|
+
return { reason: 'fresh_delegation_unsupported' };
|
|
59
|
+
try {
|
|
60
|
+
this.router.load();
|
|
61
|
+
const record = this.router.state.requests[seed.request_id];
|
|
62
|
+
if (!record || record.state !== 'complete' || record.result?.status !== 'recommended')
|
|
63
|
+
return { reason: 'recommendation_not_available' };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { reason: 'ledger_error' };
|
|
67
|
+
}
|
|
68
|
+
const retry_id = hash(['aptly-blocked-advice-v1', seed.request_id]);
|
|
69
|
+
if (this.entries.has(retry_id))
|
|
70
|
+
return { retry_id };
|
|
71
|
+
if (this.entries.size >= 128)
|
|
72
|
+
return { reason: 'context_retry_capacity' };
|
|
73
|
+
this.entries.set(retry_id, { seed: structuredClone(seed), at: this.now(), catalog: hash(this.router.policy), current, recommendation_id: seed.request_id });
|
|
74
|
+
return { retry_id };
|
|
75
|
+
}
|
|
33
76
|
async retry(retry_id, description, signal) {
|
|
34
77
|
const entry = this.entries.get(retry_id);
|
|
35
78
|
const unavailable = (reason) => ({ status: 'unavailable', reason, application: 'advisory_only', retry_id, context_retry_allowed: false });
|
|
36
79
|
if (!entry)
|
|
37
80
|
return unavailable('context_retry_not_found');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (this.now() - entry.at >= 300_000)
|
|
42
|
-
return 'context_retry_expired';
|
|
43
|
-
try {
|
|
44
|
-
const changed = entry.current?.();
|
|
45
|
-
if (changed)
|
|
46
|
-
return changed;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return 'context_changed';
|
|
50
|
-
}
|
|
51
|
-
const loaded = loadAutomaticHookPolicy(this.policyPath);
|
|
52
|
-
if (!loaded.policy?.enabled)
|
|
53
|
-
return loaded.reason;
|
|
54
|
-
if (loaded.fingerprint !== entry.seed.policy_fingerprint)
|
|
55
|
-
return 'automatic_policy_changed';
|
|
56
|
-
if (hash(this.router.policy) !== entry.catalog)
|
|
57
|
-
return 'catalog_changed';
|
|
58
|
-
return undefined;
|
|
59
|
-
};
|
|
81
|
+
if (entry.recommendation_id)
|
|
82
|
+
return unavailable('context_retry_not_eligible');
|
|
83
|
+
const check = () => this.current(entry, signal);
|
|
60
84
|
const blocked = check();
|
|
61
85
|
if (blocked)
|
|
62
86
|
return unavailable(blocked);
|
|
63
87
|
if (entry.active)
|
|
64
88
|
return unavailable('concurrency_limit');
|
|
65
89
|
if (typeof description !== 'string' || Buffer.byteLength(description) > Math.min(3800, this.router.policy.max_summary_bytes - 96) ||
|
|
66
|
-
|
|
90
|
+
!hasSufficientTaskText(description))
|
|
67
91
|
return unavailable('insufficient_context');
|
|
68
92
|
if (/\bsk-[A-Za-z0-9_-]{12,}|\bBearer\s+[A-Za-z0-9._~+\/-]{8,}={0,2}/i.test(description))
|
|
69
93
|
return unavailable('sensitive_input');
|
|
@@ -122,7 +146,7 @@ export class ContextRetries {
|
|
|
122
146
|
reason: entry.seed.application_blocked ?? 'native_execution_not_observed' },
|
|
123
147
|
...(defaults ? { next_call: { tool: entry.seed.client === 'claude' ? 'Agent' : 'spawn_agent', set_if_unspecified: defaults, preserve: 'all_other_arguments_and_history' } } : {}),
|
|
124
148
|
next_step: result.status === 'recommended'
|
|
125
|
-
? entry.seed.application_blocked ?
|
|
149
|
+
? entry.seed.application_blocked ? `Report the application constraint and preserve original history and arguments for the ORIGINAL invocation. This profile is advice only. ${entry.seed.fresh_eligible ? 'This is the SAME task but a NEW invocation, not a retry of the original call. Use only the separate caller-declared preparation protocol offered below. Only after the host reports the original tool call blocked, if you can declare that this is the same independent task, the user does not require inherited history, and you can supply complete standalone instructions, call prepare_fresh_delegation with this retry_id, task_name, standalone_task and declaration {independent_task:true,same_task:true,original_call_outcome:"blocked",history_requirement:"not_required",standalone_context_complete:true}. It prepares a separate fresh invocation without a new classification. Never use it when history is required or unknown, or when original execution is unknown.' : ''}`
|
|
126
150
|
: `Context supplementation is complete; do not call retry_spawn_recommendation again. Caller review means the parent checks arguments, not a request for new user approval. To perform the already requested delegation, on the next native ${entry.seed.client === 'claude' ? 'Agent' : 'spawn_agent'} call, include these previously unspecified fields: ${JSON.stringify(defaults)}. Do not submit another model/effort-omitted call: it will be blocked again. Preserve all other arguments, explicit choices, history, roles and permissions. This response does not execute a child.`
|
|
127
151
|
: 'Stop this recovery attempt. Report the outcome; do not create another retry ID or spawn with an unresolved recommendation.' };
|
|
128
152
|
}
|
|
@@ -131,4 +155,82 @@ export class ContextRetries {
|
|
|
131
155
|
signal?.removeEventListener('abort', cancel);
|
|
132
156
|
}
|
|
133
157
|
}
|
|
158
|
+
/** Caller-declared independent work only; never rewrites or executes the blocked call. */
|
|
159
|
+
prepareFresh(retry_id, task_name, standalone_task, declaration, signal) {
|
|
160
|
+
const reject = (reason) => ({ status: 'rejected', reason, application: 'advisory_only', source_retry_id: retry_id, execution: 'not_observed' });
|
|
161
|
+
const entry = this.entries.get(retry_id);
|
|
162
|
+
if (!entry)
|
|
163
|
+
return reject('context_retry_not_found');
|
|
164
|
+
const blocked = this.current(entry, signal);
|
|
165
|
+
if (blocked)
|
|
166
|
+
return reject(blocked);
|
|
167
|
+
if (entry.seed.client !== 'codex' || entry.seed.application_blocked !== 'inherited_context_application_unverified' || entry.seed.fresh_eligible !== true)
|
|
168
|
+
return reject('fresh_delegation_unsupported');
|
|
169
|
+
if (!declaration || declaration.history_requirement !== 'not_required')
|
|
170
|
+
return reject('history_requirement_preserved');
|
|
171
|
+
if (declaration.independent_task !== true)
|
|
172
|
+
return reject('independent_task_not_declared');
|
|
173
|
+
if (declaration.same_task !== true)
|
|
174
|
+
return reject('task_scope_changed');
|
|
175
|
+
if (declaration.original_call_outcome !== 'blocked')
|
|
176
|
+
return reject('original_execution_not_confirmed_blocked');
|
|
177
|
+
if (declaration.standalone_context_complete !== true)
|
|
178
|
+
return reject('standalone_context_incomplete');
|
|
179
|
+
if (typeof task_name !== 'string' || !task_name.trim() || Buffer.byteLength(task_name) > 128 || typeof standalone_task !== 'string' || Buffer.byteLength(standalone_task) > 12000 || !hasSufficientTaskText(standalone_task))
|
|
180
|
+
return reject('insufficient_context');
|
|
181
|
+
if (/\bsk-[A-Za-z0-9_-]{12,}|\bBearer\s+[A-Za-z0-9._~+\/-]{8,}={0,2}/i.test(task_name + '\n' + standalone_task))
|
|
182
|
+
return reject('sensitive_input');
|
|
183
|
+
if (entry.active || this.router.active)
|
|
184
|
+
return reject('concurrency_limit');
|
|
185
|
+
try {
|
|
186
|
+
this.router.load();
|
|
187
|
+
const record = this.router.state.requests[entry.recommendation_id ?? retry_id];
|
|
188
|
+
if (!record)
|
|
189
|
+
return reject('recommendation_not_found');
|
|
190
|
+
if (record.state !== 'complete')
|
|
191
|
+
return reject('outcome_unknown');
|
|
192
|
+
const result = record.result;
|
|
193
|
+
this.router.validateOutcome(result);
|
|
194
|
+
if (result.status !== 'recommended' || !result.profile)
|
|
195
|
+
return reject('recommendation_not_available');
|
|
196
|
+
const profile = this.router.policy.profiles.find(p => p.id === result.profile_id);
|
|
197
|
+
if (!profile || !entry.seed.eligible_profile_ids.includes(profile.id) || hash(profile) !== hash(result.profile) || result.policy_version !== this.router.policy.version || result.catalog_version !== this.router.policy.catalog_version)
|
|
198
|
+
return reject('profile_changed');
|
|
199
|
+
const preparation_id = hash(['aptly-fresh-delegation-v1', retry_id]);
|
|
200
|
+
const fingerprint = hash([entry.seed, entry.catalog, profile, declaration, task_name, standalone_task]);
|
|
201
|
+
const policy = loadAutomaticHookPolicy(this.policyPath).policy;
|
|
202
|
+
if (!policy)
|
|
203
|
+
return reject('automatic_policy_changed');
|
|
204
|
+
const path = join(policy.state_directory, `hook-fresh-${preparation_id}.json`);
|
|
205
|
+
assertPrivateStatePath(path);
|
|
206
|
+
let fd;
|
|
207
|
+
try {
|
|
208
|
+
try {
|
|
209
|
+
fd = openSync(path, 'wx', 0o600);
|
|
210
|
+
writeFileSync(fd, JSON.stringify({ fingerprint }));
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (error.code !== 'EEXIST')
|
|
214
|
+
throw error;
|
|
215
|
+
const previous = JSON.parse(readRegularFile(path, { privateFile: true, maxBytes: 256 }).toString('utf8'));
|
|
216
|
+
if (!previous || typeof previous !== 'object' || Object.keys(previous).length !== 1 || !('fingerprint' in previous) || previous.fingerprint !== fingerprint)
|
|
217
|
+
return reject('fresh_delegation_conflict');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
if (fd !== undefined)
|
|
222
|
+
closeSync(fd);
|
|
223
|
+
}
|
|
224
|
+
const changed = this.current(entry, signal);
|
|
225
|
+
if (changed)
|
|
226
|
+
return reject(changed);
|
|
227
|
+
return { status: 'prepared', reason: 'caller_declared_independent', application: 'advisory_only', source_retry_id: retry_id, preparation_id,
|
|
228
|
+
profile_id: profile.id, profile: structuredClone(profile), intent_provenance: 'caller_declared_not_verified', original_invocation: 'deny_returned_execution_not_observed', execution: 'not_observed',
|
|
229
|
+
next_call: { tool: 'spawn_agent', arguments: { task_name, message: standalone_task, fork_turns: 'none', model: profile.model, reasoning_effort: profile.reasoning_effort } },
|
|
230
|
+
next_step: 'Review and submit this separate native invocation only after a host-reported blocked outcome, under existing delegation authorization and unchanged host permissions. Original arguments were not rewritten; host execution is not observed by this server. Do not add history/role/resume overrides or reuse this preparation for another task. Preparation does not prove interception, permission approval, single execution or child execution.' };
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return reject('fresh_delegation_unavailable');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
134
236
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasSufficientTaskText(text: string): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A local screen for task text, not a guarantee of provider sufficiency.
|
|
2
|
+
const segmenter = new Intl.Segmenter('en', { granularity: 'word' });
|
|
3
|
+
export function hasSufficientTaskText(text) {
|
|
4
|
+
const trimmed = text.trim();
|
|
5
|
+
if ([...trimmed].length < 12)
|
|
6
|
+
return false;
|
|
7
|
+
// Numbers and repeated characters alone should not turn a vague request into
|
|
8
|
+
// a descriptive one. Identifiers still contribute their letter content.
|
|
9
|
+
const normalized = trimmed.normalize('NFKC').toLowerCase().replace(/(\p{L})\1{2,}/gu, '$1');
|
|
10
|
+
const content = [...normalized].filter(char => /\p{L}/u.test(char));
|
|
11
|
+
if (content.length < 8 || new Set(content).size < 6)
|
|
12
|
+
return false;
|
|
13
|
+
const compact = content.join('');
|
|
14
|
+
if (/^(.{1,20})\1+$/u.test(compact))
|
|
15
|
+
return false;
|
|
16
|
+
const words = [...segmenter.segment(normalized)].filter(part => part.isWordLike && /\p{L}/u.test(part.segment))
|
|
17
|
+
.map(part => part.segment);
|
|
18
|
+
if (new Set(words).size < 3)
|
|
19
|
+
return false;
|
|
20
|
+
// CJK prose and mixed CJK/identifier text do not require whitespace, but
|
|
21
|
+
// need more letter content and distinct word segments.
|
|
22
|
+
const cjk = content.filter(char => /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(char));
|
|
23
|
+
return cjk.length >= 2 ? content.length >= 12 : trimmed.split(/\s+/u).length >= 3;
|
|
24
|
+
}
|
|
@@ -7,6 +7,7 @@ export declare class RoutingObservations {
|
|
|
7
7
|
private prune;
|
|
8
8
|
record(value: AutomaticHookObservation): void;
|
|
9
9
|
begin(client: unknown, event: unknown): void;
|
|
10
|
+
recordFresh(retry_id: string, result: Record<string, unknown>): void;
|
|
10
11
|
recordRetry(retry_id: string, result: Record<string, unknown>): void;
|
|
11
12
|
lookupRetry(retry_id: string): {
|
|
12
13
|
status: 'arguments_updated' | 'advisory' | 'preserved' | 'pending' | 'awaiting_context' | 'blocked';
|
|
@@ -36,6 +37,17 @@ export declare class RoutingObservations {
|
|
|
36
37
|
reason: string;
|
|
37
38
|
};
|
|
38
39
|
};
|
|
40
|
+
fresh_delegation?: {
|
|
41
|
+
outcome?: {
|
|
42
|
+
preparation_id: string;
|
|
43
|
+
profile_id: string;
|
|
44
|
+
};
|
|
45
|
+
last_attempt: {
|
|
46
|
+
status: string;
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
49
|
+
execution: 'not_observed';
|
|
50
|
+
};
|
|
39
51
|
scope: string;
|
|
40
52
|
retention_seconds: number;
|
|
41
53
|
capacity: number;
|
|
@@ -75,6 +87,17 @@ export declare class RoutingObservations {
|
|
|
75
87
|
reason: string;
|
|
76
88
|
};
|
|
77
89
|
};
|
|
90
|
+
fresh_delegation?: {
|
|
91
|
+
outcome?: {
|
|
92
|
+
preparation_id: string;
|
|
93
|
+
profile_id: string;
|
|
94
|
+
};
|
|
95
|
+
last_attempt: {
|
|
96
|
+
status: string;
|
|
97
|
+
reason: string;
|
|
98
|
+
};
|
|
99
|
+
execution: 'not_observed';
|
|
100
|
+
};
|
|
78
101
|
scope: string;
|
|
79
102
|
retention_seconds: number;
|
|
80
103
|
capacity: number;
|
|
@@ -15,13 +15,24 @@ export class RoutingObservations {
|
|
|
15
15
|
return;
|
|
16
16
|
const previous = this.entries.get(value.correlation_id);
|
|
17
17
|
const recovery = previous?.value.context_retry;
|
|
18
|
+
const fresh = previous?.value.fresh_delegation;
|
|
18
19
|
this.entries.delete(value.correlation_id);
|
|
19
20
|
this.entries.set(value.correlation_id, { at: previous?.at ?? this.now(), value: structuredClone({ ...value,
|
|
20
|
-
...(recovery ? { retry_id: previous.value.retry_id, context_retry: recovery } : {}) }) });
|
|
21
|
+
...(recovery ? { retry_id: previous.value.retry_id, context_retry: recovery } : {}), ...(fresh ? { retry_id: previous.value.retry_id, fresh_delegation: fresh } : {}) }) });
|
|
21
22
|
while (this.entries.size > 128)
|
|
22
23
|
this.entries.delete(this.entries.keys().next().value);
|
|
23
24
|
}
|
|
24
25
|
begin(client, event) { this.record(initialHookObservation(client, event)); }
|
|
26
|
+
recordFresh(retry_id, result) {
|
|
27
|
+
this.prune();
|
|
28
|
+
const entry = [...this.entries.values()].find(entry => entry.value.retry_id === retry_id);
|
|
29
|
+
if (!entry)
|
|
30
|
+
return;
|
|
31
|
+
const status = result.status === 'prepared' ? 'prepared' : 'rejected';
|
|
32
|
+
const reason = typeof result.reason === 'string' && /^[a-z_]{1,64}$/.test(result.reason) ? result.reason : 'invalid_response';
|
|
33
|
+
const outcome = status === 'prepared' && typeof result.preparation_id === 'string' && /^[a-f0-9]{64}$/.test(result.preparation_id) && typeof result.profile_id === 'string' && /^codex-(simple|routine|deep)$/.test(result.profile_id) ? { preparation_id: result.preparation_id, profile_id: result.profile_id } : entry.value.fresh_delegation?.outcome;
|
|
34
|
+
entry.value = { ...entry.value, fresh_delegation: { ...(outcome ? { outcome } : {}), last_attempt: { status, reason }, execution: 'not_observed' } };
|
|
35
|
+
}
|
|
25
36
|
recordRetry(retry_id, result) {
|
|
26
37
|
this.prune();
|
|
27
38
|
const entry = [...this.entries.values()].find(entry => entry.value.retry_id === retry_id);
|
package/dist/src/server.js
CHANGED
|
@@ -39,7 +39,7 @@ export function createServer({ env = process.env } = {}) {
|
|
|
39
39
|
recommendation: { application: 'advisory_only', host_evidence_required: false, constraints: 'caller_declared_pins' },
|
|
40
40
|
model_information: { status: modelInfo.status, refresh: 'explicit_only', account_access_verified: false }, disabled_clients: disabledClients,
|
|
41
41
|
credential_status: credentialStatus,
|
|
42
|
-
automatic_hook: { status: loadAutomaticHookPolicy(env.APTLY_HOOK_POLICY_PATH).reason, mode: loadAutomaticHookPolicy(env.APTLY_HOOK_POLICY_PATH).policy?.mode ?? 'disabled', host_settings_verified: false, context_tool: 'prepare_spawn_context', context_scope: 'this_process_exact_event_5_minutes', context_retry_tool: 'retry_spawn_recommendation', context_retry_limit: 1, observation_tool: 'get_spawn_routing_observation', observation_scope: 'this_process_recent_calls', execution_observation: 'not_supported',
|
|
42
|
+
automatic_hook: { status: loadAutomaticHookPolicy(env.APTLY_HOOK_POLICY_PATH).reason, mode: loadAutomaticHookPolicy(env.APTLY_HOOK_POLICY_PATH).policy?.mode ?? 'disabled', host_settings_verified: false, context_tool: 'prepare_spawn_context', context_scope: 'this_process_exact_event_5_minutes', context_retry_tool: 'retry_spawn_recommendation', context_retry_limit: 1, fresh_delegation_tool: 'prepare_fresh_delegation', fresh_delegation_intent: 'caller_declared_not_verified', observation_tool: 'get_spawn_routing_observation', observation_scope: 'this_process_recent_calls', execution_observation: 'not_supported',
|
|
43
43
|
guarantee: { scope: 'enabled_trusted_connected_supported_hook_only', missing_hook_detectable: false, unavailable_host_hook: 'host_controls_fallback', eligible_defaults_failure: 'deny', inherited_application: 'defaults_deny_advisory_feedback', caller_recovery: 'model_driven_not_guaranteed' } },
|
|
44
44
|
}));
|
|
45
45
|
server.registerTool('get_spawn_routing_observation', {
|
|
@@ -80,6 +80,15 @@ export function createServer({ env = process.env } = {}) {
|
|
|
80
80
|
observations.recordRetry(retry_id, result);
|
|
81
81
|
return content(result);
|
|
82
82
|
});
|
|
83
|
+
server.registerTool('prepare_fresh_delegation', {
|
|
84
|
+
description: 'Prepare a SEPARATE intentional Codex fresh-child call from a completed inherited recommendation. No classification or spawn. Use the original Hook retry_id on this process within five minutes. Only when the caller can declare independent work, no user-required inherited history, and complete standalone instructions. Never use for required/unknown history or to bypass permissions. Explicit choices and the original blocked invocation remain intact. Same task is idempotent; changed task conflicts.',
|
|
85
|
+
annotations: { ...annotations, openWorldHint: false }, inputSchema: { retry_id: z.string().regex(/^[a-f0-9]{64}$/), task_name: z.string().min(1).max(128), standalone_task: z.string().min(1).max(12000),
|
|
86
|
+
declaration: z.object({ independent_task: z.boolean(), same_task: z.boolean(), original_call_outcome: z.enum(['blocked', 'executed', 'unknown']), history_requirement: z.enum(['not_required', 'required', 'unknown']), standalone_context_complete: z.boolean() }).strict() }
|
|
87
|
+
}, async ({ retry_id, task_name, standalone_task, declaration }, extra) => {
|
|
88
|
+
const result = retries.prepareFresh(retry_id, task_name, standalone_task, declaration, extra.signal);
|
|
89
|
+
observations.recordFresh(retry_id, result);
|
|
90
|
+
return content(result);
|
|
91
|
+
});
|
|
83
92
|
server.registerTool('get_routing_precedence', {
|
|
84
93
|
description: 'Explain preserved choices and unknown effective setting sources. Never classifies, reads a transcript, or changes permissions.', annotations: { ...annotations, openWorldHint: false }, inputSchema: hookSchema
|
|
85
94
|
}, async ({ client, event }) => {
|
|
@@ -92,7 +101,7 @@ export function createServer({ env = process.env } = {}) {
|
|
|
92
101
|
}, async ({ client, event, task }, extra) => {
|
|
93
102
|
observations.begin(client, event);
|
|
94
103
|
if (env.APTLY_HOOK_POLICY_PATH !== undefined) {
|
|
95
|
-
const result = await automaticHook({ client, event, router, policyPath: env.APTLY_HOOK_POLICY_PATH, signal: extra.signal, context: () => contexts.lookup(client, event), onObservation: value => observations.record(value), onNeedsContext: (seed, current) => retries.register(seed, current) });
|
|
104
|
+
const result = await automaticHook({ client, event, router, policyPath: env.APTLY_HOOK_POLICY_PATH, signal: extra.signal, context: () => contexts.lookup(client, event), onObservation: value => observations.record(value), onNeedsContext: (seed, current) => retries.register(seed, current), onBlockedAdvice: (seed, current) => retries.registerAdvice(seed, current) });
|
|
96
105
|
observations.record(result.observation);
|
|
97
106
|
return { content: [{ type: 'text', text: JSON.stringify(result.output) }] };
|
|
98
107
|
}
|
package/dist/src/setup.js
CHANGED
|
@@ -507,15 +507,19 @@ function prepare(options, client, removing, edit) {
|
|
|
507
507
|
/** Secure sibling staging is short-lived and never a backup; original settings stay in memory. */
|
|
508
508
|
function replace(snapshot, forward) {
|
|
509
509
|
const expected = forward ? snapshot.before : snapshot.after, next = forward ? snapshot.after : snapshot.before;
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
const check = () => {
|
|
511
|
+
const current = read(snapshot.path);
|
|
512
|
+
if (current.text !== expected || (process.platform !== 'win32' && expected !== null && current.mode !== snapshot.mode))
|
|
513
|
+
fail('concurrent_configuration_change');
|
|
514
|
+
};
|
|
515
|
+
check();
|
|
512
516
|
if (next === null) {
|
|
513
517
|
if (expected !== null)
|
|
514
518
|
unlinkSync(snapshot.path);
|
|
515
519
|
return;
|
|
516
520
|
}
|
|
517
521
|
const stage = join(dirname(snapshot.path), `.aptly-stage-${randomUUID()}`);
|
|
518
|
-
let fd;
|
|
522
|
+
let fd, staged = true;
|
|
519
523
|
try {
|
|
520
524
|
fd = openSync(stage, 'wx', 0o600);
|
|
521
525
|
if (process.platform === 'win32' && expected !== null) {
|
|
@@ -529,21 +533,23 @@ function replace(snapshot, forward) {
|
|
|
529
533
|
writeFileSync(fd, next);
|
|
530
534
|
closeSync(fd);
|
|
531
535
|
fd = undefined;
|
|
532
|
-
if (
|
|
533
|
-
|
|
536
|
+
if (process.platform !== 'win32')
|
|
537
|
+
chmodSync(stage, snapshot.mode);
|
|
538
|
+
check();
|
|
534
539
|
renameSync(stage, snapshot.path);
|
|
535
|
-
|
|
536
|
-
chmodSync(snapshot.path, snapshot.mode);
|
|
540
|
+
staged = false;
|
|
537
541
|
}
|
|
538
542
|
finally {
|
|
539
543
|
if (fd !== undefined)
|
|
540
544
|
closeSync(fd);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
545
|
+
if (staged) {
|
|
546
|
+
try {
|
|
547
|
+
unlinkSync(stage);
|
|
548
|
+
}
|
|
549
|
+
catch (e) {
|
|
550
|
+
if (e.code !== 'ENOENT')
|
|
551
|
+
throw e;
|
|
552
|
+
}
|
|
547
553
|
}
|
|
548
554
|
}
|
|
549
555
|
}
|
|
@@ -602,13 +608,16 @@ function execute(options, removing, edit, captured) {
|
|
|
602
608
|
validateObservations(plan, written);
|
|
603
609
|
}
|
|
604
610
|
catch (e) {
|
|
605
|
-
let rollbackConflict = false;
|
|
611
|
+
let rollbackConflict = false, rollbackFailure = false;
|
|
606
612
|
for (const snapshot of written.reverse()) {
|
|
607
613
|
try {
|
|
608
614
|
replace(snapshot, false);
|
|
609
615
|
}
|
|
610
|
-
catch {
|
|
611
|
-
|
|
616
|
+
catch (error) {
|
|
617
|
+
if (safeCode(error) === 'concurrent_configuration_change')
|
|
618
|
+
rollbackConflict = true;
|
|
619
|
+
else
|
|
620
|
+
rollbackFailure = true;
|
|
612
621
|
}
|
|
613
622
|
}
|
|
614
623
|
for (const path of madeDirs.reverse()) {
|
|
@@ -618,7 +627,7 @@ function execute(options, removing, edit, captured) {
|
|
|
618
627
|
catch { /* Never remove another writer's files. */ }
|
|
619
628
|
}
|
|
620
629
|
plan.result.status = 'error';
|
|
621
|
-
plan.result.codes = [safeCode(e), ...(rollbackConflict ? ['rollback_concurrent_change'] : [])];
|
|
630
|
+
plan.result.codes = [safeCode(e), ...(rollbackConflict ? ['rollback_concurrent_change'] : []), ...(rollbackFailure ? ['rollback_failed'] : [])];
|
|
622
631
|
}
|
|
623
632
|
}
|
|
624
633
|
return { status: results.some(result => result.status === 'error') ? 'partial' : results.every(result => result.status === 'skipped') ? 'skipped' : 'complete', clients: results };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { automaticCallIdentity } from './automatic-hook.js';
|
|
3
|
+
import { hasSufficientTaskText } from './context-sufficiency.js';
|
|
3
4
|
const sensitive = (text) => /\bsk-[A-Za-z0-9_-]{12,}|\bBearer\s+[A-Za-z0-9._~+\/-]{8,}={0,2}/i.test(text);
|
|
4
5
|
/** Explicit, process-local handoff. Tombstones prevent expiry/cancellation fallback. */
|
|
5
6
|
export class SpawnContexts {
|
|
@@ -17,7 +18,7 @@ export class SpawnContexts {
|
|
|
17
18
|
if (!identity)
|
|
18
19
|
return { status: 'rejected', reason: 'invalid_event' };
|
|
19
20
|
if (typeof description !== 'string' || Buffer.byteLength(description) > Math.min(3800, maxBytes - 96) ||
|
|
20
|
-
|
|
21
|
+
!hasSufficientTaskText(description))
|
|
21
22
|
return { status: 'rejected', reason: 'insufficient_context' };
|
|
22
23
|
if (sensitive(description))
|
|
23
24
|
return { status: 'rejected', reason: 'sensitive_input' };
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.6";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.6';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
type Runner = (executable: string, args: readonly string[], input: string) => string;
|
|
1
|
+
type Runner = (executable: string, args: readonly string[], input: string, timeoutMs: number) => string;
|
|
2
2
|
interface WindowsPrivateOptions {
|
|
3
3
|
execute?: Runner;
|
|
4
|
+
timeoutMs?: number;
|
|
4
5
|
}
|
|
5
6
|
/** Preserve the existing file DACL, including inheritance protection, before writing stage content. */
|
|
6
7
|
export declare function copyWindowsFilePermissions(source: string, target: string, options?: WindowsPrivateOptions): void;
|
|
@@ -8,15 +8,15 @@ $ErrorActionPreference = 'Stop'
|
|
|
8
8
|
try {
|
|
9
9
|
$request = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
10
10
|
$path = [string]$request.path
|
|
11
|
-
if ([string]::IsNullOrWhiteSpace($path) -or ![IO.Path]::IsPathRooted($path)) { throw '
|
|
11
|
+
if ([string]::IsNullOrWhiteSpace($path) -or ![IO.Path]::IsPathRooted($path)) { throw 'aptly_acl_rejected' }
|
|
12
12
|
$attributes = [IO.File]::GetAttributes($path)
|
|
13
|
-
if (($attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw '
|
|
13
|
+
if (($attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'aptly_acl_rejected' }
|
|
14
14
|
$isDirectory = ($attributes -band [IO.FileAttributes]::Directory) -ne 0
|
|
15
15
|
$sidType = [Security.Principal.SecurityIdentifier]
|
|
16
16
|
$current = [Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
17
17
|
$allowed = @($current.Value, 'S-1-5-18', 'S-1-5-32-544')
|
|
18
18
|
if ($request.action -eq 'protect-new-directory') {
|
|
19
|
-
if (!$isDirectory) { throw '
|
|
19
|
+
if (!$isDirectory) { throw 'aptly_acl_rejected' }
|
|
20
20
|
$acl = [Security.AccessControl.DirectorySecurity]::new()
|
|
21
21
|
$acl.SetOwner($current)
|
|
22
22
|
$acl.SetAccessRuleProtection($true, $false)
|
|
@@ -26,19 +26,19 @@ try {
|
|
|
26
26
|
$acl.AddAccessRule($rule)
|
|
27
27
|
}
|
|
28
28
|
[IO.Directory]::SetAccessControl($path, $acl)
|
|
29
|
-
} elseif ($request.action -ne 'assert-private') { throw '
|
|
29
|
+
} elseif ($request.action -ne 'assert-private') { throw 'aptly_acl_rejected' }
|
|
30
30
|
$acl = if ($isDirectory) { [IO.Directory]::GetAccessControl($path) } else { [IO.File]::GetAccessControl($path) }
|
|
31
|
-
if ($allowed -notcontains $acl.GetOwner($sidType).Value) { throw '
|
|
31
|
+
if ($allowed -notcontains $acl.GetOwner($sidType).Value) { throw 'aptly_acl_rejected' }
|
|
32
32
|
$descriptor = [Security.AccessControl.RawSecurityDescriptor]::new($acl.GetSecurityDescriptorBinaryForm(), 0)
|
|
33
|
-
if ($null -eq $descriptor.DiscretionaryAcl) { throw '
|
|
33
|
+
if ($null -eq $descriptor.DiscretionaryAcl) { throw 'aptly_acl_rejected' }
|
|
34
34
|
foreach ($rule in $acl.GetAccessRules($true, $true, $sidType)) {
|
|
35
|
-
if ($rule.AccessControlType -eq [Security.AccessControl.AccessControlType]::Allow -and $allowed -notcontains $rule.IdentityReference.Value) { throw '
|
|
35
|
+
if ($rule.AccessControlType -eq [Security.AccessControl.AccessControlType]::Allow -and $allowed -notcontains $rule.IdentityReference.Value) { throw 'aptly_acl_rejected' }
|
|
36
36
|
}
|
|
37
37
|
[Console]::Out.Write('private')
|
|
38
|
-
} catch { [Console]::Out.Write('rejected'); exit 1 }
|
|
38
|
+
} catch { if ($_.Exception.Message -eq 'aptly_acl_rejected') { [Console]::Out.Write('rejected') } else { [Console]::Out.Write('error') }; exit 1 }
|
|
39
39
|
`;
|
|
40
|
-
const run = (executable, args, input) => execFileSync(executable, [...args], {
|
|
41
|
-
input, encoding: 'utf8', windowsHide: true, timeout:
|
|
40
|
+
const run = (executable, args, input, timeoutMs) => execFileSync(executable, [...args], {
|
|
41
|
+
input, encoding: 'utf8', windowsHide: true, timeout: timeoutMs, maxBuffer: 4096, stdio: ['pipe', 'pipe', 'pipe']
|
|
42
42
|
});
|
|
43
43
|
const copyScript = String.raw `
|
|
44
44
|
$ErrorActionPreference = 'Stop'
|
|
@@ -47,13 +47,13 @@ try {
|
|
|
47
47
|
$request = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
48
48
|
$source = [string]$request.source
|
|
49
49
|
$target = [string]$request.target
|
|
50
|
-
if (![IO.Path]::IsPathRooted($source) -or ![IO.Path]::IsPathRooted($target)) { throw '
|
|
50
|
+
if (![IO.Path]::IsPathRooted($source) -or ![IO.Path]::IsPathRooted($target)) { throw 'aptly_acl_rejected' }
|
|
51
51
|
$source = [IO.Path]::GetFullPath($source)
|
|
52
52
|
$target = [IO.Path]::GetFullPath($target)
|
|
53
|
-
if ([string]::Equals($source, $target, [StringComparison]::OrdinalIgnoreCase) -or ![string]::Equals([IO.Path]::GetDirectoryName($source), [IO.Path]::GetDirectoryName($target), [StringComparison]::OrdinalIgnoreCase)) { throw '
|
|
53
|
+
if ([string]::Equals($source, $target, [StringComparison]::OrdinalIgnoreCase) -or ![string]::Equals([IO.Path]::GetDirectoryName($source), [IO.Path]::GetDirectoryName($target), [StringComparison]::OrdinalIgnoreCase)) { throw 'aptly_acl_rejected' }
|
|
54
54
|
foreach ($path in @($source, $target)) {
|
|
55
55
|
$attributes = [IO.File]::GetAttributes($path)
|
|
56
|
-
if (($attributes -band [IO.FileAttributes]::Directory) -ne 0 -or ($attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw '
|
|
56
|
+
if (($attributes -band [IO.FileAttributes]::Directory) -ne 0 -or ($attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'aptly_acl_rejected' }
|
|
57
57
|
}
|
|
58
58
|
$sections = [Security.AccessControl.AccessControlSections]::Access
|
|
59
59
|
$sourceAcl = [IO.File]::GetAccessControl($source, $sections)
|
|
@@ -66,20 +66,37 @@ try {
|
|
|
66
66
|
$acl.SetSecurityDescriptorSddlForm($expected, $sections)
|
|
67
67
|
[IO.File]::SetAccessControl($target, $acl)
|
|
68
68
|
$actual = [IO.File]::GetAccessControl($target, $sections).GetSecurityDescriptorSddlForm($sections)
|
|
69
|
-
if ($expected -cne $actual) { throw '
|
|
69
|
+
if ($expected -cne $actual) { throw 'aptly_acl_rejected' }
|
|
70
70
|
[Console]::Out.Write('private')
|
|
71
|
-
} catch { [Console]::Out.Write('rejected'); exit 1 }
|
|
71
|
+
} catch { if ($_.Exception.Message -eq 'aptly_acl_rejected') { [Console]::Out.Write('rejected') } else { [Console]::Out.Write('error') }; exit 1 }
|
|
72
72
|
`;
|
|
73
73
|
function runScript(scriptText, input, options) {
|
|
74
|
+
const started = Date.now();
|
|
75
|
+
const timeoutMs = options.timeoutMs === undefined ? 10000 : options.timeoutMs;
|
|
76
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 30000)
|
|
77
|
+
throw new Error('windows_private_permissions');
|
|
78
|
+
let category = 'process';
|
|
74
79
|
try {
|
|
75
80
|
const executable = windowsPowerShellPath();
|
|
76
|
-
const result = (options.execute ?? run)(executable, ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(scriptText, 'utf16le').toString('base64')], JSON.stringify(input));
|
|
77
|
-
if (result
|
|
78
|
-
|
|
81
|
+
const result = (options.execute ?? run)(executable, ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(scriptText, 'utf16le').toString('base64')], JSON.stringify(input), timeoutMs);
|
|
82
|
+
if (result === 'private')
|
|
83
|
+
return;
|
|
84
|
+
category = result === 'rejected' ? 'rejected' : result === 'error' ? 'process' : 'unexpected_output';
|
|
79
85
|
}
|
|
80
|
-
catch {
|
|
81
|
-
|
|
86
|
+
catch (error) {
|
|
87
|
+
// Inspect only bounded process metadata; never propagate stderr or input.
|
|
88
|
+
const failure = error;
|
|
89
|
+
if (failure?.code === 'ETIMEDOUT')
|
|
90
|
+
category = 'timeout';
|
|
91
|
+
else if (failure?.stdout === 'rejected')
|
|
92
|
+
category = 'rejected';
|
|
93
|
+
else if (typeof failure?.code === 'string' && ['ENOENT', 'EACCES', 'EPERM', 'ENOEXEC', 'ENOTDIR'].includes(failure.code) && failure?.status == null)
|
|
94
|
+
category = 'launch';
|
|
82
95
|
}
|
|
96
|
+
const failure = new Error('windows_private_permissions');
|
|
97
|
+
failure.category = category;
|
|
98
|
+
failure.elapsed_ms = Math.max(0, Date.now() - started);
|
|
99
|
+
throw failure;
|
|
83
100
|
}
|
|
84
101
|
function invoke(path, action, options) {
|
|
85
102
|
if (typeof path !== 'string' || !path || path.includes('\0'))
|
package/docs/SPAWN_CONTEXT.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The original exact-event handoff is available from Aptly 0.1.4, following the
|
|
4
4
|
pre-spawn routing changes in #60. Context recovery and visible routing outcomes
|
|
5
|
-
are available from Aptly 0.1.5.
|
|
5
|
+
are available from Aptly 0.1.5. Intentional fresh-delegation preparation is
|
|
6
|
+
available from Aptly 0.1.6.
|
|
6
7
|
It does not decode opaque messages, inspect conversations or modify host
|
|
7
8
|
internals. It provides an explicit caller protocol, not an automatic description
|
|
8
9
|
producer for the shipped Hook templates.
|
|
@@ -324,3 +325,101 @@ unpinned state. These trials are not a model-quality or cost comparison.
|
|
|
324
325
|
This verifies one caller-driven Claude recovery under explicit unpinned task
|
|
325
326
|
semantics. It does not guarantee every parent model follows feedback, change
|
|
326
327
|
host permission decisions, or establish inherited Codex application support.
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
## Intentional fresh delegation
|
|
331
|
+
|
|
332
|
+
Available from Aptly 0.1.6.
|
|
333
|
+
|
|
334
|
+
`prepare_fresh_delegation` is a caller protocol for a separate Codex invocation,
|
|
335
|
+
not a rewrite of the original inherited invocation. An enabled defaults Hook can
|
|
336
|
+
provide a routing reference named `retry_id` after direct completed inherited
|
|
337
|
+
advice, or the caller can use the existing context-retry reference after a
|
|
338
|
+
completed recommendation. Direct-advice references cannot request another paid
|
|
339
|
+
context supplement. Advisory paths are excluded because the original invocation
|
|
340
|
+
may already execute.
|
|
341
|
+
|
|
342
|
+
The caller supplies `task_name`, a bounded `standalone_task`, and a declaration:
|
|
343
|
+
`independent_task: true`, `same_task: true`, `original_call_outcome: "blocked"`,
|
|
344
|
+
`history_requirement: "not_required"`,
|
|
345
|
+
`standalone_context_complete: true`. Required/unknown history, undeclared
|
|
346
|
+
independence, incomplete context and changed scope reject without preparing a
|
|
347
|
+
call. These declarations are not verified user-intent provenance. The caller
|
|
348
|
+
must not make them when the user explicitly requires inheritance.
|
|
349
|
+
|
|
350
|
+
Only original native inputs with the supported task/model/effort/fork fields
|
|
351
|
+
qualify. Unknown additional execution fields are rejected rather than silently
|
|
352
|
+
dropped. Fixed roles/resume remain locally preserved before advice. Explicit
|
|
353
|
+
partial model/effort choices still constrain the completed allowlisted profile.
|
|
354
|
+
The current policy/catalog, original event/context and completed ledger result
|
|
355
|
+
are revalidated. Unknown results and missing/abstaining recommendations cannot
|
|
356
|
+
prepare a child. No new classification occurs.
|
|
357
|
+
|
|
358
|
+
A successful response provides separate `next_call.arguments` including explicit
|
|
359
|
+
`fork_turns: "none"`, the validated profile and the caller's standalone task.
|
|
360
|
+
A deny was returned for the original input, which was not rewritten. Server
|
|
361
|
+
observation does not certify that the host enforced it. The caller must have a
|
|
362
|
+
host-reported blocked tool outcome; executed/unknown declarations reject.
|
|
363
|
+
The caller reviews and submits a
|
|
364
|
+
new native call under unchanged host permissions and existing delegation
|
|
365
|
+
authorization. Neither preparation nor argument output proves dispatch/execution.
|
|
366
|
+
The process does not own native spawn or guarantee caller compliance.
|
|
367
|
+
|
|
368
|
+
The original five-minute lifetime and process/capacity boundaries apply. One
|
|
369
|
+
immutable preparation digest binds task, declaration, profile and original
|
|
370
|
+
reference; text/history are not persisted. Duplicate identical preparation is
|
|
371
|
+
idempotent; changed input conflicts. Expiry, cancellation, original-event or
|
|
372
|
+
policy/catalog changes prevent preparation. `fresh_delegation` observations
|
|
373
|
+
separate the prepared outcome from the latest rejected attempt and always keep
|
|
374
|
+
execution `not_observed`. The eventual new native call has its own identity;
|
|
375
|
+
server evidence does not automatically certify its relationship to this plan.
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
### Bounded native fresh-delegation verification — 2026-11-07
|
|
379
|
+
|
|
380
|
+
Codex CLI 0.167.0 used its existing trusted Hook with an ephemeral product-server
|
|
381
|
+
override. One standalone sorting task specified an initial inherited caller
|
|
382
|
+
default while explicitly requiring no inherited history. The original opaque
|
|
383
|
+
call stayed blocked; the parent supplied context, obtained one real Decisions
|
|
384
|
+
recommendation, declared independent same-task intent and called the preparation
|
|
385
|
+
API. It then submitted a separate native call with `fork_turns: "none"` and the
|
|
386
|
+
returned Luna/max profile. The actual linked child recorded `gpt-6-luna` / `max`,
|
|
387
|
+
returned the expected list and contained no copied parent message payloads.
|
|
388
|
+
Approval/sandbox constraints matched the parent. Preparation added no paid call.
|
|
389
|
+
|
|
390
|
+
A separate two-turn test explicitly required inherited history. It obtained one
|
|
391
|
+
real recommendation, preserved `fork_turns: "all"`, made no fresh preparation and
|
|
392
|
+
created no child. Both tests preserved persistent configuration/trust, used no
|
|
393
|
+
response-modifying adapter and removed their temporary files. These are bounded
|
|
394
|
+
caller-driven checks, not universal model compliance or verified user provenance.
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
Captured event/context checks are process-local and do not observe later native
|
|
398
|
+
host-setting changes or host cancellation unless forwarded through the request
|
|
399
|
+
signal or explicit registered-context revocation. The reused profile was chosen
|
|
400
|
+
from the original classification summary; `same_task` is a caller declaration,
|
|
401
|
+
not a semantic comparison of the standalone task. Do not reuse it for different
|
|
402
|
+
work. Repeated preparation is idempotent, not an exactly-once spawn mechanism.
|
|
403
|
+
The host still owns each actual invocation and its permissions.
|
|
404
|
+
|
|
405
|
+
Private preparation digests are intentionally immutable once written, including
|
|
406
|
+
when a final currentness check rejects the response. This fail-closed binding
|
|
407
|
+
prevents changing a task under a consumed reference; it is not a plaintext backup
|
|
408
|
+
and is not deleted to permit a different-task retry. The advisory read-only hint
|
|
409
|
+
means no user file, host configuration or native execution is changed; like the
|
|
410
|
+
existing recommendation/cache tools, private query bookkeeping is still written.
|
|
411
|
+
It is not a statelessness or permission-approval claim.
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
The final instruction-contract candidate was also checked with explicit session
|
|
415
|
+
owner authorization for Aptly to choose model/effort defaults for the independent
|
|
416
|
+
task. The original caller-default all was denied, the caller used the declared
|
|
417
|
+
preparation API, and a separate none invocation ran the recommended Luna/max
|
|
418
|
+
child with the expected output. Exactly one Decisions request was forwarded.
|
|
419
|
+
A final explicit-history case preserved all and created no child. Persistent
|
|
420
|
+
configuration/trust stayed unchanged. An intervening candidate stopped after
|
|
421
|
+
recommendation when the parent treated original-fork preservation as a blanket
|
|
422
|
+
ban; that run remains a failed caller-follow-through observation, not successful
|
|
423
|
+
execution. This motivated the stricter instruction distinguishing original-call
|
|
424
|
+
resubmission from the only supported separate preparation protocol. These results
|
|
425
|
+
remain bounded and do not guarantee arbitrary parent-model compliance.
|
package/docs/guide/en.md
CHANGED
|
@@ -225,6 +225,7 @@ For genuinely independent work, the caller can intentionally choose a fresh chil
|
|
|
225
225
|
| `prepare_spawn_context` | Registers a bounded description for one exact upcoming invocation |
|
|
226
226
|
| `cancel_spawn_context` | Revokes the description association, not native execution or a request already sent |
|
|
227
227
|
| `retry_spawn_recommendation` | Accepts one task-description supplement using a Hook-issued retry_id |
|
|
228
|
+
| `prepare_fresh_delegation` | Prepares a separate independent Codex call from completed inherited advice; never executes it |
|
|
228
229
|
|
|
229
230
|
### Outbound data and disabling automatic sharing
|
|
230
231
|
|
|
@@ -264,6 +265,14 @@ After a valid enabled policy and eligible call are established, `defaults` retur
|
|
|
264
265
|
|
|
265
266
|
With a recovery ID, use `get_spawn_routing_observation({retry_id})` on the same MCP process, or use the existing `{client, event}` form. Mixed or partial forms are rejected. Original `awaiting_context` and `context_retry.outcome` are separate stages; rejected duplicates appear under `last_attempt` without replacing an earlier classification outcome. Lookups incur no paid request and do not renew retention. Execution always remains `not_observed`; neither advice nor argument updates establish actual child execution.
|
|
266
267
|
|
|
268
|
+
### Prepare a separate independent delegation (0.1.6+)
|
|
269
|
+
|
|
270
|
+
After a defaults Hook blocks inherited application, the caller may use `prepare_fresh_delegation` only when it can declare **the same independent task, no user-required inherited history, and complete standalone instructions**. Supply the Hook/retry `retry_id`, `task_name`, `standalone_task`, and `declaration: {independent_task:true, same_task:true, original_call_outcome:"blocked", history_requirement:"not_required", standalone_context_complete:true}` on the same process. It revalidates completed allowlisted advice without another classification.
|
|
271
|
+
|
|
272
|
+
The original inherited invocation stays blocked. Review the separate `next_call.arguments` and submit it under existing delegation authorization and normal host permission checks. It includes `fork_turns: "none"` and preserves model/effort choices. This is caller-declared intent, not verified user intent or execution evidence. Do not use it for required/unknown history, fixed roles, resume or unverified additional execution arguments. A reference binds one task; five-minute expiry, cancellation, policy/catalog changes and changes to the original invocation block preparation. It is not offered for nonblocking advisory paths. See the [contract and limits](../SPAWN_CONTEXT.md#intentional-fresh-delegation).
|
|
273
|
+
|
|
274
|
+
Use this only after the host reports the original call blocked. `original_call_outcome` values `executed` and `unknown` reject preparation. This is caller-declared, not server execution observation. Repeated identical preparation does not guarantee single child execution. The profile was selected from the original classification summary and must not be reused for a different task.
|
|
275
|
+
|
|
267
276
|
## Direct recommendations
|
|
268
277
|
|
|
269
278
|
The `recommend_agent` MCP tool and CLI `recommend` accept a task summary and recommend a profile. They do not spawn subagents. Pass this JSON as MCP tool arguments, or save it to a file and provide it to the CLI through standard input.
|
package/docs/guide/ja.md
CHANGED
|
@@ -225,6 +225,7 @@ Codex の本文が不透明な場合、`cleanup_merged_worktrees` のような
|
|
|
225
225
|
| `prepare_spawn_context` | 正確に一致する予定呼び出しに上限付きの説明を登録します |
|
|
226
226
|
| `cancel_spawn_context` | 説明の対応付けを取り消します。native 実行や送信済みリクエストは取り消しません |
|
|
227
227
|
| `retry_spawn_recommendation` | Hook が返す retry_id を使い、タスク説明を一度補って再推薦します |
|
|
228
|
+
| `prepare_fresh_delegation` | 完了済みの継承推薦から別の独立 Codex 呼び出し引数を準備し、実行はしません |
|
|
228
229
|
|
|
229
230
|
### 外部送信と自動共有の無効化
|
|
230
231
|
|
|
@@ -264,6 +265,14 @@ Decisions には `client`、`task.summary`、`task.operation`、`task.context_su
|
|
|
264
265
|
|
|
265
266
|
復旧 ID があれば、同じ MCP プロセスで `get_spawn_routing_observation({retry_id})` を呼べます。従来の `{client, event}` 形式も使えますが、混在や不完全な入力は拒否します。元の `awaiting_context` と `context_retry.outcome` は別の段階です。拒否した重複要求は `last_attempt` に記録し、以前の分類結果を上書きしません。照会は有料要求を発行せず、保持期限も延長しません。実行は常に `not_observed` であり、推薦や引数更新は実際の子の実行証拠ではありません。
|
|
266
267
|
|
|
268
|
+
### 別の独立した委任を準備する(0.1.6 以降)
|
|
269
|
+
|
|
270
|
+
defaults Hook が継承呼び出しへの適用を拒否した後、呼び出し元が**同じ独立タスクであり、ユーザーが継承履歴を要求せず、完全な独立指示を渡せる**と宣言できる場合だけ `prepare_fresh_delegation` を使えます。同じプロセスで Hook または再推薦の `retry_id`、`task_name`、`standalone_task` と `declaration: {independent_task:true, same_task:true, original_call_outcome:"blocked", history_requirement:"not_required", standalone_context_complete:true}` を渡してください。完了済みの許可プロファイルを再確認し、分類を追加で呼びません。
|
|
271
|
+
|
|
272
|
+
元の継承呼び出しは拒否されたままです。別の `next_call.arguments` を確認し、既存の委任権限と通常のホスト権限確認の下で新しい呼び出しを送ってください。`fork_turns: "none"` と、元の選択を保つモデル・effort を含みます。呼び出し元の宣言であり、ユーザー意図や実行を検証するものではありません。履歴が必要・不明、固定役割、resume、未検証の追加実行引数がある場合は使わないでください。参照は一つのタスクだけに結び付き、5分の期限・取消・ポリシー/候補/元の呼び出しの変更で準備を止めます。元の実行を許す advisory 経路には提供しません。[契約と制限](../SPAWN_CONTEXT.md#intentional-fresh-delegation)を確認してください。
|
|
273
|
+
|
|
274
|
+
ホストが元の呼び出しの拒否を報告した後だけ使ってください。`original_call_outcome` が `executed` または `unknown` なら準備を拒否します。これは呼び出し元の宣言で、サーバーの実行観測ではありません。同じ準備の反復は子の一回実行を保証しません。プロファイルは元の分類要約に基づくため別タスクに再利用しないでください。
|
|
275
|
+
|
|
267
276
|
## 直接推薦
|
|
268
277
|
|
|
269
278
|
`recommend_agent` MCP と CLI の `recommend` は、タスク要約を受け取ってプロファイルを推薦します。子エージェントを直接生成することはありません。以下の JSON を MCP ツールの引数として渡すか、ファイルに保存して CLI の標準入力に渡してください。
|
package/docs/guide/ko.md
CHANGED
|
@@ -225,6 +225,7 @@ Codex 본문이 불투명할 때 `cleanup_merged_worktrees`처럼 구체적인
|
|
|
225
225
|
| `prepare_spawn_context` | 정확한 예정 호출에 제한된 설명을 등록합니다 |
|
|
226
226
|
| `cancel_spawn_context` | 등록한 설명의 연결을 취소하며 native 실행이나 이미 전송된 요청을 취소하지 않습니다 |
|
|
227
227
|
| `retry_spawn_recommendation` | Hook의 `retry_id`로 작업 설명을 한 번 보충해 재추천합니다 |
|
|
228
|
+
| `prepare_fresh_delegation` | 완료된 상속 추천으로 별도의 독립 Codex 호출 인자를 준비하며 실행하지 않습니다 |
|
|
228
229
|
|
|
229
230
|
### 외부 전송과 자동 공유 끄기
|
|
230
231
|
|
|
@@ -264,6 +265,14 @@ Decisions에는 `client`, `task.summary`, `task.operation`, `task.context_suffic
|
|
|
264
265
|
|
|
265
266
|
복구 ID가 있으면 `get_spawn_routing_observation({retry_id})`로 같은 MCP 프로세스의 관측을 조회할 수 있습니다. 또는 기존 `{client, event}`를 사용하십시오. 두 형식을 섞거나 일부만 보내면 거부합니다. 원래 `awaiting_context`와 `context_retry.outcome`은 별개이며, 거부된 중복 요청은 `last_attempt`에 표시해 이전 분류 결과를 덮어쓰지 않습니다. 조회는 유료 요청을 만들지 않고 보관 시간을 연장하지 않습니다. 실행은 항상 `not_observed`이므로 추천이나 인자 갱신을 실제 자식 실행으로 표현하지 마십시오.
|
|
266
267
|
|
|
268
|
+
### 상속 추천에서 별도 독립 위임 준비 (0.1.6부터)
|
|
269
|
+
|
|
270
|
+
`defaults`가 상속 적용을 차단한 뒤에도 호출자가 **같은 독립 작업이며 사용자에게 필요한 상속 이력이 없고 완전한 독립 지시를 제공할 수 있음**을 선언하면, 같은 프로세스에서 `prepare_fresh_delegation`을 호출할 수 있습니다. Hook 또는 재추천에서 받은 `retry_id`, `task_name`, `standalone_task`와 `declaration: {independent_task:true, same_task:true, original_call_outcome:"blocked", history_requirement:"not_required", standalone_context_complete:true}`를 전달하십시오. API는 이미 완료된 허용 프로필을 재검증하고 분류를 추가 호출하지 않습니다.
|
|
271
|
+
|
|
272
|
+
원래 상속 호출은 차단된 채 유지됩니다. 응답의 별도 `next_call.arguments`를 검토한 뒤 기존 위임 권한과 호스트 권한 검사에 따라 새 호출을 제출하십시오. `fork_turns: "none"`과 기존 선택을 보존한 모델·effort를 포함합니다. 이 API가 사용자 의도나 실제 실행을 확인한 것은 아닙니다. 이력이 필요하거나 불명확한 경우, 역할·resume·검증하지 않은 추가 실행 인자가 있는 경우에는 사용하지 마십시오. 같은 참조는 같은 작업에만 재사용할 수 있으며 5분 만료·취소·정책/후보 변경과 원래 호출 변경은 준비를 막습니다. `advisory`처럼 원래 실행을 허용한 경로에는 제공하지 않습니다. [계약과 한계](../SPAWN_CONTEXT.md#intentional-fresh-delegation)를 확인하십시오.
|
|
273
|
+
|
|
274
|
+
이 경로는 호스트가 원래 호출의 차단 결과를 돌려준 뒤에만 사용하십시오. `original_call_outcome`이 `executed` 또는 `unknown`이면 준비를 거절합니다. 이는 호출자 선언이며 서버의 실행 관측이 아닙니다. 동일 준비 응답을 여러 번 받는 것이 자식 실행 1회를 보장하지 않으며, 프로필은 원래 분류 요약을 기준으로 선택됐으므로 다른 작업에 재사용하면 안 됩니다.
|
|
275
|
+
|
|
267
276
|
## 직접 추천
|
|
268
277
|
|
|
269
278
|
`recommend_agent` MCP와 CLI `recommend`는 작업 요약을 받아 프로필을 추천합니다. 자식을 직접 생성하지 않습니다. 아래 JSON을 MCP 도구 인자로 전달하거나 파일에 저장해 CLI의 표준 입력으로 제공하십시오.
|
package/docs/guide/zh-CN.md
CHANGED
|
@@ -225,6 +225,7 @@ Codex 正文不透明时,`cleanup_merged_worktrees` 等具体的短任务名
|
|
|
225
225
|
| `prepare_spawn_context` | 为完全匹配的待执行调用注册受限说明 |
|
|
226
226
|
| `cancel_spawn_context` | 撤销说明关联,不取消原生执行或已发送的请求 |
|
|
227
227
|
| `retry_spawn_recommendation` | 使用 Hook 返回的 retry_id 补充一次任务说明并重新推荐 |
|
|
228
|
+
| `prepare_fresh_delegation` | 根据已完成的继承调用推荐准备独立 Codex 调用参数,不执行调用 |
|
|
228
229
|
|
|
229
230
|
### 对外传输与关闭自动共享
|
|
230
231
|
|
|
@@ -264,6 +265,14 @@ Decisions 会收到 `client`、`task.summary`、`task.operation`、`task.context
|
|
|
264
265
|
|
|
265
266
|
获得恢复 ID 后,可在同一 MCP 进程调用 `get_spawn_routing_observation({retry_id})`,或使用原有 `{client, event}` 格式。混用或不完整的输入会被拒绝。原始 `awaiting_context` 与 `context_retry.outcome` 是独立阶段;被拒绝的重复请求记录在 `last_attempt`,不会覆盖已有分类结果。查询不产生付费请求,也不延长保留时间。执行始终为 `not_observed`,推荐或参数更新都不能证明子代理已实际执行。
|
|
266
267
|
|
|
268
|
+
### 准备单独的独立委派(0.1.6 起)
|
|
269
|
+
|
|
270
|
+
当 defaults Hook 阻止继承调用的推荐应用后,仅当调用方能声明**这是同一项独立任务、用户不要求继承历史且可提供完整独立指令**时,才可调用 `prepare_fresh_delegation`。请在同一进程传入 Hook 或重新推荐返回的 `retry_id`、`task_name`、`standalone_task`,以及 `declaration: {independent_task:true, same_task:true, original_call_outcome:"blocked", history_requirement:"not_required", standalone_context_complete:true}`。它重新验证已完成的允许配置,不额外调用分类。
|
|
271
|
+
|
|
272
|
+
原始继承调用仍被阻止。请检查独立的 `next_call.arguments`,按现有委派授权和宿主权限检查提交新调用,其中包含 `fork_turns: "none"` 并保留模型与 effort 选择。这是调用方声明,不是已验证的用户意图或执行证据。历史必需或不明确、固定角色、resume 或含未验证额外执行参数时,请勿使用。每个引用仅绑定一项任务;五分钟到期、取消、策略或候选变化及原调用变化都会阻止准备。不会为不阻止原执行的 advisory 路径提供此功能。请参阅[契约与限制](../SPAWN_CONTEXT.md#intentional-fresh-delegation)。
|
|
273
|
+
|
|
274
|
+
仅在宿主报告原调用已被阻止后使用。`original_call_outcome` 为 `executed` 或 `unknown` 时拒绝准备。这是调用方声明,并非服务器对执行的观测。重复获得相同准备响应不能保证只执行一次子代理。配置依据原始分类摘要选择,不得用于其他任务。
|
|
275
|
+
|
|
267
276
|
## 直接推荐
|
|
268
277
|
|
|
269
278
|
`recommend_agent` MCP 与 CLI 的 `recommend` 接收任务摘要并推荐执行配置,不会直接创建子代理。请将以下 JSON 作为 MCP 工具参数传递,或保存为文件并通过 CLI 的标准输入提供。
|