@cotal-ai/connector-claude-code 0.165.4 → 0.166.0
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 +4 -22
- package/dist/agui-map.d.ts +2 -1
- package/dist/agui-map.d.ts.map +1 -1
- package/dist/agui-source.d.ts +2 -1
- package/dist/agui-source.d.ts.map +1 -1
- package/dist/app-host.d.ts +2 -2
- package/dist/app-host.d.ts.map +1 -1
- package/dist/approval-notice.d.ts +0 -1
- package/dist/approval-notice.d.ts.map +1 -1
- package/dist/desktop-config.d.ts +0 -2
- package/dist/desktop-config.d.ts.map +1 -1
- package/dist/docs-bundle.bin +0 -0
- package/dist/docs-index.bin +0 -0
- package/dist/extension.d.ts.map +1 -1
- package/dist/hook.cjs +2 -2
- package/dist/hooks.d.ts +4 -5
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/mcp.cjs +42 -43
- package/dist/mcp.d.ts.map +1 -1
- package/dist/once-exit.d.ts +2 -1
- package/dist/once-exit.d.ts.map +1 -1
- package/dist/user-mcp.d.ts +0 -6
- package/dist/user-mcp.d.ts.map +1 -1
- package/dist/wake-feed.d.ts +2 -1
- package/dist/wake-feed.d.ts.map +1 -1
- package/hooks/hooks.json +0 -21
- package/package.json +3 -5
- package/dist/permission-hook.d.ts +0 -21
- package/dist/permission-hook.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ See [docs/connect-claude.mdx](../../docs/connect-claude.mdx) for the integration
|
|
|
15
15
|
Claude Code documents every hook event and its matchers in its
|
|
16
16
|
[hooks reference](https://code.claude.com/docs/en/hooks). This README does not copy that list.
|
|
17
17
|
|
|
18
|
-
The plugin registers the
|
|
18
|
+
The plugin registers the nine hooks below in [`hooks/hooks.json`](hooks/hooks.json). Each runs
|
|
19
19
|
`dist/hook.cjs`, which relays the event to the session's connector over its authenticated control
|
|
20
20
|
socket. A Cotal session, one that Cotal launched, carries a mesh identity in its environment. A
|
|
21
21
|
plain session, such as a `claude` you started yourself, carries none until it connects. Its command
|
|
@@ -30,27 +30,9 @@ hosted connection checks in the `PreToolUse` and `PostToolUse` rows. The presenc
|
|
|
30
30
|
| `SessionStart` | all | Surfaces the channel briefing and waiting messages, sets `idle` when no turn is open, resets attention to `open`, and records the session's model when none is pinned. On `startup`, `resume` or `fork` it also records the session's directory. |
|
|
31
31
|
| `UserPromptSubmit` | all | Sets `working` and surfaces waiting messages and run turns. |
|
|
32
32
|
| `PreToolUse` | all | Records the pending tool so a permission wait can name it. In a Cotal session, it denies a Cotal tool from any server other than the local one. In a plain session, it denies a hosted `connection_id` that it recorded as opened by a different session. |
|
|
33
|
-
| `PermissionRequest` | all | In a Cotal session on an authenticated mesh, holds the prompt until the agent's owner or the terminal answers it. See [Permission prompts](#permission-prompts). |
|
|
34
33
|
| `PostToolUse` | `^mcp__.+__cotal_(connect\|disconnect)$` | Plain sessions only: records or forgets which session opened a hosted connection. |
|
|
35
|
-
| `PostToolBatch` | all |
|
|
36
|
-
| `Notification` | `permission_prompt\|agent_needs_input\|elicitation_dialog` | Sets `waiting`. `permission_prompt` adds condition `approval`,
|
|
37
|
-
| `
|
|
38
|
-
| `Stop` | all | Ends the turn: records any permission prompt the main agent still holds as answered at the terminal, closes the run on the event plane, sets `idle`, and asks for a wake turn when held messages are waiting. A subagent's prompt stays held. |
|
|
34
|
+
| `PostToolBatch` | all | Sets `working` again when the main agent's batch resolves after a prompt left the seat `waiting`. A subagent's batch changes nothing. |
|
|
35
|
+
| `Notification` | `permission_prompt\|agent_needs_input\|elicitation_dialog` | Sets `waiting`. `permission_prompt` adds condition `approval`, and `agent_needs_input` adds `input`. |
|
|
36
|
+
| `Stop` | all | Ends the turn: closes the run on the event plane, sets `idle`, and asks for a wake turn when held messages are waiting. |
|
|
39
37
|
| `StopFailure` | all | Same as `Stop`, but closes the run with `RUN_ERROR` and sets a condition mapped from the error type. |
|
|
40
38
|
| `SessionEnd` | all | Sets `offline`. |
|
|
41
|
-
|
|
42
|
-
## Permission prompts
|
|
43
|
-
|
|
44
|
-
A managed Claude seat launches with `--permission-mode bypassPermissions` unless you pass a mode,
|
|
45
|
-
so it asks nothing. To launch a seat that asks, pass a mode:
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
cotal spawn --harness claude --opt permission-mode=default
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
On a signed-in space, the seat then holds each permission prompt for the agent's owner. The owner
|
|
52
|
-
can approve or deny it from Cotal Cloud, or from any client signed in as one of the owner's own CLI
|
|
53
|
-
or browser actors that calls `CotalEndpoint.answerPermission`. Claude's dialog in the terminal keeps
|
|
54
|
-
working, and the first answer applies. A denial's note reaches Claude as
|
|
55
|
-
`Denied from Cotal: <note>`. On an open mesh or a static space, only the terminal answers.
|
|
56
|
-
[SPEC §8.2](../../SPEC.md#82-permission-requests) defines the records and the answer rail.
|
package/dist/agui-map.d.ts
CHANGED
|
@@ -138,7 +138,7 @@ export interface ClaudeBlock {
|
|
|
138
138
|
content?: unknown;
|
|
139
139
|
is_error?: boolean;
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
interface ClaudeMapperOptions {
|
|
142
142
|
/** The native session id — `threadId` for every event. §3 forbids anything else claiming it. */
|
|
143
143
|
threadId: string;
|
|
144
144
|
/** Mints a `runId`. Connector-minted by §3.1, so every `RUN_STARTED` carries `runIdSource`. */
|
|
@@ -184,4 +184,5 @@ export interface ClaudeMapper {
|
|
|
184
184
|
forgetOpenRun: (runId: string) => void;
|
|
185
185
|
}
|
|
186
186
|
export declare function createClaudeMapper(opts: ClaudeMapperOptions): ClaudeMapper;
|
|
187
|
+
export {};
|
|
187
188
|
//# sourceMappingURL=agui-map.d.ts.map
|
package/dist/agui-map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agui-map.d.ts","sourceRoot":"","sources":["../src/agui-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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AO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,mBAAmB;IAC3B,gGAAgG;IAChG,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;IAC/B;;;;;;;;;;;;;;;OAeG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAiBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CAmN1E"}
|
package/dist/agui-source.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { type DurableSource, type SourceRead } from "@cotal-ai/connector-core";
|
|
19
19
|
import type { ClaudeEntry } from "./agui-map.js";
|
|
20
|
-
|
|
20
|
+
interface ClaudeTranscriptSourceOpts {
|
|
21
21
|
/** Production defaults to five seconds for both the startup and the fork wait. Tests can shorten
|
|
22
22
|
* only the fail-loud deadline. */
|
|
23
23
|
startupFileWaitMs?: number;
|
|
@@ -40,4 +40,5 @@ export declare function createClaudeTranscriptSource(path: string, sessionSource
|
|
|
40
40
|
* captured cursor and goes straight to the file, never waiting twice.
|
|
41
41
|
*/
|
|
42
42
|
export declare function createBoundClaudeTranscriptSource(path: string, sessionSource: unknown, opts?: ClaudeTranscriptSourceOpts): Promise<DurableSource<ClaudeEntry>>;
|
|
43
|
+
export {};
|
|
43
44
|
//# sourceMappingURL=agui-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agui-source.d.ts","sourceRoot":"","sources":["../src/agui-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAqC,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAClH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAUjD,
|
|
1
|
+
{"version":3,"file":"agui-source.d.ts","sourceRoot":"","sources":["../src/agui-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAqC,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAClH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAUjD,UAAU,0BAA0B;IAClC;uCACmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAID,wBAAsB,8BAA8B,CAAC,CAAC,EACpD,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAClC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,GAC9D,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAiCxB;AA+BD,8FAA8F;AAC9F,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,OAAO,EACtB,IAAI,GAAE,0BAA+B,GACpC,aAAa,CAAC,WAAW,CAAC,CAiB5B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iCAAiC,CACrD,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,OAAO,EACtB,IAAI,GAAE,0BAA+B,GACpC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAKrC"}
|
package/dist/app-host.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface ApprovalNotice {
|
|
|
12
12
|
status: "approved" | "denied" | "expired" | "refused";
|
|
13
13
|
id: string;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
interface AppHostOptions {
|
|
16
16
|
cotal: () => readonly string[];
|
|
17
17
|
cwd: string;
|
|
18
18
|
env: NodeJS.ProcessEnv;
|
|
@@ -24,7 +24,7 @@ export interface AppHostOptions {
|
|
|
24
24
|
turn?: (session: string, connectionId: string, text: string) => boolean;
|
|
25
25
|
watch?: typeof WATCH;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
interface AppHost extends GatewayHost {
|
|
28
28
|
closeAll(): Promise<void>;
|
|
29
29
|
nativeEvent(event: Record<string, unknown>): Promise<void>;
|
|
30
30
|
sessionFor(id: string): string | undefined;
|
package/dist/app-host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-host.d.ts","sourceRoot":"","sources":["../src/app-host.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyF,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAkB,KAAK,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAQ9N;mGACmG;AACnG,QAAA,MAAM,KAAK;;;CAAsC,CAAC;AAElD;oGACoG;AACpG,MAAM,WAAW,cAAc;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AAEnH,
|
|
1
|
+
{"version":3,"file":"app-host.d.ts","sourceRoot":"","sources":["../src/app-host.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyF,KAAK,iBAAiB,EAAE,KAAK,WAAW,EAAkB,KAAK,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAQ9N;mGACmG;AACnG,QAAA,MAAM,KAAK;;;CAAsC,CAAC;AAElD;oGACoG;AACpG,MAAM,WAAW,cAAc;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AAEnH,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC;IAC9D,+EAA+E;IAC/E,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACvF,oFAAoF;IACpF,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACxE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,UAAU,OAAQ,SAAQ,WAAW;IACnC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC5C;AAyDD,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAsQxD"}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* hooks module admits only these exact shapes, so no other text reaches the model this way.
|
|
5
5
|
*/
|
|
6
6
|
import type { ApprovalNotice } from "./app-host.js";
|
|
7
|
-
export declare const APPROVAL_ID: RegExp;
|
|
8
7
|
/** The frame the host writes to the feed for a decided request, or nothing for any other shape. */
|
|
9
8
|
export declare function approvalFrame(frame: unknown): ApprovalNotice | undefined;
|
|
10
9
|
/** The line for a decision. Its shapes are fixed; the native module matches them exactly. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-notice.d.ts","sourceRoot":"","sources":["../src/approval-notice.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"approval-notice.d.ts","sourceRoot":"","sources":["../src/approval-notice.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKpD,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAQxE;AAED,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAYvD"}
|
package/dist/desktop-config.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** The server's name in Desktop's config. Not `cotal`: that name is the Claude Code plugin's server. */
|
|
2
|
-
export declare const DESKTOP_SERVER = "cotal-desktop";
|
|
3
1
|
/** Where Claude Desktop keeps its config, as the MCP docs give it, or `undefined` on a platform whose
|
|
4
2
|
* location they do not give. */
|
|
5
3
|
export declare function desktopConfigPath(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, home?: string): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desktop-config.d.ts","sourceRoot":"","sources":["../src/desktop-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"desktop-config.d.ts","sourceRoot":"","sources":["../src/desktop-config.ts"],"names":[],"mappings":"AAmBA;iCACiC;AACjC,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,GAAE,MAAkB,GAAG,MAAM,GAAG,SAAS,CAIlK;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AA2BD;4BAC4B;AAC5B,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGtD;AAED;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;yEAIyE;AACzE,wBAAgB,cAAc,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAKpF;AAED;;kBAEkB;AAClB,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,MAAM,OAAwB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,aAAa,CAc3K"}
|
package/dist/docs-bundle.bin
CHANGED
|
Binary file
|
package/dist/docs-index.bin
CHANGED
|
Binary file
|
package/dist/extension.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgD,KAAK,SAAS,EAA8E,MAAM,gBAAgB,CAAC;AAW1K;;;;;;;;;4FAS4F;AAC5F,eAAO,MAAM,oBAAoB,8/DA4EvB,CAAC;AAkJX;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgD,KAAK,SAAS,EAA8E,MAAM,gBAAgB,CAAC;AAW1K;;;;;;;;;4FAS4F;AAC5F,eAAO,MAAM,oBAAoB,8/DA4EvB,CAAC;AAkJX;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,SAwO7B,CAAC"}
|
package/dist/hook.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var import_node_net=require("node:net");var import_node_fs2=require("node:fs");var import_node_fs=require("node:fs");var import_node_child_process=require("node:child_process");var import_node_path=require("node:path");var isWin=process.platform==="win32";function sys32(exe){const root=process.env.SystemRoot||process.env.windir||"C:\\Windows";return(0,import_node_path.join)(root,"System32",exe)}var cachedSid;function ownerSid(){if(cachedSid)return cachedSid;const out=(0,import_node_child_process.execFileSync)(sys32("whoami.exe"),["/user","/fo","csv","/nh"],{encoding:"utf8"});const sid=out.trim().split(",").pop()?.replace(/^"|"$/g,"").trim();if(!sid||!/^S-1-/.test(sid))throw new Error(`could not determine the current user's SID from \`whoami\` (got: ${out.trim()})`);cachedSid=sid;return sid}var BROAD_SIDS=["S-1-1-0","S-1-5-11","S-1-5-32-545"];function hardenPrivate(path,kind){if(!isWin){if(kind==="file")(0,import_node_fs.closeSync)(openPrivate(path,import_node_fs.constants.O_RDONLY));else(0,import_node_fs.chmodSync)(path,448);return}const perm=kind==="dir"?"(OI)(CI)(F)":"(F)";const removeBroad=BROAD_SIDS.flatMap(sid=>["/remove:g",`*${sid}`]);const grant=sid=>["/grant:r",`*${sid}:${perm}`];try{(0,import_node_child_process.execFileSync)(sys32("icacls.exe"),[(0,import_node_path.toNamespacedPath)((0,import_node_path.resolve)(path)),"/inheritance:r",...removeBroad,...grant(ownerSid()),...grant("S-1-5-18"),...grant("S-1-5-32-544")],{stdio:["ignore","ignore","pipe"]})}catch(e){throw new Error(`failed to harden ${kind} "${path}" to private via icacls: ${e.message.trim()}. Cotal will not leave a secret with a permissive ACL - ensure the path is on an NTFS volume and %SystemRoot%\\System32\\icacls.exe is available.`)}}function notPrivate(path,why){const refused=new Error(`refusing to write "${path}": it ${why}; it was left unchanged`);refused.code="EPERM";return refused}function openPrivate(path,flags){if(isWin){const fd2=(0,import_node_fs.openSync)(path,flags,384);try{(0,import_node_fs.fchmodSync)(fd2,384)}catch(e){(0,import_node_fs.closeSync)(fd2);throw e}return fd2}let fd;try{fd=(0,import_node_fs.openSync)(path,flags|import_node_fs.constants.O_NOFOLLOW|import_node_fs.constants.O_NONBLOCK,384)}catch(e){if(e.code==="ELOOP")throw notPrivate(path,"is a symlink");throw e}try{const info=(0,import_node_fs.fstatSync)(fd);if(!info.isFile())throw notPrivate(path,"is not a regular file");if(info.uid!==process.getuid())throw notPrivate(path,`is owned by uid ${info.uid}, not this user`);(0,import_node_fs.fchmodSync)(fd,384);return fd}catch(e){(0,import_node_fs.closeSync)(fd);throw e}}function writeSecretFile(path,data){writePrivate(path,data,false)}function writeBytes(path,data,exclusive){const fd=openPrivate(path,import_node_fs.constants.O_WRONLY|import_node_fs.constants.O_CREAT|(exclusive?import_node_fs.constants.O_EXCL:0));try{try{(0,import_node_fs.ftruncateSync)(fd);(0,import_node_fs.writeFileSync)(fd,data)}finally{(0,import_node_fs.closeSync)(fd)}}catch(e){if(exclusive){try{(0,import_node_fs.unlinkSync)(path)}catch{}}throw e}}function writePrivate(path,data,exclusive){writeBytes(path,data,exclusive);if(!isWin)return;try{hardenPrivate(path,"file")}catch(e){try{(0,import_node_fs.unlinkSync)(path)}catch{}throw e}}function writeSecretFileAtomic(path,data){const tmp=`${path}.${process.pid}.${Date.now()}.tmp`;try{writeSecretFile(tmp,data);(0,import_node_fs.renameSync)(tmp,path)}catch(e){try{(0,import_node_fs.unlinkSync)(tmp)}catch{}throw e}}function mkSecretDir(path){(0,import_node_fs.mkdirSync)(path,{recursive:true,mode:448});hardenPrivate(path,"dir")}var LAUNCH_MATERIAL_ENV="COTAL_LAUNCH_MATERIAL";function readLaunchMaterial(path){let raw;try{if(process.platform!=="win32"){const mode=(0,import_node_fs2.statSync)(path).mode&511;if(mode&63)throw new Error(`is readable beyond its owner (mode ${mode.toString(8)}) - refusing to read connection material out of a file other local users can open`)}raw=(0,import_node_fs2.readFileSync)(path,"utf8")}catch(e){throw new Error(`launch material: cannot read ${path} (${e instanceof Error?e.message:String(e)})`)}let parsed;try{parsed=JSON.parse(raw)}catch{throw new Error(`launch material: ${path} is not valid JSON`)}if(typeof parsed!=="object"||parsed===null||Array.isArray(parsed))throw new Error(`launch material: ${path} must contain a JSON object`);return validate(parsed,path)}function validate(raw,path){const material={};const str=key=>{const v=raw[key];if(v===void 0)return;if(typeof v!=="string"||!v.trim())throw new Error(`launch material: ${path} has a ${key} that is not a non-empty string`);material[key]=v};str("servers");str("creds");str("token");str("controlToken");if(raw.eventsRequired!==void 0){if(raw.eventsRequired!==true)throw new Error(`launch material: ${path} has eventsRequired that is not exactly true`);material.eventsRequired=true}if(raw.eventPayloadsWithheld!==void 0){if(raw.eventPayloadsWithheld!==true)throw new Error(`launch material: ${path} has eventPayloadsWithheld that is not true`);material.eventPayloadsWithheld=true}if(raw.userAuth!==void 0){const u=raw.userAuth;if(typeof u!=="object"||u===null||Array.isArray(u))throw new Error(`launch material: ${path} has a userAuth that is not an object`);const{owner:owner2,actor,sentinelCredsPath,bearerCmd}=u;const named={owner:owner2,actor,sentinelCredsPath};for(const[k,v]of Object.entries(named))if(typeof v!=="string"||!v.trim())throw new Error(`launch material: ${path} has a userAuth.${k} that is not a non-empty string`);if(!Array.isArray(bearerCmd)||bearerCmd.length===0||!bearerCmd.every(a=>typeof a==="string"&&a))throw new Error(`launch material: ${path} has a userAuth.bearerCmd that is not a non-empty array of strings`);material.userAuth={owner:owner2,actor,sentinelCredsPath,bearerCmd}}if(Object.keys(material).length===0)throw new Error(`launch material: ${path} carries nothing this reader recognises. A launch that references material and supplies none is a broken launcher, not an open-mode launch, so it is refused rather than defaulted.`);return material}var DIRECT_MATERIAL_VARS=["COTAL_CREDS","COTAL_SERVERS","COTAL_TOKEN","COTAL_OWNER","COTAL_ACTOR","COTAL_SENTINEL_CREDS","COTAL_BEARER_CMD","COTAL_EVENTS_REQUIRED","COTAL_CONTROL_TOKEN","COTAL_LINK"];function readMaterial(env){const path=env[LAUNCH_MATERIAL_ENV]?.trim();if(!path)return void 0;const direct=DIRECT_MATERIAL_VARS.filter(k=>env[k]?.trim());if(direct.length)throw new Error(`COTAL config: this launch carries connection material BOTH as ${LAUNCH_MATERIAL_ENV} and as ${direct.join(", ")}. One launch carries one identity plane - drop the direct variables, or drop the material file.`);return readLaunchMaterial(path)}function controlFromEnv(env=process.env){const path=env.COTAL_CONTROL_SOCKET?.trim();const token=readMaterial(env)?.controlToken??env.COTAL_CONTROL_TOKEN?.trim();if(path&&token)return{path,token};if(!path&&!token)return void 0;if(path)throw new Error("COTAL config: COTAL_CONTROL_SOCKET is set but no control token could be resolved - neither the launch material nor COTAL_CONTROL_TOKEN carries one. Half a pair is not a control endpoint, so this launch is refused rather than started without the control plane it was configured to have.");throw new Error("COTAL config: a control token was supplied but COTAL_CONTROL_SOCKET is unset, so there is no socket to authenticate against. Half a pair is not a control endpoint, so this launch is refused rather than started without the control plane it was configured to have.")}function hasIdentity(env=process.env){return Boolean(env.COTAL_NAME?.trim()||env.COTAL_LINK?.trim()||env.COTAL_AGENT_FILE?.trim())}var HANDOFF_RECEIPT='{"handoff":"ok"}\n';var MAX_FRAME_BYTES=1<<20;var TIMEOUT_MS=2e3;var CONNECT_RETRY_INITIAL_MS=25;var CONNECT_RETRY_MAX_MS=250;var isRetryableConnectError=error=>{const code=error instanceof Error?error.code:void 0;return["ENOENT","ECONNREFUSED","ECONNRESET","EPIPE","EAGAIN","EBUSY"].includes(code??"")};var isSessionStart=event=>event!==null&&typeof event==="object"&&event.hook_event_name==="SessionStart";var warned=false;function warnOnce(message){if(warned)return;warned=true;try{process.stderr.write(`[cotal-connector] ${message}
|
|
2
|
-
`)}catch{}}function readStdin(){return new Promise(resolve2=>{if(process.stdin.isTTY)return resolve2("");let d="";process.stdin.setEncoding("utf8");process.stdin.on("data",c=>d+=c);process.stdin.on("end",()=>resolve2(d));process.stdin.on("error",()=>resolve2(d))})}function done(out,confirm){const exit=()=>process.exit(0);const t=out.trim();if(!t)return exit();process.stdout.on("error",()=>exit());process.stdout.write(t+"\n",err=>{if(err||!confirm)return exit();confirm(exit)});setTimeout(exit,1e3)}async function runHookRelay(answer,observe
|
|
3
|
-
`));socket.on("data",data=>{reply+=data;if(reply.length>128)socket.destroy()});socket.on("error",reject);socket.on("close",()=>{try{if(JSON.parse(reply).ok===true)resolve2();else reject(new Error("native lifecycle binding refused"))}catch{reject(new Error("native lifecycle binding was not confirmed"))}})})))}async function observePersonalHook(value){if(!value||typeof value!=="object")return;const event=value;if(event.agent_id!==void 0||typeof event.session_id!=="string"||!WAKE_ID.test(event.session_id)||!transcriptMatches(event.session_id,event.transcript_path)||typeof event.hook_event_name!=="string")return;if(!["SessionStart","UserPromptSubmit","PreToolUse","PostToolBatch","Notification","Stop","StopFailure","SessionEnd"].includes(event.hook_event_name))return;const file=stateFile(event.session_id);const previous=readRecord(file);if(previous&&previous.transcript_path!==event.transcript_path)throw new Error("native command hook changed its session transcript");const safe={};for(const key of["hook_event_name","session_id","transcript_path","cwd","source","notification_type","error","model"])if(typeof event[key]==="string"&&event[key].length<=4096)safe[key]=event[key];if(JSON.stringify(safe).length>8192)throw new Error("native command-hook metadata is too large");writeSecretFileAtomic(file,JSON.stringify(safe));const target=readRecord(`${file}.host`);if(target){if(!Number.isInteger(target.hostPid)||target.hostPid<=0)throw new Error("invalid native lifecycle host");await forward(safe,target.hostPid)}if(event.hook_event_name==="SessionEnd"){(0,import_node_fs5.unlinkSync)(file);if(target)(0,import_node_fs5.unlinkSync)(`${file}.host`)}}var
|
|
2
|
+
`)}catch{}}function readStdin(){return new Promise(resolve2=>{if(process.stdin.isTTY)return resolve2("");let d="";process.stdin.setEncoding("utf8");process.stdin.on("data",c=>d+=c);process.stdin.on("end",()=>resolve2(d));process.stdin.on("error",()=>resolve2(d))})}function done(out,confirm){const exit=()=>process.exit(0);const t=out.trim();if(!t)return exit();process.stdout.on("error",()=>exit());process.stdout.write(t+"\n",err=>{if(err||!confirm)return exit();confirm(exit)});setTimeout(exit,1e3)}async function runHookRelay(answer,observe){const managed=hasIdentity();if(!managed&&!answer&&!observe)return done("");const raw=(await readStdin()).trim()||"{}";let event={};try{event=JSON.parse(raw)}catch{}let local;try{local=answer?.(event,{managed})}catch{}if(local)return done(JSON.stringify(local));try{await observe?.(event,{managed})}catch{}if(!managed)return done("");let control;try{control=controlFromEnv()}catch{warnOnce("this session's control endpoint could not be resolved: the launch material is missing, unreadable, readable beyond its owner, malformed, or contradicted by direct COTAL_ variables. Lifecycle relays are disabled for this session, so presence will not advance and queued peer messages will not be injected. Check COTAL_LAUNCH_MATERIAL and COTAL_CONTROL_SOCKET.");return done("")}if(!control)return done("");const{path,token}=control;const startupCritical=isSessionStart(event);let sock;let settled=false;let retryDelayMs=CONNECT_RETRY_INITIAL_MS;const drop=(candidate=sock)=>{try{candidate?.destroy()}catch{}};const settle=()=>{if(settled)return false;settled=true;clearTimeout(timer);return true};const finish=out=>{if(!settle())return;drop();done(out)};const finishWithReceipt=(out,candidate)=>{if(!settle())return;done(out,then=>{try{candidate.write(HANDOFF_RECEIPT,()=>{drop(candidate);then()})}catch{then()}})};const timer=setTimeout(()=>finish(""),TIMEOUT_MS);const retryLater=()=>{const wait=retryDelayMs;retryDelayMs=Math.min(retryDelayMs*2,CONNECT_RETRY_MAX_MS);setTimeout(dial,wait)};const dial=()=>{if(settled)return;const candidate=(0,import_node_net.connect)(path);sock=candidate;let connected=false;let reply="";candidate.setEncoding("utf8");candidate.on("connect",()=>{if(settled||sock!==candidate)return;connected=true;try{candidate.write(JSON.stringify({token,event,handoff:true})+"\n")}catch{finish("")}});candidate.on("data",d=>{if(settled||sock!==candidate)return;reply+=d;const nl=reply.indexOf("\n");if(nl>=0)finishWithReceipt(reply.slice(0,nl),candidate)});candidate.on("error",error=>{if(settled||sock!==candidate)return;if(!connected&&startupCritical&&isRetryableConnectError(error)){drop(candidate);retryLater();return}finish("")});candidate.on("end",()=>{if(settled||sock!==candidate)return;finish(reply)})};dial()}var LOCAL_SERVERS=new Set(["cotal","plugin_cotal_cotal"]);var COTAL_TOOL=/^mcp__(.+)__(cotal_[a-z0-9]+(?:_[a-z0-9]+)*)$/;function hostedCotalTool(toolName){const m=typeof toolName==="string"?COTAL_TOOL.exec(toolName):null;return m&&!LOCAL_SERVERS.has(m[1])?m[2]:void 0}var ONE_PATH_REASON="This session is already on a Cotal mesh through its local Cotal plugin, and a session uses one Cotal path. Use the local cotal_* tools (mcp__cotal__...). To use the hosted Cotal connector, start a Claude Code session that Cotal did not launch.";var otherCotalPath=(event,session)=>{if(!session.managed)return void 0;const ev=event;if(ev?.hook_event_name!=="PreToolUse"||hostedCotalTool(ev.tool_name)===void 0)return void 0;return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:ONE_PATH_REASON}}};var import_node_fs3=require("node:fs");var import_node_path2=require("node:path");var CONNECTED=/^connection_id: (\S+)$/m;var SAFE_ID=/^[A-Za-z0-9_-]{1,128}$/;var FORKED_REASON="This connection_id was opened by another Claude Code session. This session is a fork or a copy of that one, so it needs its own connection: call cotal_connect, then use the connection_id it returns.";function connectedId(response){const blocks=Array.isArray(response)?response:[];for(const b of blocks){const text=b?.text;const id=typeof text==="string"?CONNECTED.exec(text)?.[1]:void 0;if(id!==void 0)return SAFE_ID.test(id)?id:void 0}return void 0}function connectionOwner(dataDir){const dir=dataDir?(0,import_node_path2.join)(dataDir,"hosted-connections"):void 0;return(event,session)=>{if(session.managed||!dir)return void 0;const ev=event;const tool=hostedCotalTool(ev?.tool_name);const sessionId=ev?.session_id;if(tool===void 0||typeof sessionId!=="string"||!sessionId)return void 0;const given=ev?.tool_input?.connection_id;const id=typeof given==="string"&&SAFE_ID.test(given)?given:void 0;const owner2=()=>{try{return(0,import_node_fs3.readFileSync)((0,import_node_path2.join)(dir,id),"utf8")}catch{return void 0}};if(ev?.hook_event_name==="PostToolUse"&&tool==="cotal_connect"){const opened=connectedId(ev.tool_response);if(opened===void 0)return void 0;(0,import_node_fs3.mkdirSync)(dir,{recursive:true,mode:448});(0,import_node_fs3.writeFileSync)((0,import_node_path2.join)(dir,opened),sessionId,{mode:384});return void 0}if(id===void 0)return void 0;if(ev?.hook_event_name==="PostToolUse"&&tool==="cotal_disconnect"){if(owner2()===sessionId)(0,import_node_fs3.rmSync)((0,import_node_path2.join)(dir,id),{force:true});return void 0}if(ev?.hook_event_name!=="PreToolUse")return void 0;const recorded=owner2();if(recorded===void 0||recorded===sessionId)return void 0;return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:FORKED_REASON}}}}var import_node_fs5=require("node:fs");var import_node_net2=require("node:net");var import_node_os2=require("node:os");var import_node_path4=require("node:path");var import_node_fs4=require("node:fs");var import_node_os=require("node:os");var import_node_path3=require("node:path");var WAKE_ID=/^[A-Za-z0-9_-]{1,128}$/;var WIN_PIPES="\\\\.\\pipe\\";var WIN_PREFIX="cotal-claude-wake-";function wakeDir(){if(process.platform==="win32")return WIN_PIPES;const uid=process.getuid();const dir=(0,import_node_path3.join)((0,import_node_os.tmpdir)(),`cotal-claude-wake-${uid}`);(0,import_node_fs4.mkdirSync)(dir,{recursive:true,mode:448});const st=(0,import_node_fs4.lstatSync)(dir);if(!st.isDirectory()||st.uid!==uid||(st.mode&63)!==0)throw new Error(`${dir} is not a private directory of this user's`);return dir}var entryName=(claudePid,serverPid)=>process.platform==="win32"?`${WIN_PREFIX}${claudePid}-${serverPid}`:`${claudePid}-${serverPid}.sock`;var ENTRY=process.platform==="win32"?new RegExp(`^${WIN_PREFIX}(\\d+)-(\\d+)$`):/^(\d+)-(\d+)\.sock$/;function alive(pid){try{process.kill(pid,0);return true}catch(e){return e.code==="EPERM"}}function wakeSocketPath(claudePid,serverPid=process.pid){const dir=wakeDir();return process.platform==="win32"?`${dir}${entryName(claudePid,serverPid)}`:(0,import_node_path3.join)(dir,entryName(claudePid,serverPid))}function wakeSockets(claudePid){const dir=wakeDir();return(0,import_node_fs4.readdirSync)(dir).flatMap(name=>{const m=ENTRY.exec(name);return m?.[1]===String(claudePid)&&alive(Number(m[2]))?[wakeSocketPath(claudePid,Number(m[2]))]:[]})}function nativeSocketPath(feed){return`${feed}.native`}function stateFile(session){if(!WAKE_ID.test(session))throw new Error("invalid native session identity");const root=(0,import_node_path4.join)((0,import_node_os2.tmpdir)(),`cotal-claude-native-${process.getuid?.()??"local"}`);const st=(0,import_node_fs5.lstatSync)(root,{throwIfNoEntry:false});if(st&&(!st.isDirectory()||process.getuid&&st.uid!==process.getuid()))throw new Error("native session state is not this user's private directory");mkSecretDir(root);return(0,import_node_path4.join)(root,`${session}.json`)}function readRecord(file){const st=(0,import_node_fs5.lstatSync)(file,{throwIfNoEntry:false});if(!st)return void 0;if(!st.isFile()||st.size>16384||process.getuid&&(st.uid!==process.getuid()||(st.mode&63)!==0))throw new Error("native session state is not an owner-private bounded regular file");const value=JSON.parse((0,import_node_fs5.readFileSync)(file,"utf8"));if(!value||typeof value!=="object"||Array.isArray(value))throw new Error("invalid native session state");return value}function transcriptMatches(session,path){return typeof path==="string"&&(0,import_node_path4.isAbsolute)(path)&&(0,import_node_path4.basename)(path)===`${session}.jsonl`}async function forward(event,hostPid){const paths=wakeSockets(hostPid);if(!paths.length)throw new Error("no local native lifecycle server");await Promise.all(paths.map(path=>new Promise((resolve2,reject)=>{const socket=(0,import_node_net2.createConnection)(nativeSocketPath(path));let reply="";socket.setEncoding("utf8");socket.setTimeout(2e3,()=>socket.destroy(new Error("native lifecycle relay timed out")));socket.on("connect",()=>socket.write(`${JSON.stringify({op:"native",event})}
|
|
3
|
+
`));socket.on("data",data=>{reply+=data;if(reply.length>128)socket.destroy()});socket.on("error",reject);socket.on("close",()=>{try{if(JSON.parse(reply).ok===true)resolve2();else reject(new Error("native lifecycle binding refused"))}catch{reject(new Error("native lifecycle binding was not confirmed"))}})})))}async function observePersonalHook(value){if(!value||typeof value!=="object")return;const event=value;if(event.agent_id!==void 0||typeof event.session_id!=="string"||!WAKE_ID.test(event.session_id)||!transcriptMatches(event.session_id,event.transcript_path)||typeof event.hook_event_name!=="string")return;if(!["SessionStart","UserPromptSubmit","PreToolUse","PostToolBatch","Notification","Stop","StopFailure","SessionEnd"].includes(event.hook_event_name))return;const file=stateFile(event.session_id);const previous=readRecord(file);if(previous&&previous.transcript_path!==event.transcript_path)throw new Error("native command hook changed its session transcript");const safe={};for(const key of["hook_event_name","session_id","transcript_path","cwd","source","notification_type","error","model"])if(typeof event[key]==="string"&&event[key].length<=4096)safe[key]=event[key];if(JSON.stringify(safe).length>8192)throw new Error("native command-hook metadata is too large");writeSecretFileAtomic(file,JSON.stringify(safe));const target=readRecord(`${file}.host`);if(target){if(!Number.isInteger(target.hostPid)||target.hostPid<=0)throw new Error("invalid native lifecycle host");await forward(safe,target.hostPid)}if(event.hook_event_name==="SessionEnd"){(0,import_node_fs5.unlinkSync)(file);if(target)(0,import_node_fs5.unlinkSync)(`${file}.host`)}}var owner=connectionOwner(process.env.CLAUDE_PLUGIN_DATA);void runHookRelay((event,session)=>otherCotalPath(event,session)??owner(event,session),async(event,session)=>{if(!session.managed)await observePersonalHook(event)}).catch(()=>process.exit(0));
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type MeshAgent, type InboxItem, type HookEvent, type HookHandle
|
|
1
|
+
import { type MeshAgent, type InboxItem, type HookEvent, type HookHandle } from "@cotal-ai/connector-core";
|
|
2
2
|
import type { AguiEmitterHolder } from "@cotal-ai/connector-core";
|
|
3
3
|
import type { ClaudeEntry } from "./agui-map.js";
|
|
4
|
-
|
|
4
|
+
interface ClaudeHandleDeps {
|
|
5
5
|
/** Launch environment for a hosted session's carried-fork record. Omitted uses the process env. */
|
|
6
6
|
env?: NodeJS.ProcessEnv;
|
|
7
7
|
/** The session's AG-UI emitter, read lazily — `mcp.ts` assigns it after the handler exists. */
|
|
@@ -16,8 +16,6 @@ export interface ClaudeHandleDeps {
|
|
|
16
16
|
* every session start (startup, resume, fork, clear, compact), so the model has its bearings
|
|
17
17
|
* without asking for them; a card not ready at the start is owed to the next prompt. */
|
|
18
18
|
orientation?: () => Promise<string | undefined>;
|
|
19
|
-
/** This seat's permission desk, or undefined where its prompts stay with the terminal. */
|
|
20
|
-
permissions?: () => PermissionDesk | undefined;
|
|
21
19
|
}
|
|
22
20
|
export declare const HOOK_CONTEXT_CHARS = 9000;
|
|
23
21
|
/** The hook side of the connector: the handler plus the delivery callback that commits what it
|
|
@@ -67,7 +65,7 @@ export interface ClaudeHooks {
|
|
|
67
65
|
*/
|
|
68
66
|
export declare function createClaudeHandle(deps?: ClaudeHandleDeps): ClaudeHooks;
|
|
69
67
|
/** One `claude/channel` push. A rejection is surfaced to the caller. */
|
|
70
|
-
|
|
68
|
+
type ChannelNotify = (params: {
|
|
71
69
|
content: string;
|
|
72
70
|
meta: Record<string, string> | {
|
|
73
71
|
kind: string;
|
|
@@ -101,4 +99,5 @@ export interface WakePolicy {
|
|
|
101
99
|
* it never wakes for held ambient the agent's attention mode says to hold.
|
|
102
100
|
*/
|
|
103
101
|
export declare function createWakePolicy(agent: MeshAgent, notify: ChannelNotify, log?: (msg: string) => void): WakePolicy;
|
|
102
|
+
export {};
|
|
104
103
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAcA,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAcA,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;A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