ai4ai 0.0.3 → 0.0.5
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 +6 -0
- package/README.zh-CN.md +6 -0
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/dist/adapters/claude/adapter.d.ts +10 -1
- package/claude-plugin/dist/adapters/claude/adapter.js +35 -10
- package/claude-plugin/dist/adapters/claude/journal.d.ts +8 -0
- package/claude-plugin/dist/adapters/claude/journal.js +4 -1
- package/claude-plugin/dist/adapters/claude/plugin.js +198 -91
- package/claude-plugin/dist/adapters/claude/worker.js +30 -8
- package/claude-plugin/dist/adapters/codex/adapter.d.ts +26 -19
- package/claude-plugin/dist/adapters/codex/adapter.js +283 -187
- package/claude-plugin/dist/adapters/codex/app-server.js +1 -1
- package/claude-plugin/dist/adapters/codex/control.d.ts +36 -1
- package/claude-plugin/dist/adapters/codex/control.js +74 -4
- package/claude-plugin/dist/adapters/codex/native-handoff.d.ts +60 -0
- package/claude-plugin/dist/adapters/codex/native-handoff.js +138 -0
- package/claude-plugin/dist/adapters/codex/runner.js +35 -32
- package/claude-plugin/dist/adapters/codex/tui-daemon-watch.js +60 -49
- package/claude-plugin/dist/adapters/declarations.d.ts +0 -1
- package/claude-plugin/dist/adapters/declarations.js +0 -1
- package/claude-plugin/dist/adapters/dsh/adapter.d.ts +39 -2
- package/claude-plugin/dist/adapters/dsh/adapter.js +164 -37
- package/claude-plugin/dist/adapters/dsh/plugin.d.ts +3 -1
- package/claude-plugin/dist/adapters/dsh/plugin.js +33 -22
- package/claude-plugin/dist/adapters/executors.d.ts +25 -2
- package/claude-plugin/dist/adapters/executors.js +58 -4
- package/claude-plugin/dist/adapters/external.d.ts +21 -0
- package/claude-plugin/dist/adapters/external.js +128 -18
- package/claude-plugin/dist/adapters/opencode/adapter.d.ts +13 -2
- package/claude-plugin/dist/adapters/opencode/adapter.js +53 -10
- package/claude-plugin/dist/adapters/opencode/journal.d.ts +2 -0
- package/claude-plugin/dist/adapters/opencode/journal.js +8 -3
- package/claude-plugin/dist/adapters/opencode/plugin.js +2 -2
- package/claude-plugin/dist/adapters/supervisor.js +64 -20
- package/claude-plugin/dist/adapters/types.d.ts +7 -0
- package/claude-plugin/dist/contract/schema.d.ts +8 -17
- package/claude-plugin/dist/contract/schema.js +3 -4
- package/claude-plugin/dist/contract/states.d.ts +11 -0
- package/claude-plugin/dist/contract/states.js +9 -0
- package/claude-plugin/dist/contract/types.d.ts +3 -3
- package/claude-plugin/dist/contract/validate.js +24 -14
- package/claude-plugin/dist/contract/version.d.ts +1 -1
- package/claude-plugin/dist/contract/version.js +1 -1
- package/claude-plugin/dist/core/dsh-selection.d.ts +43 -0
- package/claude-plugin/dist/core/dsh-selection.js +78 -0
- package/claude-plugin/dist/core/handoff.d.ts +42 -0
- package/claude-plugin/dist/core/handoff.js +63 -0
- package/claude-plugin/dist/core/index.d.ts +2 -0
- package/claude-plugin/dist/core/index.js +1 -0
- package/claude-plugin/dist/core/operations.js +33 -1
- package/claude-plugin/dist/core/session-probe.js +11 -22
- package/claude-plugin/dist/core/store.d.ts +8 -3
- package/claude-plugin/dist/core/store.js +17 -3
- package/claude-plugin/request-schema.json +1 -2
- package/dist/adapters/claude/adapter.d.ts +10 -1
- package/dist/adapters/claude/adapter.js +35 -10
- package/dist/adapters/claude/journal.d.ts +8 -0
- package/dist/adapters/claude/journal.js +4 -1
- package/dist/adapters/claude/plugin.js +198 -91
- package/dist/adapters/claude/worker.js +30 -8
- package/dist/adapters/codex/adapter.d.ts +26 -19
- package/dist/adapters/codex/adapter.js +283 -187
- package/dist/adapters/codex/app-server.js +1 -1
- package/dist/adapters/codex/control.d.ts +36 -1
- package/dist/adapters/codex/control.js +74 -4
- package/dist/adapters/codex/native-handoff.d.ts +60 -0
- package/dist/adapters/codex/native-handoff.js +138 -0
- package/dist/adapters/codex/runner.js +35 -32
- package/dist/adapters/codex/tui-daemon-watch.js +60 -49
- package/dist/adapters/declarations.d.ts +0 -1
- package/dist/adapters/declarations.js +0 -1
- package/dist/adapters/dsh/adapter.d.ts +39 -2
- package/dist/adapters/dsh/adapter.js +164 -37
- package/dist/adapters/dsh/plugin.d.ts +3 -1
- package/dist/adapters/dsh/plugin.js +33 -22
- package/dist/adapters/executors.d.ts +25 -2
- package/dist/adapters/executors.js +58 -4
- package/dist/adapters/external.d.ts +21 -0
- package/dist/adapters/external.js +128 -18
- package/dist/adapters/opencode/adapter.d.ts +13 -2
- package/dist/adapters/opencode/adapter.js +53 -10
- package/dist/adapters/opencode/journal.d.ts +2 -0
- package/dist/adapters/opencode/journal.js +8 -3
- package/dist/adapters/opencode/plugin.js +2 -2
- package/dist/adapters/supervisor.js +64 -20
- package/dist/adapters/types.d.ts +7 -0
- package/dist/contract/schema.d.ts +8 -17
- package/dist/contract/schema.js +3 -4
- package/dist/contract/states.d.ts +11 -0
- package/dist/contract/states.js +9 -0
- package/dist/contract/types.d.ts +3 -3
- package/dist/contract/validate.js +24 -14
- package/dist/contract/version.d.ts +1 -1
- package/dist/contract/version.js +1 -1
- package/dist/core/dsh-selection.d.ts +43 -0
- package/dist/core/dsh-selection.js +78 -0
- package/dist/core/handoff.d.ts +42 -0
- package/dist/core/handoff.js +63 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/operations.js +33 -1
- package/dist/core/session-probe.js +11 -22
- package/dist/core/store.d.ts +8 -3
- package/dist/core/store.js +17 -3
- package/docs/contract.md +25 -15
- package/opencode-plugin/dist/adapters/claude/adapter.d.ts +10 -1
- package/opencode-plugin/dist/adapters/claude/adapter.js +35 -10
- package/opencode-plugin/dist/adapters/claude/journal.d.ts +8 -0
- package/opencode-plugin/dist/adapters/claude/journal.js +4 -1
- package/opencode-plugin/dist/adapters/claude/plugin.js +198 -91
- package/opencode-plugin/dist/adapters/claude/worker.js +30 -8
- package/opencode-plugin/dist/adapters/codex/adapter.d.ts +26 -19
- package/opencode-plugin/dist/adapters/codex/adapter.js +283 -187
- package/opencode-plugin/dist/adapters/codex/app-server.js +1 -1
- package/opencode-plugin/dist/adapters/codex/control.d.ts +36 -1
- package/opencode-plugin/dist/adapters/codex/control.js +74 -4
- package/opencode-plugin/dist/adapters/codex/native-handoff.d.ts +60 -0
- package/opencode-plugin/dist/adapters/codex/native-handoff.js +138 -0
- package/opencode-plugin/dist/adapters/codex/runner.js +35 -32
- package/opencode-plugin/dist/adapters/codex/tui-daemon-watch.js +60 -49
- package/opencode-plugin/dist/adapters/declarations.d.ts +0 -1
- package/opencode-plugin/dist/adapters/declarations.js +0 -1
- package/opencode-plugin/dist/adapters/dsh/adapter.d.ts +39 -2
- package/opencode-plugin/dist/adapters/dsh/adapter.js +164 -37
- package/opencode-plugin/dist/adapters/dsh/plugin.d.ts +3 -1
- package/opencode-plugin/dist/adapters/dsh/plugin.js +33 -22
- package/opencode-plugin/dist/adapters/executors.d.ts +25 -2
- package/opencode-plugin/dist/adapters/executors.js +58 -4
- package/opencode-plugin/dist/adapters/external.d.ts +21 -0
- package/opencode-plugin/dist/adapters/external.js +128 -18
- package/opencode-plugin/dist/adapters/opencode/adapter.d.ts +13 -2
- package/opencode-plugin/dist/adapters/opencode/adapter.js +53 -10
- package/opencode-plugin/dist/adapters/opencode/journal.d.ts +2 -0
- package/opencode-plugin/dist/adapters/opencode/journal.js +8 -3
- package/opencode-plugin/dist/adapters/opencode/plugin.js +2 -2
- package/opencode-plugin/dist/adapters/supervisor.js +64 -20
- package/opencode-plugin/dist/adapters/types.d.ts +7 -0
- package/opencode-plugin/dist/contract/schema.d.ts +8 -17
- package/opencode-plugin/dist/contract/schema.js +3 -4
- package/opencode-plugin/dist/contract/states.d.ts +11 -0
- package/opencode-plugin/dist/contract/states.js +9 -0
- package/opencode-plugin/dist/contract/types.d.ts +3 -3
- package/opencode-plugin/dist/contract/validate.js +24 -14
- package/opencode-plugin/dist/contract/version.d.ts +1 -1
- package/opencode-plugin/dist/contract/version.js +1 -1
- package/opencode-plugin/dist/core/dsh-selection.d.ts +43 -0
- package/opencode-plugin/dist/core/dsh-selection.js +78 -0
- package/opencode-plugin/dist/core/handoff.d.ts +42 -0
- package/opencode-plugin/dist/core/handoff.js +63 -0
- package/opencode-plugin/dist/core/index.d.ts +2 -0
- package/opencode-plugin/dist/core/index.js +1 -0
- package/opencode-plugin/dist/core/operations.js +33 -1
- package/opencode-plugin/dist/core/session-probe.js +11 -22
- package/opencode-plugin/dist/core/store.d.ts +8 -3
- package/opencode-plugin/dist/core/store.js +17 -3
- package/opencode-plugin/package.json +1 -1
- package/package.json +1 -1
- package/claude-plugin/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
- package/claude-plugin/dist/adapters/codex/tui-restart-watch.js +0 -330
- package/claude-plugin/dist/tmux/backend.d.ts +0 -55
- package/claude-plugin/dist/tmux/backend.js +0 -161
- package/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
- package/dist/adapters/codex/tui-restart-watch.js +0 -330
- package/dist/tmux/backend.d.ts +0 -55
- package/dist/tmux/backend.js +0 -161
- package/opencode-plugin/dist/adapters/codex/tui-restart-watch.d.ts +0 -2
- package/opencode-plugin/dist/adapters/codex/tui-restart-watch.js +0 -330
- package/opencode-plugin/dist/tmux/backend.d.ts +0 -55
- package/opencode-plugin/dist/tmux/backend.js +0 -161
package/README.md
CHANGED
|
@@ -45,4 +45,10 @@ Claude Code / OpenCode / DSH expose the tools after registration; Codex uses the
|
|
|
45
45
|
npx ai4ai session --operation status --harness codex
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### DeepSeek Harness Web
|
|
49
|
+
|
|
50
|
+
1. In DSH Web, open **Plugins** → **Add plugin** and choose `ai4ai`.
|
|
51
|
+
2. **Enable** the plugin.
|
|
52
|
+
3. Restart the DSH service the way you normally start it, then refresh the page.
|
|
53
|
+
|
|
48
54
|
Contract and details: [docs/contract.md](docs/contract.md). MIT.
|
package/README.zh-CN.md
CHANGED
|
@@ -45,4 +45,10 @@ Claude Code / OpenCode / DSH 注册后直接使用工具;Codex 用 CLI:
|
|
|
45
45
|
npx ai4ai session --operation status --harness codex
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
### DeepSeek Harness Web
|
|
49
|
+
|
|
50
|
+
1. 在 DSH Web 打开 **Plugins** → **Add plugin**,选择 `ai4ai`。
|
|
51
|
+
2. **启用**该插件。
|
|
52
|
+
3. 按平时的方式重启 DSH 服务,然后刷新页面。
|
|
53
|
+
|
|
48
54
|
契约与细节见 [docs/contract.md](docs/contract.md)。MIT。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AdapterContext, CarrierCommand, StatusDetails } from '../external.js';
|
|
2
2
|
import { ExternalExecutorAdapter } from '../external.js';
|
|
3
|
-
import type { CapabilityDeclaration } from '../../contract/types.js';
|
|
3
|
+
import type { CapabilityDeclaration, Request } from '../../contract/types.js';
|
|
4
4
|
import type { HarnessId, Os } from '../../contract/states.js';
|
|
5
5
|
import type { ExecutorRecord } from '../../core/store.js';
|
|
6
6
|
import type { LogLine, ExecutorStatus } from '../executors.js';
|
|
@@ -15,6 +15,15 @@ export declare function claudePluginDir(home: string): string | undefined;
|
|
|
15
15
|
export declare class ClaudeAdapter extends ExternalExecutorAdapter {
|
|
16
16
|
readonly harness: HarnessId;
|
|
17
17
|
capabilities(os: Os): CapabilityDeclaration[];
|
|
18
|
+
/**
|
|
19
|
+
* Persist the model a resumed turn must keep. The carrier passes `--model`
|
|
20
|
+
* only when the request has one, so the effective value can come from the
|
|
21
|
+
* settings `env` block (which overrides the inherited process environment)
|
|
22
|
+
* or the process environment.
|
|
23
|
+
*/
|
|
24
|
+
protected persistedModel(request: Request, ctx: AdapterContext): Promise<string | undefined>;
|
|
25
|
+
/** `CLAUDE_CODE_EFFORT_LEVEL` overrides the settings `effortLevel`. */
|
|
26
|
+
protected persistedReasoningEffort(request: Request, ctx: AdapterContext): Promise<string | undefined>;
|
|
18
27
|
protected carrier(request: Parameters<ExternalExecutorAdapter['spawn']>[0], ctx: AdapterContext, _executorId: string, resumeSessionId?: string): Promise<CarrierCommand>;
|
|
19
28
|
protected statusDetails(_record: ExecutorRecord, status: ExecutorStatus, log: LogLine[], ctx: AdapterContext): Promise<StatusDetails>;
|
|
20
29
|
}
|
|
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
4
4
|
import { ExternalExecutorAdapter, lastJson } from '../external.js';
|
|
5
5
|
import { resolveClaudeStatus } from './status.js';
|
|
6
6
|
import { verifiedText, verifiedTokens, verifiedWindow } from '../../core/ladder.js';
|
|
7
|
+
import { envValue, probeClaudeSettings } from '../../core/config-probe.js';
|
|
7
8
|
import { declaration } from '../declarations.js';
|
|
8
9
|
/**
|
|
9
10
|
* Claude Code adapter.
|
|
@@ -31,24 +32,48 @@ export function claudePluginDir(home) {
|
|
|
31
32
|
export class ClaudeAdapter extends ExternalExecutorAdapter {
|
|
32
33
|
harness = 'claude-code';
|
|
33
34
|
capabilities(os) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const linux = os === 'linux';
|
|
36
|
+
const mac = os === 'darwin';
|
|
37
|
+
// macOS proves both the handoff and the detached carrier in this release.
|
|
38
|
+
const reason = linux
|
|
39
|
+
? 'The mods plugin loads and the zero-summary restart replaces the context in place through the native compact hook while keeping the session id; a disabled-compaction session is reported unsupported. Detached carriers spawn, report status and survive the parent. Exercised on Linux.'
|
|
40
|
+
: mac
|
|
41
|
+
? 'The mods plugin loads and the zero-summary in-place restart completed on macOS with the session id preserved (handoff verified). The detached carrier was exercised on macOS with a real two-turn executor: spawn, status, message queued into the same session (both turn markers in the executor log), stop, and the error paths (unauthorized target, message to a completed executor) all completed.'
|
|
39
42
|
: 'The mods plugin and the detached carrier are implemented; native Windows is out of scope (WSL counts as Linux) and was not exercised.';
|
|
40
|
-
const
|
|
43
|
+
const carrier = linux || mac ? 'supported' : 'not-tested';
|
|
41
44
|
const common = {
|
|
42
|
-
handoff: { availability:
|
|
43
|
-
spawn: { availability:
|
|
44
|
-
status: { availability:
|
|
45
|
-
...(
|
|
45
|
+
handoff: { availability: linux || mac ? 'supported' : 'not-tested', modes: ['restart'] },
|
|
46
|
+
spawn: { availability: carrier, maxConcurrent: 4 },
|
|
47
|
+
status: { availability: carrier, model: carrier, reasoningEffort: 'unsupported', context: carrier, percentSource: 'derived' },
|
|
48
|
+
...(linux || mac ? { evidence: `matrix:claude-code/${os}/2026-11-21` } : {}),
|
|
46
49
|
};
|
|
47
50
|
return [
|
|
48
51
|
declaration({ harness: 'claude-code', os, interface: 'tui', reason, ...common }),
|
|
49
52
|
declaration({ harness: 'claude-code', os, interface: 'headless', reason, ...common }),
|
|
50
53
|
];
|
|
51
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Persist the model a resumed turn must keep. The carrier passes `--model`
|
|
57
|
+
* only when the request has one, so the effective value can come from the
|
|
58
|
+
* settings `env` block (which overrides the inherited process environment)
|
|
59
|
+
* or the process environment.
|
|
60
|
+
*/
|
|
61
|
+
async persistedModel(request, ctx) {
|
|
62
|
+
if (request.model)
|
|
63
|
+
return request.model;
|
|
64
|
+
const settings = await probeClaudeSettings(ctx.identity.workspace, undefined, ['ANTHROPIC_MODEL']).catch(() => null);
|
|
65
|
+
return settings?.env[0]?.value ?? envValue('ANTHROPIC_MODEL') ?? undefined;
|
|
66
|
+
}
|
|
67
|
+
/** `CLAUDE_CODE_EFFORT_LEVEL` overrides the settings `effortLevel`. */
|
|
68
|
+
async persistedReasoningEffort(request, ctx) {
|
|
69
|
+
if (request.reasoningEffort)
|
|
70
|
+
return request.reasoningEffort;
|
|
71
|
+
const env = envValue('CLAUDE_CODE_EFFORT_LEVEL');
|
|
72
|
+
if (env)
|
|
73
|
+
return env;
|
|
74
|
+
const settings = await probeClaudeSettings(ctx.identity.workspace, undefined, []).catch(() => null);
|
|
75
|
+
return settings?.effortLevel?.value ?? undefined;
|
|
76
|
+
}
|
|
52
77
|
async carrier(request, ctx, _executorId, resumeSessionId) {
|
|
53
78
|
// A detached executor has no one to answer permission prompts: run it in the
|
|
54
79
|
// harness's non-interactive bypass mode, consistent with the spawn contract.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Identity, Request, Result } from '../../contract/types.js';
|
|
2
|
+
import type { StoredProofMechanism } from '../../contract/states.js';
|
|
2
3
|
export type ClaudePhase = 'pending' | 'scheduled' | 'applied' | 'completed' | 'cancelled' | 'failed' | 'unknown';
|
|
3
4
|
export interface ClaudeRecord {
|
|
4
5
|
format: 2;
|
|
@@ -11,6 +12,12 @@ export interface ClaudeRecord {
|
|
|
11
12
|
reason: string;
|
|
12
13
|
/** Native context replacement strategy recorded for this handoff. */
|
|
13
14
|
mechanism?: 'restart' | 'compact';
|
|
15
|
+
/**
|
|
16
|
+
* Explicit proof mechanism. New records always set it. Records written
|
|
17
|
+
* before 0.0.5 lack it; their proof is derived from `mechanism` under the
|
|
18
|
+
* historical rules and is exempt from the same-session gate.
|
|
19
|
+
*/
|
|
20
|
+
proofMechanism?: StoredProofMechanism;
|
|
14
21
|
successor?: Identity;
|
|
15
22
|
}
|
|
16
23
|
export interface ClaudeCommand {
|
|
@@ -25,6 +32,7 @@ export interface ClaudeCommand {
|
|
|
25
32
|
/** Native successor identity after a restart (new session id) or compact generation. */
|
|
26
33
|
successor?: Identity;
|
|
27
34
|
mechanism?: 'restart' | 'compact';
|
|
35
|
+
proofMechanism?: StoredProofMechanism;
|
|
28
36
|
usage?: {
|
|
29
37
|
window?: number | null;
|
|
30
38
|
used?: number | null;
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { atomicJson, bytes, contained, digest, ownership, withScopeLock } from '../../install/scope.js';
|
|
4
4
|
import { result } from '../../contract/validate.js';
|
|
5
5
|
import { handoffOutcome } from '../../contract/states.js';
|
|
6
|
+
import { legacyProofMechanism } from '../../core/handoff.js';
|
|
6
7
|
const PHASES = ['pending', 'scheduled', 'applied', 'completed', 'cancelled', 'failed', 'unknown'];
|
|
7
8
|
const sessionKey = (identity) => `${identity.workspace}\0${identity.surface}\0${identity.session}`;
|
|
8
9
|
function response(record, operation = 'handoff') {
|
|
@@ -16,7 +17,9 @@ function response(record, operation = 'handoff') {
|
|
|
16
17
|
? {
|
|
17
18
|
proof: {
|
|
18
19
|
source: record.source, successor: record.successor,
|
|
19
|
-
|
|
20
|
+
// New records carry the explicit field; old records keep the
|
|
21
|
+
// mechanism they historically implied and stay legacy-exempt.
|
|
22
|
+
mechanism: record.proofMechanism ?? legacyProofMechanism(record.mechanism),
|
|
20
23
|
nativeEvidence: record.marker,
|
|
21
24
|
},
|
|
22
25
|
}
|
|
@@ -1,10 +1,91 @@
|
|
|
1
1
|
import { TOOL_DESCRIPTION, TOOL_NAME, normalizeToolRequest } from '../../contract/tool.js';
|
|
2
|
-
import { resolveBindingFile } from '../../install/binding.js';
|
|
3
2
|
const tool = 'mcp__ai4ai__session';
|
|
4
3
|
const dbg = ($, message) => { try {
|
|
5
4
|
$.ui.log('ai4ai debug: ' + message, { to: 'debug' });
|
|
6
5
|
}
|
|
7
6
|
catch { /* debug only */ } };
|
|
7
|
+
// Import-free path helpers for the hooks sandbox (see the import comment).
|
|
8
|
+
const trimTrailing = (value) => value.replace(/[\\/]+$/, '');
|
|
9
|
+
const absolutePath = (value) => typeof value === 'string'
|
|
10
|
+
&& (value.startsWith('/') || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith('\\\\'));
|
|
11
|
+
const normalizedPath = (value) => {
|
|
12
|
+
const trimmed = trimTrailing(value).replace(/\\/g, '/');
|
|
13
|
+
// Windows paths compare case-insensitively; POSIX paths do not.
|
|
14
|
+
return /^[A-Za-z]:/.test(trimmed) || trimmed.startsWith('//') ? trimmed.toLowerCase() : trimmed;
|
|
15
|
+
};
|
|
16
|
+
const containsWorkspace = (root, candidate) => {
|
|
17
|
+
const owner = normalizedPath(root);
|
|
18
|
+
const target = normalizedPath(candidate);
|
|
19
|
+
return target === owner || target.startsWith(owner.endsWith('/') ? owner : `${owner}/`);
|
|
20
|
+
};
|
|
21
|
+
const parentPath = (value) => {
|
|
22
|
+
const trimmed = trimTrailing(value);
|
|
23
|
+
const index = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'));
|
|
24
|
+
if (index < 0)
|
|
25
|
+
return trimmed;
|
|
26
|
+
if (index === 0)
|
|
27
|
+
return '/';
|
|
28
|
+
if (index === 2 && /^[A-Za-z]:/.test(trimmed))
|
|
29
|
+
return trimmed.slice(0, 3);
|
|
30
|
+
return trimmed.slice(0, index);
|
|
31
|
+
};
|
|
32
|
+
const joinPath = (directory, name) => {
|
|
33
|
+
const trimmed = trimTrailing(directory);
|
|
34
|
+
const separator = trimmed.includes('\\') && !trimmed.includes('/') ? '\\' : '/';
|
|
35
|
+
return `${trimmed}${separator}${name}`;
|
|
36
|
+
};
|
|
37
|
+
/** Read one binding candidate through the host API; malformed/foreign records are skipped. */
|
|
38
|
+
async function readBinding($, file) {
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = await $.fs.read(file);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (typeof raw !== 'string')
|
|
47
|
+
return undefined;
|
|
48
|
+
let value;
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (!value || value.product !== 'ai4ai' || value.format !== 2 || !absolutePath(value.home) || !absolutePath(value.workspace)
|
|
56
|
+
|| typeof value.ownerToken !== 'string' || value.ownerToken.length === 0)
|
|
57
|
+
return undefined;
|
|
58
|
+
return {
|
|
59
|
+
home: value.home, workspace: value.workspace, ownerToken: value.ownerToken,
|
|
60
|
+
...(typeof value.node === 'string' && absolutePath(value.node) ? { node: value.node } : {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Import-free binding resolution: the nearest workspace-local binding whose
|
|
65
|
+
* recorded workspace contains the caller wins; the plugin-root binding is a
|
|
66
|
+
* compatible fallback. The worker validates ownership again when used.
|
|
67
|
+
*/
|
|
68
|
+
async function resolveBinding($) {
|
|
69
|
+
const workspace = await $.session.cwd();
|
|
70
|
+
if (typeof workspace !== 'string' || !absolutePath(workspace))
|
|
71
|
+
return undefined;
|
|
72
|
+
const candidates = [];
|
|
73
|
+
let current = workspace;
|
|
74
|
+
for (let depth = 0; depth < 16; depth += 1) {
|
|
75
|
+
candidates.push(joinPath(current, '.ai4ai/binding.json'));
|
|
76
|
+
const parent = parentPath(current);
|
|
77
|
+
if (parent === current)
|
|
78
|
+
break;
|
|
79
|
+
current = parent;
|
|
80
|
+
}
|
|
81
|
+
candidates.push(joinPath($.plugin.root, 'binding.json'));
|
|
82
|
+
for (const file of candidates) {
|
|
83
|
+
const binding = await readBinding($, file);
|
|
84
|
+
if (binding && containsWorkspace(binding.workspace, workspace))
|
|
85
|
+
return { binding, path: file };
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
8
89
|
const projection = (rows) => JSON.stringify(rows.map((message) => ({
|
|
9
90
|
role: message.role, text: message.text, toolUses: message.toolUses, toolResults: message.toolResults ?? [],
|
|
10
91
|
})));
|
|
@@ -42,9 +123,9 @@ async function currentSurface($) {
|
|
|
42
123
|
async function transition($, current, phase, reason, extra = {}, caller) {
|
|
43
124
|
if (!current.binding || !current.active)
|
|
44
125
|
return undefined;
|
|
45
|
-
// The journal is keyed by the record's source session.
|
|
46
|
-
//
|
|
47
|
-
// source identity
|
|
126
|
+
// The journal is keyed by the record's source session. The in-place
|
|
127
|
+
// replacement keeps that session, but transitions still use the record's
|
|
128
|
+
// source identity so a later generation cannot be mistaken for it.
|
|
48
129
|
const from = caller ?? current.active.source ?? current.binding;
|
|
49
130
|
const out = await rpc($, current.node, {
|
|
50
131
|
caller: from, action: 'transition', operationId: current.active.operationId,
|
|
@@ -93,62 +174,49 @@ async function pump($, s) {
|
|
|
93
174
|
if (s.active?.phase !== 'scheduled')
|
|
94
175
|
return;
|
|
95
176
|
const mode = s.active.mechanism ?? s.active.request.mode ?? 'restart';
|
|
96
|
-
if (mode
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!source)
|
|
102
|
-
return;
|
|
103
|
-
s.restarting = true;
|
|
104
|
-
try {
|
|
105
|
-
await $.command.run({ command: 'clear' });
|
|
106
|
-
let after = before;
|
|
107
|
-
for (let i = 0; i < 80 && after === before; i++) {
|
|
108
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
109
|
-
after = await $.session.id();
|
|
110
|
-
}
|
|
111
|
-
if (after === before) {
|
|
112
|
-
await transition($, s, 'unknown', 'Native /clear did not produce a new session id; no task redelivery');
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
let display = '';
|
|
116
|
-
try {
|
|
117
|
-
display = JSON.stringify(await $.session.messages());
|
|
118
|
-
}
|
|
119
|
-
catch {
|
|
120
|
-
display = '';
|
|
121
|
-
}
|
|
122
|
-
const clearSeen = display.includes('/clear') || display.includes('local_command');
|
|
123
|
-
if (!clearSeen)
|
|
124
|
-
dbg($, 'restart: /clear entry was not exposed by the plugin transcript view; the session id change is the native evidence');
|
|
125
|
-
const successor = { ...source, session: after, generation: s.active.marker };
|
|
126
|
-
await transition($, s, 'applied', clearSeen
|
|
127
|
-
? 'Native /clear reset the context in place; successor delivery pending'
|
|
128
|
-
: 'Native /clear changed the session id in place; successor delivery pending', { successor, mechanism: 'restart' }, source);
|
|
129
|
-
s.binding = successor;
|
|
130
|
-
s.appliedHere = true;
|
|
131
|
-
}
|
|
132
|
-
finally {
|
|
133
|
-
s.restarting = false;
|
|
134
|
-
}
|
|
177
|
+
if (mode !== 'restart') {
|
|
178
|
+
// The native pump implements the zero-summary restart only. A compact
|
|
179
|
+
// request must be refused by the worker before it reaches this point.
|
|
180
|
+
await transition($, s, 'unknown', 'The native pump implements restart only; no replacement attempted');
|
|
181
|
+
return;
|
|
135
182
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
183
|
+
const before = await $.session.id();
|
|
184
|
+
const source = s.binding;
|
|
185
|
+
if (!source)
|
|
186
|
+
return;
|
|
187
|
+
s.appliedHere = false;
|
|
188
|
+
s.replacement = undefined;
|
|
189
|
+
// `compact` runs the session.compact hook, which supplies a replacement
|
|
190
|
+
// message window and prevents the core compaction (and its summarizer)
|
|
191
|
+
// from running. The hook must finish inside the host's 10s budget, so it
|
|
192
|
+
// returns the window immediately and journals the transition separately.
|
|
193
|
+
await $.command.run({ command: 'compact', args: s.active.marker });
|
|
194
|
+
if (s.replacement)
|
|
195
|
+
await s.replacement;
|
|
196
|
+
// Explicit same-SID assertion: the replacement must not change the native
|
|
197
|
+
// session. A changed id is a defect, never a successful handoff.
|
|
198
|
+
const after = await $.session.id();
|
|
199
|
+
if (after !== before) {
|
|
200
|
+
await transition($, s, 'unknown', 'The native replacement changed the session id; the handoff was refused and the task was not delivered');
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!s.appliedHere || s.active?.phase !== 'applied') {
|
|
204
|
+
await transition($, s, 'unknown', 'Native replacement could not be proved; no task redelivery');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
let api = '';
|
|
208
|
+
try {
|
|
209
|
+
api = JSON.stringify(await $.session.messages({ as: 'api' }));
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
api = '';
|
|
213
|
+
}
|
|
214
|
+
if (api !== '' && !api.includes(s.active.marker)) {
|
|
215
|
+
await transition($, s, 'unknown', 'The replacement window does not contain the AI4AI binding; no task redelivery');
|
|
216
|
+
return;
|
|
151
217
|
}
|
|
218
|
+
if (s.binding)
|
|
219
|
+
s.binding = { ...s.binding, generation: s.active.marker };
|
|
152
220
|
const delivery = {
|
|
153
221
|
text: `AI4AI handoff delivery ${s.active.marker}. Adopt the caller-supplied task in this fresh context. Carry out this task now:\n${s.active.request.task ?? ''}\nNative system/security instructions remain authoritative. Query ai4ai status if you need context or model details.`,
|
|
154
222
|
operationId: s.active.operationId, marker: s.active.marker, invalid: false, adopted: false,
|
|
@@ -158,8 +226,11 @@ async function pump($, s) {
|
|
|
158
226
|
}
|
|
159
227
|
catch (error) {
|
|
160
228
|
dbg($, 'pump failed: ' + String(error?.message ?? error));
|
|
229
|
+
const disabled = /DISABLE_COMPACT/i.test(String(error?.message ?? error));
|
|
161
230
|
try {
|
|
162
|
-
await transition($, s, '
|
|
231
|
+
await transition($, s, 'failed', disabled
|
|
232
|
+
? 'Compaction is switched off in this session (DISABLE_COMPACT); the in-place restart is unsupported'
|
|
233
|
+
: 'Native scheduling outcome unknown; no replay');
|
|
163
234
|
}
|
|
164
235
|
catch { /* intent remains unreplayed */ }
|
|
165
236
|
}
|
|
@@ -169,23 +240,14 @@ async function pump($, s) {
|
|
|
169
240
|
}
|
|
170
241
|
/** Native Claude Code mods: in-place handoff without a summarizer, daemon or history fork. */
|
|
171
242
|
export const register = on => {
|
|
172
|
-
const s = { instance: '', node: '', busy: false, pumping: false,
|
|
243
|
+
const s = { instance: '', node: '', busy: false, pumping: false, turnId: '', expectedWindow: '', appliedHere: false };
|
|
173
244
|
let tail = Promise.resolve();
|
|
174
245
|
const serial = (fn) => { const pending = tail.then(fn); tail = pending.catch(() => undefined); return pending; };
|
|
175
246
|
on('session.start', async ($, e, next) => {
|
|
176
247
|
// A plugin cache can be shared by several workspaces. The workspace-local
|
|
177
248
|
// binding always wins; the plugin-root copy is only a compatible fallback.
|
|
178
249
|
try {
|
|
179
|
-
const resolved = await
|
|
180
|
-
workspace: await $.session.cwd(),
|
|
181
|
-
pluginRoot: $.plugin.root,
|
|
182
|
-
read: async (file) => { try {
|
|
183
|
-
return await $.fs.read(file);
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
return undefined;
|
|
187
|
-
} },
|
|
188
|
-
});
|
|
250
|
+
const resolved = await resolveBinding($);
|
|
189
251
|
if (resolved) {
|
|
190
252
|
s.bindingPath = resolved.path;
|
|
191
253
|
s.node = resolved.binding.node || process.execPath;
|
|
@@ -201,10 +263,9 @@ export const register = on => {
|
|
|
201
263
|
inputSchema: JSON.parse(await $.fs.read(`${$.plugin.root}/request-schema.json`)),
|
|
202
264
|
});
|
|
203
265
|
try {
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
if (!s.restarting && (!s.binding || await $.session.id() !== s.binding.session))
|
|
266
|
+
// The in-place replacement keeps the same session, so an existing
|
|
267
|
+
// binding remains authoritative across a handoff.
|
|
268
|
+
if (!s.binding || await $.session.id() !== s.binding.session)
|
|
208
269
|
await serial(() => bindNative($, s));
|
|
209
270
|
}
|
|
210
271
|
catch { /* Tool calls fail closed until a later successful bind. */ }
|
|
@@ -259,16 +320,47 @@ export const register = on => {
|
|
|
259
320
|
await pump($, s);
|
|
260
321
|
return out;
|
|
261
322
|
});
|
|
323
|
+
// The host skips a hook that throws or exceeds its budget and then runs the
|
|
324
|
+
// core compaction, which would summarize the context and break the
|
|
325
|
+
// zero-token guarantee. This handler therefore never performs slow work: it
|
|
326
|
+
// validates in memory, returns the replacement window immediately and starts
|
|
327
|
+
// the journal write in the background. The mods loader requires the hook to
|
|
328
|
+
// be an inline function at the `on(...)` call site, so the fail-closed
|
|
329
|
+
// try/catch lives here rather than in an attached `.catch`.
|
|
262
330
|
on('session.compact', async ($, e, next) => {
|
|
263
331
|
if (e.agentId || !e.instructions?.startsWith('ai4ai-context-'))
|
|
264
332
|
return next(e);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return { skip:
|
|
333
|
+
try {
|
|
334
|
+
const refuse = (detail) => {
|
|
335
|
+
void transition($, s, 'unknown', `Native compaction input changed or intent is not owned: ${detail}`).catch(() => undefined);
|
|
336
|
+
return { skip: `AI4AI did not authorize this replacement; original native context retained (${detail})` };
|
|
337
|
+
};
|
|
338
|
+
if (!s.binding)
|
|
339
|
+
return refuse('no native binding');
|
|
340
|
+
if (!s.active)
|
|
341
|
+
return refuse('no active handoff record');
|
|
342
|
+
// Fault-injection seam used only by the release gate: a caller that
|
|
343
|
+
// deliberately uses this operation id exercises the fail-closed catch.
|
|
344
|
+
// It is inert for every other operation id.
|
|
345
|
+
if (s.active.operationId === 'ai4ai-hook-fault-throw')
|
|
346
|
+
throw new Error('injected session.compact hook fault');
|
|
347
|
+
if (s.active.phase !== 'scheduled')
|
|
348
|
+
return refuse(`handoff phase is ${String(s.active.phase)}`);
|
|
349
|
+
if (e.instructions !== s.active.marker)
|
|
350
|
+
return refuse('marker does not match the owned intent');
|
|
351
|
+
if (s.busy)
|
|
352
|
+
return refuse('the plugin is busy with another native turn');
|
|
353
|
+
let observed = '';
|
|
354
|
+
try {
|
|
355
|
+
observed = projection(e.messages ?? []);
|
|
269
356
|
}
|
|
270
|
-
|
|
357
|
+
catch {
|
|
358
|
+
return refuse('the native window could not be read');
|
|
359
|
+
}
|
|
360
|
+
if (s.expectedWindow !== '' && observed !== s.expectedWindow)
|
|
361
|
+
return refuse('the native window changed since scheduling');
|
|
271
362
|
s.appliedHere = true;
|
|
363
|
+
s.replacement = transition($, s, 'applied', 'Native compact hook supplied a fresh task window; successor adoption pending');
|
|
272
364
|
return {
|
|
273
365
|
messages: [{
|
|
274
366
|
role: 'user',
|
|
@@ -276,27 +368,42 @@ export const register = on => {
|
|
|
276
368
|
toolUses: [],
|
|
277
369
|
}],
|
|
278
370
|
};
|
|
279
|
-
}
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
s.appliedHere = false;
|
|
374
|
+
const detail = String(error?.message ?? error).slice(0, 300);
|
|
375
|
+
dbg($, 'session.compact gate failed closed: ' + detail);
|
|
376
|
+
return { skip: 'AI4AI native gate failed closed; no replacement authorized (' + detail + ')' };
|
|
377
|
+
}
|
|
280
378
|
});
|
|
281
379
|
on('prompt.submit', async ($, e, next) => {
|
|
282
380
|
const own = e.origin.kind === 'plugin' && e.origin.name === $.plugin.name;
|
|
381
|
+
const isDelivery = own && String(e.text ?? '').startsWith('AI4AI handoff delivery ');
|
|
283
382
|
const ownCompact = e.command?.name === 'compact' && e.command.args === s.active?.marker && s.pumping;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
383
|
+
try {
|
|
384
|
+
if (isDelivery) {
|
|
385
|
+
// Delivery admission must prove the replacement actually happened in
|
|
386
|
+
// this session; anything uncertain drops the task instead of injecting
|
|
387
|
+
// it into a stale context.
|
|
388
|
+
const allow = await serial(async () => e.text === s.delivery?.text && admitted(s) && await $.session.id() === s.binding?.session);
|
|
389
|
+
if (!allow)
|
|
390
|
+
return { drop: 'Superseded or uncertain AI4AI delivery; task not admitted' };
|
|
391
|
+
}
|
|
392
|
+
else if (!ownCompact && !s.pumping)
|
|
393
|
+
await serial(async () => { if (s.active && s.active.phase === 'pending')
|
|
394
|
+
await transition($, s, 'cancelled', 'Later user input retained; handoff not replayed'); });
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
// Never fail open on the one path that injects handoff material.
|
|
398
|
+
if (isDelivery)
|
|
399
|
+
return { drop: 'AI4AI delivery admission failed closed; task not admitted' };
|
|
288
400
|
}
|
|
289
|
-
else if (!ownCompact && !s.restarting && !s.pumping)
|
|
290
|
-
await serial(async () => { if (s.active && s.active.phase === 'pending')
|
|
291
|
-
await transition($, s, 'cancelled', 'Later user input retained; handoff not replayed'); });
|
|
292
401
|
return next(e);
|
|
293
402
|
});
|
|
294
403
|
on('session.end', async ($, e, next) => {
|
|
295
|
-
// The
|
|
296
|
-
// session
|
|
404
|
+
// The in-place replacement keeps this session; an unfinished handoff at
|
|
405
|
+
// session end is genuinely uncertain and never replayed.
|
|
297
406
|
await serial(async () => {
|
|
298
|
-
if (s.restarting || (s.active?.mechanism === 'restart' && s.delivery))
|
|
299
|
-
return;
|
|
300
407
|
if (s.active && !['completed', 'cancelled', 'failed', 'unknown'].includes(s.active.phase))
|
|
301
408
|
await transition($, s, 'unknown', 'Native session ended; unfinished handoff is not resumed automatically');
|
|
302
409
|
});
|
|
@@ -12,7 +12,7 @@ import { handoffMode, handoffOutcome } from '../../contract/states.js';
|
|
|
12
12
|
import { fingerprint } from '../../core/fingerprint.js';
|
|
13
13
|
import { activeRecord } from '../../core/journal.js';
|
|
14
14
|
import { Ai4aiStore } from '../../core/store.js';
|
|
15
|
-
import { execute } from '../../core/operations.js';
|
|
15
|
+
import { currentOs, execute } from '../../core/operations.js';
|
|
16
16
|
import { ClaudeJournal, response } from './journal.js';
|
|
17
17
|
import { ClaudeAdapter } from './adapter.js';
|
|
18
18
|
import { resolveClaudeStatus } from './status.js';
|
|
@@ -99,12 +99,19 @@ if (command.action === 'transition') {
|
|
|
99
99
|
const to = command.phase ?? 'unknown';
|
|
100
100
|
if (!allowed[to]?.includes(latest.phase))
|
|
101
101
|
throw new Error(`Unexpected transition ${latest.phase} -> ${to}; no replay`);
|
|
102
|
+
const successor = command.successor ?? { ...latest.source, generation: latest.marker };
|
|
103
|
+
// A handoff never changes the native session identity; the plugin asserts
|
|
104
|
+
// this too, and the journal refuses a mismatched record rather than storing
|
|
105
|
+
// a false success.
|
|
106
|
+
if (successor.session !== latest.source.session)
|
|
107
|
+
throw new Error('Handoff successor changed the native session id; no transition recorded');
|
|
102
108
|
const next = {
|
|
103
109
|
...latest, phase: to, reason: command.reason ?? to,
|
|
104
110
|
...(to === 'applied'
|
|
105
111
|
? {
|
|
106
|
-
successor
|
|
107
|
-
mechanism: command.mechanism ?? latest.mechanism ?? '
|
|
112
|
+
successor,
|
|
113
|
+
mechanism: command.mechanism ?? latest.mechanism ?? 'restart',
|
|
114
|
+
proofMechanism: command.proofMechanism ?? latest.proofMechanism ?? 'surface-replacement',
|
|
108
115
|
}
|
|
109
116
|
: {}),
|
|
110
117
|
};
|
|
@@ -131,9 +138,12 @@ if (request.operation === 'status' && (request.target === undefined || request.t
|
|
|
131
138
|
});
|
|
132
139
|
const pointer = await sessionPointer('claude-code', caller.workspace, caller.session).catch(() => null);
|
|
133
140
|
const activity = await sessionActivity(pointer?.path ?? null);
|
|
141
|
+
const compactionDisabled = !!process.env.DISABLE_COMPACT && process.env.DISABLE_COMPACT !== '0';
|
|
134
142
|
console.log(JSON.stringify({
|
|
135
143
|
result: result(request, 'completed', 'Native session status', {
|
|
136
144
|
durable: true,
|
|
145
|
+
// A session-level limit, reported honestly without blocking status.
|
|
146
|
+
...(compactionDisabled ? { notices: [{ code: 'claude-compaction-disabled', impact: 'none', action_required: false, message: 'Compaction is switched off in this session (DISABLE_COMPACT); the in-place restart handoff is unsupported here.' }] } : {}),
|
|
137
147
|
// The session is alive while it serves this call; handoff progress is
|
|
138
148
|
// reported separately, and quiescence is inferred from lastActivityAt.
|
|
139
149
|
state: 'running',
|
|
@@ -155,7 +165,7 @@ if (request.operation === 'status' && (request.target === undefined || request.t
|
|
|
155
165
|
process.exit(0);
|
|
156
166
|
}
|
|
157
167
|
if (request.operation === 'capabilities') {
|
|
158
|
-
console.log(JSON.stringify({ result: result(request, 'completed', 'Claude adapter capabilities are declared by the installed plugin', { durable: false }) }));
|
|
168
|
+
console.log(JSON.stringify({ result: result(request, 'completed', 'Claude adapter capabilities are declared by the installed plugin', { durable: false, capabilities: new ClaudeAdapter().capabilities(currentOs()) }) }));
|
|
159
169
|
process.exit(0);
|
|
160
170
|
}
|
|
161
171
|
if (request.operation === 'cancel' || request.operation === 'stop') {
|
|
@@ -183,8 +193,21 @@ if (request.operation === 'handoff' && request.target === 'self') {
|
|
|
183
193
|
console.log(JSON.stringify({ result: result(request, 'failed', 'Another handoff is unresolved; reconcile it before requesting a transition') }));
|
|
184
194
|
process.exit(0);
|
|
185
195
|
}
|
|
196
|
+
// Compaction can be switched off per session; the restart path needs it, so
|
|
197
|
+
// report the limitation up front instead of failing midway.
|
|
198
|
+
if (process.env.DISABLE_COMPACT && process.env.DISABLE_COMPACT !== '0') {
|
|
199
|
+
console.log(JSON.stringify({ result: result(request, 'unsupported', 'Compaction is switched off in this session (DISABLE_COMPACT); the in-place restart handoff needs it', { unavailable: ['handoff.restart'], error: { code: 'claude-compaction-disabled', message: 'DISABLE_COMPACT is set for this session' } }) }));
|
|
200
|
+
process.exit(0);
|
|
201
|
+
}
|
|
202
|
+
// This version declares restart only. `compact` means a native summary,
|
|
203
|
+
// which Claude does not implement here; refuse it instead of silently
|
|
204
|
+
// running the zero-summary replacement under a compact label.
|
|
205
|
+
if (request.mode === 'compact') {
|
|
206
|
+
console.log(JSON.stringify({ result: result(request, 'unsupported', 'Claude Code handoff implements restart only in this version; native compaction plus task delivery is not available', { unavailable: ['handoff.compact'] }) }));
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
186
209
|
const mechanism = handoffMode(request.mode);
|
|
187
|
-
if (
|
|
210
|
+
if (!request.task) {
|
|
188
211
|
console.log(JSON.stringify({ result: result(request, 'unsupported', 'A restart handoff needs task material: the new context contains only that material', { unavailable: ['handoff.task'] }) }));
|
|
189
212
|
process.exit(0);
|
|
190
213
|
}
|
|
@@ -192,9 +215,8 @@ if (request.operation === 'handoff' && request.target === 'self') {
|
|
|
192
215
|
const record = {
|
|
193
216
|
format: 2, operationId: request.operationId, fingerprint: fingerprint(request), request, source: caller, marker, phase: 'pending',
|
|
194
217
|
mechanism,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
: 'Finish this turn; the native safe point will replace the context with the caller task material',
|
|
218
|
+
proofMechanism: 'surface-replacement',
|
|
219
|
+
reason: 'Finish this turn; the native compact hook replaces this context in place with the caller task material (no summary model is called)',
|
|
198
220
|
};
|
|
199
221
|
await journal.transaction(caller, async (_rows, commit) => commit(record));
|
|
200
222
|
console.log(JSON.stringify({ result: response(record), record }));
|