@chronova/wiki-agent 1.6.5 → 1.7.0

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/dist/prompt.js CHANGED
@@ -34,9 +34,9 @@ You have a FIXED, LIMITED set of tools. You CANNOT execute arbitrary commands on
34
34
  - ast_search: search code using an inline ast-grep YAML rule. More powerful than ast_grep — supports relational/inside/has constraints. Use for complex structural queries a single pattern cannot express.
35
35
  - write_file, edit_file: write or edit documentation files. These are the ONLY mutating tools and are constrained to paths under .wiki/.
36
36
  - git: run a READ-ONLY git subcommand (log, diff, show, ls-files, blame, status, remote, describe, rev-parse, shortlog, name-rev, ls-tree, cat-file, reflog). This is the ONLY way to access repository history. Mutating git operations and arbitrary shell commands are NOT available — do not attempt them and do not assume any command outside this list will work.
37
- - gh: run a READ-ONLY GitHub CLI (gh) subcommand in the project root. Use to inspect open pull requests, check wiki staging PR branches, and compare timestamps. Only read-only inspection subcommands are allowed (pr list, pr view, pr diff, pr checks, repo view, issue list, issue view, run list, run view, search, release list, release view, label list, workflow list, workflow view). Mutating operations (create, edit, close, merge, delete, etc.) are blocked.
37
+ - gh: run a GitHub CLI (gh) subcommand in the project root. Read-only inspection is always allowed (pr list, pr view, pr diff, repo view, issue list, etc.). Two mutating operations are permitted ONLY on wiki staging PRs (branches matching wiki/staging-*): 'pr close' and 'pr comment'. All other mutating operations (create, merge, edit, delete, etc.) are blocked.
38
38
 
39
- You cannot run build tools, package managers, test runners, scripts, or any program other than git (read-only) and gh (read-only). If documentation requires information only obtainable by executing code, say so explicitly rather than attempting to run it. Ground every important claim in source files, existing docs, or git evidence you have inspected.
39
+ You cannot run build tools, package managers, test runners, scripts, or any program other than git (read-only) and gh. If documentation requires information only obtainable by executing code, say so explicitly rather than attempting to run it. Ground every important claim in source files, existing docs, or git evidence you have inspected.
40
40
 
41
41
  # Output location
42
42
  - Write documentation under .wiki/ in the project root. Use paths such as .wiki/quickstart.md, .wiki/architecture/overview.md, .wiki/cli/usage.md.
@@ -78,8 +78,12 @@ Use only the tools listed above. Do not invent files, modules, APIs, business ru
78
78
  - Step 3: Get the repository's latest commit timestamp (also Unix seconds):
79
79
  git log -1 --format=%ct
80
80
  - Step 4: Compare the integers. If any open staging PR's branch timestamp is greater than or equal to the latest commit timestamp, that staging PR already reflects this commit (or a newer one). Abandon the update: do not write or edit any files. State that a newer staging PR already exists (include the PR number and branch name) and stop.
81
+ - Step 5: Close stale staging PRs. For every open wiki/staging-* PR whose branch timestamp is LESS than the latest commit timestamp (i.e. it is older than the current commit), close it with a comment:
82
+ gh pr comment <number> --body "This branch is from an earlier staging run and is stale. Closing"
83
+ gh pr close <number>
84
+ Do this BEFORE proceeding with your own update. This keeps the PR queue clean and avoids confusing reviewers with outdated snapshots.
81
85
  - If the gh command fails (e.g. gh is not authenticated, no GitHub remote), skip this check and proceed with the update normally.
82
- - This check prevents duplicate staging PRs and avoids overwriting a newer pending review with older content.
86
+ - This check prevents duplicate staging PRs, closes stale ones, and avoids overwriting a newer pending review with older content.
83
87
 
84
88
  # Loop prevention
85
89
  - Work in phases: discover → plan → write → verify. Do not restart discovery once you have moved to planning or writing.
package/dist/tools.js CHANGED
@@ -444,13 +444,13 @@ export function createTools(projectRoot) {
444
444
  type: "function",
445
445
  function: {
446
446
  name: "gh",
447
- description: "Run a read-only GitHub CLI (gh) subcommand in the project root. Use to inspect open pull requests, check wiki staging PR branches, and compare timestamps. Only read-only inspection subcommands are permitted no mutating operations (create, edit, close, merge, delete, etc.).",
447
+ description: "Run a GitHub CLI (gh) subcommand in the project root. Read-only inspection (pr list, pr view, pr diff, repo view, issue list, etc.) is always allowed. Two mutating operations are permitted but ONLY on wiki staging PRs (branches matching wiki/staging-*): `gh pr close <number>` and `gh pr comment <number> --body <text>`. Use to inspect open PRs, check staging branch timestamps, and close stale wiki staging PRs with a comment.",
448
448
  parameters: {
449
449
  type: "object",
450
450
  properties: {
451
451
  args: {
452
452
  type: "string",
453
- description: "gh subcommand and arguments, without the leading 'gh'. Example: 'pr list --state open --head wiki/staging-* --json headRefName,updatedAt,number,title', 'pr view <number> --json updatedAt,headRefName,body', 'pr view <number> --json files'.",
453
+ description: "gh subcommand and arguments, without the leading 'gh'. Example: 'pr list --state open --json number,headRefName,title', 'pr view <number> --json headRefName', 'pr close <number> --comment \"This branch is from an earlier staging run and is stale. Closing\"', 'pr comment <number> --body \"stale\"'.",
454
454
  },
455
455
  },
456
456
  required: ["args"],
@@ -459,33 +459,57 @@ export function createTools(projectRoot) {
459
459
  },
460
460
  handler: async (args) => {
461
461
  const argString = args.args ?? "";
462
- // Only read-only / inspection subcommands are permitted. The agent
463
- // cannot mutate GitHub state through this tool.
464
462
  const ALLOWED_GH_SUBCOMMANDS = {
465
463
  pr: true, issue: true, repo: true, run: true, api: true,
466
464
  "search": true, release: true, label: true, workflow: true,
467
465
  };
468
- // Mutating subcommand prefixes that must never run, even under an
469
- // allowed top-level command (e.g. `gh pr create`, `gh pr merge`).
466
+ // Actions that are always blocked (never safe for an automated agent).
470
467
  const BLOCKED_ACTIONS = {
471
- create: true, edit: true, close: true, reopen: true, merge: true,
472
- delete: true, ready: true, review: true, comment: true,
468
+ create: true, edit: true, reopen: true, merge: true,
469
+ delete: true, ready: true, review: true,
473
470
  lock: true, unlock: true, assign: true, unassign: true,
474
471
  label: true, unlabel: true, transfer: true, archive: true,
475
472
  unarchive: true, deploy: true, rerun: true, cancel: true,
476
473
  publish: true, set: true, add: true, remove: true,
477
474
  };
475
+ // Actions allowed ONLY on wiki staging PRs (branches matching
476
+ // wiki/staging-*). The handler verifies the PR's headRefName before
477
+ // executing these.
478
+ const STAGING_ONLY_ACTIONS = {
479
+ close: true, comment: true,
480
+ };
478
481
  const tokens = argString.trim().split(/\s+/);
479
482
  const subcommand = tokens[0] ?? "";
480
483
  if (!ALLOWED_GH_SUBCOMMANDS[subcommand]) {
481
- return `Error: gh subcommand '${subcommand}' is not permitted. Only read-only inspection subcommands are allowed (pr, issue, repo, run, api, search, release, label, workflow).`;
484
+ return `Error: gh subcommand '${subcommand}' is not permitted. Only inspection subcommands and pr close/comment on wiki staging PRs are allowed (pr, issue, repo, run, api, search, release, label, workflow).`;
482
485
  }
483
- // For `gh pr` and similar, check the action token (second token)
484
- // against the blocklist. `gh pr list`, `gh pr view`, `gh pr diff`,
485
- // `gh pr checks` are read-only and allowed.
486
486
  const action = tokens[1] ?? "";
487
487
  if (BLOCKED_ACTIONS[action]) {
488
- return `Error: gh ${subcommand} ${action} is a mutating operation. Only read-only inspection is allowed (list, view, diff, checks, status).`;
488
+ return `Error: gh ${subcommand} ${action} is a blocked operation.`;
489
+ }
490
+ // For close/comment on PRs, verify the target is a wiki staging PR.
491
+ // The PR number is the third token: 'gh pr close <number>' or
492
+ // 'gh pr comment <number> --body ...'.
493
+ if (STAGING_ONLY_ACTIONS[action] && subcommand === "pr") {
494
+ const prNumber = tokens[2] ?? "";
495
+ if (!/^\d+$/.test(prNumber)) {
496
+ return `Error: a valid PR number is required for gh pr ${action}.`;
497
+ }
498
+ // Fetch the PR's headRefName to verify it's a wiki staging branch.
499
+ try {
500
+ const { stdout } = await execAsync(`gh pr view ${prNumber} --json headRefName`, { cwd: projectRoot, maxBuffer: 1024 * 1024, timeout: 30_000 });
501
+ const parsed = JSON.parse(stdout);
502
+ if (!parsed.headRefName?.startsWith("wiki/staging-")) {
503
+ return `Error: gh pr ${action} is only permitted on wiki staging PRs (branches matching wiki/staging-*). PR #${prNumber} has headRefName '${parsed.headRefName ?? "unknown"}'.`;
504
+ }
505
+ }
506
+ catch (error) {
507
+ const message = error instanceof Error ? error.message : String(error);
508
+ return `Error: could not verify PR #${prNumber} is a wiki staging PR: ${message}`;
509
+ }
510
+ }
511
+ else if (STAGING_ONLY_ACTIONS[action]) {
512
+ return `Error: gh ${subcommand} ${action} is not supported. Only gh pr ${action} is permitted, and only on wiki staging PRs.`;
489
513
  }
490
514
  // Reject shell metacharacters that could chain commands or inject
491
515
  // flags, same guard as the git tool.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chronova/wiki-agent",
3
- "version": "1.6.5",
3
+ "version": "1.7.0",
4
4
  "description": "Standalone Ollama-only documentation agent",
5
5
  "type": "module",
6
6
  "bin": {