@yandy-r/ycc-opencode 6.0.0 → 6.1.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 (63) hide show
  1. package/AGENTS.md +3 -2
  2. package/README.md +10 -1
  3. package/agents/backport-conflict-resolver.md +346 -4
  4. package/agents/db-modifier.md +346 -4
  5. package/agents/git-cleanup.md +3 -2
  6. package/agents/pr-comment-fixer.md +365 -23
  7. package/agents/release-fix-applier.md +383 -19
  8. package/agents/review-fixer.md +371 -26
  9. package/index.js +268 -5
  10. package/package.json +3 -2
  11. package/registration.json +4113 -1238
  12. package/shared/references/ci-monitoring.md +11 -1
  13. package/shared/references/goal-pairing.md +4 -2
  14. package/shared/references/question-policy.md +99 -0
  15. package/shared/references/review-dispatch.md +4 -2
  16. package/shared/references/standalone-dispatch.md +4 -2
  17. package/shared/references/target-capability-matrix.md +227 -36
  18. package/shared/references/worktree-strategy.md +20 -4
  19. package/shared/scripts/worktree-paths.sh +7 -2
  20. package/skills/backport/SKILL.md +2 -0
  21. package/skills/blueprint/SKILL.md +2 -0
  22. package/skills/bundle-author/SKILL.md +2 -0
  23. package/skills/bundle-release/SKILL.md +11 -7
  24. package/skills/bundle-release/references/release-checklist.md +4 -4
  25. package/skills/bundle-release/references/version-policy.md +21 -15
  26. package/skills/bundle-release/scripts/bump-version.sh +5 -3
  27. package/skills/bundle-release/scripts/draft-notes.sh +1 -1
  28. package/skills/bundle-release/scripts/preflight.sh +2 -1
  29. package/skills/bundle-release/scripts/release_versions.py +21 -7
  30. package/skills/clean/SKILL.md +2 -0
  31. package/skills/code-report/SKILL.md +2 -0
  32. package/skills/code-review/SKILL.md +2 -0
  33. package/skills/compatibility-audit/SKILL.md +9 -6
  34. package/skills/compatibility-audit/references/reading-the-report.md +4 -1
  35. package/skills/compatibility-audit/scripts/audit-install-assumptions.sh +71 -12
  36. package/skills/compatibility-audit/scripts/audit-target-features.sh +58 -20
  37. package/skills/feature-research/SKILL.md +2 -0
  38. package/skills/formatters/SKILL.md +2 -0
  39. package/skills/git-cleanup/SKILL.md +19 -5
  40. package/skills/git-cleanup/references/active-code-rules.md +8 -3
  41. package/skills/git-workflow/SKILL.md +2 -0
  42. package/skills/implement-plan/SKILL.md +2 -0
  43. package/skills/init/SKILL.md +2 -0
  44. package/skills/init/templates/git/gitignore.tmpl +1 -0
  45. package/skills/plan/SKILL.md +2 -0
  46. package/skills/plan-workflow/SKILL.md +4 -1
  47. package/skills/pr-autofix/SKILL.md +2 -0
  48. package/skills/prp-implement/SKILL.md +2 -0
  49. package/skills/prp-plan/SKILL.md +2 -2
  50. package/skills/prp-pr/SKILL.md +2 -0
  51. package/skills/prp-prd/SKILL.md +2 -0
  52. package/skills/prp-spec/SKILL.md +2 -0
  53. package/skills/quick-review/SKILL.md +5 -3
  54. package/skills/release-model/SKILL.md +2 -0
  55. package/skills/releaser/SKILL.md +2 -0
  56. package/skills/research-to-issues/SKILL.md +2 -0
  57. package/skills/resume-session/SKILL.md +2 -0
  58. package/skills/review-fix/SKILL.md +11 -9
  59. package/skills/save-session/SKILL.md +2 -0
  60. package/ycc-sensitive-guard/index.js +621 -0
  61. package/ycc-sensitive-guard/package.json +7 -0
  62. package/ycc-sensitive-guard/policy.json +40 -0
  63. package/skills/prp-plan/scripts/preflight-enhanced-agents.sh +0 -111
package/index.js CHANGED
@@ -28,6 +28,54 @@
28
28
  // - Instructions have no config entry on v2.0.29; the only plugin-side
29
29
  // mechanism is session.hook("context") pushing a typed
30
30
  // { type: "text", text } SystemPart (packages/plugin/src/promise/session.ts).
31
+ // - The sensitive-file guard (ycc-sensitive-guard/, the same module
32
+ // the file-copy install loads as its own plugin) registers
33
+ // tool.hook("execute.before"/"execute.after"), the guarded ycc_grep/
34
+ // ycc_glob tools, and their context hook for the restricted specialists
35
+ // named in its policy.json (verified on v2.0.32 sources).
36
+ // - Permission floor for those restricted specialists. Agent state is built
37
+ // as built-ins (`pre`) -> package transforms -> opencode.config.agent
38
+ // (`post`; plugin/supervisor.ts, plugin/internal.ts), and config.agent
39
+ // appends the config documents' top-level permissions to every agent
40
+ // already registered (config/plugin/agent.ts). Evaluation is last match
41
+ // wins (permission.ts evaluate), so a host-wide allow would otherwise
42
+ // override a package agent's own rules. Three hooks re-apply the
43
+ // restricted agent's packaged ruleset with the same wildcard and
44
+ // last-match semantics; none of them loosens anything:
45
+ // * ctx.permission.hook("evaluate") runs after the merged rules produce
46
+ // an allow/ask effect (permission.ts evaluateInput; a deny
47
+ // short-circuits before hooks) and its mutated effect/message is
48
+ // final (plugin/src/promise/permission.ts). It turns the effect into
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.
53
+ // * ctx.tool.hook("execute.before") rejects a call to a tool whose
54
+ // permission action the packaged rules wholly deny, which also covers
55
+ // tools that never request a permission.
56
+ // * ctx.session.hook("context") removes those tools from the model's
57
+ // view (the host offers what the merged rules allow; tool.ts
58
+ // snapshot/whollyDisabled).
59
+ // registerAgents assigns each record its own copy of the packaged rules
60
+ // and request settings, because config.agent mutates them in place.
61
+ //
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.
31
79
  //
32
80
  // Coexistence with the primary file-copy install (install.sh --target
33
81
  // opencode): config agents/skills/commands apply in the `post` plugin group,
@@ -42,15 +90,31 @@
42
90
  // Commands never collide: every package command is `ycc:<skill>` while the
43
91
  // file-copy commands stay bare, so both remain available side by side. The
44
92
  // context hook does not push instructions already present on the event, so
45
- // an installed file-copy AGENTS.md is not duplicated.
93
+ // an installed file-copy AGENTS.md is not duplicated. When both channels load
94
+ // the sensitive-file guard, both hook sets apply the same policy; a call one
95
+ // rejects is rejected, and filtering grep/glob results twice is idempotent.
46
96
 
47
97
  import { fileURLToPath } from "node:url";
48
98
  import { dirname, isAbsolute, join, relative as relativePath } from "node:path";
49
99
  import { cpSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
50
100
  import { tmpdir } from "node:os";
51
101
 
102
+ import { registerSensitiveGuard } from "./ycc-sensitive-guard/index.js";
103
+
52
104
  const PACKAGE_ROOT = dirname(fileURLToPath(import.meta.url));
53
105
  const REGISTRATION = JSON.parse(readFileSync(join(PACKAGE_ROOT, "registration.json"), "utf8"));
106
+ // Restricted specialists come from the guard policy the package ships (one
107
+ // source of truth with the file-copy guard). Their packaged rules are
108
+ // snapshotted at load, before any host transform can touch them.
109
+ const GUARD_POLICY = JSON.parse(readFileSync(join(PACKAGE_ROOT, "ycc-sensitive-guard", "policy.json"), "utf8"));
110
+ const RESTRICTED_RULES = new Map(
111
+ (REGISTRATION.agents ?? [])
112
+ .filter((agent) => GUARD_POLICY.restricted_agents.includes(agent.id) && Array.isArray(agent.permissions))
113
+ .map((agent) => [agent.id, structuredClone(agent.permissions)]),
114
+ );
115
+ const FLOOR_DENIED = "Permission denied by ycc restricted-agent rules: ";
116
+ // The only action the floor raises from allow to ask.
117
+ const EXTERNAL = "external_directory";
54
118
 
55
119
  // Token the generator writes where a package asset path is needed; it points
56
120
  // at the *rendered* tree created below, which sits beside the package root.
@@ -171,11 +235,12 @@ async function registerAgents(ctx, renderedRoot) {
171
235
  record.description = agent.description;
172
236
  record.mode = agent.mode;
173
237
  record.system = prompt;
174
- if (agent.permissions !== undefined) record.permissions = agent.permissions;
238
+ // A copy: the host appends its own rules to this array in place.
239
+ if (agent.permissions) record.permissions = structuredClone(agent.permissions);
175
240
  if (agent.color !== undefined) record.color = agent.color;
176
241
  if (agent.steps !== undefined) record.steps = agent.steps;
177
242
  if (agent.hidden !== undefined) record.hidden = agent.hidden;
178
- if (agent.request !== undefined) record.request = agent.request;
243
+ if (agent.request !== undefined) record.request = structuredClone(agent.request);
179
244
  if (agent.model !== undefined) record.model = parseModelRef(agent.model);
180
245
  });
181
246
  }
@@ -241,20 +306,218 @@ async function registerInstructions(ctx) {
241
306
  });
242
307
  }
243
308
 
309
+ // Exact port of opencode v2.0.32 core/src/util/wildcard.ts match().
310
+ function wildcardMatch(input, pattern) {
311
+ let escaped = pattern
312
+ .replaceAll("\\", "/")
313
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
314
+ .replace(/\*/g, ".*")
315
+ .replace(/\?/g, ".");
316
+ if (escaped.endsWith(" .*")) escaped = escaped.slice(0, -3) + "( .*)?";
317
+ return new RegExp("^" + escaped + "$", process.platform === "win32" ? "si" : "s").test(
318
+ String(input).replaceAll("\\", "/"),
319
+ );
320
+ }
321
+
322
+ // Last matching rule wins (core/src/permission.ts evaluate).
323
+ function packagedEffect(rules, action, resource) {
324
+ return rules.findLast((rule) => wildcardMatch(action, rule.action) && wildcardMatch(resource, rule.resource))
325
+ ?.effect;
326
+ }
327
+
328
+ // core/src/tool.ts whollyDisabled: the last rule for the action denies `*`.
329
+ function whollyDenied(rules, action) {
330
+ const rule = rules.findLast((item) => wildcardMatch(action, item.action));
331
+ return rule?.resource === "*" && rule.effect === "deny";
332
+ }
333
+
334
+ // Registered tool id -> the permission action that gates it (`options.permission`,
335
+ // e.g. write/patch -> edit; otherwise the id, namespaced like
336
+ // core/src/tool/runtime.ts effectiveName). Unknown tools are gated by their own
337
+ // name, which every restricted ruleset's `* * deny` covers.
338
+ async function toolPermissions(ctx) {
339
+ const permissions = new Map();
340
+ try {
341
+ for (const tool of (await ctx.tool.list?.()) ?? []) {
342
+ const name = String(tool.name).replace(/[^a-zA-Z0-9_-]/g, "_");
343
+ const namespace = tool.options?.namespace;
344
+ const id = namespace === undefined ? name : `${namespace.replaceAll(".", "_")}_${name}`;
345
+ permissions.set(id, tool.options?.permission ?? id);
346
+ }
347
+ } catch {
348
+ // Fall back to tool names.
349
+ }
350
+ return permissions;
351
+ }
352
+
353
+ // The guard shows ycc_grep/ycc_glob to restricted agents as grep/glob. A call
354
+ // under the built-in name is judged as the guarded tool by execute.before; a
355
+ // call that reaches the unguarded built-in still asks for `grep`/`glob`, which
356
+ // the evaluate hook denies. In the context hook a `grep`/`glob` key is the
357
+ // guarded tool only once the guard has renamed it (a guard loaded before this
358
+ // package), i.e. when the guarded key itself is no longer offered.
359
+ const GUARDED_ALIASES = { grep: "ycc_grep", glob: "ycc_glob" };
360
+
361
+ async function sessionAgent(ctx, sessionID) {
362
+ const session = await ctx.session.get({ sessionID });
363
+ return (session?.data ?? session)?.agent;
364
+ }
365
+
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) {
389
+ try {
390
+ return [...recorded, ...(await storedPatterns(ctx))];
391
+ } catch {
392
+ return [...recorded];
393
+ }
394
+ }
395
+
396
+ function matches(resource, patterns) {
397
+ return patterns.some((pattern) => wildcardMatch(resource, pattern));
398
+ }
399
+
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 })) {
412
+ 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
+ }
427
+ } catch {
428
+ // Unrecorded patterns prompt again once this instance is rebuilt.
429
+ }
430
+ }
431
+ })().catch(() => {
432
+ // Without the event stream nothing is recorded: saved approvals prompt.
433
+ });
434
+ }
435
+
436
+ // A packaged deny is enforced on top of the host's effect for every action.
437
+ // Every restricted ruleset starts with `* * deny`, so any action or resource
438
+ // outside the agent's own allowlist is denied here. The packaged `ask` a
439
+ // 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,
441
+ // so a config-level allow cannot skip the prompt and an "always" answer is not
442
+ // prompted again. Every other action keeps the host's allow or ask.
443
+ async function registerPermissionFloor(ctx, signal) {
444
+ 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
+ }
452
+ await ctx.permission.hook("evaluate", async (event) => {
453
+ if (event.effect === "deny") return;
454
+ let agent = event.agent;
455
+ if (agent === undefined) {
456
+ try {
457
+ agent = await sessionAgent(ctx, event.sessionID);
458
+ } catch {
459
+ // The session's agent is unknown, so it may be restricted.
460
+ event.effect = "deny";
461
+ event.message = FLOOR_DENIED + event.action;
462
+ return;
463
+ }
464
+ }
465
+ const rules = RESTRICTED_RULES.get(agent);
466
+ if (!rules) return;
467
+ const effects = event.resources.map((resource) => packagedEffect(rules, event.action, resource));
468
+ if (effects.includes("deny")) {
469
+ event.effect = "deny";
470
+ event.message = FLOOR_DENIED + event.action;
471
+ return;
472
+ }
473
+ if (event.effect !== "allow" || event.action !== EXTERNAL) return;
474
+ const asked = event.resources.filter((_, index) => effects[index] === "ask");
475
+ 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";
479
+ });
480
+ await ctx.tool.hook("execute.before", async (event) => {
481
+ const rules = RESTRICTED_RULES.get(event.agent);
482
+ if (!rules) return;
483
+ const permissions = await toolPermissions(ctx);
484
+ const name = GUARDED_ALIASES[event.tool] ?? event.tool;
485
+ const action = permissions.get(name) ?? name;
486
+ if (whollyDenied(rules, action)) throw new Error(FLOOR_DENIED + action);
487
+ });
488
+ await ctx.session.hook("context", async (event) => {
489
+ const rules = RESTRICTED_RULES.get(event.agent);
490
+ if (!rules) return;
491
+ const permissions = await toolPermissions(ctx);
492
+ for (const name of Object.keys(event.tools)) {
493
+ const alias = GUARDED_ALIASES[name];
494
+ const tool = alias && !(alias in event.tools) ? alias : name;
495
+ if (whollyDenied(rules, permissions.get(tool) ?? tool)) delete event.tools[name];
496
+ }
497
+ });
498
+ }
499
+
244
500
  export default {
245
501
  id: "yandy-r.ycc-opencode",
246
502
  async setup(ctx) {
247
503
  const renderedRoot = renderTree();
504
+ const events = new AbortController();
505
+ const dispose = () => {
506
+ events.abort();
507
+ teardown(renderedRoot);
508
+ };
248
509
  try {
249
510
  await registerSkills(ctx, renderedRoot);
250
511
  await registerAgents(ctx, renderedRoot);
251
512
  await registerCommands(ctx);
252
513
  await registerMcp(ctx);
253
514
  await registerInstructions(ctx);
515
+ await registerPermissionFloor(ctx, events.signal);
516
+ await registerSensitiveGuard(ctx);
254
517
  } catch (error) {
255
- teardown(renderedRoot);
518
+ dispose();
256
519
  throw error;
257
520
  }
258
- return () => teardown(renderedRoot);
521
+ return dispose;
259
522
  },
260
523
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yandy-r/ycc-opencode",
3
- "version": "6.0.0",
4
- "description": "Experimental opt-in OpenCode V2 plugin registering the ycc bundle (skills, agents, commands, MCP servers, and session instructions) through its setup hook. Unlisted; the file-copy install remains the primary path.",
3
+ "version": "6.1.1",
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",
7
7
  "exports": {
@@ -10,6 +10,7 @@
10
10
  "files": [
11
11
  "index.js",
12
12
  "registration.json",
13
+ "ycc-sensitive-guard/",
13
14
  "skills/",
14
15
  "shared/",
15
16
  "agents/",