Skip to content

Commit bc735f4

Browse files
feat(workspace): oc-path addressing substrate + openclaw path CLI (md/jsonc/jsonl/yaml) (#78678)
Implements #78051 — oc:// addressing substrate for workspace files. New src/oc-path/ substrate (parser/formatter, per-kind parse+emit for md/jsonc/jsonl/yaml, universal resolveOcPath/setOcPath/findOcPaths verbs, sentinel emit guard) + openclaw path resolve|find|set|validate|emit CLI + docs/cli/path.md reference page + CHANGELOG entry. Co-authored-by: giodl73-repo <[email protected]> Co-authored-by: galiniliev <[email protected]>
1 parent 11d0c5e commit bc735f4

86 files changed

Lines changed: 14273 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ docs/internal/
9595
tmp/
9696
IDENTITY.md
9797
USER.md
98+
# Exception: oc-path real-world test fixtures need to be tracked even
99+
# though the bare names match the local-untracked rule above.
100+
!src/oc-path/tests/fixtures/real/IDENTITY.md
101+
!src/oc-path/tests/fixtures/real/USER.md
98102
*.tgz
99103
*.tar.gz
100104
*.zip

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Docs: https://docs.openclaw.ai
1111
- Control UI/usage: add transcript-backed historical lineage rollups for rotated logical sessions, with current-instance vs historical-lineage scope controls and long-range presets so usage history stays visible after restarts and updates. Fixes #50701. Thanks @dev-gideon-llc and @BunsDev.
1212
- Agents/failover: harden state-aware lane suspension by persisting quota resume transitions, restoring configured lane concurrency, preserving non-quota failure reasons, and exporting model failover events through diagnostics OTLP. Thanks @BunsDev.
1313
- Channels/streaming: make progress draft labels scroll away with other progress lines, render structured tool rows as compact emoji/title/details, show web-search queries from provider-native argument shapes, and skip empty Discord apply-patch starts until a patch summary exists. (#79146)
14+
- Workspace/oc-path: add the `oc://` addressing substrate (`src/oc-path/`) — a universal, kind-dispatched path scheme for addressing leaves and nodes inside markdown, jsonc, jsonl, and yaml workspace files, with `parseOcPath`/`formatOcPath`, per-kind `parseXxx`/`emitXxx`, universal `resolveOcPath`/`setOcPath`/`findOcPaths` verbs, the `__OPENCLAW_REDACTED__` sentinel emit guard, and the new `openclaw path resolve|find|set|validate|emit` CLI for shell-level inspection and surgical edits. Implements #78051. (#78678) Thanks @giodl73-repo.
1415
- Telegram: preserve the channel-specific 10-option poll cap in the unified outbound adapter so over-limit polls are rejected before send. (#78762) Thanks @obviyus.
1516
- Slack: route handled top-level channel turns in implicit-conversation channels to thread-scoped sessions when Slack reply threading is enabled, keeping the root turn and later thread replies on one OpenClaw session. (#78522) Thanks @zeroth-blip.
1617
- Telegram: re-probe the primary fetch transport after repeated sticky fallback success so transient IPv4 or pinned-IP fallback promotion can recover without a gateway restart. Fixes #77088. (#77157) Thanks @MkDev11.

‎docs/cli/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ apply across the CLI.
2424
| Network and nodes | [`directory`](/cli/directory) · [`nodes`](/cli/nodes) · [`devices`](/cli/devices) · [`node`](/cli/node) |
2525
| Runtime and sandbox | [`approvals`](/cli/approvals) · `exec-policy` (see [`approvals`](/cli/approvals)) · [`sandbox`](/cli/sandbox) · [`tui`](/cli/tui) · `chat`/`terminal` (aliases for [`tui --local`](/cli/tui)) · [`browser`](/cli/browser) |
2626
| Automation | [`cron`](/cli/cron) · [`tasks`](/cli/tasks) · [`hooks`](/cli/hooks) · [`webhooks`](/cli/webhooks) |
27-
| Discovery and docs | [`dns`](/cli/dns) · [`docs`](/cli/docs) |
27+
| Discovery and docs | [`dns`](/cli/dns) · [`docs`](/cli/docs) · [`path`](/cli/path) |
2828
| Pairing and channels | [`pairing`](/cli/pairing) · [`qr`](/cli/qr) · [`channels`](/cli/channels) |
2929
| Security and plugins | [`security`](/cli/security) · [`secrets`](/cli/secrets) · [`skills`](/cli/skills) · [`plugins`](/cli/plugins) · [`proxy`](/cli/proxy) |
3030
| Legacy aliases | [`daemon`](/cli/daemon) (gateway service) · [`clawbot`](/cli/clawbot) (namespace) |

‎docs/cli/path.md‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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)

‎src/cli/path-cli.ts‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import type { Command } from "commander";
2+
import {
3+
pathEmitCommand,
4+
pathFindCommand,
5+
pathResolveCommand,
6+
pathSetCommand,
7+
pathValidateCommand,
8+
type PathCommandOptions,
9+
} from "../commands/path.js";
10+
import { defaultRuntime } from "../runtime.js";
11+
import { formatDocsLink } from "../terminal/links.js";
12+
import { theme } from "../terminal/theme.js";
13+
import { runCommandWithRuntime } from "./cli-utils.js";
14+
import { applyParentDefaultHelpAction } from "./program/parent-default-help.js";
15+
16+
interface RawPathOptions {
17+
json?: boolean;
18+
human?: boolean;
19+
cwd?: string;
20+
file?: string;
21+
dryRun?: boolean;
22+
}
23+
24+
function normalize(opts: RawPathOptions): PathCommandOptions {
25+
return {
26+
json: opts.json,
27+
human: opts.human,
28+
cwd: opts.cwd,
29+
file: opts.file,
30+
dryRun: opts.dryRun,
31+
};
32+
}
33+
34+
export function registerPathCli(program: Command) {
35+
const path = program
36+
.command("path")
37+
.description("Inspect and edit workspace files via the oc:// addressing scheme")
38+
.addHelpText(
39+
"after",
40+
() =>
41+
`\n${theme.muted("Docs:")} ${formatDocsLink("/cli/path", "docs.openclaw.ai/cli/path")}\n`,
42+
);
43+
44+
path
45+
.command("resolve")
46+
.description("Print the match at an oc:// path")
47+
.argument("<oc-path>", "oc:// path to resolve")
48+
.option("--json", "Force JSON output")
49+
.option("--human", "Force human output")
50+
.option("--cwd <dir>", "Resolve file slot against this directory")
51+
.option("--file <file>", "Override the file slot's resolved path (absolute access)")
52+
.action(async (pathStr: string, opts: RawPathOptions) => {
53+
await runCommandWithRuntime(defaultRuntime, async () => {
54+
await pathResolveCommand(pathStr, normalize(opts), defaultRuntime);
55+
});
56+
});
57+
58+
path
59+
.command("find")
60+
.description("Enumerate matches for a wildcard / predicate oc:// pattern")
61+
.argument("<pattern>", "oc:// pattern (supports * and **)")
62+
.option("--json", "Force JSON output")
63+
.option("--human", "Force human output")
64+
.option("--cwd <dir>", "Resolve file slot against this directory")
65+
.option("--file <file>", "Override the file slot's resolved path (absolute access)")
66+
.action(async (patternStr: string, opts: RawPathOptions) => {
67+
await runCommandWithRuntime(defaultRuntime, async () => {
68+
await pathFindCommand(patternStr, normalize(opts), defaultRuntime);
69+
});
70+
});
71+
72+
path
73+
.command("set")
74+
.description("Write a leaf value at an oc:// path")
75+
.argument("<oc-path>", "oc:// path to write")
76+
.argument("<value>", "string value to write")
77+
.option("--dry-run", "Print bytes without writing")
78+
.option("--json", "Force JSON output")
79+
.option("--human", "Force human output")
80+
.option("--cwd <dir>", "Resolve file slot against this directory")
81+
.option("--file <file>", "Override the file slot's resolved path (absolute access)")
82+
.action(async (pathStr: string, value: string, opts: RawPathOptions) => {
83+
await runCommandWithRuntime(defaultRuntime, async () => {
84+
await pathSetCommand(pathStr, value, normalize(opts), defaultRuntime);
85+
});
86+
});
87+
88+
path
89+
.command("validate")
90+
.description("Parse an oc:// path and print its slot structure")
91+
.argument("<oc-path>", "oc:// path to validate")
92+
.option("--json", "Force JSON output")
93+
.option("--human", "Force human output")
94+
.action((pathStr: string, opts: RawPathOptions) => {
95+
pathValidateCommand(pathStr, normalize(opts), defaultRuntime);
96+
});
97+
98+
path
99+
.command("emit")
100+
.description("Round-trip a file through parseXxx + emitXxx (byte-fidelity diagnostic)")
101+
.argument("<file>", "Path to a workspace file (md / jsonc / jsonl / yaml)")
102+
.option("--cwd <dir>", "Resolve <file> against this directory (default: process.cwd())")
103+
.option("--file <file>", "Override the file's resolved path (absolute access)")
104+
.option("--json", "Force JSON output")
105+
.option("--human", "Force human output")
106+
.action(async (fileArg: string, opts: RawPathOptions) => {
107+
await runCommandWithRuntime(defaultRuntime, async () => {
108+
await pathEmitCommand(fileArg, normalize(opts), defaultRuntime);
109+
});
110+
});
111+
112+
applyParentDefaultHelpAction(path);
113+
}

‎src/cli/program/register.subclis-core.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ const entrySpecs: readonly CommandGroupDescriptorSpec<SubCliRegistrar>[] = [
167167
loadModule: () => import("../docs-cli.js"),
168168
exportName: "registerDocsCli",
169169
},
170+
{
171+
commandNames: ["path"],
172+
loadModule: () => import("../path-cli.js"),
173+
exportName: "registerPathCli",
174+
},
170175
{
171176
commandNames: ["qa"],
172177
loadModule: loadPrivateQaCliModule,

‎src/cli/program/subcli-descriptors.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ const subCliCommandCatalog = defineCommandDescriptorCatalog([
9393
description: "Search the live OpenClaw docs",
9494
hasSubcommands: false,
9595
},
96+
{
97+
name: "path",
98+
description: "Inspect and edit workspace files via the oc:// addressing scheme",
99+
hasSubcommands: true,
100+
},
96101
{
97102
name: "qa",
98103
description: "Run QA scenarios and launch the private QA debugger UI",

0 commit comments

Comments
 (0)