@gitset-dev/cli 2.4.1 → 2.4.3
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/README.md +35 -0
- package/lib/knowledge/ci.js +12 -2
- package/package.json +1 -1
- package/src/commands/knowledge.js +48 -5
package/README.md
CHANGED
|
@@ -87,6 +87,41 @@ Local tools (no AI):
|
|
|
87
87
|
Common flags: `--provider` `--model` `--yes` `--print` `--json`. Run
|
|
88
88
|
`gitset help <command>` for everything else.
|
|
89
89
|
|
|
90
|
+
## Knowledge Mapper
|
|
91
|
+
|
|
92
|
+
`gitset knowledge` builds and maintains `docs/gitset-knowledge/` — a
|
|
93
|
+
structured, always-current map of your codebase (architecture, module
|
|
94
|
+
boundaries, commands, dependency graph) that both developers and AI coding
|
|
95
|
+
agents can read before touching your code. It's generated from your source
|
|
96
|
+
code, manifests, and CI configuration — never from your existing prose docs,
|
|
97
|
+
so it can't inherit their drift.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
gitset knowledge init # scaffold optional .gitset-knowledge.json (include/exclude globs)
|
|
101
|
+
gitset knowledge scan # zero AI calls — discovers files, prints the plan + exact cost estimate
|
|
102
|
+
gitset knowledge generate # shows the estimate again, asks to confirm, then writes the knowledge base
|
|
103
|
+
gitset knowledge update # incremental — only changed modules (and their direct importers) are re-summarized
|
|
104
|
+
gitset knowledge automate # writes a GitHub Actions workflow that runs `update` in CI and opens a review PR
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
It's a six-stage local pipeline (Discover → Map → Summarize → Plan → Write →
|
|
108
|
+
Validate): Discover and Map walk the repository and build an import graph
|
|
109
|
+
with zero AI calls; only Summarize and Write touch your configured provider
|
|
110
|
+
— there's no separate "default model" for this tool, it uses whatever you
|
|
111
|
+
picked with `gitset config`; and a deterministic Validate pass checks every
|
|
112
|
+
generated link, command, and script before anything is written to disk.
|
|
113
|
+
Secrets are redacted locally before any file content is sent, and prose
|
|
114
|
+
docs / test file bodies are listed structurally but never sent at all.
|
|
115
|
+
|
|
116
|
+
`gitset knowledge automate` needs "Allow GitHub Actions to create and
|
|
117
|
+
approve pull requests" enabled (**Settings > Actions > General > Workflow
|
|
118
|
+
permissions**) for the update PR to open. It detects this automatically and
|
|
119
|
+
offers to enable it via the GitHub API — asked first, like everything else
|
|
120
|
+
in this command. If you decline, or the API call fails (no admin access, an
|
|
121
|
+
org policy locking the setting), the scheduled update still runs and
|
|
122
|
+
commits safely; only the review-PR step fails, and the workflow run shows
|
|
123
|
+
that failure clearly rather than hide it.
|
|
124
|
+
|
|
90
125
|
## Templates
|
|
91
126
|
|
|
92
127
|
Define your commit style, issue structure, PR format, README skeleton, or
|
package/lib/knowledge/ci.js
CHANGED
|
@@ -59,6 +59,16 @@ function buildKnowledgeWorkflow({ mode, provider, envKey, model, defaultBranch =
|
|
|
59
59
|
'# permissions. Without it, the update still commits and pushes',
|
|
60
60
|
'# safely, but opening the review PR fails and this job reports it',
|
|
61
61
|
'# as a failure so it is never silently missed.',
|
|
62
|
+
'#',
|
|
63
|
+
'# If your organization enforces that setting off and it cannot be',
|
|
64
|
+
'# changed (the checkbox is greyed out even at the org level), add an',
|
|
65
|
+
'# optional repository secret GITSET_PR_TOKEN — a personal access',
|
|
66
|
+
'# token (classic: repo scope; fine-grained: Pull requests write) —',
|
|
67
|
+
'# and this workflow uses it instead of the default token, which is',
|
|
68
|
+
"# the standard workaround: an organization's PR-creation restriction",
|
|
69
|
+
'# applies to the auto-generated Actions token, not to a real PAT.',
|
|
70
|
+
'# No workflow changes needed after adding it — the next run picks it',
|
|
71
|
+
'# up automatically.',
|
|
62
72
|
...buildTrigger(mode, defaultBranch),
|
|
63
73
|
'permissions:',
|
|
64
74
|
' contents: write',
|
|
@@ -81,7 +91,7 @@ function buildKnowledgeWorkflow({ mode, provider, envKey, model, defaultBranch =
|
|
|
81
91
|
` run: ${updateCmd}`,
|
|
82
92
|
' - name: Open a PR when the knowledge base changed',
|
|
83
93
|
' env:',
|
|
84
|
-
' GH_TOKEN: ${{ github.token }}',
|
|
94
|
+
' GH_TOKEN: ${{ secrets.GITSET_PR_TOKEN || github.token }}',
|
|
85
95
|
' run: |',
|
|
86
96
|
' if git diff --quiet -- docs/gitset-knowledge AGENTS.md; then',
|
|
87
97
|
' echo "Knowledge base already up to date."',
|
|
@@ -101,7 +111,7 @@ function buildKnowledgeWorkflow({ mode, provider, envKey, model, defaultBranch =
|
|
|
101
111
|
' echo "$PR_OUTPUT"',
|
|
102
112
|
' else',
|
|
103
113
|
' echo "$PR_OUTPUT"',
|
|
104
|
-
' echo "::error::Could not open the pull request automatically (the branch and commit ARE safely pushed — no work was lost).
|
|
114
|
+
' echo "::error::Could not open the pull request automatically (the branch and commit ARE safely pushed — no work was lost). Try, in order: (1) enable \'Allow GitHub Actions to create and approve pull requests\' under Settings > Actions > General > Workflow permissions; (2) if that checkbox is greyed out, your organization enforces it off — add a repository secret named GITSET_PR_TOKEN with a personal access token (repo scope) and re-run, no workflow change needed; (3) open the PR yourself: https://github.com/${{ github.repository }}/pull/new/gitset/knowledge-update"',
|
|
105
115
|
' exit 1',
|
|
106
116
|
' fi',
|
|
107
117
|
'',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitset-dev/cli",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "Gitset CLI — drafts commits, PRs, issues, READMEs and release notes with your own AI key. Fully local: your code and keys never touch a Gitset server. Draft. Refine. Ship.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -492,6 +492,40 @@ async function runUpdate(rootDir, argv) {
|
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
function ghApiJson(args) {
|
|
496
|
+
try {
|
|
497
|
+
const out = execFileSync('gh', ['api', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
498
|
+
return JSON.parse(out);
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function ensurePrPermission(repo, argv) {
|
|
505
|
+
if (!repo.includes('/')) return 'unknown';
|
|
506
|
+
const current = ghApiJson([`/repos/${repo}/actions/permissions/workflow`]);
|
|
507
|
+
if (!current) return 'unknown';
|
|
508
|
+
if (current.can_approve_pull_request_reviews) return 'already-enabled';
|
|
509
|
+
|
|
510
|
+
log('\n"Allow GitHub Actions to create and approve pull requests" is currently OFF for this repository. The update step will still run and commit safely without it — only opening the review PR will fail.', 'yellow');
|
|
511
|
+
const proceed = await confirmOrAbort('Enable it now via the GitHub API? (only this one setting changes)', argv);
|
|
512
|
+
if (!proceed) return 'declined';
|
|
513
|
+
|
|
514
|
+
try {
|
|
515
|
+
execFileSync('gh', [
|
|
516
|
+
'api', '--method', 'PUT', `/repos/${repo}/actions/permissions/workflow`,
|
|
517
|
+
'-f', `default_workflow_permissions=${current.default_workflow_permissions}`,
|
|
518
|
+
'-F', 'can_approve_pull_request_reviews=true',
|
|
519
|
+
], { stdio: 'pipe' });
|
|
520
|
+
log('Enabled — CI will be able to open the review PR.', 'green');
|
|
521
|
+
return 'enabled';
|
|
522
|
+
} catch {
|
|
523
|
+
log('Could not change it automatically — you may not have admin access on this repo, or an organization policy locks this setting (if it appears greyed out in the GitHub UI at both the repo and org level, that\'s a hard enforcement you cannot toggle either way).', 'yellow');
|
|
524
|
+
log('Workaround: add a repository secret named GITSET_PR_TOKEN with a personal access token (repo scope). It is not subject to the organization\'s Actions PR-creation restriction, and the workflow picks it up automatically — no need to re-run automate.', 'dim');
|
|
525
|
+
return 'failed';
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
495
529
|
async function runAutomate(rootDir, argv) {
|
|
496
530
|
let cfg;
|
|
497
531
|
try {
|
|
@@ -558,6 +592,8 @@ async function runAutomate(rootDir, argv) {
|
|
|
558
592
|
log(`\nWrote ${km.WORKFLOW_PATH}.`, 'green');
|
|
559
593
|
|
|
560
594
|
const repo = repoLabel(rootDir);
|
|
595
|
+
const prPermission = await ensurePrPermission(repo, argv);
|
|
596
|
+
|
|
561
597
|
log('\nNext steps:', 'cyan');
|
|
562
598
|
log(` 1. Add the repository secret ${envKey} with your ${cfg.provider} API key:`, 'reset');
|
|
563
599
|
if (repo.includes('/')) {
|
|
@@ -565,13 +601,20 @@ async function runAutomate(rootDir, argv) {
|
|
|
565
601
|
} else {
|
|
566
602
|
log(' GitHub repo > Settings > Secrets and variables > Actions', 'dim');
|
|
567
603
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
log(` https://github.com/${repo}/settings/actions`, 'dim');
|
|
604
|
+
if (prPermission === 'enabled' || prPermission === 'already-enabled') {
|
|
605
|
+
log(' 2. "Allow GitHub Actions to create and approve pull requests" is already on — the update PR step is ready.', 'reset');
|
|
571
606
|
} else {
|
|
572
|
-
log('
|
|
607
|
+
log(' 2. Enable "Allow GitHub Actions to create and approve pull requests" (required for the update PR):', 'reset');
|
|
608
|
+
if (repo.includes('/')) {
|
|
609
|
+
log(` https://github.com/${repo}/settings/actions`, 'dim');
|
|
610
|
+
} else {
|
|
611
|
+
log(' GitHub repo > Settings > Actions > General > Workflow permissions', 'dim');
|
|
612
|
+
}
|
|
613
|
+
log(' Without this, the update still runs and commits safely — only opening the review PR fails, and the workflow run will show that failure clearly rather than hide it.', 'dim');
|
|
614
|
+
if (prPermission === 'failed') {
|
|
615
|
+
log(' If that checkbox is greyed out even at the organization level, it is enforced off and cannot be toggled: add a repository secret named GITSET_PR_TOKEN with a personal access token (repo scope) instead — the workflow uses it automatically, no changes needed.', 'dim');
|
|
616
|
+
}
|
|
573
617
|
}
|
|
574
|
-
log(' Without this, the update still runs and commits safely — only opening the review PR fails, and the workflow run will show that failure clearly rather than hide it.', 'dim');
|
|
575
618
|
log(' 3. Make sure the knowledge base itself is committed (gitset knowledge generate, then commit docs/gitset-knowledge/ and AGENTS.md).', 'reset');
|
|
576
619
|
log(' 4. Commit and push the workflow file.', 'reset');
|
|
577
620
|
log('\nWhen mapped source changes land, CI opens a PR on branch gitset/knowledge-update — you review it like any docs change. Runs with no mapped changes make zero AI calls.', 'dim');
|