@agentchatme/openclaw 0.7.8211111 → 0.8.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/README.md +174 -253
  3. package/RUNBOOK.md +86 -91
  4. package/SECURITY.md +36 -20
  5. package/dist/binding/agents-anchor.cjs +41 -53
  6. package/dist/binding/agents-anchor.cjs.map +1 -1
  7. package/dist/binding/agents-anchor.d.cts +61 -74
  8. package/dist/binding/agents-anchor.d.ts +61 -74
  9. package/dist/binding/agents-anchor.js +35 -53
  10. package/dist/binding/agents-anchor.js.map +1 -1
  11. package/dist/credentials/read-env.cjs +35 -1
  12. package/dist/credentials/read-env.cjs.map +1 -1
  13. package/dist/credentials/read-env.d.cts +31 -3
  14. package/dist/credentials/read-env.d.ts +31 -3
  15. package/dist/credentials/read-env.js +29 -2
  16. package/dist/credentials/read-env.js.map +1 -1
  17. package/dist/index.cjs +1990 -3571
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +498 -317
  20. package/dist/index.d.ts +498 -317
  21. package/dist/index.js +2013 -3610
  22. package/dist/index.js.map +1 -1
  23. package/dist/openclaw-layout.cjs +120 -0
  24. package/dist/openclaw-layout.cjs.map +1 -0
  25. package/dist/openclaw-layout.d.cts +64 -0
  26. package/dist/openclaw-layout.d.ts +64 -0
  27. package/dist/openclaw-layout.js +90 -0
  28. package/dist/openclaw-layout.js.map +1 -0
  29. package/dist/{setup-entry-BuDCZ44W.d.cts → setup-entry-DU51IFUF.d.cts} +58 -8
  30. package/dist/{setup-entry-BuDCZ44W.d.ts → setup-entry-DU51IFUF.d.ts} +58 -8
  31. package/dist/setup-entry.cjs +1997 -3608
  32. package/dist/setup-entry.cjs.map +1 -1
  33. package/dist/setup-entry.d.cts +1 -1
  34. package/dist/setup-entry.d.ts +1 -1
  35. package/dist/setup-entry.js +1995 -3607
  36. package/dist/setup-entry.js.map +1 -1
  37. package/openclaw.plugin.json +8 -2
  38. package/package.json +9 -6
  39. package/skills/agentchat/SKILL.md +741 -227
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ var os = require('os');
4
+ var path = require('path');
5
+ var readEnv_js = require('./credentials/read-env.cjs');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
26
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
27
+
28
+ // src/openclaw-layout.ts
29
+ var DEFAULT_AGENT_ID = "main";
30
+ function isRecord(value) {
31
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
+ }
33
+ function expandUserPath(value) {
34
+ const trimmed = value.trim();
35
+ if (trimmed === "~") return os__namespace.homedir();
36
+ if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return path__namespace.join(os__namespace.homedir(), trimmed.slice(2));
37
+ return path__namespace.resolve(trimmed);
38
+ }
39
+ function resolveOpenClawStateDir() {
40
+ const override = readEnv_js.readOpenClawStateDirFromEnv();
41
+ if (override) return expandUserPath(override);
42
+ const profile = readEnv_js.readOpenClawProfileFromEnv();
43
+ return path__namespace.join(os__namespace.homedir(), profile ? `.openclaw-${profile}` : ".openclaw");
44
+ }
45
+ function resolveOpenClawDefaultWorkspaceDir() {
46
+ const override = readEnv_js.readOpenClawWorkspaceDirFromEnv();
47
+ if (override) return path__namespace.resolve(override);
48
+ return path__namespace.join(resolveOpenClawStateDir(), "workspace");
49
+ }
50
+ function listOpenClawAgentEntries(cfg) {
51
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
52
+ if (!agents) return [];
53
+ if (Object.hasOwn(agents, "entries") && agents.entries !== void 0) {
54
+ if (!isRecord(agents.entries)) return [];
55
+ return Object.entries(agents.entries).filter(([, entry]) => isRecord(entry)).map(([id, entry]) => toEntry(id, entry));
56
+ }
57
+ if (Object.hasOwn(agents, "list") && agents.list !== void 0) {
58
+ if (!Array.isArray(agents.list)) return [];
59
+ return agents.list.filter((entry) => isRecord(entry) && typeof entry.id === "string").map((entry) => toEntry(entry.id, entry));
60
+ }
61
+ return [];
62
+ }
63
+ function toEntry(id, raw) {
64
+ return {
65
+ id: id.trim().toLowerCase(),
66
+ ...raw.default === true ? { default: true } : {},
67
+ ...typeof raw.workspace === "string" && raw.workspace.trim() ? { workspace: raw.workspace } : {}
68
+ };
69
+ }
70
+ function hasAgentRoster(cfg) {
71
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
72
+ if (!agents) return false;
73
+ return Object.hasOwn(agents, "entries") && agents.entries !== void 0 || Object.hasOwn(agents, "list") && agents.list !== void 0;
74
+ }
75
+ function resolveOpenClawDefaultAgentId(cfg) {
76
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
77
+ const entries = listOpenClawAgentEntries(cfg);
78
+ if (agents?.ownership !== "explicit") {
79
+ const marked = entries.filter((entry) => entry.default === true);
80
+ if (marked.length === 1) return marked[0].id;
81
+ }
82
+ if (entries.length === 0) return hasAgentRoster(cfg) ? void 0 : DEFAULT_AGENT_ID;
83
+ return entries.length === 1 ? entries[0].id : void 0;
84
+ }
85
+ function resolveBoundAgentId(cfg, channel, accountId, defaultAccountId = "default") {
86
+ const bindings = isRecord(cfg) ? cfg.bindings : void 0;
87
+ if (!Array.isArray(bindings)) return void 0;
88
+ let wildcard;
89
+ for (const binding of bindings) {
90
+ if (!isRecord(binding) || typeof binding.agentId !== "string" || !isRecord(binding.match)) continue;
91
+ const match = binding.match;
92
+ if (match.channel !== channel) continue;
93
+ if (match.peer !== void 0 && match.peer !== null) continue;
94
+ const matchAccount = typeof match.accountId === "string" ? match.accountId.trim() : "";
95
+ if (matchAccount === accountId) return binding.agentId.trim().toLowerCase();
96
+ if (matchAccount === "" && accountId === defaultAccountId) return binding.agentId.trim().toLowerCase();
97
+ if (matchAccount === "*" && wildcard === void 0) wildcard = binding.agentId.trim().toLowerCase();
98
+ }
99
+ return wildcard;
100
+ }
101
+ function resolveOpenClawWorkspaceDir(cfg, agentId) {
102
+ const id = (agentId ?? resolveOpenClawDefaultAgentId(cfg) ?? DEFAULT_AGENT_ID).trim().toLowerCase();
103
+ const entry = listOpenClawAgentEntries(cfg).find((candidate) => candidate.id === id);
104
+ if (entry?.workspace) return expandUserPath(entry.workspace);
105
+ const defaults = isRecord(cfg) && isRecord(cfg.agents) && isRecord(cfg.agents.defaults) ? cfg.agents.defaults : void 0;
106
+ const configured = defaults?.workspace;
107
+ if (typeof configured === "string" && configured.trim().length > 0) return expandUserPath(configured);
108
+ return resolveOpenClawDefaultWorkspaceDir();
109
+ }
110
+
111
+ exports.DEFAULT_AGENT_ID = DEFAULT_AGENT_ID;
112
+ exports.expandUserPath = expandUserPath;
113
+ exports.listOpenClawAgentEntries = listOpenClawAgentEntries;
114
+ exports.resolveBoundAgentId = resolveBoundAgentId;
115
+ exports.resolveOpenClawDefaultAgentId = resolveOpenClawDefaultAgentId;
116
+ exports.resolveOpenClawDefaultWorkspaceDir = resolveOpenClawDefaultWorkspaceDir;
117
+ exports.resolveOpenClawStateDir = resolveOpenClawStateDir;
118
+ exports.resolveOpenClawWorkspaceDir = resolveOpenClawWorkspaceDir;
119
+ //# sourceMappingURL=openclaw-layout.cjs.map
120
+ //# sourceMappingURL=openclaw-layout.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openclaw-layout.ts"],"names":["os","path","readOpenClawStateDirFromEnv","readOpenClawProfileFromEnv","readOpenClawWorkspaceDirFromEnv"],"mappings":";;;;;;;;;;;;;;;;;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,EAAA,IAAI,KAAA,EAAO,SAAA,EAAW,OAAO,cAAA,CAAe,MAAM,SAAS,CAAA;AAC3D,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,GAAG,CAAA,IAAK,SAAS,GAAA,CAAI,MAAM,CAAA,IAAK,QAAA,CAAS,IAAI,MAAA,CAAO,QAAQ,CAAA,GAAI,GAAA,CAAI,OAAO,QAAA,GAAW,MAAA;AAChH,EAAA,MAAM,aAAa,QAAA,EAAU,SAAA;AAC7B,EAAA,IAAI,OAAO,UAAA,KAAe,QAAA,IAAY,UAAA,CAAW,IAAA,GAAO,MAAA,GAAS,CAAA,EAAG,OAAO,cAAA,CAAe,UAAU,CAAA;AACpG,EAAA,OAAO,kCAAA,EAAmC;AAC5C","file":"openclaw-layout.cjs","sourcesContent":["/**\n * Where OpenClaw keeps things — resolved the way OpenClaw resolves them.\n *\n * Pure: environment + config + `os.homedir()` in, paths and ids out. No\n * filesystem reads, no network. Every env read goes through\n * `credentials/read-env.ts`. One resolver, shared by the identity-line\n * placement (`binding/agents-anchor.ts`), the key placement\n * (`doorbell/placement.ts`), the gateway and the doctor, so the four never\n * disagree about which workspace or state dir an agent uses.\n *\n * Mirrors OpenClaw 2026.10.9 (`src/agents/workspace-default-path.ts`,\n * `src/agents/agent-roster.ts`, `src/config/paths.ts` in its dist):\n *\n * state dir = $OPENCLAW_STATE_DIR\n * | ~/.openclaw-<profile> when OPENCLAW_PROFILE is not \"default\"\n * | ~/.openclaw\n * workspace = agents.entries.<id>.workspace (or agents.list[].workspace)\n * | agents.defaults.workspace\n * | $OPENCLAW_WORKSPACE_DIR\n * | <state dir>/workspace\n * default agent = the one entry marked `default: true` (unless agents.ownership\n * is \"explicit\") | the sole entry | \"main\" when no roster exists\n */\n\nimport * as os from 'node:os'\nimport * as path from 'node:path'\n\nimport {\n readOpenClawProfileFromEnv,\n readOpenClawStateDirFromEnv,\n readOpenClawWorkspaceDirFromEnv,\n} from './credentials/read-env.js'\n\n/** OpenClaw's implicit agent id when no roster is configured. */\nexport const DEFAULT_AGENT_ID = 'main'\n\n/** The loosest config shape these readers need; the real `OpenClawConfig` satisfies it. */\nexport type OpenClawConfigLike = object | undefined\n\nexport interface OpenClawAgentEntry {\n readonly id: string\n readonly default?: boolean\n readonly workspace?: string\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** `~` and `~/…` → the home directory; anything else resolved as given. */\nexport function expandUserPath(value: string): string {\n const trimmed = value.trim()\n if (trimmed === '~') return os.homedir()\n if (trimmed.startsWith('~/') || trimmed.startsWith('~\\\\')) return path.join(os.homedir(), trimmed.slice(2))\n return path.resolve(trimmed)\n}\n\n/** OpenClaw's state dir: `$OPENCLAW_STATE_DIR`, else the profile dir, else `~/.openclaw`. */\nexport function resolveOpenClawStateDir(): string {\n const override = readOpenClawStateDirFromEnv()\n if (override) return expandUserPath(override)\n const profile = readOpenClawProfileFromEnv()\n return path.join(os.homedir(), profile ? `.openclaw-${profile}` : '.openclaw')\n}\n\n/** OpenClaw's default agent workspace: `$OPENCLAW_WORKSPACE_DIR`, else `<state dir>/workspace`. */\nexport function resolveOpenClawDefaultWorkspaceDir(): string {\n const override = readOpenClawWorkspaceDirFromEnv()\n if (override) return path.resolve(override)\n return path.join(resolveOpenClawStateDir(), 'workspace')\n}\n\n/** The agent roster from either representation OpenClaw accepts: `agents.entries` (record) or `agents.list` (array). */\nexport function listOpenClawAgentEntries(cfg: OpenClawConfigLike): OpenClawAgentEntry[] {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n if (!agents) return []\n if (Object.hasOwn(agents, 'entries') && agents.entries !== undefined) {\n if (!isRecord(agents.entries)) return []\n return Object.entries(agents.entries)\n .filter(([, entry]) => isRecord(entry))\n .map(([id, entry]) => toEntry(id, entry as Record<string, unknown>))\n }\n if (Object.hasOwn(agents, 'list') && agents.list !== undefined) {\n if (!Array.isArray(agents.list)) return []\n return agents.list\n .filter((entry): entry is Record<string, unknown> => isRecord(entry) && typeof entry.id === 'string')\n .map((entry) => toEntry(entry.id as string, entry))\n }\n return []\n}\n\nfunction toEntry(id: string, raw: Record<string, unknown>): OpenClawAgentEntry {\n return {\n id: id.trim().toLowerCase(),\n ...(raw.default === true ? { default: true } : {}),\n ...(typeof raw.workspace === 'string' && raw.workspace.trim() ? { workspace: raw.workspace } : {}),\n }\n}\n\nfunction hasAgentRoster(cfg: OpenClawConfigLike): boolean {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n if (!agents) return false\n return (Object.hasOwn(agents, 'entries') && agents.entries !== undefined) || (Object.hasOwn(agents, 'list') && agents.list !== undefined)\n}\n\n/**\n * The agent OpenClaw treats as the ambient default — the one `llm.complete`\n * uses when a plugin passes no `agentId`. Mirrors OpenClaw's\n * `tryResolveDefaultAgentId`: one entry marked `default: true` (unless the\n * roster declares `ownership: \"explicit\"`), else the sole entry, else `main`\n * when no roster exists. `undefined` when several agents exist and none is\n * marked — OpenClaw then has no single default either.\n */\nexport function resolveOpenClawDefaultAgentId(cfg: OpenClawConfigLike): string | undefined {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n const entries = listOpenClawAgentEntries(cfg)\n if (agents?.ownership !== 'explicit') {\n const marked = entries.filter((entry) => entry.default === true)\n if (marked.length === 1) return marked[0]!.id\n }\n if (entries.length === 0) return hasAgentRoster(cfg) ? undefined : DEFAULT_AGENT_ID\n return entries.length === 1 ? entries[0]!.id : undefined\n}\n\n/**\n * The agent an explicit `bindings[]` entry routes this channel account to,\n * if any. OpenClaw's `AgentBindingMatch`: `accountId` omitted/empty matches\n * only the channel default account, `\"*\"` matches every account, any other\n * string that account id.\n */\nexport function resolveBoundAgentId(cfg: OpenClawConfigLike, channel: string, accountId: string, defaultAccountId = 'default'): string | undefined {\n const bindings = isRecord(cfg) ? cfg.bindings : undefined\n if (!Array.isArray(bindings)) return undefined\n let wildcard: string | undefined\n for (const binding of bindings) {\n if (!isRecord(binding) || typeof binding.agentId !== 'string' || !isRecord(binding.match)) continue\n const match = binding.match\n if (match.channel !== channel) continue\n if (match.peer !== undefined && match.peer !== null) continue // peer-specific bindings route single conversations, not the account\n const matchAccount = typeof match.accountId === 'string' ? match.accountId.trim() : ''\n if (matchAccount === accountId) return binding.agentId.trim().toLowerCase()\n if (matchAccount === '' && accountId === defaultAccountId) return binding.agentId.trim().toLowerCase()\n if (matchAccount === '*' && wildcard === undefined) wildcard = binding.agentId.trim().toLowerCase()\n }\n return wildcard\n}\n\n/**\n * The workspace OpenClaw loads for `agentId` — the file `AGENTS.md` is read\n * from on every turn. Per-agent `workspace` first, then\n * `agents.defaults.workspace`, then the environment default.\n */\nexport function resolveOpenClawWorkspaceDir(cfg: OpenClawConfigLike, agentId?: string): string {\n const id = (agentId ?? resolveOpenClawDefaultAgentId(cfg) ?? DEFAULT_AGENT_ID).trim().toLowerCase()\n const entry = listOpenClawAgentEntries(cfg).find((candidate) => candidate.id === id)\n if (entry?.workspace) return expandUserPath(entry.workspace)\n const defaults = isRecord(cfg) && isRecord(cfg.agents) && isRecord(cfg.agents.defaults) ? cfg.agents.defaults : undefined\n const configured = defaults?.workspace\n if (typeof configured === 'string' && configured.trim().length > 0) return expandUserPath(configured)\n return resolveOpenClawDefaultWorkspaceDir()\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Where OpenClaw keeps things — resolved the way OpenClaw resolves them.
3
+ *
4
+ * Pure: environment + config + `os.homedir()` in, paths and ids out. No
5
+ * filesystem reads, no network. Every env read goes through
6
+ * `credentials/read-env.ts`. One resolver, shared by the identity-line
7
+ * placement (`binding/agents-anchor.ts`), the key placement
8
+ * (`doorbell/placement.ts`), the gateway and the doctor, so the four never
9
+ * disagree about which workspace or state dir an agent uses.
10
+ *
11
+ * Mirrors OpenClaw 2026.10.9 (`src/agents/workspace-default-path.ts`,
12
+ * `src/agents/agent-roster.ts`, `src/config/paths.ts` in its dist):
13
+ *
14
+ * state dir = $OPENCLAW_STATE_DIR
15
+ * | ~/.openclaw-<profile> when OPENCLAW_PROFILE is not "default"
16
+ * | ~/.openclaw
17
+ * workspace = agents.entries.<id>.workspace (or agents.list[].workspace)
18
+ * | agents.defaults.workspace
19
+ * | $OPENCLAW_WORKSPACE_DIR
20
+ * | <state dir>/workspace
21
+ * default agent = the one entry marked `default: true` (unless agents.ownership
22
+ * is "explicit") | the sole entry | "main" when no roster exists
23
+ */
24
+ /** OpenClaw's implicit agent id when no roster is configured. */
25
+ declare const DEFAULT_AGENT_ID = "main";
26
+ /** The loosest config shape these readers need; the real `OpenClawConfig` satisfies it. */
27
+ type OpenClawConfigLike = object | undefined;
28
+ interface OpenClawAgentEntry {
29
+ readonly id: string;
30
+ readonly default?: boolean;
31
+ readonly workspace?: string;
32
+ }
33
+ /** `~` and `~/…` → the home directory; anything else resolved as given. */
34
+ declare function expandUserPath(value: string): string;
35
+ /** OpenClaw's state dir: `$OPENCLAW_STATE_DIR`, else the profile dir, else `~/.openclaw`. */
36
+ declare function resolveOpenClawStateDir(): string;
37
+ /** OpenClaw's default agent workspace: `$OPENCLAW_WORKSPACE_DIR`, else `<state dir>/workspace`. */
38
+ declare function resolveOpenClawDefaultWorkspaceDir(): string;
39
+ /** The agent roster from either representation OpenClaw accepts: `agents.entries` (record) or `agents.list` (array). */
40
+ declare function listOpenClawAgentEntries(cfg: OpenClawConfigLike): OpenClawAgentEntry[];
41
+ /**
42
+ * The agent OpenClaw treats as the ambient default — the one `llm.complete`
43
+ * uses when a plugin passes no `agentId`. Mirrors OpenClaw's
44
+ * `tryResolveDefaultAgentId`: one entry marked `default: true` (unless the
45
+ * roster declares `ownership: "explicit"`), else the sole entry, else `main`
46
+ * when no roster exists. `undefined` when several agents exist and none is
47
+ * marked — OpenClaw then has no single default either.
48
+ */
49
+ declare function resolveOpenClawDefaultAgentId(cfg: OpenClawConfigLike): string | undefined;
50
+ /**
51
+ * The agent an explicit `bindings[]` entry routes this channel account to,
52
+ * if any. OpenClaw's `AgentBindingMatch`: `accountId` omitted/empty matches
53
+ * only the channel default account, `"*"` matches every account, any other
54
+ * string that account id.
55
+ */
56
+ declare function resolveBoundAgentId(cfg: OpenClawConfigLike, channel: string, accountId: string, defaultAccountId?: string): string | undefined;
57
+ /**
58
+ * The workspace OpenClaw loads for `agentId` — the file `AGENTS.md` is read
59
+ * from on every turn. Per-agent `workspace` first, then
60
+ * `agents.defaults.workspace`, then the environment default.
61
+ */
62
+ declare function resolveOpenClawWorkspaceDir(cfg: OpenClawConfigLike, agentId?: string): string;
63
+
64
+ export { DEFAULT_AGENT_ID, type OpenClawAgentEntry, type OpenClawConfigLike, expandUserPath, listOpenClawAgentEntries, resolveBoundAgentId, resolveOpenClawDefaultAgentId, resolveOpenClawDefaultWorkspaceDir, resolveOpenClawStateDir, resolveOpenClawWorkspaceDir };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Where OpenClaw keeps things — resolved the way OpenClaw resolves them.
3
+ *
4
+ * Pure: environment + config + `os.homedir()` in, paths and ids out. No
5
+ * filesystem reads, no network. Every env read goes through
6
+ * `credentials/read-env.ts`. One resolver, shared by the identity-line
7
+ * placement (`binding/agents-anchor.ts`), the key placement
8
+ * (`doorbell/placement.ts`), the gateway and the doctor, so the four never
9
+ * disagree about which workspace or state dir an agent uses.
10
+ *
11
+ * Mirrors OpenClaw 2026.10.9 (`src/agents/workspace-default-path.ts`,
12
+ * `src/agents/agent-roster.ts`, `src/config/paths.ts` in its dist):
13
+ *
14
+ * state dir = $OPENCLAW_STATE_DIR
15
+ * | ~/.openclaw-<profile> when OPENCLAW_PROFILE is not "default"
16
+ * | ~/.openclaw
17
+ * workspace = agents.entries.<id>.workspace (or agents.list[].workspace)
18
+ * | agents.defaults.workspace
19
+ * | $OPENCLAW_WORKSPACE_DIR
20
+ * | <state dir>/workspace
21
+ * default agent = the one entry marked `default: true` (unless agents.ownership
22
+ * is "explicit") | the sole entry | "main" when no roster exists
23
+ */
24
+ /** OpenClaw's implicit agent id when no roster is configured. */
25
+ declare const DEFAULT_AGENT_ID = "main";
26
+ /** The loosest config shape these readers need; the real `OpenClawConfig` satisfies it. */
27
+ type OpenClawConfigLike = object | undefined;
28
+ interface OpenClawAgentEntry {
29
+ readonly id: string;
30
+ readonly default?: boolean;
31
+ readonly workspace?: string;
32
+ }
33
+ /** `~` and `~/…` → the home directory; anything else resolved as given. */
34
+ declare function expandUserPath(value: string): string;
35
+ /** OpenClaw's state dir: `$OPENCLAW_STATE_DIR`, else the profile dir, else `~/.openclaw`. */
36
+ declare function resolveOpenClawStateDir(): string;
37
+ /** OpenClaw's default agent workspace: `$OPENCLAW_WORKSPACE_DIR`, else `<state dir>/workspace`. */
38
+ declare function resolveOpenClawDefaultWorkspaceDir(): string;
39
+ /** The agent roster from either representation OpenClaw accepts: `agents.entries` (record) or `agents.list` (array). */
40
+ declare function listOpenClawAgentEntries(cfg: OpenClawConfigLike): OpenClawAgentEntry[];
41
+ /**
42
+ * The agent OpenClaw treats as the ambient default — the one `llm.complete`
43
+ * uses when a plugin passes no `agentId`. Mirrors OpenClaw's
44
+ * `tryResolveDefaultAgentId`: one entry marked `default: true` (unless the
45
+ * roster declares `ownership: "explicit"`), else the sole entry, else `main`
46
+ * when no roster exists. `undefined` when several agents exist and none is
47
+ * marked — OpenClaw then has no single default either.
48
+ */
49
+ declare function resolveOpenClawDefaultAgentId(cfg: OpenClawConfigLike): string | undefined;
50
+ /**
51
+ * The agent an explicit `bindings[]` entry routes this channel account to,
52
+ * if any. OpenClaw's `AgentBindingMatch`: `accountId` omitted/empty matches
53
+ * only the channel default account, `"*"` matches every account, any other
54
+ * string that account id.
55
+ */
56
+ declare function resolveBoundAgentId(cfg: OpenClawConfigLike, channel: string, accountId: string, defaultAccountId?: string): string | undefined;
57
+ /**
58
+ * The workspace OpenClaw loads for `agentId` — the file `AGENTS.md` is read
59
+ * from on every turn. Per-agent `workspace` first, then
60
+ * `agents.defaults.workspace`, then the environment default.
61
+ */
62
+ declare function resolveOpenClawWorkspaceDir(cfg: OpenClawConfigLike, agentId?: string): string;
63
+
64
+ export { DEFAULT_AGENT_ID, type OpenClawAgentEntry, type OpenClawConfigLike, expandUserPath, listOpenClawAgentEntries, resolveBoundAgentId, resolveOpenClawDefaultAgentId, resolveOpenClawDefaultWorkspaceDir, resolveOpenClawStateDir, resolveOpenClawWorkspaceDir };
@@ -0,0 +1,90 @@
1
+ import * as os from 'os';
2
+ import * as path from 'path';
3
+ import { readOpenClawStateDirFromEnv, readOpenClawProfileFromEnv, readOpenClawWorkspaceDirFromEnv } from './credentials/read-env.js';
4
+
5
+ // src/openclaw-layout.ts
6
+ var DEFAULT_AGENT_ID = "main";
7
+ function isRecord(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+ function expandUserPath(value) {
11
+ const trimmed = value.trim();
12
+ if (trimmed === "~") return os.homedir();
13
+ if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) return path.join(os.homedir(), trimmed.slice(2));
14
+ return path.resolve(trimmed);
15
+ }
16
+ function resolveOpenClawStateDir() {
17
+ const override = readOpenClawStateDirFromEnv();
18
+ if (override) return expandUserPath(override);
19
+ const profile = readOpenClawProfileFromEnv();
20
+ return path.join(os.homedir(), profile ? `.openclaw-${profile}` : ".openclaw");
21
+ }
22
+ function resolveOpenClawDefaultWorkspaceDir() {
23
+ const override = readOpenClawWorkspaceDirFromEnv();
24
+ if (override) return path.resolve(override);
25
+ return path.join(resolveOpenClawStateDir(), "workspace");
26
+ }
27
+ function listOpenClawAgentEntries(cfg) {
28
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
29
+ if (!agents) return [];
30
+ if (Object.hasOwn(agents, "entries") && agents.entries !== void 0) {
31
+ if (!isRecord(agents.entries)) return [];
32
+ return Object.entries(agents.entries).filter(([, entry]) => isRecord(entry)).map(([id, entry]) => toEntry(id, entry));
33
+ }
34
+ if (Object.hasOwn(agents, "list") && agents.list !== void 0) {
35
+ if (!Array.isArray(agents.list)) return [];
36
+ return agents.list.filter((entry) => isRecord(entry) && typeof entry.id === "string").map((entry) => toEntry(entry.id, entry));
37
+ }
38
+ return [];
39
+ }
40
+ function toEntry(id, raw) {
41
+ return {
42
+ id: id.trim().toLowerCase(),
43
+ ...raw.default === true ? { default: true } : {},
44
+ ...typeof raw.workspace === "string" && raw.workspace.trim() ? { workspace: raw.workspace } : {}
45
+ };
46
+ }
47
+ function hasAgentRoster(cfg) {
48
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
49
+ if (!agents) return false;
50
+ return Object.hasOwn(agents, "entries") && agents.entries !== void 0 || Object.hasOwn(agents, "list") && agents.list !== void 0;
51
+ }
52
+ function resolveOpenClawDefaultAgentId(cfg) {
53
+ const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : void 0;
54
+ const entries = listOpenClawAgentEntries(cfg);
55
+ if (agents?.ownership !== "explicit") {
56
+ const marked = entries.filter((entry) => entry.default === true);
57
+ if (marked.length === 1) return marked[0].id;
58
+ }
59
+ if (entries.length === 0) return hasAgentRoster(cfg) ? void 0 : DEFAULT_AGENT_ID;
60
+ return entries.length === 1 ? entries[0].id : void 0;
61
+ }
62
+ function resolveBoundAgentId(cfg, channel, accountId, defaultAccountId = "default") {
63
+ const bindings = isRecord(cfg) ? cfg.bindings : void 0;
64
+ if (!Array.isArray(bindings)) return void 0;
65
+ let wildcard;
66
+ for (const binding of bindings) {
67
+ if (!isRecord(binding) || typeof binding.agentId !== "string" || !isRecord(binding.match)) continue;
68
+ const match = binding.match;
69
+ if (match.channel !== channel) continue;
70
+ if (match.peer !== void 0 && match.peer !== null) continue;
71
+ const matchAccount = typeof match.accountId === "string" ? match.accountId.trim() : "";
72
+ if (matchAccount === accountId) return binding.agentId.trim().toLowerCase();
73
+ if (matchAccount === "" && accountId === defaultAccountId) return binding.agentId.trim().toLowerCase();
74
+ if (matchAccount === "*" && wildcard === void 0) wildcard = binding.agentId.trim().toLowerCase();
75
+ }
76
+ return wildcard;
77
+ }
78
+ function resolveOpenClawWorkspaceDir(cfg, agentId) {
79
+ const id = (agentId ?? resolveOpenClawDefaultAgentId(cfg) ?? DEFAULT_AGENT_ID).trim().toLowerCase();
80
+ const entry = listOpenClawAgentEntries(cfg).find((candidate) => candidate.id === id);
81
+ if (entry?.workspace) return expandUserPath(entry.workspace);
82
+ const defaults = isRecord(cfg) && isRecord(cfg.agents) && isRecord(cfg.agents.defaults) ? cfg.agents.defaults : void 0;
83
+ const configured = defaults?.workspace;
84
+ if (typeof configured === "string" && configured.trim().length > 0) return expandUserPath(configured);
85
+ return resolveOpenClawDefaultWorkspaceDir();
86
+ }
87
+
88
+ export { DEFAULT_AGENT_ID, expandUserPath, listOpenClawAgentEntries, resolveBoundAgentId, resolveOpenClawDefaultAgentId, resolveOpenClawDefaultWorkspaceDir, resolveOpenClawStateDir, resolveOpenClawWorkspaceDir };
89
+ //# sourceMappingURL=openclaw-layout.js.map
90
+ //# sourceMappingURL=openclaw-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openclaw-layout.ts"],"names":[],"mappings":";;;;;AAkCO,IAAM,gBAAA,GAAmB;AAWhC,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AAGO,SAAS,eAAe,KAAA,EAAuB;AACpD,EAAA,MAAM,OAAA,GAAU,MAAM,IAAA,EAAK;AAC3B,EAAA,IAAI,OAAA,KAAY,GAAA,EAAK,OAAU,EAAA,CAAA,OAAA,EAAQ;AACvC,EAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,IAAI,CAAA,IAAK,QAAQ,UAAA,CAAW,KAAK,CAAA,EAAG,OAAY,UAAQ,EAAA,CAAA,OAAA,EAAQ,EAAG,OAAA,CAAQ,KAAA,CAAM,CAAC,CAAC,CAAA;AAC1G,EAAA,OAAY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.homedir()` in, paths and ids out. No\n * filesystem reads, no network. Every env read goes through\n * `credentials/read-env.ts`. One resolver, shared by the identity-line\n * placement (`binding/agents-anchor.ts`), the key placement\n * (`doorbell/placement.ts`), the gateway and the doctor, so the four never\n * disagree about which workspace or state dir an agent uses.\n *\n * Mirrors OpenClaw 2026.10.9 (`src/agents/workspace-default-path.ts`,\n * `src/agents/agent-roster.ts`, `src/config/paths.ts` in its dist):\n *\n * state dir = $OPENCLAW_STATE_DIR\n * | ~/.openclaw-<profile> when OPENCLAW_PROFILE is not \"default\"\n * | ~/.openclaw\n * workspace = agents.entries.<id>.workspace (or agents.list[].workspace)\n * | agents.defaults.workspace\n * | $OPENCLAW_WORKSPACE_DIR\n * | <state dir>/workspace\n * default agent = the one entry marked `default: true` (unless agents.ownership\n * is \"explicit\") | the sole entry | \"main\" when no roster exists\n */\n\nimport * as os from 'node:os'\nimport * as path from 'node:path'\n\nimport {\n readOpenClawProfileFromEnv,\n readOpenClawStateDirFromEnv,\n readOpenClawWorkspaceDirFromEnv,\n} from './credentials/read-env.js'\n\n/** OpenClaw's implicit agent id when no roster is configured. */\nexport const DEFAULT_AGENT_ID = 'main'\n\n/** The loosest config shape these readers need; the real `OpenClawConfig` satisfies it. */\nexport type OpenClawConfigLike = object | undefined\n\nexport interface OpenClawAgentEntry {\n readonly id: string\n readonly default?: boolean\n readonly workspace?: string\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** `~` and `~/…` → the home directory; anything else resolved as given. */\nexport function expandUserPath(value: string): string {\n const trimmed = value.trim()\n if (trimmed === '~') return os.homedir()\n if (trimmed.startsWith('~/') || trimmed.startsWith('~\\\\')) return path.join(os.homedir(), trimmed.slice(2))\n return path.resolve(trimmed)\n}\n\n/** OpenClaw's state dir: `$OPENCLAW_STATE_DIR`, else the profile dir, else `~/.openclaw`. */\nexport function resolveOpenClawStateDir(): string {\n const override = readOpenClawStateDirFromEnv()\n if (override) return expandUserPath(override)\n const profile = readOpenClawProfileFromEnv()\n return path.join(os.homedir(), profile ? `.openclaw-${profile}` : '.openclaw')\n}\n\n/** OpenClaw's default agent workspace: `$OPENCLAW_WORKSPACE_DIR`, else `<state dir>/workspace`. */\nexport function resolveOpenClawDefaultWorkspaceDir(): string {\n const override = readOpenClawWorkspaceDirFromEnv()\n if (override) return path.resolve(override)\n return path.join(resolveOpenClawStateDir(), 'workspace')\n}\n\n/** The agent roster from either representation OpenClaw accepts: `agents.entries` (record) or `agents.list` (array). */\nexport function listOpenClawAgentEntries(cfg: OpenClawConfigLike): OpenClawAgentEntry[] {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n if (!agents) return []\n if (Object.hasOwn(agents, 'entries') && agents.entries !== undefined) {\n if (!isRecord(agents.entries)) return []\n return Object.entries(agents.entries)\n .filter(([, entry]) => isRecord(entry))\n .map(([id, entry]) => toEntry(id, entry as Record<string, unknown>))\n }\n if (Object.hasOwn(agents, 'list') && agents.list !== undefined) {\n if (!Array.isArray(agents.list)) return []\n return agents.list\n .filter((entry): entry is Record<string, unknown> => isRecord(entry) && typeof entry.id === 'string')\n .map((entry) => toEntry(entry.id as string, entry))\n }\n return []\n}\n\nfunction toEntry(id: string, raw: Record<string, unknown>): OpenClawAgentEntry {\n return {\n id: id.trim().toLowerCase(),\n ...(raw.default === true ? { default: true } : {}),\n ...(typeof raw.workspace === 'string' && raw.workspace.trim() ? { workspace: raw.workspace } : {}),\n }\n}\n\nfunction hasAgentRoster(cfg: OpenClawConfigLike): boolean {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n if (!agents) return false\n return (Object.hasOwn(agents, 'entries') && agents.entries !== undefined) || (Object.hasOwn(agents, 'list') && agents.list !== undefined)\n}\n\n/**\n * The agent OpenClaw treats as the ambient default — the one `llm.complete`\n * uses when a plugin passes no `agentId`. Mirrors OpenClaw's\n * `tryResolveDefaultAgentId`: one entry marked `default: true` (unless the\n * roster declares `ownership: \"explicit\"`), else the sole entry, else `main`\n * when no roster exists. `undefined` when several agents exist and none is\n * marked — OpenClaw then has no single default either.\n */\nexport function resolveOpenClawDefaultAgentId(cfg: OpenClawConfigLike): string | undefined {\n const agents = isRecord(cfg) && isRecord(cfg.agents) ? cfg.agents : undefined\n const entries = listOpenClawAgentEntries(cfg)\n if (agents?.ownership !== 'explicit') {\n const marked = entries.filter((entry) => entry.default === true)\n if (marked.length === 1) return marked[0]!.id\n }\n if (entries.length === 0) return hasAgentRoster(cfg) ? undefined : DEFAULT_AGENT_ID\n return entries.length === 1 ? entries[0]!.id : undefined\n}\n\n/**\n * The agent an explicit `bindings[]` entry routes this channel account to,\n * if any. OpenClaw's `AgentBindingMatch`: `accountId` omitted/empty matches\n * only the channel default account, `\"*\"` matches every account, any other\n * string that account id.\n */\nexport function resolveBoundAgentId(cfg: OpenClawConfigLike, channel: string, accountId: string, defaultAccountId = 'default'): string | undefined {\n const bindings = isRecord(cfg) ? cfg.bindings : undefined\n if (!Array.isArray(bindings)) return undefined\n let wildcard: string | undefined\n for (const binding of bindings) {\n if (!isRecord(binding) || typeof binding.agentId !== 'string' || !isRecord(binding.match)) continue\n const match = binding.match\n if (match.channel !== channel) continue\n if (match.peer !== undefined && match.peer !== null) continue // peer-specific bindings route single conversations, not the account\n const matchAccount = typeof match.accountId === 'string' ? match.accountId.trim() : ''\n if (matchAccount === accountId) return binding.agentId.trim().toLowerCase()\n if (matchAccount === '' && accountId === defaultAccountId) return binding.agentId.trim().toLowerCase()\n if (matchAccount === '*' && wildcard === undefined) wildcard = binding.agentId.trim().toLowerCase()\n }\n return wildcard\n}\n\n/**\n * The workspace OpenClaw loads for `agentId` — the file `AGENTS.md` is read\n * from on every turn. Per-agent `workspace` first, then\n * `agents.defaults.workspace`, then the environment default.\n */\nexport function resolveOpenClawWorkspaceDir(cfg: OpenClawConfigLike, agentId?: string): string {\n const id = (agentId ?? resolveOpenClawDefaultAgentId(cfg) ?? DEFAULT_AGENT_ID).trim().toLowerCase()\n const entry = listOpenClawAgentEntries(cfg).find((candidate) => candidate.id === id)\n if (entry?.workspace) return expandUserPath(entry.workspace)\n const defaults = isRecord(cfg) && isRecord(cfg.agents) && isRecord(cfg.agents.defaults) ? cfg.agents.defaults : undefined\n const configured = defaults?.workspace\n if (typeof configured === 'string' && configured.trim().length > 0) return expandUserPath(configured)\n return resolveOpenClawDefaultWorkspaceDir()\n}\n"]}
@@ -13,6 +13,7 @@ import { z } from 'zod';
13
13
  */
14
14
 
15
15
  declare const agentchatChannelConfigSchema: z.ZodObject<{
16
+ enabled: z.ZodOptional<z.ZodBoolean>;
16
17
  apiBase: z.ZodDefault<z.ZodString>;
17
18
  apiKey: z.ZodString;
18
19
  agentHandle: z.ZodOptional<z.ZodString>;
@@ -32,10 +33,10 @@ declare const agentchatChannelConfigSchema: z.ZodObject<{
32
33
  observability: z.ZodPrefault<z.ZodObject<{
33
34
  logLevel: z.ZodDefault<z.ZodEnum<{
34
35
  error: "error";
35
- warn: "warn";
36
- trace: "trace";
37
36
  debug: "debug";
38
37
  info: "info";
38
+ warn: "warn";
39
+ trace: "trace";
39
40
  }>>;
40
41
  redactKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
41
42
  }, z.core.$strict>>;
@@ -60,13 +61,45 @@ type AgentchatChannelConfig = z.infer<typeof agentchatChannelConfigSchema>;
60
61
  declare function parseChannelConfig(input: unknown): AgentchatChannelConfig;
61
62
 
62
63
  /**
63
- * ChannelStatusAdapter — account health + configured-state probe.
64
+ * Placing the four things the main line authored where OpenClaw loads them.
65
+ *
66
+ * 1. **The key** — `AGENTCHAT_API_KEY=…` in OpenClaw's state-dir `.env`
67
+ * (`~/.openclaw/.env`, or `$OPENCLAW_STATE_DIR/.env`), which OpenClaw
68
+ * reads at start as its global environment fallback. The hosted MCP
69
+ * server's bearer header is a template on that variable, so the key is
70
+ * never written into `openclaw.json` as part of the tool declaration.
71
+ * (The channel's own `channels.agentchat.apiKey` keeps holding the key
72
+ * for the socket, as before.)
73
+ * 2. **The identity line** — the manual's anchor text in the workspace
74
+ * `AGENTS.md`, loaded into every turn (`../binding/agents-anchor.ts`).
75
+ * 3. **The manual** — `https://agentchat.me/skill.md` verbatim, bundled as
76
+ * the `agentchat` skill. Nothing to write; verified present.
77
+ * 4. **The tools** — `mcp.servers.agentchat` in `openclaw.json` (`./mcp.ts`),
78
+ * returned as a config patch for OpenClaw to persist.
79
+ *
80
+ * Every placer is idempotent and reports what it did; the wizard prints the
81
+ * report, the status probe and the doctor run the checks again.
82
+ */
83
+
84
+ interface PlacementCheck {
85
+ readonly name: 'key' | 'anchor' | 'manual' | 'mcp';
86
+ readonly ok: boolean;
87
+ readonly detail: string;
88
+ }
89
+
90
+ /**
91
+ * ChannelStatusAdapter — the doctor-style status for `openclaw channels status`.
92
+ *
93
+ * `probeAccount` reports three things an operator needs to know, with one
94
+ * short timeout each:
95
+ *
96
+ * 1. the key authenticates (`GET /v1/agents/me`) and the account is active;
97
+ * 2. the hosted MCP server is reachable with that key (one MCP
98
+ * `initialize`), because that is where every AgentChat tool lives;
99
+ * 3. placement: the key in the gateway environment, the identity line in
100
+ * AGENTS.md, the manual, the `mcp.servers.agentchat` entry.
64
101
  *
65
- * `probeAccount` hits `/v1/agents/me` with a short timeout and reports
66
- * whether the configured key still authenticates and whether the account
67
- * is active / restricted / suspended. The gateway uses this to surface a
68
- * red/yellow/green status in `openclaw channels status` and to decide when
69
- * to page an operator for stuck accounts.
102
+ * Plus the socket's live state when the doorbell is running.
70
103
  */
71
104
 
72
105
  type AgentchatProbeResult = {
@@ -75,6 +108,23 @@ type AgentchatProbeResult = {
75
108
  readonly status?: 'active' | 'restricted' | 'suspended' | 'deleted';
76
109
  readonly pausedByOwner?: 'none' | 'send' | 'full';
77
110
  readonly error?: string;
111
+ readonly mcp?: {
112
+ readonly ok: boolean;
113
+ readonly detail: string;
114
+ };
115
+ readonly placement?: readonly PlacementCheck[];
116
+ readonly doorbell?: {
117
+ readonly mode: 'v3' | 'off';
118
+ readonly state?: string;
119
+ readonly ackNegotiated?: boolean;
120
+ readonly knocks?: number;
121
+ readonly cycles?: number;
122
+ readonly turns?: number;
123
+ };
124
+ /** Set when the doorbell refuses to start (more than one account configured). */
125
+ readonly refusal?: string;
126
+ /** Set when the account is disabled: the re-enable route (never `channels add`, which would fetch the npm build while the plugin is not loaded). */
127
+ readonly disabled?: string;
78
128
  };
79
129
 
80
130
  interface AgentchatResolvedAccount {
@@ -13,6 +13,7 @@ import { z } from 'zod';
13
13
  */
14
14
 
15
15
  declare const agentchatChannelConfigSchema: z.ZodObject<{
16
+ enabled: z.ZodOptional<z.ZodBoolean>;
16
17
  apiBase: z.ZodDefault<z.ZodString>;
17
18
  apiKey: z.ZodString;
18
19
  agentHandle: z.ZodOptional<z.ZodString>;
@@ -32,10 +33,10 @@ declare const agentchatChannelConfigSchema: z.ZodObject<{
32
33
  observability: z.ZodPrefault<z.ZodObject<{
33
34
  logLevel: z.ZodDefault<z.ZodEnum<{
34
35
  error: "error";
35
- warn: "warn";
36
- trace: "trace";
37
36
  debug: "debug";
38
37
  info: "info";
38
+ warn: "warn";
39
+ trace: "trace";
39
40
  }>>;
40
41
  redactKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
41
42
  }, z.core.$strict>>;
@@ -60,13 +61,45 @@ type AgentchatChannelConfig = z.infer<typeof agentchatChannelConfigSchema>;
60
61
  declare function parseChannelConfig(input: unknown): AgentchatChannelConfig;
61
62
 
62
63
  /**
63
- * ChannelStatusAdapter — account health + configured-state probe.
64
+ * Placing the four things the main line authored where OpenClaw loads them.
65
+ *
66
+ * 1. **The key** — `AGENTCHAT_API_KEY=…` in OpenClaw's state-dir `.env`
67
+ * (`~/.openclaw/.env`, or `$OPENCLAW_STATE_DIR/.env`), which OpenClaw
68
+ * reads at start as its global environment fallback. The hosted MCP
69
+ * server's bearer header is a template on that variable, so the key is
70
+ * never written into `openclaw.json` as part of the tool declaration.
71
+ * (The channel's own `channels.agentchat.apiKey` keeps holding the key
72
+ * for the socket, as before.)
73
+ * 2. **The identity line** — the manual's anchor text in the workspace
74
+ * `AGENTS.md`, loaded into every turn (`../binding/agents-anchor.ts`).
75
+ * 3. **The manual** — `https://agentchat.me/skill.md` verbatim, bundled as
76
+ * the `agentchat` skill. Nothing to write; verified present.
77
+ * 4. **The tools** — `mcp.servers.agentchat` in `openclaw.json` (`./mcp.ts`),
78
+ * returned as a config patch for OpenClaw to persist.
79
+ *
80
+ * Every placer is idempotent and reports what it did; the wizard prints the
81
+ * report, the status probe and the doctor run the checks again.
82
+ */
83
+
84
+ interface PlacementCheck {
85
+ readonly name: 'key' | 'anchor' | 'manual' | 'mcp';
86
+ readonly ok: boolean;
87
+ readonly detail: string;
88
+ }
89
+
90
+ /**
91
+ * ChannelStatusAdapter — the doctor-style status for `openclaw channels status`.
92
+ *
93
+ * `probeAccount` reports three things an operator needs to know, with one
94
+ * short timeout each:
95
+ *
96
+ * 1. the key authenticates (`GET /v1/agents/me`) and the account is active;
97
+ * 2. the hosted MCP server is reachable with that key (one MCP
98
+ * `initialize`), because that is where every AgentChat tool lives;
99
+ * 3. placement: the key in the gateway environment, the identity line in
100
+ * AGENTS.md, the manual, the `mcp.servers.agentchat` entry.
64
101
  *
65
- * `probeAccount` hits `/v1/agents/me` with a short timeout and reports
66
- * whether the configured key still authenticates and whether the account
67
- * is active / restricted / suspended. The gateway uses this to surface a
68
- * red/yellow/green status in `openclaw channels status` and to decide when
69
- * to page an operator for stuck accounts.
102
+ * Plus the socket's live state when the doorbell is running.
70
103
  */
71
104
 
72
105
  type AgentchatProbeResult = {
@@ -75,6 +108,23 @@ type AgentchatProbeResult = {
75
108
  readonly status?: 'active' | 'restricted' | 'suspended' | 'deleted';
76
109
  readonly pausedByOwner?: 'none' | 'send' | 'full';
77
110
  readonly error?: string;
111
+ readonly mcp?: {
112
+ readonly ok: boolean;
113
+ readonly detail: string;
114
+ };
115
+ readonly placement?: readonly PlacementCheck[];
116
+ readonly doorbell?: {
117
+ readonly mode: 'v3' | 'off';
118
+ readonly state?: string;
119
+ readonly ackNegotiated?: boolean;
120
+ readonly knocks?: number;
121
+ readonly cycles?: number;
122
+ readonly turns?: number;
123
+ };
124
+ /** Set when the doorbell refuses to start (more than one account configured). */
125
+ readonly refusal?: string;
126
+ /** Set when the account is disabled: the re-enable route (never `channels add`, which would fetch the npm build while the plugin is not loaded). */
127
+ readonly disabled?: string;
78
128
  };
79
129
 
80
130
  interface AgentchatResolvedAccount {