opencode-agent-skill 12.0.0-beta.0 → 13.0.0-beta.1
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 +48 -0
- package/README.md +110 -11
- package/bin/ocskill.mjs +394 -84
- package/docs/NPM-PUBLISH.md +20 -6
- package/docs/OPENCODE-COMPAT.md +12 -2
- package/docs/V13-PARALLEL-WEAK-MODEL-RUNTIME.md +75 -0
- package/global-config/AGENTS.md +4 -0
- package/global-config/commands/resume.md +4 -1
- package/global-config/commands/run.md +9 -7
- package/global-config/plugins/ues-router/capabilities.js +1 -0
- package/global-config/plugins/ues-router/command-runtime.js +111 -0
- package/global-config/plugins/ues-router/index.js +381 -43
- package/global-config/plugins/ues-router/parallel-runtime.js +271 -0
- package/global-config/plugins/ues-router/text-runtime.js +115 -0
- package/global-config/plugins/ues-router/verifier-runtime.js +33 -0
- package/global-config/skills/dynamic-workflow/SKILL.md +7 -6
- package/global-config/skills/dynamic-workflow/references/workflow.md +8 -6
- package/global-config/skills/engineering-orchestrator/references/long-horizon.md +7 -5
- package/lib/cli-utils.mjs +17 -4
- package/lib/installer.mjs +50 -16
- package/lib/task-engine.mjs +19 -9
- package/lib/task-graph.mjs +32 -0
- package/lib/text-encoding.mjs +74 -0
- package/lib/worktree-sandbox.mjs +141 -12
- package/package.json +5 -4
- package/scripts/check-release-consistency.mjs +33 -1
- package/scripts/smoke-packed-install.mjs +39 -3
- package/scripts/smoke-plain-install.mjs +27 -7
- package/scripts/validate.mjs +18 -1
package/docs/NPM-PUBLISH.md
CHANGED
|
@@ -27,36 +27,50 @@ Use:
|
|
|
27
27
|
|
|
28
28
|
```cmd
|
|
29
29
|
npm pack
|
|
30
|
-
npm install -g .\opencode-agent-skill-
|
|
30
|
+
npm install -g .\opencode-agent-skill-13.0.0-beta.1.tgz --allow-scripts=opencode-agent-skill
|
|
31
|
+
ocskill install
|
|
31
32
|
ocskill status
|
|
32
33
|
ocskill doctor
|
|
33
34
|
```
|
|
34
35
|
|
|
36
|
+
For the current V13 beta, also open a fresh OpenCode V2 session, check `/plugins`, and call `ues.capabilities`. Native parallel should only be exercised when `freshDispatch` is `true`.
|
|
37
|
+
|
|
35
38
|
For routine development, the automated `smoke:pack` test uses an isolated npm prefix/OpenCode config so it does not replace the developer's currently installed UES.
|
|
36
39
|
|
|
37
40
|
## Manual publish
|
|
38
41
|
|
|
42
|
+
Before publishing, verify the exact prerelease version is not already present:
|
|
43
|
+
|
|
44
|
+
```cmd
|
|
45
|
+
npm view opencode-agent-skill@13.0.0-beta.1 version --registry=https://registry.npmjs.org/
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If it is not present, a manual prerelease publish uses `next`, not `latest`:
|
|
49
|
+
|
|
39
50
|
```cmd
|
|
40
51
|
npm login
|
|
41
52
|
npm whoami
|
|
42
53
|
npm run ci
|
|
43
|
-
npm publish --access public
|
|
54
|
+
npm publish --access public --provenance --tag next
|
|
44
55
|
```
|
|
45
56
|
|
|
46
57
|
After publication verify:
|
|
47
58
|
|
|
48
59
|
```cmd
|
|
49
60
|
npm view opencode-agent-skill versions --json
|
|
50
|
-
npm view opencode-agent-skill@
|
|
61
|
+
npm view opencode-agent-skill@13.0.0-beta.1 version
|
|
51
62
|
npm dist-tag ls opencode-agent-skill
|
|
52
63
|
```
|
|
53
64
|
|
|
54
|
-
|
|
65
|
+
For V13 beta the expected dist-tags are:
|
|
55
66
|
|
|
56
67
|
```text
|
|
57
68
|
latest: 11.0.0
|
|
69
|
+
next: 13.0.0-beta.1
|
|
58
70
|
```
|
|
59
71
|
|
|
72
|
+
Do not move `latest` to V13 until the prerelease is intentionally promoted stable.
|
|
73
|
+
|
|
60
74
|
## GitHub Actions publishing
|
|
61
75
|
|
|
62
76
|
The repository's publish workflow is OIDC/provenance-ready and runs the same package validation before `npm publish`.
|
|
@@ -71,7 +85,7 @@ Workflow: publish.yml
|
|
|
71
85
|
|
|
72
86
|
Then the GitHub-hosted workflow can authenticate through OIDC instead of a long-lived npm publish token. npm Trusted Publishing requires the corresponding publisher relationship to be configured on npm; repository code alone cannot create that account-side trust relationship.
|
|
73
87
|
|
|
74
|
-
|
|
88
|
+
The current `publish.yml` is tag-only. A matching prerelease tag such as `v13.0.0-beta.1` runs the full package gate and publishes with npm dist-tag `next`; a stable version publishes to `latest`. The workflow first checks whether that exact version already exists and skips duplicate publication.
|
|
75
89
|
|
|
76
90
|
## Release checklist
|
|
77
91
|
|
|
@@ -84,7 +98,7 @@ Until the npm-side Trusted Publisher relationship is configured, the workflow ca
|
|
|
84
98
|
7. Commit and push the release branch.
|
|
85
99
|
8. Merge only after review/local validation is clean.
|
|
86
100
|
9. Create/push the matching `vX.Y.Z` tag or run the publish workflow.
|
|
87
|
-
10. Verify registry version and `latest`
|
|
101
|
+
10. Verify registry version and dist-tags (`next` for prerelease, `latest` for stable).
|
|
88
102
|
11. Install the published package on a clean environment before announcing it.
|
|
89
103
|
|
|
90
104
|
## One-command user install
|
package/docs/OPENCODE-COMPAT.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenCode compatibility
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
V13 ships one npm package for OpenCode 1.x and 2.x. CLI/state/verification features remain available on both lines, while V2-native fresh-session and parallel runtime features are enabled only when the required V2 capabilities are detected.
|
|
4
4
|
|
|
5
5
|
## Detection
|
|
6
6
|
|
|
@@ -30,7 +30,7 @@ UES installs:
|
|
|
30
30
|
|
|
31
31
|
The V2 runtime plugin is not installed.
|
|
32
32
|
|
|
33
|
-
Durable CLI state, task DAG, plan/integration gates and model-policy configuration remain available.
|
|
33
|
+
Durable CLI state, task DAG, plan/integration gates, Windows UTF text recovery and model-policy configuration remain available. `ues.dispatch_task` and `ues.dispatch_parallel` are unavailable because those tools live in the V2 router plugin.
|
|
34
34
|
|
|
35
35
|
## OpenCode 2.x
|
|
36
36
|
|
|
@@ -40,6 +40,8 @@ UES converts managed agent permission frontmatter to V2 ordered `permissions` an
|
|
|
40
40
|
<global-config>/plugins/ues-router/
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
V13 also installs the 11 UES slash-command templates inside the managed router as V2 **prompt aliases** instead of registering them as native global custom commands. Typing `/ues-run ...`, `/ues-fix ...`, and the other `/ues-*` aliases therefore travels through `session.prompt`; the router expands the same bundled command contract before routing skills. This is a compatibility workaround for V2 custom-command transport failures such as `UnsupportedContentType` from the `session.command` path. Re-syncing with `ocskill install` removes stale UES-managed native command files from older installs.
|
|
44
|
+
|
|
43
45
|
The plugin provides:
|
|
44
46
|
|
|
45
47
|
- prompt-admission skill routing
|
|
@@ -48,6 +50,7 @@ The plugin provides:
|
|
|
48
50
|
- durable-state/task-graph/context-pack tools
|
|
49
51
|
- `ues.dispatch_task` bounded fresh executor runtime
|
|
50
52
|
- `ues.cancel_task` and `ues.recover_task` when session interruption is supported
|
|
53
|
+
- `ues.dispatch_parallel` when the full fresh-dispatch surface is present; it runs independent approved tasks in isolated same-model sessions, verifies each task independently, and serializes integration
|
|
51
54
|
|
|
52
55
|
`ues.dispatch_task` uses V2 session APIs to create a fresh session rooted at the selected execution directory, bind its session ID to the task lease, select `ues-executor`, optionally switch model tier, prompt one approved task, heartbeat while waiting, and interrupt on timeout. Concurrent writing tasks can be isolated in Git worktrees.
|
|
53
56
|
|
|
@@ -110,3 +113,10 @@ The managed V2 plugin probes for:
|
|
|
110
113
|
- permission hooks
|
|
111
114
|
|
|
112
115
|
`ues.capabilities` exposes the observed surface. Fresh dispatch fails closed when the minimum create/prompt/wait/interrupt/context/switch-agent surface is unavailable. Optional context/prompt/permission hooks degrade safely instead of preventing the plugin from loading.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## V13 parallel compatibility
|
|
119
|
+
|
|
120
|
+
`ues.dispatch_parallel` is capability-gated, not version-string-gated. It requires the complete fresh-dispatch surface reported by `ues.capabilities`: session create, prompt, wait, interrupt, context retrieval and agent switching. If any required API is missing, V13 fails closed and the durable CLI workflow remains usable in serial mode.
|
|
121
|
+
|
|
122
|
+
OpenCode 1.x users can still use V13 CLI hardening, durable `.ues-work/<slug>/` state, receipts, task graphs and Windows text normalization. To use native multi-session parallel execution, use a runtime that exposes the V2 fresh-session APIs.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# V13 Parallel Weak-Model Runtime
|
|
2
|
+
|
|
3
|
+
Status: beta prerelease (`13.0.0-beta.1`).
|
|
4
|
+
|
|
5
|
+
## Goal
|
|
6
|
+
|
|
7
|
+
V13 reduces wall-clock time for large engineering work by letting multiple fresh sessions of the **same configured model** execute independent approved tasks concurrently without sharing mutable context.
|
|
8
|
+
|
|
9
|
+
## Runtime contract
|
|
10
|
+
|
|
11
|
+
- `ues.dispatch_parallel` defaults to one shared model for every worker and verifier.
|
|
12
|
+
- The root must be a Git repository. A pre-existing dirty working tree is allowed: V13 snapshots that baseline into each sandbox and integrates only the task delta, so valid inherited/user changes are preserved.
|
|
13
|
+
- Writers execute in isolated Git worktrees.
|
|
14
|
+
- Resource leases serialize overlapping files, unknown scope and shared configuration surfaces.
|
|
15
|
+
- The scheduler is event-driven: when one task is independently verified, transactionally integrated and completed, newly unblocked dependencies may start immediately.
|
|
16
|
+
- Initial and downstream sandboxes inherit the current dirty root through an internal snapshot commit on the sandbox branch; the user's root branch is never auto-committed.
|
|
17
|
+
- A fresh `ues-verifier` session using the same model must return PASS before integration.
|
|
18
|
+
- Integration is serialized. If receipt/completion fails after patch application, V13 reverses that task patch before marking the run failed.
|
|
19
|
+
- No parallel worker pushes, publishes or deploys.
|
|
20
|
+
|
|
21
|
+
## Same-model execution
|
|
22
|
+
|
|
23
|
+
One model is sufficient. Parallelism means multiple isolated sessions, not multiple model families:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
provider/weak-model
|
|
27
|
+
├─ fresh session A
|
|
28
|
+
├─ fresh session B
|
|
29
|
+
├─ fresh session C
|
|
30
|
+
└─ fresh verifier sessions
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If no explicit model is supplied, the configured executor model is shared. If no configured model is selected, all sessions keep the OpenCode default model.
|
|
34
|
+
|
|
35
|
+
## Runtime compatibility
|
|
36
|
+
|
|
37
|
+
V13 keeps CLI, durable state, receipts, task graphs and Windows text hardening available on OpenCode 1.x. Native `ues.dispatch_task` and `ues.dispatch_parallel` require the V2 router plugin plus the fresh-session capability surface. The router checks capabilities at runtime and fails closed if create/prompt/wait/interrupt/context/switch-agent are incomplete.
|
|
38
|
+
|
|
39
|
+
When npm blocks lifecycle scripts (common with stricter npm 11+ `allowScripts` policy), install still leaves the CLI available; run `ocskill install` to perform the documented resource sync explicitly.
|
|
40
|
+
|
|
41
|
+
## CLI hardening
|
|
42
|
+
|
|
43
|
+
V13 parses `--help` before positional arguments, so commands such as these are safe:
|
|
44
|
+
|
|
45
|
+
```cmd
|
|
46
|
+
ocskill work init --help
|
|
47
|
+
ocskill work status --help
|
|
48
|
+
ocskill work gate-receipt --help
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`ocskill work status .` now lists durable workspaces instead of treating `.` as a slug.
|
|
52
|
+
|
|
53
|
+
For machine callers, append `--json` to receive structured errors.
|
|
54
|
+
|
|
55
|
+
On Windows, prefer:
|
|
56
|
+
|
|
57
|
+
```cmd
|
|
58
|
+
ocskill diff . --out dirty.diff
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This writes UTF-8 directly and avoids PowerShell 5 redirection producing UTF-16 text that generic readers may classify as binary. On OpenCode 1.x, where the V2 `ues.text_read` tool is unavailable, read known text safely without creating a converted copy:
|
|
62
|
+
|
|
63
|
+
```cmd
|
|
64
|
+
ocskill text-read .ues-work/<slug>/PLAN.json --json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Existing UTF-8/UTF-16 text can be normalized with:
|
|
68
|
+
|
|
69
|
+
```cmd
|
|
70
|
+
ocskill normalize-text dirty.diff
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Release evidence
|
|
74
|
+
|
|
75
|
+
V13 remains beta until parallel execution demonstrates measurable wall-clock improvement without reducing correctness, and Windows/Linux CI proves help parsing, encoding, dirty-baseline worktree inheritance, rollback, verifier receipts and package installation.
|
package/global-config/AGENTS.md
CHANGED
|
@@ -34,8 +34,10 @@ Useful deterministic helpers include:
|
|
|
34
34
|
|
|
35
35
|
- `ocskill inspect [dir]`
|
|
36
36
|
- `ocskill impact <symbol-or-term> [dir]`
|
|
37
|
+
- `ocskill repo-graph [dir] --compact` for an initial hotspot summary; request the full graph only when exact edge detail is needed
|
|
37
38
|
- `ocskill aci search|refs|view|text ...`
|
|
38
39
|
- `ocskill working-tree [dir]`
|
|
40
|
+
- `ocskill text-read <file> --json` when OpenCode/generic readers classify known UTF text as binary
|
|
39
41
|
- `ocskill verification-plan [dir]`
|
|
40
42
|
- `ocskill context-pack <slug> <task> [dir]`
|
|
41
43
|
- `ocskill work verify-command ... -- <command>`
|
|
@@ -111,6 +113,8 @@ Never claim a test, build, migration, deployment, push or release succeeded unle
|
|
|
111
113
|
|
|
112
114
|
For interruption-prone or dependent multi-task work, use durable `.ues-work/<slug>/` state instead of relying on conversation memory.
|
|
113
115
|
|
|
116
|
+
`.ues-work/<slug>/` is the only UES durable-state location. Never create or treat a top-level `ues-work/` directory (without the leading dot) as official UES state, even if an older/manual run left files there. On resume, prefer the initialized `.ues-work/<slug>/` item plus current Git evidence.
|
|
117
|
+
|
|
114
118
|
The required sequence is:
|
|
115
119
|
|
|
116
120
|
`SPEC -> PLAN -> plan check/receipt -> approved tasks -> fresh executor per task -> task verification receipts -> integration verification/receipt -> finalize`
|
|
@@ -7,10 +7,13 @@ Resume this UES work item: $ARGUMENTS
|
|
|
7
7
|
|
|
8
8
|
Read the matching `.ues-work/<slug>/SPEC.md`, `PLAN.json`, `STATE.json`, `EVIDENCE.json`, task reports and current Git status. Run `ocskill work resume <slug> .` and revalidate assumptions that may have gone stale.
|
|
9
9
|
|
|
10
|
+
Ignore a top-level `ues-work/` directory as official workflow state. Only `.ues-work/<slug>/` created/managed by `ocskill work` is canonical durable state.
|
|
11
|
+
|
|
10
12
|
Trust durable task state and Git evidence over conversational recollection. Respect the machine gates:
|
|
11
13
|
- if the plan is awaiting approval, run `ues-plan-checker` and record PASS with `ocskill work approve-plan`;
|
|
12
14
|
- resume failed/pending work from the last verified boundary;
|
|
13
|
-
- on OpenCode V2 prefer `ues.dispatch_task` for a fresh executor
|
|
15
|
+
- on OpenCode V2, prefer `ues.dispatch_parallel` when two or more dependency-ready tasks have independent declared write/resource scopes; otherwise use `ues.dispatch_task` for a fresh executor. Keep one shared model for parallel worker/verifier sessions unless the user explicitly changes the design;
|
|
16
|
+
- do not force-clean inherited user changes just to enable parallel resume; V13 snapshots an existing dirty Git baseline into isolated worktrees and integrates only each task delta;
|
|
14
17
|
- do not repeat completed tasks unless fresh evidence invalidates them;
|
|
15
18
|
- after all tasks complete, run `ues-integration-verifier`, record its verdict with `ocskill work verify-integration`, then finalize only after PASS and an unchanged workspace fingerprint.
|
|
16
19
|
|
|
@@ -7,20 +7,22 @@ Run this task using the UES long-horizon workflow: $ARGUMENTS
|
|
|
7
7
|
|
|
8
8
|
Treat this command as permission to create a repository-local, git-ignored `.ues-work/<slug>/` execution workspace for durable non-secret planning state.
|
|
9
9
|
|
|
10
|
+
Never create or use `ues-work/` (without the leading dot) as durable UES state. If such a directory exists from an older/manual run, treat it as ordinary repository content unless the user explicitly asks to migrate it; official state must come from `ocskill work init` under `.ues-work/<slug>/`.
|
|
11
|
+
|
|
10
12
|
Required workflow:
|
|
11
|
-
1. Classify the request with `ocskill task-policy "
|
|
12
|
-
2. Inspect repository instructions and deterministic evidence with `ocskill inspect`, `ocskill repo-graph`, and targeted impact searches.
|
|
13
|
+
1. Classify the request with `ocskill task-policy "<concise task summary>"`. Do not duplicate the full user prompt into shell arguments; use the returned risk/mode/context guidance rather than assuming every non-trivial task needs the same workflow.
|
|
14
|
+
2. Inspect repository instructions and deterministic evidence with `ocskill inspect`, `ocskill repo-graph . --compact`, and targeted impact searches. Expand to the full graph only when exact edge detail is needed.
|
|
13
15
|
3. Create a concise SPEC with observable acceptance criteria.
|
|
14
16
|
4. Initialize persistent state with `ocskill work init`.
|
|
15
17
|
5. Produce a file-aware `PLAN.json` using the UES plan schema, then import it with `ocskill work plan`.
|
|
16
18
|
6. Dispatch `ues-plan-checker` in fresh context. For long/high-risk work, bind the PASS to the current plan with a structured receipt, then approve it:
|
|
17
19
|
`ocskill work gate-receipt <slug> plan . --verifier ues-plan-checker --evidence "<summary>" --out .ues-work/<slug>/reports/plan-receipt.json`
|
|
18
20
|
followed by `ocskill work approve-plan <slug> . --evidence "<summary>" --receipt-file .ues-work/<slug>/reports/plan-receipt.json`.
|
|
19
|
-
7. Use `ocskill task-graph` and execute only
|
|
20
|
-
8.
|
|
21
|
-
9.
|
|
22
|
-
10.
|
|
23
|
-
11.
|
|
21
|
+
7. Use `ocskill task-graph` and execute only dependency-ready tasks. On OpenCode V2, when two or more independent tasks are ready, prefer `ues.dispatch_parallel`. V13 uses multiple fresh sessions of one shared model, not multiple model families. For a single task or a deliberately serial path, use `ues.dispatch_task`.
|
|
22
|
+
8. `ues.dispatch_parallel` is event-driven rather than wave-barrier driven: as soon as a task is independently verified, transactionally integrated and durably completed, newly unblocked dependencies may start in the next free worker slot. Resource leases serialize overlapping writers, unknown scopes and shared configuration surfaces.
|
|
23
|
+
9. Each parallel writer gets an isolated Git worktree. A pre-existing dirty root is treated as an inherited baseline, and downstream worktrees also inherit already integrated root changes through an internal sandbox snapshot; only task-local deltas are integrated and the user's root branch is not auto-committed. Integration is serialized and rolled back if post-integration verification/receipt/completion fails.
|
|
24
|
+
10. For machine-checkable verification, add `verificationCommands` to the approved task, for example `{"command":"node","args":["--test","test/foo.test.mjs"]}`. V13 runs these exact commands after integration via `ocskill work verify-command`, records deterministic receipts, then also records the fresh independent verifier verdict. For long/high-risk plans, current-fingerprint receipt evidence remains mandatory.
|
|
25
|
+
11. During long execution keep task leases alive (the V2 dispatcher does this automatically). On resume, `ocskill work recover` or `ocskill work resume` recovers expired leases instead of leaving tasks stuck in `running`. In parallel mode, keep one shared model for all worker/verifier sessions unless the user explicitly changes the run design.
|
|
24
26
|
12. After all tasks complete, dispatch `ues-integration-verifier`. For PASS on long/high-risk work, create an integration receipt bound to the current workspace fingerprint:
|
|
25
27
|
`ocskill work gate-receipt <slug> integration . --verifier ues-integration-verifier --verdict PASS --evidence "<summary>" --out .ues-work/<slug>/reports/integration-receipt.json`
|
|
26
28
|
then record it with `ocskill work verify-integration <slug> . --verdict PASS --evidence "<summary>" --receipt-file .ues-work/<slug>/reports/integration-receipt.json`.
|
|
@@ -11,6 +11,7 @@ export function runtimeCapabilities(ctx) {
|
|
|
11
11
|
sessionSwitchModel: typeof session.switchModel === "function",
|
|
12
12
|
sessionHook: typeof session.hook === "function",
|
|
13
13
|
permissionHook: typeof permission.hook === "function",
|
|
14
|
+
permissionRules: typeof permission.rules === "function",
|
|
14
15
|
}
|
|
15
16
|
capabilities.freshDispatch =
|
|
16
17
|
capabilities.sessionCreate &&
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
export const UES_PROMPT_ALIASES = Object.freeze([
|
|
5
|
+
"ues-audit",
|
|
6
|
+
"ues-critique",
|
|
7
|
+
"ues-debug",
|
|
8
|
+
"ues-feature",
|
|
9
|
+
"ues-fix",
|
|
10
|
+
"ues-plan",
|
|
11
|
+
"ues-research",
|
|
12
|
+
"ues-resume",
|
|
13
|
+
"ues-review",
|
|
14
|
+
"ues-run",
|
|
15
|
+
"ues-verify",
|
|
16
|
+
])
|
|
17
|
+
|
|
18
|
+
const ALIAS_SET = new Set(UES_PROMPT_ALIASES)
|
|
19
|
+
|
|
20
|
+
export function normalizeUesPromptPaste(text) {
|
|
21
|
+
let value = String(text || "")
|
|
22
|
+
.replace(/^\uFEFF/, "")
|
|
23
|
+
.replace(/^[\u200B-\u200D]+/, "")
|
|
24
|
+
|
|
25
|
+
const trimmed = value.trim()
|
|
26
|
+
const fenced = trimmed.match(/^\`\`\`(?:text|txt|md|markdown|prompt|plaintext)?[ \t]*\r?\n([\s\S]*?)\r?\n\`\`\`\s*$/i)
|
|
27
|
+
if (fenced) value = fenced[1]
|
|
28
|
+
|
|
29
|
+
return value
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function policyPromptForCli(text, maxChars = 12_000) {
|
|
33
|
+
const raw = normalizeUesPromptPaste(text).trim()
|
|
34
|
+
const limit = Math.max(2_000, Number(maxChars) || 12_000)
|
|
35
|
+
if (raw.length <= limit) {
|
|
36
|
+
return { text: raw, truncated: false, originalChars: raw.length, cliChars: raw.length }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const marker = "\n\n[UES_POLICY_INPUT_TRUNCATED_FOR_CLI]\n\n"
|
|
40
|
+
const usable = Math.max(1, limit - marker.length)
|
|
41
|
+
const headChars = Math.floor(usable * 0.72)
|
|
42
|
+
const tailChars = usable - headChars
|
|
43
|
+
const bounded = raw.slice(0, headChars) + marker + raw.slice(-tailChars)
|
|
44
|
+
return {
|
|
45
|
+
text: bounded,
|
|
46
|
+
truncated: true,
|
|
47
|
+
originalChars: raw.length,
|
|
48
|
+
cliChars: bounded.length,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parseFrontmatter(source) {
|
|
53
|
+
const text = String(source || "")
|
|
54
|
+
if (!text.startsWith("---")) return { metadata: {}, body: text }
|
|
55
|
+
const end = text.indexOf("\n---", 3)
|
|
56
|
+
if (end < 0) return { metadata: {}, body: text }
|
|
57
|
+
|
|
58
|
+
const block = text.slice(3, end).trim()
|
|
59
|
+
const metadata = {}
|
|
60
|
+
for (const line of block.split(/\r?\n/)) {
|
|
61
|
+
const match = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/)
|
|
62
|
+
if (!match) continue
|
|
63
|
+
metadata[match[1]] = match[2].trim()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
metadata,
|
|
68
|
+
body: text.slice(end + 4).replace(/^\r?\n/, ""),
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function splitArgs(input) {
|
|
73
|
+
const value = String(input || "")
|
|
74
|
+
const matches = value.match(/"[^"]*"|'[^']*'|\S+/g) || []
|
|
75
|
+
return matches.map((item) => item.replace(/^(['"])([\s\S]*)\1$/, "$2"))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function expandUesPromptAlias(text, templateDir) {
|
|
79
|
+
const raw = normalizeUesPromptPaste(text)
|
|
80
|
+
const match = raw.match(/^\s*\/(ues-[a-z0-9]+(?:-[a-z0-9]+)*)(?:\s+([\s\S]*?))?\s*$/i)
|
|
81
|
+
if (!match) return null
|
|
82
|
+
|
|
83
|
+
const alias = match[1].toLowerCase()
|
|
84
|
+
if (!ALIAS_SET.has(alias)) return null
|
|
85
|
+
|
|
86
|
+
const args = String(match[2] || "").trim()
|
|
87
|
+
const sourceName = alias.slice("ues-".length) + ".md"
|
|
88
|
+
const file = path.join(templateDir, sourceName)
|
|
89
|
+
if (!existsSync(file)) return null
|
|
90
|
+
|
|
91
|
+
const { metadata, body } = parseFrontmatter(readFileSync(file, "utf8"))
|
|
92
|
+
const positional = splitArgs(args)
|
|
93
|
+
let expanded = body.replaceAll("$ARGUMENTS", args)
|
|
94
|
+
expanded = expanded.replace(/\$(\d+)/g, (_, value) => positional[Number(value) - 1] || "")
|
|
95
|
+
|
|
96
|
+
const agent = metadata.agent || null
|
|
97
|
+
const prelude = [
|
|
98
|
+
`UES V2 prompt alias: /${alias}. Preserve the command contract below while using the normal session.prompt path.`,
|
|
99
|
+
agent && agent !== "build"
|
|
100
|
+
? `Preferred specialist: ${agent}. When fresh subagent dispatch is available, delegate to that specialist and preserve the command's read/write restrictions.`
|
|
101
|
+
: null,
|
|
102
|
+
].filter(Boolean).join("\n")
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
alias,
|
|
106
|
+
arguments: args,
|
|
107
|
+
agent,
|
|
108
|
+
sourceName,
|
|
109
|
+
text: `${prelude}\n\n${expanded.trim()}`,
|
|
110
|
+
}
|
|
111
|
+
}
|