AGENTS.md · diff

git:20261003.12a46c7 to git:20261004.49633a6

159 added, 150 removed. Audit A to A.

- # AGENTS.md - Your Workspace
+ # AGENTS.md
- This folder is home.
+ Instructions for every agent in this repository: the OpenClaw investment assistant
+ (Rick, see `IDENTITY.md`) and the coding agents (Claude Code, Codex, OpenCode).
+ `CLAUDE.md` only bridges here. Humans read `README.md` and `docs/README.md`.
- ## Every Session
+ ## Session start
- Use the workspace files already supplied in the current context. OpenClaw injects the
- bootstrap files according to the session profile; loading a file and reading it again
- are not separate requirements.
+ OpenClaw injects the bootstrap files for the session profile. Use what is already in
+ context; do not read an injected file again.
- - `SOUL.md` / `USER.md`: use the supplied identity and preferences; read missing files only when relevant.
- - Direct chat: use injected `MEMORY.md` and `TOOLS.md`; read a missing one when its rules or routes are needed.
- Keep main-session memory out of group/shared contexts.
- - Investment questions: read `INVESTMENT_SOP.md` and the selected skill, then load relevant data.
- - Ordinary chat and explicit task delegation: answer or forward the request with known context.
- Investigate only missing routing facts; let the delegated worker inspect code, issues and CI.
- Requests to investigate or optimize together stay in the current conversation unless delegation is requested.
- - A user instruction naming Claude Code (Claude/claudecode), Codex, or OpenCode as the actor
- ("让 claudecode 看看…", "have Codex fix…") is explicit delegation, even for a small task
- and without words such as "委派" or "后台跑". The named worker is distinct from the main
- session even when both use the same model family. Use `agent-dispatch` and return after
- successful dispatch. Explicit "你直接做 / 当前会话做 / 不要委派" ("do it here / current
- session / no delegation") instructions override this routing. Already-dispatched workers
- (`AGENT_DISPATCH_TASK_ID` or the unattended 【派发约定】) finish their task themselves;
- they do not dispatch it again.
- - Isolated cron/subagent runs: follow their explicit context profile and job instructions, not the direct-chat startup path.
+ - Direct chat: `SOUL.md`, `IDENTITY.md`, `USER.md`, `TOOLS.md`, `HEARTBEAT.md` and
+ `MEMORY.md` are injected. Keep `MEMORY.md` out of group and shared contexts.
+ - Isolated cron and subagent runs: follow the job payload and its skill. `MEMORY.md` is
+ not injected there, so a rule a scheduled run must obey belongs in the payload, the
+ skill mode or a postflight gate.
+ - Investment question: follow `INVESTMENT_SOP.md` and the skill `TOOLS.md` routes to.
+ - Ordinary chat: answer with known context. Load holdings, cron or repository state only
+ when the question needs it.
+ - Coding work: no persona, SOP or holdings reads. Start at § Code changes.
- ## kcn 偏好
+ ### Delegation
- 详见 `USER.md` § 沟通偏好 + § 不要做的事。要点:表格、不 hedging、数据缺口必说、terse 风格、14:00 HKT 也盘中查。
+ - A request naming Claude Code (Claude/claudecode), Codex or OpenCode as the actor
+ ("让 claudecode 看看…", "have Codex fix…") is explicit delegation, even for a small task
+ and without words such as "委派" or "后台跑". Use the `agent-dispatch` skill and return
+ once the dispatch succeeded. The named worker is distinct from the main session even
+ when both use the same model family.
+ - Forward the request with known context. Look up only missing routing facts; the worker
+ inspects code, issues and CI.
+ - "你直接做 / 当前会话做 / 不要委派" ("do it here / no delegation") overrides this routing.
+ A request to investigate or optimize together stays in the current conversation.
+ - A dispatched worker (`AGENT_DISPATCH_TASK_ID` set, or a 【派发约定】 block in its prompt)
+ finishes its own task and does not dispatch it again.
- ## Git hook (one-time setup per clone)
+ ## Commands
+ Runtime commands are the installed `clawock` entry points; source is `src/clawock/`.
+ Host, publishing, CI and growth wiring lives under `ops/`. Parameters:
+ `docs/reference/commands.md`. Skill routing: `TOOLS.md` § Skill 路由表.
+
```bash
- git config core.hooksPath .githooks
- ```
+ # market data and book
+ clawock analyze-us [TICKER] # live US quotes + signals; run before any P&L statement
+ clawock analyze-hk [TICKER] # live HK quotes + signals
+ clawock fx --json # USD/HKD rate with source and timestamp
+ clawock reconcile # after editing holdings[].trades[] or shares
+ clawock mark-followed DECISION_ID [--no]
- `.githooks/pre-commit` enforces on every commit (openclaw cron / GH Action / manual):
- - portfolio.json valid JSON + required structure
- - memory/*-plan.json schema (bucket enum, trigger_type enum, confidence ∈ [0,1])
- - the dashboard write set rebuilds when portfolio.json is staged, but is no longer
- staged with it: since #319 the dashboard payloads live on the `data-plane` branch and
- `git add` on a now-ignored path fails the commit rather than skipping
- - paranoid scan for leaked API keys (`sk-…`, `tp-…`, `FINNHUB_API_KEY=`, etc.)
+ # scheduled jobs (the cron payload names which one)
+ clawock {brief|report|intraday} preflight [args]
+ clawock {brief|report|intraday} postflight [args]
- Override with `--no-verify` if false positive (rare).
+ # development, from a task worktree
+ git config core.hooksPath .githooks # once per clone
+ pip install -e '.[test]' # isolated environment only
+ env -u CLAWOCK_WORKSPACE PYTHONPATH="$PWD/src" python3 -m pytest tests/<file>.py -q
+ ruff check . # CI pins the version in ci.yml (job `lint`)
+ python3 ops/ci/generate_tool_reference.py --check # docs/reference/commands.md drift
+ python3 ops/host/generate_cron_docs.py --check # docs/operations/cron-schedules.md drift
+ python3 ops/system_check.py # live workspace audit
+ ops/host/refresh_live.sh # apply a merged PR to this host
+ ```
- ## Git Auto-Commit Rules
+ CI runs the full suite on every PR; run only the tests your change touches locally.
- The workspace is a local git repo. **`origin` is the public repo `github.com/KCNyu/clawock`** — the
- published investment contents (positions, plans, daily briefs and the curated
- OpenClaw memory) are intentionally public per kcn's instruction. This does not
- authorize publishing private chat/session metadata, credentials or coding-agent memory.
- This table governs the live runtime workspace and its scheduled writers. Interactive
- Codex/Claude code changes follow the PR workflow in the next section.
- After any of the following changes, run a git commit automatically — no need to ask:
+ ## Where things live
- | Change | Commit |
+ | Path | What it is |
|---|---|
- | `portfolio.json` updated (price refresh / buy / sell) | `portfolio: <brief>` |
- | Harness produced new `memory/{date}-pre-open.md` + `-plan.json` | `memory: daily deep brief <date>` (postflight auto-commits) |
- | KCNyu harness/publisher refreshed dashboard outputs | publish the complete semantic generation through the data plane; do not stage individual generated files ad hoc |
- | `assets/data/risk.json` refreshed via `clawock portfolio-risk` | bundled with brief commit |
- | `memory/decisions.jsonl` execution status marked via `clawock mark-followed` | `decisions: mark execution` |
- | Package, profile or `ops/` code changed | `refactor:`/`fix:`/`feat: <what changed>` (via PR, never direct) |
- | Workspace docs changed (SOUL/AGENTS/TOOLS/USER/CLAUDE/README) | `docs: <what changed>` |
-
- Message style: `<type>: <concise description>`, Chinese is fine. Commit message
- bodies use real newlines (multi-line `-m` / heredoc), never a literal `\n`
- (#615: two past commits shipped the two characters `\n` and rendered as one
- blob).
- **Never commit:** `.api_keys`, scratch `*.png`/`*.jpg` outside the shipped `site/assets/`/`docs/` allowlists, `.openclaw/`, `.clawhub/`, `memory/.dreams/`, `memory/.tmp/` (gitignored). Shipped `site/assets/*.png` are committed; `screenshot-refresh.yml` generates `site/assets/social-card.png` directly from the light editorial HTML/CSS composition plus a fresh dashboard capture, refreshes `site/assets/shadow-backtest.png`, and updates `site/assets/dashboard.gif` only on manual dispatch.
-
- Push: harness postflight now **auto-pushes** after commit (rebase+retry on race).
- Interactive Codex/Claude work must never push `master`; it may push only its task
- branch to create or update a PR.
+ | `src/clawock/` | the portable package: CLI, workflows, market data, harness, publishing |
+ | `config/`, `config/profiles/` | declarative desk configuration; `config/cron-schedules.json` is the cron contract |
+ | `skills/<name>/SKILL.md` | skill bodies; a cron job runs the mode its payload names |
+ | `ops/{host,publish,ci,pages,growth}/` | host, publishing, CI and Pages wiring; not in the wheel |
+ | `site/` | website source; `site/index.html` is the dashboard |
+ | `portfolio.json` | authoritative holdings, written by the price-refresh commands |
+ | `memory/{date}-pre-open.md`, `memory/{date}-plan.json` | the daily brief and its plan |
+ | `memory/snapshots/`, `memory/bars/`, `memory/decisions.jsonl` | daily snapshots, bars, the decision ledger |
+ | `memory/.tmp/` | preflight context; ignored |
+ | `assets/data/` | generated dashboard inputs and history |
+ | `docs/` | project documentation; index in `docs/README.md` |
- ## Interactive Codex/Claude PR workflow
+ ## Boundaries
- This section governs how the executing agent delivers changes; it does not decide
- whether the OpenClaw main session should handle a user request inline. Apply the
- delegation rules above before starting this workflow.
+ ### Always
- The live checkout `/root/.openclaw/workspace` must stay on `master` because cron and
- OpenClaw write runtime data there throughout the day. Never switch that checkout to a
- feature branch and never make interactive code edits in it.
+ - Fetch live prices with `clawock analyze-us` / `clawock analyze-hk` before stating a
+ price, P&L or position value. Say which source failed when one did.
+ - Report book totals in both USD and HKD with the FX rate, its source and timestamp.
+ - Commit runtime changes as § Runtime commits lists, without asking.
+ - Deliver code, skill, workflow, configuration and documentation changes through
+ § Code changes.
+ - Read, organise and edit inside the workspace freely.
- For changes to code, scripts, workflows, skills, UI, configuration, or repository
- documentation:
+ ### Ask first
- 1. Create an isolated worktree from current `origin/master`, using a branch named
- `codex/<task>` or `claude/<task>`.
- 2. Make and commit the change in that worktree, then push the task branch and open a PR.
- 3. Let GitHub Actions run the full test suite. Local full-suite runs are optional; the
- required remote checks are the merge gate.
- 4. The author reviews its own diff, checks and merge state, and squash-merges once
- the required checks pass (kcn, 2026-08-19). A cross-agent review happens only when
- kcn asks for one in that task.
- 5. **Never post a review as a PR comment.** Both agents authenticate as the GitHub
- user `KCNyu`, so a posted review reads as kcn talking to themself — findings go in
- the interactive handoff instead. Do not add a signature, an `AI-REVIEW` prefix, or
- any other marker to work around this; it is an identity problem, not a labelling one.
- 6. Finishing alone is never permission to skip a required check.
- 7. Do not merge while any required check is pending or failing. Fix the branch, push,
- and let the PR rerun its checks.
- 8. Squash-merge only after required checks pass, then remove the task worktree/branch.
- 9. Apply the merge to this host with `ops/host/refresh_live.sh` — **merging is what
- makes a fix live here; a release is for people who are not this host.** 本机不用为
- 每个修复发版。The install is editable, so a fast-forward is usually the whole job;
- the script re-runs the launcher installer only when `pyproject.toml` moved, the
- DSH plugin installer only when `examples/dsh/packages/clawock-dsh/` moved and the
- agent-dispatch runner installer only when the installed runner differs from the checkout, then
- verifies what is actually serving. Rule and evidence:
- `docs/operations/release.md` § Running the latest code on this host.
+ - Anything that leaves the machine in kcn's name: email, public posts, messages to
+ anyone other than kcn.
+ - `git push` from a chat-triggered session. Harness postflights push on their own.
+ - Destructive commands: `rm -r`, `git reset --hard`, `git clean`, force-push.
+ - Editing `~/.openclaw/openclaw.json`. Back it up first:
+ `cp -p ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak.$(date +%Y%m%d-%H%M)`.
+ - Installing a skill: `docs/operations/skills-store-policy.md`.
- Public GitHub issues, PRs and comments must not link third-party repositories, issues, PRs or
- commits, use owner/repo#N or owner/repo@revision references, or mention third-party users.
- Describe the idea in your own words and name the project as plain text. Keep external source
- links in repository documentation instead; avoid cross-reference backlinks and notifications.
+ ### Never
- ### Closing issues
+ - Compute P&L from `portfolio.json` `current_price`. It is a cache.
+ - Add HKD and USD amounts without converting.
+ - Invent a quote, a level or a "new high" claim. Without a verified number, say the data
+ is missing.
+ - Push `master` or use the repository-admin bypass for an interactive change.
+ - Switch `/root/.openclaw/workspace` off `master`, or edit code in it. Cron and OpenClaw
+ write runtime data there all day.
+ - Post a review as a PR comment. Every agent authenticates as the GitHub user `KCNyu`, so
+ it reads as kcn reviewing their own work. Do not work around it with a signature or an
+ `AI-REVIEW` prefix. Findings go in the handoff.
+ - Merge while a required check is pending or failing.
+ - Commit `.api_keys`, credentials, `.openclaw/`, `.clawhub/`, `memory/.tmp/`,
+ `memory/.dreams/`, or scratch `*.png`/`*.jpg` outside `site/assets/` and `docs/`.
+ - Commit coding-agent notes under `memory/*.md`. Their store is outside this repository;
+ `.gitignore` and `.githooks/pre-commit` refuse that class.
+ - Never write dated diaries (`memory/YYYY-MM-DD.md`). `MEMORY.md` is the only prose memory.
+ - `git add` a dashboard payload on `master`. They are published on the `data-plane` branch
+ and the path is ignored, so the commit fails.
+ - Edit the cron store (SQLite or the old `jobs.json`) by hand. Use `openclaw cron edit`
+ or `ops/host/sync_us_cron_dst.py`, then regenerate `docs/operations/cron-schedules.md`.
+ - Run an old root script or anything under `scripts/data/`, or rebuild one from old notes.
+ - Link third-party repositories, issues, PRs, commits or users in public GitHub issues,
+ PRs and comments. Name the project as plain text; keep source links in repository docs.
- Handle every open issue on its evidence; there is no issue-count ceiling. Close verified fixes
- as completed with the merged PR or reproducible verification. For patrol findings that are
- false, duplicates, out of scope, or deliberately not worth fixing, record the verified reason
- and close as not planned (or apply `patrol:noise`). These closure signals feed patrol's quality
- feedback; do not mark an unimplemented finding completed merely to clear the queue. For a
- partially resolved digest, record each item's result and keep the unresolved items open.
+ ## Runtime commits
- Runtime-generated market data, snapshots, reports, ledgers, and dashboard artifacts
- remain on the existing direct-to-`master` bot path. They do not open high-frequency PRs.
- Never use the repository-admin bypass for an interactive code change.
+ `origin` is the public repository `github.com/KCNyu/clawock`. Positions, plans, briefs
+ and `MEMORY.md` are public on purpose; chat or session metadata, credentials and
+ coding-agent memory are not. This table covers the live workspace and its scheduled
+ writers.
- ## Memory
+ | Change | Commit |
+ |---|---|
+ | `portfolio.json` updated (price refresh / buy / sell) | `portfolio: <brief>` |
+ | New `memory/{date}-pre-open.md` + `-plan.json` | `memory: daily deep brief <date>` (postflight commits it) |
+ | Dashboard outputs refreshed | published as one generation through the data plane; never staged file by file |
+ | `assets/data/risk.json` refreshed by `clawock portfolio-risk` | bundled with the brief commit |
+ | `memory/decisions.jsonl` execution status set by `clawock mark-followed` | `decisions: mark execution` |
+ | `MEMORY.md` / `DREAMS.md` appended by dreaming | `ops/host/commit_dreaming.sh` commits them at 03:20 HKT |
- You wake up fresh each session. `MEMORY.md` is your continuity, and it **is** in
- the repository (#1074) — it is yours: openclaw's dreaming job appends to it at
- 03:00 HKT and `ops/host/commit_dreaming.sh` commits it at 03:20. Direct chat has it
- injected; isolated cron runs neither inject nor read it (their profile excludes it),
- so a rule a scheduled run must obey belongs in its payload, SKILL mode or postflight
- gate, not only here. Keep it self-contained; write the conclusion into the index
- rather than into a side file.
+ Message style: `<type>: <concise description>`; Chinese is fine. Write the body with real
+ newlines (multi-line `-m` or a heredoc), never a literal `\n`.
- What must NOT enter the repository is coding-agent prose under `memory/*.md` — written by the
- interactive coding agents (Claude Code / Codex) in their own memory format, their
- durable store is `/root/.shared-memory`, and a copy here is a leak. `.gitignore`
- and `.githooks/pre-commit` both refuse that class; `ops/system_check.py` reports
- any that pile up on the host so somebody can clean them. The existing
- `memory/*-pre-open.md` exception is the published investment brief, not a coding-agent
- diary; its plan JSON is also runtime data. Do not create new prose exceptions.
- - **Long-term:** `MEMORY.md` — curated wisdom; **only load in main session**, do NOT load in shared contexts (Discord, group chats)
- - Don't keep "mental notes" — if it matters, write it to `MEMORY.md` (or, for the
- interactive coding agents, their own durable memory outside this repository).
- - Dated diaries (`memory/YYYY-MM-DD.md`) were retired in #1038: untracked first,
- then removed from disk. They were raw session logs nothing read back — the
- curated surfaces (`MEMORY.md`, the interactive agents' own memory) carry what
- actually gets reused. Do not start writing them again.
+ `.githooks/pre-commit` checks every commit: `portfolio.json` structure, the
+ `memory/*-plan.json` schema, and a scan for API keys. Use `--no-verify` only for a
+ confirmed false positive.
- ## Safety
+ Harness postflights push after committing, with rebase and retry. Runtime data stays on
+ this direct-to-`master` bot path and never opens PRs.
- - Don't exfiltrate private data
- - Don't run destructive commands without asking
- - `trash` > `rm`
- - External actions (emails, public posts) → ask first
- - Internal actions (read, organize, edit workspace) → freely
+ ## Code changes
- ## Tools & Skills
+ For code, scripts, workflows, skills, UI, configuration and repository documentation:
- Skills live under `skills/<name>/SKILL.md`. **Full routing + edge-cases → `TOOLS.md` § Skill 路由表.**
+ 1. Create a worktree from current `origin/master` on a branch named `codex/<task>` or
+ `claude/<task>`.
+ 2. Commit there, push the branch, open a PR. Commit types: `fix:`, `feat:`, `refactor:`,
+ `docs:`.
+ 3. Review your own diff, checks and merge state. A cross-agent review happens only when
+ kcn asks for one in that task.
+ 4. Squash-merge once the required checks pass, then remove the worktree and branch.
+ 5. Run `ops/host/refresh_live.sh`. Merging plus this script is what makes a fix live on
+ this host; no release is needed. Details: `docs/operations/release.md` § Running the
+ latest code on this host.
- Runtime commands come from the installed distributions: portable workflows and
- tools, harness, watchdogs and automation all use the installed `clawock` distribution
- entry points. Host, publishing, CI and growth wiring lives under `ops/`. Never
- recover an old command by executing a root script or a file under `scripts/data/`.
+ A document under `docs/` describes how the project works now. Measurements, before/after
+ captures, command output and proposed patches from one task go in its PR description.
- Default to action: pick the skill, run the script, return the answer — don't ask permission unless going destructive.
+ ### Closing issues
- ## Heartbeats
+ Handle every open issue on its evidence; there is no issue-count ceiling.
- If you receive a heartbeat poll, openclaw auto-injects:
- > Read HEARTBEAT.md if it exists. Follow it strictly. If nothing needs attention, reply `HEARTBEAT_OK`.
+ - Verified fix: close as completed, citing the merged PR or a reproducible check.
+ - Patrol finding that is false, a duplicate, out of scope or not worth fixing: record the
+ verified reason and close as not planned, or apply `patrol:noise`. These closures feed
+ patrol's quality signal.
+ - Never mark an unimplemented finding completed to clear the queue.
+ - Partly resolved digest: record each item's result and keep the unresolved items open.
- So just follow `HEARTBEAT.md`. Don't repeat old tasks. Reply `HEARTBEAT_OK` when idle.
+ ## Memory
- In group chats: be smart about when to contribute. Reply only when adding genuine value. Otherwise stay silent. Don't be the bot that responds to everything.
+ - `MEMORY.md` is the OpenClaw assistant's long-term memory and is tracked. If something
+ must survive the session, write the conclusion there, self-contained.
+ - The dreaming job appends to `MEMORY.md` and `DREAMS.md` at 03:00 HKT. Leave the
+ `openclaw:dreaming` and `openclaw-memory-promotion` markers intact.
+ - `memory/*-pre-open.md` and `memory/weekly/` are published briefs, and the plan JSON is
+ runtime data. Do not add other prose under `memory/`.
- ## Make It Yours
+ ## Heartbeats and group chats
- Add your own conventions as you learn what works. Keep this file short.
+ - On a heartbeat poll, follow `HEARTBEAT.md`. Reply `HEARTBEAT_OK` when it lists no task.
+ - In a group chat, reply only when it adds something. Otherwise stay silent.