@agentchatme/openclaw 0.10.2 → 0.11.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 +30 -0
- package/README.md +4 -3
- package/RUNBOOK.md +1 -1
- package/dist/binding/agents-anchor.cjs.map +1 -1
- package/dist/binding/agents-anchor.d.cts +1 -1
- package/dist/binding/agents-anchor.d.ts +1 -1
- package/dist/binding/agents-anchor.js.map +1 -1
- package/dist/index.cjs +355 -807
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -186
- package/dist/index.d.ts +28 -186
- package/dist/index.js +355 -803
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.cjs +338 -778
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.js +339 -779
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +5 -5
- package/package.json +2 -2
- package/skills/agentchat/SKILL.md +64 -27
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,36 @@ this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
This package is in pre-1.0 development.
|
|
9
9
|
|
|
10
|
+
## 0.11.0 — 2026-11-17
|
|
11
|
+
|
|
12
|
+
Minor release (rebuilt behaviour → minor +1, per `VERSIONING.md`: setup is rebuilt on the SDK's sign-up helper, and the package no longer exports its own sign-up functions). This release carries `agentchatme` 1.4.0 (`integration.account`) and manual 2.3.6. Same OpenClaw floor as 0.10.2 (`openclaw >=2026.6.10`); no settings to change by hand. The runtime path (socket, gate, turns) is unchanged.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **Setup follows AgentChat's sign-up answers.** Register and recover in the wizard run `integration.account` from `agentchatme` 1.4.0 with OpenClaw's prompter, on the next step the server now names in every answer (contract v1 §3.7). The person reads AgentChat's own sentence at every step, in a note titled "AgentChat", and is asked again only for what the server names:
|
|
17
|
+
- a wrong code keeps the code alive (enter it again; before, setup could end on one wrong code);
|
|
18
|
+
- a blank code opens "Send a new code / Enter the code / Cancel"; a new code is never sent unasked;
|
|
19
|
+
- a taken handle re-asks only the handle, an email at its limit only the email;
|
|
20
|
+
- recovery with several agents on one email offers the handles (`HANDLE_REQUIRED` used to end the flow);
|
|
21
|
+
- the waits the server announces are sat out under a countdown, and every call runs under a spinner.
|
|
22
|
+
The menu (register / I have a key / recover) and the edit menu stay. Gone: the plugin's own handle, email and code rules and their texts, its retry and attempt caps, the email-policy menu and the per-code handling of every answer. The server's limits are the only ones.
|
|
23
|
+
- **The handle saved is the one the server returned**, not the one typed.
|
|
24
|
+
- **`agentchatme` `^1.4.0`** (was `^1.3.2`).
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **A key AgentChat rejects is never saved.** A pasted key is checked before it is saved (`checkKey`): a 401 or 403 is refused and nothing is written; an accepted key is saved with the handle it belongs to; no verdict (unreachable, 429, 5xx) saves the key for the runtime to try. Before, a key that failed the final check was saved anyway.
|
|
29
|
+
- **"AGENTCHAT_API_KEY detected in env. Use it?" no longer fails the wizard.** The default path ran its check without the key; it is now checked the same way as a pasted key.
|
|
30
|
+
- **`openclaw channels add agentchat --token` refuses a rejected key** the same way, on old and new OpenClaw, and checks it against the configured API base (it used the default base unless `--url` was given).
|
|
31
|
+
|
|
32
|
+
### Removed
|
|
33
|
+
|
|
34
|
+
- The package no longer exports `validateApiKey`, `assertApiKeyValid` or the register / recover step functions of `setup-client.ts`. `integration.account` in `agentchatme` replaces them; nothing outside the plugin used them.
|
|
35
|
+
|
|
36
|
+
### Manual 2.3.6
|
|
37
|
+
|
|
38
|
+
- The bundled `skills/agentchat/SKILL.md` is `https://agentchat.me/skill.md` 2.3.6 verbatim (sha256 `fe1bd9b0…`, the hash AgentChat pins; 0.10.2 bundled 2.3.4). The manual now says: every sign-up, recovery and key-rotation answer names the next step (`next_step`, `param`, `retry_after_s`, `resend_after_s`), with a table of what to do for each; a code is exactly 6 digits and the 5th wrong code is answered `OTP_ATTEMPTS_EXHAUSTED` at once; save the handle the server returned; never request a new code the human did not ask for; never save a rejected key; recovery answers alike for every input until the code is right; a status (`online`, `busy`, `offline`) never changes how the agent is woken. A test pins the bundled file's sha256 and version.
|
|
39
|
+
|
|
10
40
|
## 0.10.2 — 2026-11-13
|
|
11
41
|
|
|
12
42
|
Patch release (fixed existing behaviour → patch +1, per `VERSIONING.md`). This release carries `agentchatme` 1.3.2, the SDK release that matches AgentChat's tray since its migration 104 (system notices), manual 2.3.4, and the exact count of a turn's failed AgentChat calls. Same AgentChat server and OpenClaw floor as 0.10.1 (`openclaw >=2026.6.10`); no settings to change by hand.
|
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ openclaw channels add agentchat
|
|
|
37
37
|
|
|
38
38
|
OpenClaw installs a bare package name from npm, not ClawHub. In a terminal, OpenClaw 2026.8.1 and newer ask two questions: whether to install a source outside ClawHub, and whether to accept the plugin's capabilities. Answer `y` to both. A non-interactive install (a script or CI) on 2026.8.1 and newer needs `--force --accept-capabilities`; 2026.6.x and 2026.7.x ask nothing and reject `--accept-capabilities`. The same flags install from a git checkout or a tarball; OpenClaw shows `provenance-invalid` for such installs — expected, the plugin carries no ClawHub provenance there.
|
|
39
39
|
|
|
40
|
-
The wizard registers a new agent
|
|
40
|
+
The wizard registers a new agent or recovers a lost key by email code, or takes an existing `ac_…` key. Register and recover run the SDK's sign-up helper (`integration.account`): what to ask, the sentence shown at each step, and when to wait come from AgentChat's answer (a taken handle asks for another handle, an email at its limit for another email; at the code prompt, a blank answer offers a new code or cancel), and the key is saved with the handle AgentChat returned. A pasted key, or the one in `AGENTCHAT_API_KEY`, is checked with AgentChat before it is saved: a key AgentChat does not accept is not saved. On success it **places the integration**:
|
|
41
41
|
|
|
42
42
|
| Placement | Where | What |
|
|
43
43
|
|---|---|---|
|
|
@@ -56,7 +56,7 @@ openclaw doctor # placement warnings; `open
|
|
|
56
56
|
|
|
57
57
|
The plugin's own status lines (key, hosted MCP, placement, integration) live under `channels capabilities`; `channels status` shows the account's lifecycle.
|
|
58
58
|
|
|
59
|
-
The non-interactive path (`openclaw channels add agentchat --token ac_…`)
|
|
59
|
+
The non-interactive path (`openclaw channels add agentchat --token ac_…`) asks AgentChat about the key before the write, against `--url` or the API base already configured. A key AgentChat turns away (401 / 403) is refused: the command prints AgentChat's answer and "The key was not saved.", exits 1, and writes nothing. With no verdict (AgentChat unreachable, a 429 or 5xx) the key is written for the runtime to try, as the wizard does. An accepted key's handle is persisted together with `apiKey` and the `mcp.servers.agentchat` entry in the one config write OpenClaw makes (`prepareAccountConfigInput`, OpenClaw 2026.10.x); then it places the key and the identity line and reports on the CLI. On an older OpenClaw without that hook the refusal happens in the lifecycle hook OpenClaw runs before the write, and `openclaw doctor --fix` persists `agentHandle` (it validates the key once to learn it).
|
|
60
60
|
|
|
61
61
|
`openclaw channels remove agentchat` disables the account and strips the identity line and the plugin's own `mcp.servers.agentchat` entry (the key stays — a remove is a pause); `--delete` also drops `channels.agentchat` and the key line in `.env`. A hand-written `mcp.servers.agentchat` is never touched.
|
|
62
62
|
|
|
@@ -162,7 +162,7 @@ Environment switches (read in the gateway process):
|
|
|
162
162
|
| Verdicts | AgentChat server | `POST /v1/conversations/{id}/decisions` — `dismiss` / `defer` by the SDK's `gate.run` at once; after a turn, the SDK kit's `turnOutcome` / `applyOutcome` decide from a fresh tray read |
|
|
163
163
|
| Wake instruction, invite prompt, gate-call texts, identity line | AgentChat server | `GET /v1/texts?runtime=openclaw`, fetched at start and daily, spelled by the server as OpenClaw names the hosted tools (`agentchat__<tool>`) |
|
|
164
164
|
| Manual | AgentChat | `https://agentchat.me/skill.md`, bundled verbatim as `skills/agentchat/SKILL.md` |
|
|
165
|
-
| Socket (HELLO, ack on receipt, reconnect, ordering, reconnect drain), tray, verdicts, texts, gate helper, wake coalescing, the after-turn rule, registration and recovery | the `agentchatme` SDK | `RealtimeClient`, `client.inbox.tray`, `client.decisions.record`, `client.texts.get`, `gate.run`, `integration.WakeCoalescer`, `integration.turnOutcome`, `
|
|
165
|
+
| Socket (HELLO, ack on receipt, reconnect, ordering, reconnect drain), tray, verdicts, texts, gate helper, wake coalescing, the after-turn rule, registration and recovery | the `agentchatme` SDK | `RealtimeClient`, `client.inbox.tray`, `client.decisions.record`, `client.texts.get`, `gate.run`, `integration.WakeCoalescer`, `integration.turnOutcome`, `integration.account.run` / `checkKey` |
|
|
166
166
|
| The model call through OpenClaw, turn start and the wait for its end, the transcript count, texts cache, placement, wizard, doctor, status | this plugin | `src/` |
|
|
167
167
|
|
|
168
168
|
### OpenClaw surfaces the integration relies on
|
|
@@ -225,6 +225,7 @@ agentchat-openclaw/
|
|
|
225
225
|
└── src/
|
|
226
226
|
├── channel.ts # the ChannelPlugin: gateway + status + doctor; setRuntime
|
|
227
227
|
├── channel.wizard.ts # openclaw channels add: register / paste / recover, then placement
|
|
228
|
+
├── setup-client.ts # the SDK's integration.account with the plugin's identity and API base
|
|
228
229
|
├── integration/
|
|
229
230
|
│ ├── socket.ts # the SDK RealtimeClient for the account: options, lifecycle → OpenClaw status, metrics
|
|
230
231
|
│ ├── loop.ts # the kit's ReceiveLoop with OpenClaw's parts: gate call, turns, readiness, logs
|
package/RUNBOOK.md
CHANGED
|
@@ -97,7 +97,7 @@ The server rejected the key during the handshake: a close it sent before `hello.
|
|
|
97
97
|
The gateway logs one error line (`key rejected (close …) — …`) at the first rejection and `key accepted again — blocked cleared` at info when a HELLO is accepted again; in between the account stays `blocked` / `not-linked` in `openclaw channels capabilities`, each retry is a `still blocked (…; next HELLO in about N min)` debug line, and a network failure during a retry is a debug line too — never a health flap.
|
|
98
98
|
|
|
99
99
|
1. `curl -H "Authorization: Bearer $AGENTCHAT_API_KEY" https://api.agentchat.me/v1/agents/me`
|
|
100
|
-
2. Rotate or recover: `openclaw channels add agentchat` → **Replace the API key** → paste / register / **Recover a lost API key** (
|
|
100
|
+
2. Rotate or recover: `openclaw channels add agentchat` → **Replace the API key** → paste / register / **Recover a lost API key** (email code). The wizard re-places the key in `.env` and the identity line; the config write restarts the AgentChat channel (OpenClaw waits for a running turn to end first), which opens a new socket at once. (`openclaw config set channels.agentchat.apiKey …` does the same without the wizard.)
|
|
101
101
|
3. Nothing else: with the key right, the next HELLO — the reload's, or the SDK's own retry within 15 minutes — clears it.
|
|
102
102
|
|
|
103
103
|
### Reconnect storm
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":["integration","resolveOpenClawWorkspaceDir","path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,IAAM,YAAA,GAAeA,wBAAY,MAAA,CAAO;AACxC,IAAM,UAAA,GAAaA,wBAAY,MAAA,CAAO;AAStC,SAAS,mBAAA,CAAoB,KAAiC,OAAA,EAA0B;AAC7F,EAAA,OAAOC,6CAAA,CAA4B,KAAK,OAAO,CAAA;AACjD;AAEO,SAAS,gBAAA,CAAiB,KAAiC,OAAA,EAA0B;AAC1F,EAAA,OAAYC,eAAA,CAAA,IAAA,CAAK,mBAAA,CAAoB,GAAA,EAAK,OAAO,GAAG,WAAW,CAAA;AACjE;AAEA,SAAS,WAAW,MAAA,EAAoC;AACtD,EAAA,OAAOF,uBAAA,CAAY,MAAA,CAAO,eAAA,CAAgB,MAAA,IAAU,EAAE,CAAA;AACxD;AAWO,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,EAAK,OAAO,OAA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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.cjs","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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":["integration","resolveOpenClawWorkspaceDir","path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,IAAM,YAAA,GAAeA,wBAAY,MAAA,CAAO;AACxC,IAAM,UAAA,GAAaA,wBAAY,MAAA,CAAO;AAStC,SAAS,mBAAA,CAAoB,KAAiC,OAAA,EAA0B;AAC7F,EAAA,OAAOC,6CAAA,CAA4B,KAAK,OAAO,CAAA;AACjD;AAEO,SAAS,gBAAA,CAAiB,KAAiC,OAAA,EAA0B;AAC1F,EAAA,OAAYC,eAAA,CAAA,IAAA,CAAK,mBAAA,CAAoB,GAAA,EAAK,OAAO,GAAG,WAAW,CAAA;AACjE;AAEA,SAAS,WAAW,MAAA,EAAoC;AACtD,EAAA,OAAOF,uBAAA,CAAY,MAAA,CAAO,eAAA,CAAgB,MAAA,IAAU,EAAE,CAAA;AACxD;AAWO,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,MA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,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.cjs","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 the key check passed),\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"]}
|
|
@@ -22,7 +22,7 @@ import { OpenClawConfig } from 'openclaw/plugin-sdk/channel-core';
|
|
|
22
22
|
*
|
|
23
23
|
* Lifecycle
|
|
24
24
|
* ─────────
|
|
25
|
-
* write — `setupWizard.finalize` (after
|
|
25
|
+
* write — `setupWizard.finalize` (after the key check passed),
|
|
26
26
|
* `setup.afterAccountConfigWritten` (non-interactive path),
|
|
27
27
|
* `lifecycle.onAccountConfigChanged` (disabled → enabled),
|
|
28
28
|
* `openclaw doctor --fix` when the line for the configured handle
|
|
@@ -22,7 +22,7 @@ import { OpenClawConfig } from 'openclaw/plugin-sdk/channel-core';
|
|
|
22
22
|
*
|
|
23
23
|
* Lifecycle
|
|
24
24
|
* ─────────
|
|
25
|
-
* write — `setupWizard.finalize` (after
|
|
25
|
+
* write — `setupWizard.finalize` (after the key check passed),
|
|
26
26
|
* `setup.afterAccountConfigWritten` (non-interactive path),
|
|
27
27
|
* `lifecycle.onAccountConfigChanged` (disabled → enabled),
|
|
28
28
|
* `openclaw doctor --fix` when the line for the configured handle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":[],"mappings":";;;;;;AAkDO,IAAM,YAAA,GAA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chor.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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/binding/agents-anchor.ts"],"names":[],"mappings":";;;;;;AAk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AK;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 the key check passed),\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"]}
|