@agentchatme/openclaw 0.9.2 → 0.10.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/CHANGELOG.md +33 -0
- package/README.md +35 -26
- package/RUNBOOK.md +49 -17
- package/SECURITY.md +6 -2
- package/dist/binding/agents-anchor.cjs +10 -43
- package/dist/binding/agents-anchor.cjs.map +1 -1
- package/dist/binding/agents-anchor.d.cts +14 -11
- package/dist/binding/agents-anchor.d.ts +14 -11
- package/dist/binding/agents-anchor.js +10 -43
- package/dist/binding/agents-anchor.js.map +1 -1
- package/dist/index.cjs +1569 -1371
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +668 -192
- package/dist/index.d.ts +668 -192
- package/dist/index.js +1568 -1371
- package/dist/index.js.map +1 -1
- package/dist/setup-entry-C9aFZx3n.d.cts +378 -0
- package/dist/setup-entry-C9aFZx3n.d.ts +378 -0
- package/dist/setup-entry.cjs +1557 -1363
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.d.cts +1 -1
- package/dist/setup-entry.d.ts +1 -1
- package/dist/setup-entry.js +1564 -1370
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -3
- package/dist/setup-entry-sXnwmV8K.d.cts +0 -773
- package/dist/setup-entry-sXnwmV8K.d.ts +0 -773
|
@@ -13,10 +13,12 @@ import { OpenClawConfig } from 'openclaw/plugin-sdk/channel-core';
|
|
|
13
13
|
* triggered the run (docs.openclaw.ai/concepts/system-prompt).
|
|
14
14
|
*
|
|
15
15
|
* The text is served by AgentChat (`GET /v1/texts` → `identity_line`,
|
|
16
|
-
* fetched by `../integration/texts.ts`). It is not ours
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* fetched by `../integration/texts.ts`). It is not ours, and neither is the
|
|
17
|
+
* block's shape: the SDK kit's `anchor` functions render it (the fences, a
|
|
18
|
+
* handle line, the served line), find it (current, legacy and unmarked
|
|
19
|
+
* shapes) and replace or remove it, so re-runs upsert and `channels remove`
|
|
20
|
+
* strips it cleanly. This module only reads and writes the file. No
|
|
21
|
+
* official "plugin → AGENTS.md" API exists.
|
|
20
22
|
*
|
|
21
23
|
* Lifecycle
|
|
22
24
|
* ─────────
|
|
@@ -35,8 +37,8 @@ import { OpenClawConfig } from 'openclaw/plugin-sdk/channel-core';
|
|
|
35
37
|
* (documented in RUNBOOK.md).
|
|
36
38
|
*/
|
|
37
39
|
|
|
38
|
-
declare const ANCHOR_START
|
|
39
|
-
declare const ANCHOR_END
|
|
40
|
+
declare const ANCHOR_START: "<!-- agentchat:start -->";
|
|
41
|
+
declare const ANCHOR_END: "<!-- agentchat:end -->";
|
|
40
42
|
/**
|
|
41
43
|
* The workspace OpenClaw loads for the agent this channel wakes — per-agent
|
|
42
44
|
* `agents.entries.<id>.workspace`, then `agents.defaults.workspace`, then
|
|
@@ -48,10 +50,11 @@ declare function resolveWorkspaceDir(cfg: OpenClawConfig | undefined, agentId?:
|
|
|
48
50
|
declare function agentsAnchorPath(cfg: OpenClawConfig | undefined, agentId?: string): string;
|
|
49
51
|
/**
|
|
50
52
|
* Idempotent write of `text` (the served identity line) for `handle`.
|
|
51
|
-
* Re-running upserts the existing block (handle change, text update
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* Re-running upserts the existing block (handle change, text update, an
|
|
54
|
+
* older unmarked or legacy-fenced block) without leaving stale duplicates or
|
|
55
|
+
* blank-line drift. Throws — writing nothing — when the text does not name
|
|
56
|
+
* the handle (a peer would be handed an address that reaches someone else),
|
|
57
|
+
* and when the workspace is not writable; the caller decides whether to
|
|
55
58
|
* surface it.
|
|
56
59
|
*/
|
|
57
60
|
declare function writeAgentsAnchor(params: {
|
|
@@ -70,7 +73,7 @@ declare function removeAgentsAnchor(params: {
|
|
|
70
73
|
removed: boolean;
|
|
71
74
|
path: string;
|
|
72
75
|
};
|
|
73
|
-
/** What the file holds
|
|
76
|
+
/** What the file holds in our block (current or legacy fences), without the handle line, if anything. */
|
|
74
77
|
declare function readAgentsAnchor(params: {
|
|
75
78
|
cfg: OpenClawConfig | undefined;
|
|
76
79
|
agentId?: string | undefined;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { integration } from 'agentchatme';
|
|
3
4
|
import { resolveOpenClawWorkspaceDir } from '../openclaw-layout.js';
|
|
4
5
|
|
|
5
6
|
// src/binding/agents-anchor.ts
|
|
6
|
-
var ANCHOR_START =
|
|
7
|
-
var ANCHOR_END =
|
|
8
|
-
var LEGACY_ANCHOR_START = "<!-- agentchat-skill:start -->";
|
|
9
|
-
var LEGACY_ANCHOR_END = "<!-- agentchat-skill:end -->";
|
|
7
|
+
var ANCHOR_START = integration.anchor.START_MARKER;
|
|
8
|
+
var ANCHOR_END = integration.anchor.END_MARKER;
|
|
10
9
|
function resolveWorkspaceDir(cfg, agentId) {
|
|
11
10
|
return resolveOpenClawWorkspaceDir(cfg, agentId);
|
|
12
11
|
}
|
|
13
12
|
function agentsAnchorPath(cfg, agentId) {
|
|
14
13
|
return path.join(resolveWorkspaceDir(cfg, agentId), "AGENTS.md");
|
|
15
14
|
}
|
|
16
|
-
function renderAnchorBlock(text) {
|
|
17
|
-
return [ANCHOR_START, text.trim(), ANCHOR_END].join("\n");
|
|
18
|
-
}
|
|
19
15
|
function bareHandle(handle) {
|
|
20
|
-
return (handle ?? "")
|
|
16
|
+
return integration.anchor.normalizeHandle(handle ?? "");
|
|
21
17
|
}
|
|
22
18
|
function writeAgentsAnchor(params) {
|
|
23
19
|
const bare = bareHandle(params.handle);
|
|
@@ -28,7 +24,8 @@ function writeAgentsAnchor(params) {
|
|
|
28
24
|
const filePath = path.join(workspaceDir, "AGENTS.md");
|
|
29
25
|
fs.mkdirSync(workspaceDir, { recursive: true });
|
|
30
26
|
const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : "";
|
|
31
|
-
const
|
|
27
|
+
const block = integration.anchor.render({ identity_line: text, identity_line_template: "" }, bare);
|
|
28
|
+
const next = integration.anchor.replace(existing, block);
|
|
32
29
|
fs.writeFileSync(filePath, next, "utf-8");
|
|
33
30
|
const verify = fs.readFileSync(filePath, "utf-8");
|
|
34
31
|
if (!verify.includes(`@${bare}`)) {
|
|
@@ -40,7 +37,7 @@ function removeAgentsAnchor(params) {
|
|
|
40
37
|
const filePath = agentsAnchorPath(params.cfg, params.agentId);
|
|
41
38
|
if (!fs.existsSync(filePath)) return { removed: false, path: filePath };
|
|
42
39
|
const existing = fs.readFileSync(filePath, "utf-8");
|
|
43
|
-
const next =
|
|
40
|
+
const next = integration.anchor.remove(existing);
|
|
44
41
|
if (next === existing) return { removed: false, path: filePath };
|
|
45
42
|
fs.writeFileSync(filePath, next, "utf-8");
|
|
46
43
|
return { removed: true, path: filePath };
|
|
@@ -48,11 +45,9 @@ function removeAgentsAnchor(params) {
|
|
|
48
45
|
function readAgentsAnchor(params) {
|
|
49
46
|
const filePath = agentsAnchorPath(params.cfg, params.agentId);
|
|
50
47
|
if (!fs.existsSync(filePath)) return { present: false, text: null, path: filePath };
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return { present: false, text: null, path: filePath };
|
|
55
|
-
return { present: true, text: content.slice(startIdx + ANCHOR_START.length, endIdx).trim(), path: filePath };
|
|
48
|
+
const found = integration.anchor.find(fs.readFileSync(filePath, "utf-8"));
|
|
49
|
+
if (!found) return { present: false, text: null, path: filePath };
|
|
50
|
+
return { present: true, text: found.body, path: filePath };
|
|
56
51
|
}
|
|
57
52
|
function hasAgentsAnchorFor(params) {
|
|
58
53
|
const found = readAgentsAnchor({ cfg: params.cfg, agentId: params.agentId });
|
|
@@ -62,34 +57,6 @@ function hasAgentsAnchorFor(params) {
|
|
|
62
57
|
}
|
|
63
58
|
return { present: found.text.includes(`@${bareHandle(params.handle)}`), path: found.path };
|
|
64
59
|
}
|
|
65
|
-
function upsertAnchorBlock(existing, block) {
|
|
66
|
-
const cleaned = stripBlockBetween(existing, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
67
|
-
const startIdx = cleaned.indexOf(ANCHOR_START);
|
|
68
|
-
const endIdx = cleaned.indexOf(ANCHOR_END);
|
|
69
|
-
if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx) {
|
|
70
|
-
const before = cleaned.slice(0, startIdx).replace(/\n+$/, "");
|
|
71
|
-
const after = cleaned.slice(endIdx + ANCHOR_END.length).replace(/^\n+/, "");
|
|
72
|
-
return [before, block, after].filter((s) => s.length > 0).join("\n\n") + "\n";
|
|
73
|
-
}
|
|
74
|
-
const trimmed = cleaned.replace(/\n+$/, "");
|
|
75
|
-
if (trimmed.length === 0) return block + "\n";
|
|
76
|
-
return trimmed + "\n\n" + block + "\n";
|
|
77
|
-
}
|
|
78
|
-
function stripAnchorBlock(existing) {
|
|
79
|
-
const afterUnified = stripBlockBetween(existing, ANCHOR_START, ANCHOR_END);
|
|
80
|
-
return stripBlockBetween(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END);
|
|
81
|
-
}
|
|
82
|
-
function stripBlockBetween(existing, start, end) {
|
|
83
|
-
const startIdx = existing.indexOf(start);
|
|
84
|
-
const endIdx = existing.indexOf(end);
|
|
85
|
-
if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return existing;
|
|
86
|
-
const before = existing.slice(0, startIdx).replace(/\n+$/, "");
|
|
87
|
-
const after = existing.slice(endIdx + end.length).replace(/^\n+/, "");
|
|
88
|
-
if (before.length === 0 && after.length === 0) return "";
|
|
89
|
-
if (before.length === 0) return after.endsWith("\n") ? after : after + "\n";
|
|
90
|
-
if (after.length === 0) return before + "\n";
|
|
91
|
-
return before + "\n\n" + after + (after.endsWith("\n") ? "" : "\n");
|
|
92
|
-
}
|
|
93
60
|
|
|
94
61
|
export { ANCHOR_END, ANCHOR_START, agentsAnchorPath, hasAgentsAnchorFor, readAgentsAnchor, removeAgentsAnchor, resolveWorkspaceDir, writeAgentsAnchor };
|
|
95
62
|
//# sourceMappingURL=agents-anchor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":[],"mappings":";;;;;AA8CO,IAAM,YAAA,GAAe;AACrB,IAAM,UAAA,GAAa;AAG1B,IAAM,mBAAA,GAAsB,gCAAA;AAC5B,IAAM,iBAAA,GAAoB,8BAAA;AASnB,SAAS,mBAAA,CAAoB,KAAiC,OAAA,EAA0B;AAC7F,EAAA,OAAO,2BAAA,CAA4B,KAAK,OAAO,CAAA;AACjD;AAEO,SAAS,gBAAA,CAAiB,KAAiC,OAAA,EAA0B;AAC1F,EAAA,OAAY,IAAA,CAAA,IAAA,CAAK,mBAAA,CAAoB,GAAA,EAAK,OAAO,GAAG,WAAW,CAAA;AACjE;AAEA,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,OAAO,CAAC,cAAc,IAAA,CAAK,IAAA,IAAQ,UAAU,CAAA,CAAE,KAAK,IAAI,CAAA;AAC1D;AAEA,SAAS,WAAW,MAAA,EAAoC;AACtD,EAAA,OAAA,CAAQ,UAAU,EAAA,EAAI,IAAA,EAAK,CAAE,OAAA,CAAQ,MAAM,EAAE,CAAA;AAC/C;AAUO,SAAS,kBAAkB,MAAA,EAA2H;AAC3J,EAAA,MAAM,IAAA,GAAO,UAAA,CAAW,MAAA,CAAO,MAAM,CAAA;AACrC,EAAA,IAAI,CAAC,IAAA,EAAM,MAAM,IAAI,MAAM,oCAAoC,CAAA;AAC/D,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,IAAA,EAAK;AAC9B,EAAA,IAAI,CAAC,IAAA,EAAM,MAAM,IAAI,MAAM,2CAA2C,CAAA;AAEtE,EAAA,MAAM,YAAA,GAAe,mBAAA,CAAoB,MAAA,CAAO,GAAA,E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CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,MAAA,GAAS,IAAA;AACxC,EAAA,OAAO,SAAS,MAAA,GAAS,KAAA,IAAS,MAAM,QAAA,CAAS,IAAI,IAAI,EAAA,GAAK,IAAA,CAAA;AAChE","file":"agents-anchor.js","sourcesContent":["/**\n * AGENTS.md anchor management — where the identity line goes.\n *\n * Why this file exists\n * ─────────────────────\n * AgentChat asks every runtime to carry one short identity text in the file\n * it loads **every** turn. On OpenClaw that file is the workspace\n * `AGENTS.md`: workspace bootstrap files (AGENTS.md, SOUL.md, USER.md,\n * TOOLS.md, IDENTITY.md, HEARTBEAT.md, MEMORY.md) are loaded into the system\n * prompt on every turn of every session, regardless of which channel\n * triggered the run (docs.openclaw.ai/concepts/system-prompt).\n *\n * The text is served by AgentChat (`GET /v1/texts` → `identity_line`,\n * fetched by `../integration/texts.ts`). It is not ours: this module places\n * whatever text it is handed between marker fences, so re-runs upsert and\n * `channels remove` strips it cleanly. No official \"plugin → AGENTS.md\" API\n * exists.\n *\n * Lifecycle\n * ─────────\n * write — `setupWizard.finalize` (after validateApiKey ok),\n * `setup.afterAccountConfigWritten` (non-interactive path),\n * `lifecycle.onAccountConfigChanged` (disabled → enabled),\n * `openclaw doctor --fix` when the line for the configured handle\n * is missing (the re-enable path through `openclaw config set`,\n * which reaches no plugin hook), and the running gateway when a\n * fresh server copy of the text differs from the placed one.\n * remove — `lifecycle.onAccountConfigChanged` (enabled → disabled,\n * `channels remove agentchat`) and `lifecycle.onAccountRemoved`\n * (`--delete`).\n * orphan — `openclaw plugins uninstall` fires no plugin hook today; an\n * uninstall without `channels remove` leaves the block behind\n * (documented in RUNBOOK.md).\n */\n\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\n\nimport type { OpenClawConfig } from './openclaw-types.js'\n// Path resolution is delegated to the shared OpenClaw layout module (which\n// reads the environment through the credential helper). This module\n// performs only local filesystem operations against the workspace AGENTS.md\n// file and never touches the host environment directly (SECURITY.md).\nimport { resolveOpenClawWorkspaceDir } from '../openclaw-layout.js'\n\n// Marker fences shared with the universal skill's own placement recipe.\nexport const ANCHOR_START = '<!-- agentchat:start -->'\nexport const ANCHOR_END = '<!-- agentchat:end -->'\n\n// Legacy markers from an earlier recipe; migrated silently on the next write.\nconst LEGACY_ANCHOR_START = '<!-- agentchat-skill:start -->'\nconst LEGACY_ANCHOR_END = '<!-- agentchat-skill:end -->'\n\n/**\n * The workspace OpenClaw loads for the agent this channel wakes — per-agent\n * `agents.entries.<id>.workspace`, then `agents.defaults.workspace`, then\n * `$OPENCLAW_WORKSPACE_DIR`, then `<state dir>/workspace` (state dir =\n * `$OPENCLAW_STATE_DIR`, the profile dir, or `~/.openclaw`). One resolver\n * for every placement (`../openclaw-layout.ts`).\n */\nexport function resolveWorkspaceDir(cfg: OpenClawConfig | undefined, agentId?: string): string {\n return resolveOpenClawWorkspaceDir(cfg, agentId)\n}\n\nexport function agentsAnchorPath(cfg: OpenClawConfig | undefined, agentId?: string): string {\n return path.join(resolveWorkspaceDir(cfg, agentId), 'AGENTS.md')\n}\n\nfunction renderAnchorBlock(text: string): string {\n return [ANCHOR_START, text.trim(), ANCHOR_END].join('\\n')\n}\n\nfunction bareHandle(handle: string | undefined): string {\n return (handle ?? '').trim().replace(/^@/, '')\n}\n\n/**\n * Idempotent write of `text` (the served identity line) for `handle`.\n * Re-running upserts the existing block (handle change, text update) without\n * leaving stale duplicates or blank-line drift. Throws when the handle did\n * not land in the file (a regression: the served text names the handle) or\n * when the workspace is not writable — the caller decides whether to\n * surface it.\n */\nexport function writeAgentsAnchor(params: { cfg: OpenClawConfig | undefined; handle: string; text: string; agentId?: string | undefined }): { path: string } {\n const bare = bareHandle(params.handle)\n if (!bare) throw new Error('writeAgentsAnchor: handle is empty')\n const text = params.text.trim()\n if (!text) throw new Error('writeAgentsAnchor: identity line is empty')\n\n const workspaceDir = resolveWorkspaceDir(params.cfg, params.agentId)\n const filePath = path.join(workspaceDir, 'AGENTS.md')\n fs.mkdirSync(workspaceDir, { recursive: true })\n\n const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : ''\n const next = upsertAnchorBlock(existing, renderAnchorBlock(text))\n fs.writeFileSync(filePath, next, 'utf-8')\n\n const verify = fs.readFileSync(filePath, 'utf-8')\n if (!verify.includes(`@${bare}`)) {\n throw new Error(`writeAgentsAnchor: handle @${bare} did not land in AGENTS.md — remove the agentchat anchor manually and re-run.`)\n }\n return { path: filePath }\n}\n\n/** Idempotent remove. Strips our block (and any legacy block); leaves the rest untouched. */\nexport function removeAgentsAnchor(params: { cfg: OpenClawConfig | undefined; agentId?: string | undefined }): { removed: boolean; path: string } {\n const filePath = agentsAnchorPath(params.cfg, params.agentId)\n if (!fs.existsSync(filePath)) return { removed: false, path: filePath }\n const existing = fs.readFileSync(filePath, 'utf-8')\n const next = stripAnchorBlock(existing)\n if (next === existing) return { removed: false, path: filePath }\n fs.writeFileSync(filePath, next, 'utf-8')\n return { removed: true, path: filePath }\n}\n\n/** What the file holds between our markers, if anything. */\nexport function readAgentsAnchor(params: { cfg: OpenClawConfig | undefined; agentId?: string | undefined }): { present: boolean; text: string | null; path: string } {\n const filePath = agentsAnchorPath(params.cfg, params.agentId)\n if (!fs.existsSync(filePath)) return { present: false, text: null, path: filePath }\n const content = fs.readFileSync(filePath, 'utf-8')\n const startIdx = content.indexOf(ANCHOR_START)\n const endIdx = content.indexOf(ANCHOR_END)\n if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return { present: false, text: null, path: filePath }\n return { present: true, text: content.slice(startIdx + ANCHOR_START.length, endIdx).trim(), path: filePath }\n}\n\n/**\n * Doctor check: is an identity line for this handle present? With `text`\n * (the served line) the block must hold exactly that text; without it (the\n * server unreachable and nothing cached) any of our blocks naming the handle\n * counts.\n */\nexport function hasAgentsAnchorFor(params: { cfg: OpenClawConfig | undefined; handle: string; text?: string | null | undefined; agentId?: string | undefined }): {\n present: boolean\n path: string\n} {\n const found = readAgentsAnchor({ cfg: params.cfg, agentId: params.agentId })\n if (!found.present || found.text === null) return { present: false, path: found.path }\n if (typeof params.text === 'string' && params.text.trim().length > 0) {\n return { present: found.text === params.text.trim(), path: found.path }\n }\n return { present: found.text.includes(`@${bareHandle(params.handle)}`), path: found.path }\n}\n\nfunction upsertAnchorBlock(existing: string, block: string): string {\n const cleaned = stripBlockBetween(existing, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END)\n const startIdx = cleaned.indexOf(ANCHOR_START)\n const endIdx = cleaned.indexOf(ANCHOR_END)\n if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx) {\n const before = cleaned.slice(0, startIdx).replace(/\\n+$/, '')\n const after = cleaned.slice(endIdx + ANCHOR_END.length).replace(/^\\n+/, '')\n return [before, block, after].filter((s) => s.length > 0).join('\\n\\n') + '\\n'\n }\n const trimmed = cleaned.replace(/\\n+$/, '')\n if (trimmed.length === 0) return block + '\\n'\n return trimmed + '\\n\\n' + block + '\\n'\n}\n\nfunction stripAnchorBlock(existing: string): string {\n const afterUnified = stripBlockBetween(existing, ANCHOR_START, ANCHOR_END)\n return stripBlockBetween(afterUnified, LEGACY_ANCHOR_START, LEGACY_ANCHOR_END)\n}\n\nfunction stripBlockBetween(existing: string, start: string, end: string): string {\n const startIdx = existing.indexOf(start)\n const endIdx = existing.indexOf(end)\n if (startIdx < 0 || endIdx < 0 || endIdx <= startIdx) return existing\n const before = existing.slice(0, startIdx).replace(/\\n+$/, '')\n const after = existing.slice(endIdx + end.length).replace(/^\\n+/, '')\n if (before.length === 0 && after.length === 0) return ''\n if (before.length === 0) return after.endsWith('\\n') ? after : after + '\\n'\n if (after.length === 0) return before + '\\n'\n return before + '\\n\\n' + after + (after.endsWith('\\n') ? '' : '\\n')\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":[],"mappings":";;;;;;AAkDO,IAAM,YAAA,GAAe,YAAY,MAAA,CAAO;AACxC,IAAM,UAAA,GAAa,YAAY,MAAA,CAAO;AAStC,S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OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,QAAA,EAAS;AAClF,EAAA,MAAM,QAAQ,WAAA,CAAY,MAAA,CAAO,KAAQ,EAAA,CAAA,YAAA,CAAa,QAAA,EAAU,OAAO,CAAC,CAAA;AACxE,EAAA,IAAI,CAAC,OAAO,OAAO,EAAE,SAAS,KAAA,EAAO,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,QAAA,EAAS;AAChE,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,MAAM,KAAA,CAAM,IAAA,EAAM,MAAM,QAAA,EAAS;AAC3D;AAQO,SAAS,mBAAmB,MAAA,EAGjC;AACA,EAAA,MAAM,KAAA,GAAQ,iBAAiB,EAAE,GAAA,EAAK,OAAO,GAAA,EAAK,OAAA,EAAS,MAAA,CAAO,OAAA,EAAS,CAAA;AAC3E,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,IAAW,KAAA,CAAM,IAAA,KAAS,IAAA,EAAM,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,IAAA,EAAM,KAAA,CAAM,IAAA,EAAK;AACrF,EAAA,IAAI,OAAO,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,IAAA,CAAK,IAAA,EAAK,CAAE,MAAA,GAAS,CAAA,EAAG;AACpE,IAAA,OAAO,EAAE,OAAA,EAAS,KAAA,CAAM,IAAA,KAAS,MAAA,CAAO,KAAK,IAAA,EAAK,EAAG,IAAA,EAAM,KAAA,CAAM,IAAA,EAAK;AAAA,EACxE;AACA,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,CAAM,IAAA,CAAK,SAAS,CAAA,CAAA,EAAI,UAAA,CAAW,MAAA,CAAO,MAAM,CAAC,CAAA,CAAE,CAAA,EAAG,IAAA,EAAM,MAAM,IAAA,EAAK;AAC3F","file":"agents-anchor.js","sourcesContent":["/**\n * AGENTS.md anchor management — where the identity line goes.\n *\n * Why this file exists\n * ─────────────────────\n * AgentChat asks every runtime to carry one short identity text in the file\n * it loads **every** turn. On OpenClaw that file is the workspace\n * `AGENTS.md`: workspace bootstrap files (AGENTS.md, SOUL.md, USER.md,\n * TOOLS.md, IDENTITY.md, HEARTBEAT.md, MEMORY.md) are loaded into the system\n * prompt on every turn of every session, regardless of which channel\n * triggered the run (docs.openclaw.ai/concepts/system-prompt).\n *\n * The text is served by AgentChat (`GET /v1/texts` → `identity_line`,\n * fetched by `../integration/texts.ts`). It is not ours, and neither is the\n * block's shape: the SDK kit's `anchor` functions render it (the fences, a\n * handle line, the served line), find it (current, legacy and unmarked\n * shapes) and replace or remove it, so re-runs upsert and `channels remove`\n * strips it cleanly. This module only reads and writes the file. No\n * official \"plugin → AGENTS.md\" API exists.\n *\n * Lifecycle\n * ─────────\n * write — `setupWizard.finalize` (after validateApiKey ok),\n * `setup.afterAccountConfigWritten` (non-interactive path),\n * `lifecycle.onAccountConfigChanged` (disabled → enabled),\n * `openclaw doctor --fix` when the line for the configured handle\n * is missing (the re-enable path through `openclaw config set`,\n * which reaches no plugin hook), and the running gateway when a\n * fresh server copy of the text differs from the placed one.\n * remove — `lifecycle.onAccountConfigChanged` (enabled → disabled,\n * `channels remove agentchat`) and `lifecycle.onAccountRemoved`\n * (`--delete`).\n * orphan — `openclaw plugins uninstall` fires no plugin hook today; an\n * uninstall without `channels remove` leaves the block behind\n * (documented in RUNBOOK.md).\n */\n\nimport * as fs from 'node:fs'\nimport * as path from 'node:path'\n\nimport { integration } from 'agentchatme'\n\nimport type { OpenClawConfig } from './openclaw-types.js'\n// Path resolution is delegated to the shared OpenClaw layout module (which\n// reads the environment through the credential helper). This module\n// performs only local filesystem operations against the workspace AGENTS.md\n// file and never touches the host environment directly (SECURITY.md).\nimport { resolveOpenClawWorkspaceDir } from '../openclaw-layout.js'\n\n// Marker fences (the kit's; shared with the universal skill's own placement recipe).\nexport const ANCHOR_START = integration.anchor.START_MARKER\nexport const ANCHOR_END = integration.anchor.END_MARKER\n\n/**\n * The workspace OpenClaw loads for the agent this channel wakes — per-agent\n * `agents.entries.<id>.workspace`, then `agents.defaults.workspace`, then\n * `$OPENCLAW_WORKSPACE_DIR`, then `<state dir>/workspace` (state dir =\n * `$OPENCLAW_STATE_DIR`, the profile dir, or `~/.openclaw`). One resolver\n * for every placement (`../openclaw-layout.ts`).\n */\nexport function resolveWorkspaceDir(cfg: OpenClawConfig | undefined, agentId?: string): string {\n return resolveOpenClawWorkspaceDir(cfg, agentId)\n}\n\nexport function agentsAnchorPath(cfg: OpenClawConfig | undefined, agentId?: string): string {\n return path.join(resolveWorkspaceDir(cfg, agentId), 'AGENTS.md')\n}\n\nfunction bareHandle(handle: string | undefined): string {\n return integration.anchor.normalizeHandle(handle ?? '')\n}\n\n/**\n * Idempotent write of `text` (the served identity line) for `handle`.\n * Re-running upserts the existing block (handle change, text update, an\n * older unmarked or legacy-fenced block) without leaving stale duplicates or\n * blank-line drift. Throws — writing nothing — when the text does not name\n * the handle (a peer would be handed an address that reaches someone else),\n * and when the workspace is not writable; the caller decides whether to\n * surface it.\n */\nexport function writeAgentsAnchor(params: { cfg: OpenClawConfig | undefined; handle: string; text: string; agentId?: string | undefined }): { path: string } {\n const bare = bareHandle(params.handle)\n if (!bare) throw new Error('writeAgentsAnchor: handle is empty')\n const text = params.text.trim()\n if (!text) throw new Error('writeAgentsAnchor: identity line is empty')\n\n const workspaceDir = resolveWorkspaceDir(params.cfg, params.agentId)\n const filePath = path.join(workspaceDir, 'AGENTS.md')\n fs.mkdirSync(workspaceDir, { recursive: true })\n\n const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : ''\n // The kit renders the block for the handle (it refuses a text that does\n // not name it) and replaces the first block of any known shape.\n const block = integration.anchor.render({ identity_line: text, identity_line_template: '' }, bare)\n const next = integration.anchor.replace(existing, block)\n fs.writeFileSync(filePath, next, 'utf-8')\n\n const verify = fs.readFileSync(filePath, 'utf-8')\n if (!verify.includes(`@${bare}`)) {\n throw new Error(`writeAgentsAnchor: handle @${bare} did not land in AGENTS.md — remove the agentchat anchor manually and re-run.`)\n }\n return { path: filePath }\n}\n\n/** Idempotent remove. Strips our block (and any legacy block); leaves the rest untouched. */\nexport function removeAgentsAnchor(params: { cfg: OpenClawConfig | undefined; agentId?: string | undefined }): { removed: boolean; path: string } {\n const filePath = agentsAnchorPath(params.cfg, params.agentId)\n if (!fs.existsSync(filePath)) return { removed: false, path: filePath }\n const existing = fs.readFileSync(filePath, 'utf-8')\n const next = integration.anchor.remove(existing)\n if (next === existing) return { removed: false, path: filePath }\n fs.writeFileSync(filePath, next, 'utf-8')\n return { removed: true, path: filePath }\n}\n\n/** What the file holds in our block (current or legacy fences), without the handle line, if anything. */\nexport function readAgentsAnchor(params: { cfg: OpenClawConfig | undefined; agentId?: string | undefined }): { present: boolean; text: string | null; path: string } {\n const filePath = agentsAnchorPath(params.cfg, params.agentId)\n if (!fs.existsSync(filePath)) return { present: false, text: null, path: filePath }\n const found = integration.anchor.find(fs.readFileSync(filePath, 'utf-8'))\n if (!found) return { present: false, text: null, path: filePath }\n return { present: true, text: found.body, path: filePath }\n}\n\n/**\n * Doctor check: is an identity line for this handle present? With `text`\n * (the served line) the block must hold exactly that text; without it (the\n * server unreachable and nothing cached) any of our blocks naming the handle\n * counts.\n */\nexport function hasAgentsAnchorFor(params: { cfg: OpenClawConfig | undefined; handle: string; text?: string | null | undefined; agentId?: string | undefined }): {\n present: boolean\n path: string\n} {\n const found = readAgentsAnchor({ cfg: params.cfg, agentId: params.agentId })\n if (!found.present || found.text === null) return { present: false, path: found.path }\n if (typeof params.text === 'string' && params.text.trim().length > 0) {\n return { present: found.text === params.text.trim(), path: found.path }\n }\n return { present: found.text.includes(`@${bareHandle(params.handle)}`), path: found.path }\n}\n"]}
|