@yandy-r/ycc-opencode 6.1.1 → 6.2.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.
Files changed (126) hide show
  1. package/README.md +7 -3
  2. package/agents/code-researcher.md +3 -3
  3. package/agents/feature-researcher.md +1 -1
  4. package/agents/implementor.md +4 -4
  5. package/agents/pr-comment-fixer.md +1 -1
  6. package/agents/release-fix-applier.md +1 -1
  7. package/agents/review-fixer.md +1 -1
  8. package/index.js +146 -95
  9. package/package.json +1 -1
  10. package/registration.json +0 -4
  11. package/shared/references/artifact-store.md +613 -0
  12. package/shared/references/branch-prep.md +2 -0
  13. package/shared/references/forge-detection.md +3 -2
  14. package/shared/references/review-artifact-format.md +13 -6
  15. package/shared/references/review-checklist.md +3 -2
  16. package/shared/references/review-dispatch.md +15 -10
  17. package/shared/references/target-capability-matrix.md +140 -32
  18. package/shared/references/visual-mode.md +19 -13
  19. package/shared/references/worktree-strategy.md +12 -8
  20. package/shared/scripts/artifact-body.sh +71 -0
  21. package/shared/scripts/artifact-store-pointer.sh +245 -0
  22. package/shared/scripts/ci-monitor.sh +9 -4
  23. package/shared/scripts/collect-linear-keys.sh +77 -0
  24. package/shared/scripts/lib/ci-classify.sh +13 -10
  25. package/shared/scripts/lib/forge.sh +13 -4
  26. package/shared/scripts/prepare-feature-branch.sh +118 -10
  27. package/shared/scripts/release-ci-monitor.sh +2 -2
  28. package/shared/scripts/report-bundle-drift.sh +1 -1
  29. package/shared/scripts/resolve-artifact-store.sh +636 -0
  30. package/shared/scripts/validate-file-paths.sh +11 -4
  31. package/skills/blueprint/SKILL.md +48 -13
  32. package/skills/bundle-release/scripts/draft-notes.sh +1 -1
  33. package/skills/bundle-release/scripts/release_versions.py +9 -1
  34. package/skills/clean/SKILL.md +1 -1
  35. package/skills/clean/scripts/detect-project-type.sh +2 -2
  36. package/skills/clean/scripts/generate-report.sh +34 -5
  37. package/skills/clean/scripts/validate-safety.sh +9 -6
  38. package/skills/code-report/SKILL.md +26 -14
  39. package/skills/code-report/scripts/check-prerequisites.sh +72 -12
  40. package/skills/code-report/templates/report-structure.md +1 -1
  41. package/skills/code-review/SKILL.md +68 -17
  42. package/skills/code-review/references/pr-procedure.md +28 -15
  43. package/skills/compatibility-audit/SKILL.md +10 -5
  44. package/skills/compatibility-audit/references/reading-the-report.md +4 -1
  45. package/skills/compatibility-audit/scripts/audit-install-assumptions.sh +64 -7
  46. package/skills/compatibility-audit/scripts/audit-target-features.sh +13 -10
  47. package/skills/deep-research/SKILL.md +28 -5
  48. package/skills/deep-research/references/completion-summary-template.md +3 -2
  49. package/skills/deep-research/scripts/validate-research.sh +8 -2
  50. package/skills/feature-research/SKILL.md +48 -25
  51. package/skills/feature-research/scripts/validate-research.sh +51 -12
  52. package/skills/feature-research/scripts/validate-spec.sh +53 -22
  53. package/skills/feature-research/templates/research-agents.md +15 -14
  54. package/skills/feature-research/templates/spec-structure.md +5 -0
  55. package/skills/formatters/scripts/apply-aliases.sh +3 -1
  56. package/skills/formatters/scripts/apply-ci.sh +3 -1
  57. package/skills/git-workflow/SKILL.md +2 -1
  58. package/skills/git-workflow/references/pr-creation.md +10 -0
  59. package/skills/git-workflow/scripts/analyze-changes.sh +21 -11
  60. package/skills/git-workflow/scripts/create-pr.sh +51 -6
  61. package/skills/git-workflow/scripts/validate-commit.sh +26 -14
  62. package/skills/hooks-workflow/scripts/verify-hooks.sh +1 -1
  63. package/skills/implement-plan/SKILL.md +35 -16
  64. package/skills/implement-plan/references/agent-task-prompt.md +8 -5
  65. package/skills/implement-plan/references/linear-sync.md +20 -0
  66. package/skills/implement-plan/references/output-formats.md +17 -2
  67. package/skills/implement-plan/references/plan-inputs.md +23 -4
  68. package/skills/implement-plan/scripts/check-prerequisites.sh +95 -49
  69. package/skills/implement-plan/scripts/parse-dependencies.sh +10 -10
  70. package/skills/init/SKILL.md +77 -42
  71. package/skills/init/references/flag-reference.md +41 -17
  72. package/skills/init/references/project-profile-heuristics.md +3 -0
  73. package/skills/init/references/template-library.md +15 -5
  74. package/skills/init/scripts/profile-project.sh +26 -0
  75. package/skills/init/scripts/render-template.py +2 -2
  76. package/skills/init/templates/AGENTS.md.tmpl +6 -0
  77. package/skills/init/templates/git/gitignore.tmpl +5 -0
  78. package/skills/orchestrate/SKILL.md +17 -2
  79. package/skills/parallel-plan/SKILL.md +14 -8
  80. package/skills/plan/SKILL.md +18 -2
  81. package/skills/plan/references/planning-tracks.md +1 -1
  82. package/skills/plan-workflow/SKILL.md +67 -32
  83. package/skills/plan-workflow/references/checkpoint-messages.md +23 -14
  84. package/skills/plan-workflow/references/plan-structure.md +1 -1
  85. package/skills/plan-workflow/references/planning-agents.md +11 -9
  86. package/skills/plan-workflow/references/research-agents-optimized.md +12 -10
  87. package/skills/plan-workflow/references/research-agents.md +11 -10
  88. package/skills/plan-workflow/scripts/check-prerequisites.sh +50 -11
  89. package/skills/plan-workflow/scripts/check-state.sh +53 -9
  90. package/skills/plan-workflow/scripts/persist-or-fail.sh +21 -7
  91. package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +28 -14
  92. package/skills/plan-workflow/scripts/validate-research-artifacts.sh +35 -10
  93. package/skills/plan-workflow/scripts/validate-shared.sh +56 -15
  94. package/skills/plan-workflow/scripts/validate-workflow-plan.sh +48 -17
  95. package/skills/pr-autofix/SKILL.md +19 -4
  96. package/skills/pr-autofix/references/output-templates.md +3 -2
  97. package/skills/pr-autofix/scripts/fetch-pr-comments.sh +1 -2
  98. package/skills/pr-autofix/scripts/post-summary.sh +1 -2
  99. package/skills/pr-autofix/scripts/resolve-thread.sh +3 -4
  100. package/skills/prp-implement/SKILL.md +31 -16
  101. package/skills/prp-implement/references/agent-task-prompt.md +5 -2
  102. package/skills/prp-implement/references/detection.md +4 -1
  103. package/skills/prp-implement/references/linear-sync.md +25 -0
  104. package/skills/prp-implement/references/report-output.md +15 -2
  105. package/skills/prp-plan/SKILL.md +62 -30
  106. package/skills/prp-plan/references/enhanced-researchers.md +8 -9
  107. package/skills/prp-plan/scripts/validate-prp-plan.sh +42 -18
  108. package/skills/prp-pr/SKILL.md +14 -1
  109. package/skills/prp-prd/SKILL.md +21 -9
  110. package/skills/prp-spec/SKILL.md +30 -20
  111. package/skills/quick-fix/SKILL.md +6 -4
  112. package/skills/quick-review/SKILL.md +62 -25
  113. package/skills/release-model/scripts/collect-signals.sh +9 -3
  114. package/skills/releaser/scripts/publish-release.sh +6 -3
  115. package/skills/research-to-issues/SKILL.md +33 -14
  116. package/skills/research-to-issues/scripts/validate-prerequisites.sh +45 -23
  117. package/skills/research-to-issues/templates/task-issue.md +4 -0
  118. package/skills/research-to-issues/templates/tracking-issue.md +3 -0
  119. package/skills/review-fix/SKILL.md +96 -14
  120. package/skills/review-fix/references/fix-report.md +10 -10
  121. package/skills/review-fix/references/plan.md +5 -2
  122. package/skills/shared-context/SKILL.md +14 -11
  123. package/skills/visual-plan/SKILL.md +26 -8
  124. package/skills/visual-recap/SKILL.md +1 -1
  125. package/skills/write-docs/scripts/audit-documentation.sh +44 -10
  126. package/skills/write-docs/scripts/generate-doc-index.sh +10 -3
package/README.md CHANGED
@@ -1,19 +1,23 @@
1
1
  # @yandy-r/ycc-opencode
2
2
 
3
3
  Experimental, opt-in [OpenCode](https://opencode.ai) V2 plugin carrying the ycc bundle
4
- (version 6.1.1). It is unlisted and never the default install: the
4
+ (version 6.2.1). It is unlisted and never the default install: the
5
5
  `install.sh --target opencode` file copy remains the primary path.
6
6
 
7
7
  Requires OpenCode `>=2.0.30` (V2 plugin API; V1 hook plugins are not supported).
8
8
 
9
9
  ## Enable
10
10
 
11
- Add the package to the V2 `plugins` array in your own `opencode.json`:
11
+ Add the package to the V2 `plugins` array in your own `opencode.json`, pinned to an exact release:
12
12
 
13
13
  ```json
14
- { "plugins": ["@yandy-r/ycc-opencode"] }
14
+ { "plugins": ["@yandy-r/ycc-opencode@6.2.1"] }
15
15
  ```
16
16
 
17
+ Pin the version instead of using the bare name. Right after a release, the registry can briefly serve
18
+ stale `latest` metadata, and early placeholder versions of this package (`0.0.0-*`) were never
19
+ loadable plugins. Bump the pin when you upgrade.
20
+
17
21
  A local checkout loads with a directory entry (`"file:///abs/path/to/packages/opencode/ycc-opencode"`),
18
22
  not the `index.js` file.
19
23
 
@@ -54,7 +54,7 @@ When tasked with codebase research, you will:
54
54
  1. **Conduct Wide-Scope Analysis**: Systematically explore the codebase structure, focusing on understanding the overall architecture, data flow patterns, and component relationships specific to your research focus. Pay special attention to existing patterns that relate to the research objective.
55
55
  2. **Identify Edge Cases and Gotchas**: Actively search for unusual implementations, workarounds, legacy code patterns, and potential pitfalls. Look for comments that explain "why" decisions were made, especially those that seem counterintuitive.
56
56
  3. **Document Architectural Patterns**: Catalog recurring design patterns, architectural decisions, and structural approaches used throughout the codebase.
57
- 4. **Generate Research Report**: Create a concise markdown document at docs/internal-docs/[relevant-name].md:
57
+ 4. **Generate Research Report**: Create a concise markdown report at the caller-supplied path, or return it inline when no path is supplied:
58
58
  - **Overview**: Brief summary of key findings (2-3 sentences)
59
59
  - **Relevant Files**: List of important file paths with one-line descriptions
60
60
  - **Architectural Patterns**: Identified design patterns and architectural decisions (brief bullet points)
@@ -71,7 +71,7 @@ When tasked with codebase research, you will:
71
71
  - Keep descriptions concise and actionable
72
72
  - Focus on linking to relevant code rather than reproducing it
73
73
  - Highlight patterns that would impact new feature development
74
- As a quick example format, you might make the file `docs/features/custom-feature.md`
74
+ Use this example report structure (the caller chooses any output path):
75
75
 
76
76
  ```md
77
77
  # Title
@@ -98,5 +98,5 @@ When tasked with codebase research, you will:
98
98
  - External documentation, or file paths to other internal documentation
99
99
  ```
100
100
 
101
- You do NOT modify source code or create executable/source files. You DO write your research and analysis findings to the markdown file path the caller provides — that is your primary deliverable. If the caller provides a target markdown path, write your report there using the Write tool without asking. Only ask if no path is provided. Your sole focus is thorough research and clear documentation of findings.
101
+ You do NOT modify source code or create executable/source files. Write findings only to the markdown file path the caller provides, using the Write tool without asking. With no supplied path, return findings inline without creating a file or asking for a destination. The caller owns artifact-store resolution and persistence. Your sole focus is thorough research and clear documentation of findings.
102
102
  Your research reports should be comprehensive yet concise, focusing on actionable insights that will help developers understand the codebase architecture and make informed implementation decisions.
@@ -68,7 +68,7 @@ When researching for a new feature, you will:
68
68
 
69
69
  ### 3. **Create Planning Document**
70
70
 
71
- Generate a concise research report at `plans/[feature-name]/[topic-name].md`:
71
+ Generate a concise research report using the structure below. If the caller supplies a target markdown path, write only to that path using the Write tool and return the findings inline. With no supplied path, return the report inline without creating a file; the caller owns artifact-store resolution and persistence.
72
72
 
73
73
  ```markdown
74
74
  # [Feature/Topic Name] Research
@@ -47,17 +47,17 @@ You implement specific software changes as instructed. You do NOT:
47
47
  - Add features not explicitly requested
48
48
  - Attempt to solve broader architectural problems
49
49
 
50
+ Never call Linear MCP or other external tracker tools; report status only to the orchestrator. Never edit plan files or their frontmatter.
51
+
50
52
  ## Working Directory
51
53
 
52
54
  If your task prompt contains a `Working directory: <path>` line, treat that path
53
55
  as your repo root for ALL file operations. Specifically:
54
56
 
55
- - Every Read / Write / Edit / Glob / Grep must target paths underneath this directory.
57
+ - Every Write / Edit must target paths underneath this directory. Read / Glob / Grep do too, except explicitly supplied absolute plan/context paths are read-only inputs and may live in the invoking checkout's artifact cache.
56
58
  - Every Bash `cd`, `git`, or path-dependent command must operate relative to this
57
59
  directory (use `git -C <path>` or `cd` at the top of the command).
58
- - Never mix paths from the parent repo clone with the working directory. The two
59
- are distinct git checkouts; mixing them corrupts the single-worktree setup the
60
- orchestrating skill selected.
60
+ - Never mix implementation writes between the parent repo clone and the working directory. They are distinct git checkouts; only explicitly supplied read-only plan/context paths may cross that boundary.
61
61
  - In the current contract, the working directory is usually the shared feature
62
62
  worktree (`<worktree-root>/<repo>-<feature>/`) used by every task in the run.
63
63
  `<worktree-root>` is the active runtime's repo-local worktree root; the
@@ -523,7 +523,7 @@ Validate `PROJECT TYPE-CHECK COMMAND` against this allowlist before execution:
523
523
 
524
524
  If the value starts with `SKIP (` and ends with `)`, skip validation and report `TYPE-CHECK: Skipped (<reason>)`.
525
525
 
526
- If the value is not allowlisted and is not a `SKIP (...)` token, do NOT run it (on OpenCode, native rules deny any other shell command). Report `STATUS: Failed` with `BLOCKER: type-check command not allowlisted — <value>`.
526
+ If the value is not allowlisted and is not a `SKIP (...)` token, do NOT run it (OpenCode and OMP block any other shell command natively; on other runtimes this rule is yours to keep). Report `STATUS: Failed` with `BLOCKER: type-check command not allowlisted — <value>`.
527
527
 
528
528
  Execute the allowlisted command via Bash. If type-check passes for your modified file: report success.
529
529
 
@@ -513,7 +513,7 @@ If `PROJECT TYPE-CHECK COMMAND` or `PROJECT BUILD COMMAND` is included and appli
513
513
  | Go | `go vet ./...` | `go build ./...` |
514
514
  | Python | `pytest` / `python -m mypy <file>` / `python3 -m mypy <file>` | — |
515
515
 
516
- Do not run a provided command outside this table (on OpenCode, native rules deny any other shell command). Return `RESULT: cannot-fix` with `REASON: command not allowlisted — <value>`.
516
+ Do not run a provided command outside this table (OpenCode and OMP block any other shell command natively; on other runtimes this rule is yours to keep). Return `RESULT: cannot-fix` with `REASON: command not allowlisted — <value>`.
517
517
 
518
518
  ### 5. Return one of two response shapes
519
519
 
@@ -521,7 +521,7 @@ other non-allowlisted value as safe.
521
521
 
522
522
  Execute the validated command via a safe program+args API (for example, `spawn` or `execFile`), never via shell-string interpolation. If file scoping is used, pass the filename as a separate argument token.
523
523
 
524
- If `PROJECT TYPE-CHECK COMMAND` is not allowlisted, do NOT run it (on OpenCode, native rules deny any other shell command). Report `STATUS: Failed` with `BLOCKER: type-check command not allowlisted — <value>`.
524
+ If `PROJECT TYPE-CHECK COMMAND` is not allowlisted, do NOT run it (OpenCode and OMP block any other shell command natively; on other runtimes this rule is yours to keep). Report `STATUS: Failed` with `BLOCKER: type-check command not allowlisted — <value>`.
525
525
 
526
526
  If the type-check passes for your modified file: report success.
527
527
 
package/index.js CHANGED
@@ -47,9 +47,9 @@
47
47
  // short-circuits before hooks) and its mutated effect/message is
48
48
  // final (plugin/src/promise/permission.ts). It turns the effect into
49
49
  // deny when the packaged rules deny any resource, and an
50
- // external_directory allow into ask when the packaged rules ask for a
51
- // resource no saved approval covers. The event's agent is optional;
52
- // without it the session's agent is used, as the host does.
50
+ // external_directory allow into ask unless a saved approval covers
51
+ // every resource the packaged rules ask for. The event's agent is
52
+ // optional; without it the session's agent is used, as the host does.
53
53
  // * ctx.tool.hook("execute.before") rejects a call to a tool whose
54
54
  // permission action the packaged rules wholly deny, which also covers
55
55
  // tools that never request a permission.
@@ -60,23 +60,42 @@
60
60
  // and request settings, because config.agent mutates them in place.
61
61
  //
62
62
  // Saved approvals: an "always" reply makes the host save the request's
63
- // `save` patterns for the project (permission.ts reply, saved.add) and
64
- // append them as allow rules after every configured rule, so the evaluate
65
- // event cannot tell a saved approval from a config-level allow, and no
66
- // plugin API lists saved permissions (v2.0.30-v2.1.1). The host publishes
67
- // permission.asked (the request, `save` included) and permission.replied
68
- // on the bus that ctx.event.subscribe streams for this location, so the
69
- // package records the same patterns in its own storage, one key per
70
- // pattern under the project (ctx.storage.scan reads them back), and keeps
71
- // an allow they cover. After saving, the host re-evaluates every other
72
- // pending request in the same fiber and publishes an "always" reply,
73
- // without saving anything, for each one that now evaluates to allow. At
74
- // least one resource of such a request is covered by the patterns just
75
- // recorded (the rest may be allowed by config), so a reply to a request
76
- // any recorded pattern already partly covers records nothing. Recording
77
- // happens in memory before any await, so that same-fiber re-evaluation
78
- // already sees it.
79
- //
63
+ // `save` patterns for the project (permission.ts reply, saved.add). The
64
+ // evaluate event cannot tell a saved approval from a config-level allow,
65
+ // and plugins get no API or bus event for saved approvals (v2.0.30-v2.2.5;
66
+ // ctx.permission is list/get/reply for pending requests, hook, assert).
67
+ // The floor therefore asks the host itself, with a saved-approval probe:
68
+ // a child session of the asking session (ctx.session.create with
69
+ // parentID), run as the same agent, whose own permissions are
70
+ // `external_directory * ask`, and a ctx.permission.assert there for the
71
+ // resources in question. evaluateInput merges the agent's rules (config
72
+ // rules included) with the session's, so the session's ask comes last
73
+ // and overrides any config-level allow; it then appends the project's
74
+ // saved approvals as allow rules after all of them. The probe's effect is
75
+ // therefore allow exactly when saved approvals cover every resource, as
76
+ // long as no evaluate hook running before this package's changed it. So
77
+ // a second assert in the same session asks for a sentinel directory no
78
+ // real approval covers; if that also comes back allow (a hook approves
79
+ // every request, or a saved approval covers `/`), the probe proves
80
+ // nothing and the floor prompts. This package's own evaluate hook
81
+ // recognises each probe evaluation by the session id and a per-assert
82
+ // metadata token, records the effect, and turns it into deny so the probe
83
+ // never prompts; the assert's rejection is expected. An assert that does
84
+ // not settle within PROBE_TIMEOUT_MS (this hook gone, e.g. the plugin
85
+ // unloaded mid-probe, or an earlier hook slow) counts as no answer and
86
+ // has its pending request rejected (ctx.permission.list/reply); its token
87
+ // stays registered until the assert settles, so a late evaluation is
88
+ // still denied. The probe session is removed again
89
+ // (ctx.session.remove) in every case. Because the host is asked each
90
+ // time, a removed saved approval takes effect at once and one saved
91
+ // before this package loaded is honoured. Each loaded copy of this module
92
+ // has its own probe map: another copy whose hook runs first sees this
93
+ // copy's probe evaluation as an ordinary check and may run one nested
94
+ // probe of its own, whose evaluation this copy's hook then sees already
95
+ // denied and leaves alone, so the nesting stops after one level and both
96
+ // copies reach the same answer. Older package versions kept their own
97
+ // copy of saved approvals in plugin storage; setup removes those records.
98
+
80
99
  // Coexistence with the primary file-copy install (install.sh --target
81
100
  // opencode): config agents/skills/commands apply in the `post` plugin group,
82
101
  // which replays after any user package on every state rebuild
@@ -98,6 +117,7 @@ import { fileURLToPath } from "node:url";
98
117
  import { dirname, isAbsolute, join, relative as relativePath } from "node:path";
99
118
  import { cpSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
100
119
  import { tmpdir } from "node:os";
120
+ import { randomUUID } from "node:crypto";
101
121
 
102
122
  import { registerSensitiveGuard } from "./ycc-sensitive-guard/index.js";
103
123
 
@@ -115,6 +135,12 @@ const RESTRICTED_RULES = new Map(
115
135
  const FLOOR_DENIED = "Permission denied by ycc restricted-agent rules: ";
116
136
  // The only action the floor raises from allow to ask.
117
137
  const EXTERNAL = "external_directory";
138
+ // Saved-approval probe asserts in flight: metadata token -> { sessionID, effect }.
139
+ const PROBES = new Map();
140
+ const PROBE_KEY = "yccSavedApprovalProbe";
141
+ const PROBE_TITLE = "ycc saved-approval probe";
142
+ // How long one probe assert may take before its pending request is rejected.
143
+ const PROBE_TIMEOUT_MS = 5000;
118
144
 
119
145
  // Token the generator writes where a package asset path is needed; it points
120
146
  // at the *rendered* tree created below, which sits beside the package root.
@@ -363,93 +389,124 @@ async function sessionAgent(ctx, sessionID) {
363
389
  return (session?.data ?? session)?.agent;
364
390
  }
365
391
 
366
- // Saved external_directory approvals of one project, mirrored from the host:
367
- // one storage key per pattern, so instances sharing a project never
368
- // overwrite each other's records.
369
- function savedPrefix(ctx) {
370
- return `saved/${EXTERNAL}/${encodeURIComponent(ctx.location.project.id)}/`;
371
- }
372
-
373
- async function storedPatterns(ctx) {
374
- const patterns = [];
375
- const prefix = savedPrefix(ctx);
376
- let after;
377
- do {
378
- const page = await ctx.storage.scan({ prefix, after });
379
- for (const entry of page.entries) if (typeof entry.value === "string") patterns.push(entry.value);
380
- after = page.next;
381
- } while (after !== undefined);
382
- return patterns;
383
- }
384
-
385
- // Recorded patterns: this instance's in-memory records (loaded at setup, then
386
- // set as soon as a reply arrives) plus those other locations of the project
387
- // stored since.
388
- async function savedPatterns(ctx, recorded) {
392
+ // Reject every pending permission request of a probe session. Best effort.
393
+ async function rejectPending(ctx, sessionID) {
389
394
  try {
390
- return [...recorded, ...(await storedPatterns(ctx))];
395
+ const listed = await ctx.permission.list({ sessionID });
396
+ const requests = listed?.data ?? listed;
397
+ for (const request of Array.isArray(requests) ? requests : []) {
398
+ try {
399
+ await ctx.permission.reply({ sessionID, requestID: request.id, decision: "reject" });
400
+ } catch {
401
+ // The request may have settled meanwhile.
402
+ }
403
+ }
391
404
  } catch {
392
- return [...recorded];
405
+ // Removing the session ends whatever is left.
393
406
  }
394
407
  }
395
408
 
396
- function matches(resource, patterns) {
397
- return patterns.some((pattern) => wildcardMatch(resource, pattern));
409
+ // One probe assert in the probe session: the effect this package's evaluate
410
+ // hook saw for it, or undefined when it saw none or the assert timed out. The
411
+ // token stays registered until the assert settles, so an evaluation that
412
+ // reaches the hook only after the timeout (a slow earlier hook) is still
413
+ // denied instead of prompting in a probe session that is already gone.
414
+ async function probeEffect(ctx, sessionID, agent, resources) {
415
+ const token = randomUUID();
416
+ const slot = { sessionID, effect: undefined };
417
+ PROBES.set(token, slot);
418
+ const settled = Promise.resolve()
419
+ .then(() =>
420
+ ctx.permission.assert({ sessionID, agent, action: EXTERNAL, resources, metadata: { [PROBE_KEY]: token } }),
421
+ )
422
+ .then(
423
+ () => "settled",
424
+ // Expected: the evaluate hook denies every probe evaluation.
425
+ () => "settled",
426
+ )
427
+ .finally(() => PROBES.delete(token));
428
+ let timer;
429
+ try {
430
+ const expired = new Promise((resolve) => {
431
+ timer = setTimeout(resolve, PROBE_TIMEOUT_MS, "expired");
432
+ });
433
+ if ((await Promise.race([settled, expired])) === "expired") {
434
+ await rejectPending(ctx, sessionID);
435
+ return undefined;
436
+ }
437
+ return slot.effect;
438
+ } finally {
439
+ clearTimeout(timer);
440
+ }
398
441
  }
399
442
 
400
- // Record the `save` patterns of every external_directory request the user
401
- // answers "always", as the host saves them (any agent and session of the
402
- // project). A reply this package never saw asked, any other reply, and a reply
403
- // to a request a recorded pattern already partly covers (the host's
404
- // re-evaluation of other pending requests, which saves nothing) record
405
- // nothing; the cost is one more prompt when a genuine "always" overlaps an
406
- // earlier record. Events are handled one at a time; a failed write loses only
407
- // that record, until this instance is rebuilt.
408
- function trackSavedApprovals(ctx, signal, recorded) {
409
- const asked = new Map();
410
- void (async () => {
411
- for await (const event of ctx.event.subscribe({ signal })) {
443
+ // Whether the project's saved approvals cover every resource for this agent,
444
+ // asked of the host in a short-lived child session (see the contract above).
445
+ // The sentinel sits at the filesystem root rather than under the temp
446
+ // directory, which users commonly approve. Any failure, or no effect seen,
447
+ // counts as not covered.
448
+ async function savedApprovalsCover(ctx, sessionID, agent, resources) {
449
+ let probe;
450
+ try {
451
+ const created = await ctx.session.create({
452
+ parentID: sessionID,
453
+ agent,
454
+ title: PROBE_TITLE,
455
+ permissions: [{ action: EXTERNAL, resource: "*", effect: "ask" }],
456
+ });
457
+ probe = (created?.data ?? created)?.id;
458
+ if (typeof probe !== "string") return false;
459
+ if ((await probeEffect(ctx, probe, agent, resources)) !== "allow") return false;
460
+ const sentinel = await probeEffect(ctx, probe, agent, [`/ycc-saved-approval-probe-${randomUUID()}/*`]);
461
+ return sentinel !== undefined && sentinel !== "allow";
462
+ } catch {
463
+ return false;
464
+ } finally {
465
+ if (probe !== undefined) {
412
466
  try {
413
- if (event.type === "permission.asked") {
414
- const { id, action, resources, save } = event.data;
415
- if (action === EXTERNAL && save?.length) asked.set(id, { resources, save });
416
- } else if (event.type === "permission.replied") {
417
- const request = asked.get(event.data.requestID);
418
- asked.delete(event.data.requestID);
419
- if (!request || event.data.reply !== "always") continue;
420
- const known = [...recorded];
421
- if (request.resources.some((resource) => matches(resource, known))) continue;
422
- for (const pattern of request.save) recorded.add(pattern);
423
- for (const pattern of request.save) {
424
- await ctx.storage.set(savedPrefix(ctx) + encodeURIComponent(pattern), pattern);
425
- }
426
- }
467
+ await ctx.session.remove({ sessionID: probe });
427
468
  } catch {
428
- // Unrecorded patterns prompt again once this instance is rebuilt.
469
+ // Best effort: the probe holds no pending request by now.
429
470
  }
430
471
  }
431
- })().catch(() => {
432
- // Without the event stream nothing is recorded: saved approvals prompt.
433
- });
472
+ }
473
+ }
474
+
475
+ // Old package versions kept their own record of saved approvals, one key per
476
+ // pattern under this prefix. Best effort; setup never waits for it.
477
+ async function removeStaleRecords(ctx) {
478
+ const prefix = `saved/${EXTERNAL}/${encodeURIComponent(ctx.location.project.id)}/`;
479
+ const keys = [];
480
+ let after;
481
+ do {
482
+ const page = await ctx.storage.scan({ prefix, after });
483
+ for (const entry of page.entries) keys.push(entry.key);
484
+ after = page.next;
485
+ } while (after !== undefined);
486
+ for (const key of keys) await ctx.storage.remove(key);
434
487
  }
435
488
 
436
489
  // A packaged deny is enforced on top of the host's effect for every action.
437
490
  // Every restricted ruleset starts with `* * deny`, so any action or resource
438
491
  // outside the agent's own allowlist is denied here. The packaged `ask` a
439
492
  // restricted agent ships is external_directory: a host allow is raised back
440
- // to ask unless a recorded saved approval covers every resource it asks for,
493
+ // to ask unless the host's saved approvals cover every resource it asks for,
441
494
  // so a config-level allow cannot skip the prompt and an "always" answer is not
442
495
  // prompted again. Every other action keeps the host's allow or ask.
443
- async function registerPermissionFloor(ctx, signal) {
496
+ async function registerPermissionFloor(ctx) {
444
497
  if (RESTRICTED_RULES.size === 0) return;
445
- const recorded = new Set();
446
- trackSavedApprovals(ctx, signal, recorded);
447
- try {
448
- for (const pattern of await storedPatterns(ctx)) recorded.add(pattern);
449
- } catch {
450
- // Unloaded records are still read by the evaluate hook's own scan.
451
- }
498
+ void removeStaleRecords(ctx).catch(() => {
499
+ // Stale records grant nothing; they only take up storage.
500
+ });
452
501
  await ctx.permission.hook("evaluate", async (event) => {
502
+ const token = event.metadata?.[PROBE_KEY];
503
+ const probe = typeof token === "string" ? PROBES.get(token) : undefined;
504
+ if (probe && probe.sessionID === event.sessionID) {
505
+ // This copy's saved-approval probe: keep the effect, never prompt.
506
+ probe.effect = event.effect;
507
+ event.effect = "deny";
508
+ return;
509
+ }
453
510
  if (event.effect === "deny") return;
454
511
  let agent = event.agent;
455
512
  if (agent === undefined) {
@@ -473,9 +530,7 @@ async function registerPermissionFloor(ctx, signal) {
473
530
  if (event.effect !== "allow" || event.action !== EXTERNAL) return;
474
531
  const asked = event.resources.filter((_, index) => effects[index] === "ask");
475
532
  if (asked.length === 0) return;
476
- if (asked.every((resource) => matches(resource, [...recorded]))) return;
477
- const saved = await savedPatterns(ctx, recorded);
478
- if (!asked.every((resource) => matches(resource, saved))) event.effect = "ask";
533
+ if (!(await savedApprovalsCover(ctx, event.sessionID, agent, asked))) event.effect = "ask";
479
534
  });
480
535
  await ctx.tool.hook("execute.before", async (event) => {
481
536
  const rules = RESTRICTED_RULES.get(event.agent);
@@ -501,18 +556,14 @@ export default {
501
556
  id: "yandy-r.ycc-opencode",
502
557
  async setup(ctx) {
503
558
  const renderedRoot = renderTree();
504
- const events = new AbortController();
505
- const dispose = () => {
506
- events.abort();
507
- teardown(renderedRoot);
508
- };
559
+ const dispose = () => teardown(renderedRoot);
509
560
  try {
510
561
  await registerSkills(ctx, renderedRoot);
511
562
  await registerAgents(ctx, renderedRoot);
512
563
  await registerCommands(ctx);
513
564
  await registerMcp(ctx);
514
565
  await registerInstructions(ctx);
515
- await registerPermissionFloor(ctx, events.signal);
566
+ await registerPermissionFloor(ctx);
516
567
  await registerSensitiveGuard(ctx);
517
568
  } catch (error) {
518
569
  dispose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yandy-r/ycc-opencode",
3
- "version": "6.1.1",
3
+ "version": "6.2.1",
4
4
  "description": "Experimental opt-in OpenCode V2 plugin registering the ycc bundle (skills, agents, commands, MCP servers, and session instructions) through its setup hook. The file-copy install remains the primary path.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/registration.json CHANGED
@@ -7230,10 +7230,6 @@
7230
7230
  "type": "remote",
7231
7231
  "url": "https://mcp.linear.app/mcp"
7232
7232
  },
7233
- "linear-personal": {
7234
- "type": "remote",
7235
- "url": "https://mcp.linear.app/mcp"
7236
- },
7237
7233
  "vercel": {
7238
7234
  "type": "remote",
7239
7235
  "url": "https://mcp.vercel.com"