|
| 1 | +--- |
| 2 | +summary: "CLI reference for `openclaw path` (inspect and edit workspace files via the `oc://` addressing scheme)" |
| 3 | +read_when: |
| 4 | + - You want to read or write a leaf inside a workspace file from the terminal |
| 5 | + - You're scripting against workspace state and want a stable, kind-agnostic addressing scheme |
| 6 | + - You're debugging a `oc://` path (validate the syntax, see what it resolves to) |
| 7 | +title: "Path" |
| 8 | +--- |
| 9 | + |
| 10 | +# `openclaw path` |
| 11 | + |
| 12 | +Shell-level access to the `oc://` addressing substrate — one universal, |
| 13 | +kind-dispatched path scheme for inspecting and surgically editing workspace |
| 14 | +files (markdown, jsonc, jsonl, yaml). Self-hosters and editor extensions use |
| 15 | +it to read or write a single leaf inside a workspace file without scripting |
| 16 | +against the SDK directly. |
| 17 | + |
| 18 | +## Subcommands |
| 19 | + |
| 20 | +| Subcommand | Purpose | |
| 21 | +| ----------------------- | ---------------------------------------------------------------------------- | |
| 22 | +| `resolve <oc-path>` | Print the match at the path (or "not found"). | |
| 23 | +| `find <pattern>` | Enumerate matches for a wildcard / predicate path. | |
| 24 | +| `set <oc-path> <value>` | Write a leaf at the path. Supports `--dry-run`. | |
| 25 | +| `validate <oc-path>` | Parse-only — print structural breakdown (file / section / item / field). | |
| 26 | +| `emit <file>` | Round-trip a file through `parseXxx` + `emitXxx` (byte-fidelity diagnostic). | |
| 27 | + |
| 28 | +## Global flags |
| 29 | + |
| 30 | +| Flag | Purpose | |
| 31 | +| --------------- | ------------------------------------------------------------------------ | |
| 32 | +| `--cwd <dir>` | Resolve the file slot against this directory (default: `process.cwd()`). | |
| 33 | +| `--file <path>` | Override the file slot's resolved path (absolute access). | |
| 34 | +| `--json` | Force JSON output (default when stdout is not a TTY). | |
| 35 | +| `--human` | Force human output (default when stdout is a TTY). | |
| 36 | +| `--dry-run` | (only on `set`) print the bytes that would be written without writing. | |
| 37 | + |
| 38 | +## `oc://` syntax |
| 39 | + |
| 40 | +``` |
| 41 | +oc://FILE/SECTION/ITEM/FIELD?session=SCOPE |
| 42 | +``` |
| 43 | + |
| 44 | +Slot rules — `field` requires `item`, `item` requires `section`. Across all |
| 45 | +four slots: |
| 46 | + |
| 47 | +- **Quoted segments** — `"a/b.c"` survives `/` and `.` separators. |
| 48 | + `"\\"` and `"\""` are the only escapes inside quotes. |
| 49 | + The file slot is also quote-aware: `oc://"skills/email-drafter"/Tools/-1` |
| 50 | + treats `skills/email-drafter` as a single file path. |
| 51 | +- **Predicates** — `[k=v]`, `[k!=v]`, `[k*=v]`, `[k^=v]`, `[k$=v]`, |
| 52 | + `[k<v]`, `[k<=v]`, `[k>v]`, `[k>=v]`. |
| 53 | +- **Unions** — `{a,b,c}` matches any of the alternatives. |
| 54 | +- **Wildcards** — `*` (single sub-segment) and `**` (zero-or-more, |
| 55 | + recursive). `find` accepts these; `resolve` and `set` reject them as |
| 56 | + ambiguous. |
| 57 | +- **Positional** — `$first`, `$last`, `-N` (Nth from end). |
| 58 | +- **Ordinal** — `#N` for Nth match. |
| 59 | +- **Insertion markers** — `+`, `+key`, `+nnn` for keyed / indexed |
| 60 | + insertion (use with `set`). |
| 61 | +- **Session scope** — `?session=cron:daily` etc. Orthogonal to slot |
| 62 | + nesting. |
| 63 | + |
| 64 | +Reserved characters (`?`, `&`, `%`) outside quoted, predicate, or union |
| 65 | +segments are rejected. Control characters (U+0000–U+001F, U+007F) are |
| 66 | +rejected anywhere. |
| 67 | + |
| 68 | +## Examples |
| 69 | + |
| 70 | +```bash |
| 71 | +# Validate a path (no filesystem access) |
| 72 | +openclaw path validate 'oc://AGENTS.md/Tools/-1/risk' |
| 73 | + |
| 74 | +# Read a leaf |
| 75 | +openclaw path resolve 'oc://gateway.jsonc/version' |
| 76 | + |
| 77 | +# Wildcard search |
| 78 | +openclaw path find 'oc://session.jsonl/*/event' --file ./logs/session.jsonl |
| 79 | + |
| 80 | +# Dry-run a write |
| 81 | +openclaw path set 'oc://gateway.jsonc/version' '2.0' --dry-run |
| 82 | + |
| 83 | +# Apply the write |
| 84 | +openclaw path set 'oc://gateway.jsonc/version' '2.0' |
| 85 | + |
| 86 | +# Byte-fidelity round-trip (diagnostic) |
| 87 | +openclaw path emit ./AGENTS.md |
| 88 | +``` |
| 89 | + |
| 90 | +## Exit codes |
| 91 | + |
| 92 | +| Code | Meaning | |
| 93 | +| ---- | -------------------------------------------------------------------------- | |
| 94 | +| `0` | Success. (`resolve` / `find`: at least one match. `set`: write succeeded.) | |
| 95 | +| `1` | No match, or `set` rejected by the substrate (no system-level error). | |
| 96 | +| `2` | Argument or parse error. | |
| 97 | + |
| 98 | +## Output mode |
| 99 | + |
| 100 | +`openclaw path` is TTY-aware: human-readable output on a terminal, JSON when |
| 101 | +stdout is piped or redirected. `--json` and `--human` override the |
| 102 | +auto-detection. |
| 103 | + |
| 104 | +## Notes |
| 105 | + |
| 106 | +- `set` writes raw bytes through the substrate's emit path, which applies the |
| 107 | + redaction-sentinel guard automatically. A leaf carrying |
| 108 | + `__OPENCLAW_REDACTED__` (verbatim or as a substring) is refused at write |
| 109 | + time. |
| 110 | +- `set` on a JSONC file currently re-renders the file (drops comments and |
| 111 | + trailing-comma formatting) when it mutates a leaf. Read-path round-trip is |
| 112 | + byte-identical. A byte-splice editor that preserves comments through |
| 113 | + writes is planned as a follow-up. |
| 114 | +- `path` does not know about LKG. If the file is LKG-tracked, the next |
| 115 | + observe call decides whether to promote / recover. `set --batch` for |
| 116 | + atomic multi-set through the LKG promote/recover lifecycle is planned |
| 117 | + alongside the LKG-recovery substrate. |
| 118 | + |
| 119 | +## Related |
| 120 | + |
| 121 | +- [CLI reference](/cli) |
0 commit comments