Files
openclaw/src/oc-path/dispatch.ts
Gio Della-Libera bc735f4fde 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 <235387111+giodl73-repo@users.noreply.github.com>
Co-authored-by: galiniliev <5711535+galiniliev@users.noreply.github.com>
2026-05-07 22:26:28 -07:00

32 lines
1.2 KiB
TypeScript

/**
* Cross-kind utilities. The substrate exposes per-kind verbs only;
* `inferKind` is a convention helper for callers who want to map
* filename → kind so they can pick the right `parseXxx` / `setXxx` /
* `resolveXxx` function.
*
* Earlier drafts had `resolveOcPath` / `setOcPath` / `appendOcPath`
* universal dispatchers with tagged-union AST inputs. They were dropped
* — the kind tag bled through every consumer (lint runner, doctor
* fixers, tests) since those code paths still needed to know the kind
* to use the result. Per-kind verbs are honest about input/output.
*
* @module @openclaw/oc-path/dispatch
*/
export type OcKind = 'md' | 'jsonc' | 'jsonl' | 'yaml';
/**
* Recommend a kind from a filename. Pure convention helper — returns
* the substrate's default mapping. Consumers can override.
*/
export function inferKind(filename: string): OcKind | null {
const lower = filename.toLowerCase();
if (lower.endsWith('.md')) {return 'md';}
if (lower.endsWith('.jsonl') || lower.endsWith('.ndjson')) {return 'jsonl';}
if (lower.endsWith('.jsonc') || lower.endsWith('.json')) {return 'jsonc';}
if (lower.endsWith('.yaml') || lower.endsWith('.yml') || lower.endsWith('.lobster')) {
return 'yaml';
}
return null;
}