claude-nomad 0.29.1 → 0.31.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/.gitleaks.toml +20 -0
- package/CHANGELOG.md +25 -0
- package/README.md +90 -6
- package/package.json +1 -1
- package/src/commands.doctor.checks.deps.ts +97 -0
- package/src/commands.doctor.ts +2 -0
- package/src/commands.drop-session.scrub-hint.ts +12 -10
- package/src/commands.push.recovery.actions.ts +165 -0
- package/src/commands.push.recovery.drop.ts +47 -0
- package/src/commands.push.recovery.redact.ts +113 -0
- package/src/commands.push.recovery.seams.ts +66 -0
- package/src/commands.push.recovery.ts +198 -0
- package/src/commands.push.ts +20 -18
- package/src/commands.redact.core.ts +94 -0
- package/src/commands.redact.ts +187 -0
- package/src/config.ts +1 -0
- package/src/nomad.dispatch.ts +57 -0
- package/src/nomad.help.ts +10 -0
- package/src/nomad.ts +21 -11
- package/src/push-gitleaks.scan.ts +72 -1
- package/src/push-gitleaks.ts +35 -6
- package/src/push-leak-verdict.ts +15 -3
- package/src/push-preview.ts +1 -1
- package/src/settings-keys.ts +1 -1
package/.gitleaks.toml
CHANGED
|
@@ -38,3 +38,23 @@ paths = [
|
|
|
38
38
|
'''^shared/projects/[^/]+/.*\.jsonl$''',
|
|
39
39
|
]
|
|
40
40
|
condition = "AND"
|
|
41
|
+
|
|
42
|
+
# Path-scoped: SonarCloud issue-listing tool output (`gh`/sonar API dumps of
|
|
43
|
+
# the form `key: <20-char id>` immediately followed by `rule: <lang>:S<n>`)
|
|
44
|
+
# lands in session transcripts during PR reviews. The issue key is an opaque
|
|
45
|
+
# 20-char base64url identifier, not a credential, but it is shaped like a
|
|
46
|
+
# generic API key and does not carry the `AY` prefix the noise allowlist
|
|
47
|
+
# above keys on. Anchoring on the surrounding `key:`/`rule:` structure (via
|
|
48
|
+
# regexTarget = "line") keeps this from whitelisting a bare token: a real API
|
|
49
|
+
# key is never followed by `\n rule: <lang>:S####`. `condition = "AND"` plus
|
|
50
|
+
# the session-jsonl path scope double-locks it to synced transcripts.
|
|
51
|
+
[[allowlists]]
|
|
52
|
+
description = "claude-nomad: SonarCloud issue-listing output (key: <id> / rule: <lang>:S<n>) in synced session transcripts"
|
|
53
|
+
regexTarget = "line"
|
|
54
|
+
regexes = [
|
|
55
|
+
'''key:\s*[A-Za-z0-9_-]{19,24}\\n\s*rule:\s*\w+:S\d+''',
|
|
56
|
+
]
|
|
57
|
+
paths = [
|
|
58
|
+
'''^shared/projects/[^/]+/.*\.jsonl$''',
|
|
59
|
+
]
|
|
60
|
+
condition = "AND"
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.31.0](https://github.com/funkadelic/claude-nomad/compare/v0.30.0...v0.31.0) (2026-05-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Added
|
|
7
|
+
|
|
8
|
+
* **push:** interactive secret recovery on push and nomad redact ([#181](https://github.com/funkadelic/claude-nomad/issues/181)) ([4931e27](https://github.com/funkadelic/claude-nomad/commit/4931e27ba30998a02b123c71edc1315069c9181a))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
* **gitleaks:** allowlist SonarCloud issue-key tool-output noise in synced transcripts ([#179](https://github.com/funkadelic/claude-nomad/issues/179)) ([0f7d816](https://github.com/funkadelic/claude-nomad/commit/0f7d8161d4de3379cd6a4db00482f560c8b3f280))
|
|
14
|
+
* **settings-drift:** author PRs via app token and make regen idempotent ([#182](https://github.com/funkadelic/claude-nomad/issues/182)) ([062397c](https://github.com/funkadelic/claude-nomad/commit/062397c565926471eccc8e75f72d1ccf2e5cc8c0))
|
|
15
|
+
|
|
16
|
+
## [0.30.0](https://github.com/funkadelic/claude-nomad/compare/v0.29.1...v0.30.0) (2026-05-29)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
* **doctor:** report gh and curl presence in Version Checks ([#175](https://github.com/funkadelic/claude-nomad/issues/175)) ([5163833](https://github.com/funkadelic/claude-nomad/commit/516383301dbd9c64cfc8f1c7a654655b61c29280))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
* widen npm-publish smoke-test propagation window ([#176](https://github.com/funkadelic/claude-nomad/issues/176)) ([f8b1eef](https://github.com/funkadelic/claude-nomad/commit/f8b1eef18dcee91fb894d2036c42356f82c76f79))
|
|
27
|
+
|
|
3
28
|
## [0.29.1](https://github.com/funkadelic/claude-nomad/compare/v0.29.0...v0.29.1) (2026-05-29)
|
|
4
29
|
|
|
5
30
|
|
package/README.md
CHANGED
|
@@ -60,7 +60,9 @@ box, a personal rig and a work machine. [Get started in three steps.](#quickstar
|
|
|
60
60
|
- [Commands](#commands)
|
|
61
61
|
- [Recovery flows](#recovery-flows)
|
|
62
62
|
- [`nomad drop-session <id>`](#nomad-drop-session-id)
|
|
63
|
+
- [`nomad redact <session-id>`](#nomad-redact-session-id)
|
|
63
64
|
- [Recovery flow: gitleaks FATAL on a session JSONL](#recovery-flow-gitleaks-fatal-on-a-session-jsonl)
|
|
65
|
+
- [Recovery flow: push-time interactive menu](#recovery-flow-push-time-interactive-menu)
|
|
64
66
|
- [`.gitleaks.toml` allowlist policy](#gitleakstoml-allowlist-policy)
|
|
65
67
|
- [Cross-OS resume](#cross-os-resume)
|
|
66
68
|
- [Run tests](#run-tests)
|
|
@@ -380,10 +382,11 @@ Read these before adopting so you opt in with eyes open.
|
|
|
380
382
|
|
|
381
383
|
- `gh` ([GitHub CLI](https://cli.github.com/)), used only by `nomad init` to auto-disable Actions on
|
|
382
384
|
the private repo; if it is missing or unauthenticated, init prints a manual fallback tip and
|
|
383
|
-
continues
|
|
385
|
+
continues. `nomad doctor` reports its presence in the Version Checks section.
|
|
384
386
|
- [curl](https://curl.se/), used by the version/update check (the `nomad doctor` latest-release line
|
|
385
387
|
and the post-`nomad update` check) and by `nomad doctor --check-schema`; it degrades silently when
|
|
386
|
-
curl is absent or offline, so the rest of the CLI works without it
|
|
388
|
+
curl is absent or offline, so the rest of the CLI works without it. `nomad doctor` reports its
|
|
389
|
+
presence in the Version Checks section.
|
|
387
390
|
|
|
388
391
|
## Setup
|
|
389
392
|
|
|
@@ -609,7 +612,11 @@ point under your npm prefix's `bin/`), then delete the alias line from your shel
|
|
|
609
612
|
| `nomad diff` | Offline, lockless twin of `pull --dry-run`. No network, no lock. Works against the current local repo state. |
|
|
610
613
|
| `nomad push` | Export local sessions and opted-in per-project extras to logical names, commit (`chore: sync from <NOMAD_HOST>`), push. |
|
|
611
614
|
| `nomad push --dry-run` | Run pre-push safety checks (gitleaks probe, rebase, remap preview, gitlink scan, allow-list) and a read-only gitleaks leak preview over a throwaway temp copy of the sessions and extras this host would stage; skip stage, commit, and push. Exits 1 if a leak is found in the preview. Nothing is written to the sync repo. |
|
|
615
|
+
| `nomad push --redact-all` | Redact all findings non-interactively (backup written first) without a TTY. Does not auto-Allow findings. After redaction re-stages and re-scans; aborts with the session-aware FATAL if any finding survives. Use this in scripts or when you are confident every finding is a real secret that should be scrubbed. See [Recovery flow: push-time interactive menu](#recovery-flow-push-time-interactive-menu). |
|
|
612
616
|
| `nomad drop-session <id>` | Surgically unstage every `shared/projects/*/<id>.jsonl` and the sibling `shared/projects/*/<id>/` subagent directory from the staged tree of `~/claude-nomad/`. Idempotent; the local `~/.claude/projects/<encoded>/<id>.jsonl` and `<id>/` tree are preserved. See [Recovery flows](#recovery-flows). |
|
|
617
|
+
| `nomad redact <session-id>` | Rewrite the secret span in the local source transcript for a session, backed up to `~/.cache/claude-nomad/backup/`. Refuses to touch a session that was modified recently (potential active session). Safe to re-run. See [`nomad redact <session-id>`](#nomad-redact-session-id). |
|
|
618
|
+
| `nomad redact --rule <id>` | Limit redaction to findings of one gitleaks rule id only. |
|
|
619
|
+
| `nomad redact --dry-run` | Show what `nomad redact` would change without writing anything. |
|
|
613
620
|
| `nomad update` | Topology-aware upgrade to the latest upstream. Flags: `--dry-run`, `--force`, `--push-origin`. See [Upgrading the tool](#upgrading-the-tool). |
|
|
614
621
|
| `nomad doctor` | Read-only health check. Each line carries a status glyph (`✓` pass, `✗` fail, `⚠︎` warn); any `✗` sets `process.exitCode = 1` (`⚠︎` does not). Includes an offline-tolerant release-version staleness check, a Hook targets check that fails (`✗`, exit 1) when `settings.json` references a hook command whose script under `~/.claude/` is missing on this host, plus two `⚠︎`-only drift checks: gitleaks version drift and, on a private GitHub mirror, re-enabled Actions. |
|
|
615
622
|
| `nomad doctor --resume-cmd <id>` | Print a host-local `cd ... && claude --resume <id>` line for a session (see [Cross-OS resume](#cross-os-resume)). |
|
|
@@ -761,6 +768,38 @@ scrubbing (the exact path when `path-map.json` maps the project to the current h
|
|
|
761
768
|
`~/.claude/projects/` source, not the staged tree, so it keeps flagging the secret until the local
|
|
762
769
|
transcript is scrubbed.
|
|
763
770
|
|
|
771
|
+
### `nomad redact <session-id>`
|
|
772
|
+
|
|
773
|
+
Rewrites the secret span in the local source transcript at
|
|
774
|
+
`~/.claude/projects/<encoded>/<session-id>.jsonl` in place, replacing each flagged span with
|
|
775
|
+
`[REDACTED:<rule>]`. Before rewriting, the original transcript is backed up to
|
|
776
|
+
`~/.cache/claude-nomad/backup/<timestamp>/`.
|
|
777
|
+
|
|
778
|
+
```bash
|
|
779
|
+
$ nomad redact <session-id>
|
|
780
|
+
$ nomad redact <session-id> --rule github-pat # one rule only
|
|
781
|
+
$ nomad redact <session-id> --dry-run # preview without writing
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
What it does: rewrites the LOCAL source transcript (not just the staged copy). This is the durable
|
|
785
|
+
fix for a gitleaks finding: `nomad drop-session` only removes the staged copy, but `remapPush`
|
|
786
|
+
re-copies from local on the next push, so the secret resurfaces. Redacting the local source means
|
|
787
|
+
future pushes carry clean content.
|
|
788
|
+
|
|
789
|
+
What it does NOT do: rotate credentials. Always rotate the secret at its provider first.
|
|
790
|
+
|
|
791
|
+
Safety checks:
|
|
792
|
+
|
|
793
|
+
- A session whose transcript was modified within the last 5 minutes is treated as potentially active
|
|
794
|
+
(Claude Code may still be writing to it). `nomad redact` refuses to touch it and suggests
|
|
795
|
+
`nomad drop-session` or waiting for the session to end.
|
|
796
|
+
- Before every rewrite, a backup is written to `~/.cache/claude-nomad/backup/<timestamp>/`, so the
|
|
797
|
+
original content is recoverable.
|
|
798
|
+
- `--dry-run` prints the planned redactions and writes nothing.
|
|
799
|
+
|
|
800
|
+
This command is safe to re-run: if the span was already redacted (the replacement token is already
|
|
801
|
+
present), the content is unchanged.
|
|
802
|
+
|
|
764
803
|
### Recovery flow: gitleaks FATAL on a session JSONL
|
|
765
804
|
|
|
766
805
|
`nomad push` runs `gitleaks protect --staged` before commit. To catch the same findings before you
|
|
@@ -791,10 +830,12 @@ Two branches from here:
|
|
|
791
830
|
contaminated copy from the current staged tree, but that alone is NOT durable: `remapPush` (in
|
|
792
831
|
`src/remap.ts`) does a full rm-and-copy mirror of your LOCAL transcripts into `shared/projects/`
|
|
793
832
|
on every push, so the next `nomad push` re-copies the un-scrubbed local file forward and
|
|
794
|
-
re-stages the same secret. The durable fix is to rotate AND scrub
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
833
|
+
re-stages the same secret. The durable fix is to rotate AND scrub the local transcript. The
|
|
834
|
+
easiest way: `nomad redact <sid-aaaa>` (see [`nomad redact`](#nomad-redact-session-id)), which
|
|
835
|
+
rewrites the secret span in place with a backup. Alternatively, remove the local transcript at
|
|
836
|
+
`~/.claude/projects/<encoded>/<sid-aaaa>.jsonl` (plus the sibling `<sid-aaaa>/` subagent
|
|
837
|
+
directory, if present). Do not leave the local file un-scrubbed and expect the staged-tree drop
|
|
838
|
+
to hold.
|
|
798
839
|
|
|
799
840
|
2. **False positive.** Add an allowlist regex to `.gitleaks.toml` at the repo root that matches the
|
|
800
841
|
noise pattern but not real-secret formats, commit it, then re-run `nomad push`. The new allowlist
|
|
@@ -803,6 +844,49 @@ Two branches from here:
|
|
|
803
844
|
`nomad drop-session` only acts on the staged tree of `~/claude-nomad/`. Active Claude Code sessions
|
|
804
845
|
writing to the local file are not disturbed.
|
|
805
846
|
|
|
847
|
+
### Recovery flow: push-time interactive menu
|
|
848
|
+
|
|
849
|
+
When `nomad push` detects a secret and the process is running on an interactive TTY, it presents a
|
|
850
|
+
per-finding menu instead of aborting immediately. Each finding is shown with its rule id, file, and
|
|
851
|
+
line number (the secret value is never printed: the scan uses `--redact`).
|
|
852
|
+
|
|
853
|
+
```text
|
|
854
|
+
Finding: github-pat in shared/projects/my-proj/abc123.jsonl line 42 (session: abc123)
|
|
855
|
+
[R]edact [A]llow [D]rop session [S]kip (default)
|
|
856
|
+
>
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
What the actions do:
|
|
860
|
+
|
|
861
|
+
- **Redact** rewrites the secret span in the LOCAL source transcript in place (same flow as
|
|
862
|
+
`nomad redact`), backs up first, then re-copies the file to the staged tree. Refuses if the
|
|
863
|
+
session was modified in the last 5 minutes (potential active session): choose Drop or Skip instead
|
|
864
|
+
and wait for the session to end.
|
|
865
|
+
- **Allow** appends the finding's fingerprint to `.gitleaksignore` at the repo root. Use this for
|
|
866
|
+
confirmed false positives. The fingerprint format (`file:rule:line`) is tied to the current line,
|
|
867
|
+
so if the content moves gitleaks re-prompts rather than silently suppressing a new hit.
|
|
868
|
+
- **Drop session** excludes this session from the current push by unstaging it from the repo's git
|
|
869
|
+
index (same as `nomad drop-session <id>`). The local `~/.claude/projects/.../` transcript is kept
|
|
870
|
+
intact and any running Claude session is not stopped. Not durable: the next push re-copies from
|
|
871
|
+
local unless you also redact or remove the local transcript.
|
|
872
|
+
- **Skip** (default on bare Enter) leaves the finding unresolved for now.
|
|
873
|
+
|
|
874
|
+
After you respond to every finding, the menu applies your choices. If any finding was Skipped, the
|
|
875
|
+
push aborts with the session-aware FATAL (same exit as a non-interactive push with findings). If all
|
|
876
|
+
findings were resolved, the staged tree is updated and re-scanned. A clean re-scan proceeds to
|
|
877
|
+
commit and push. If new findings appear after the first round of actions, the menu loops on the new
|
|
878
|
+
set.
|
|
879
|
+
|
|
880
|
+
On a non-TTY (CI, piped input, or scripted `nomad push`), the menu never appears and the push aborts
|
|
881
|
+
with the existing session-aware FATAL unchanged.
|
|
882
|
+
|
|
883
|
+
**Batch redact without a TTY:** `nomad push --redact-all` redacts every finding non-interactively
|
|
884
|
+
(backup written first) without prompting and without requiring a TTY. It does not auto-Allow. After
|
|
885
|
+
redaction the staged tree is re-scanned; any surviving finding aborts with the FATAL. Use this in
|
|
886
|
+
scripts or when every finding is a real secret that should be scrubbed. For a single session,
|
|
887
|
+
`nomad redact <session-id>` (see [`nomad redact`](#nomad-redact-session-id)) gives you per-session
|
|
888
|
+
control with `--rule` and `--dry-run` options.
|
|
889
|
+
|
|
806
890
|
### `.gitleaks.toml` allowlist policy
|
|
807
891
|
|
|
808
892
|
`gitleaks protect` runs against the staged tree on every `nomad push` and can flag
|
package/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
import { green, okGlyph, warnGlyph, yellow } from './color.ts';
|
|
4
|
+
import { addItem, type DoctorSection } from './commands.doctor.format.ts';
|
|
5
|
+
import type { SpawnSyncFn } from './gh-actions.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Optional-dependency presence reporter for `nomad doctor`. Probes for `gh`
|
|
9
|
+
* and `curl` (both optional CLIs used by nomad features) and emits one row
|
|
10
|
+
* per binary in the Version Checks section:
|
|
11
|
+
* - present with parsed version: `okGlyph gh: X.Y.Z`
|
|
12
|
+
* - present but version unparseable: `okGlyph gh: present`
|
|
13
|
+
* - not installed (ENOENT): `warnGlyph gh: not installed (optional; ...)`
|
|
14
|
+
*
|
|
15
|
+
* This reporter MUST NOT set `process.exitCode`: absent optional deps are
|
|
16
|
+
* informational only (D-02). Both probes always run unconditionally.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Regex to extract the first X.Y.Z version token from a string. Each segment
|
|
21
|
+
* is bounded (`{1,9}`) rather than `+` so the pattern is provably linear: a
|
|
22
|
+
* `--version` line never has a segment longer than a few digits, and bounding
|
|
23
|
+
* the repetition removes the super-linear backtracking an unbounded
|
|
24
|
+
* `\d+\.\d+\.\d+` carries on a degenerate all-digit input.
|
|
25
|
+
*/
|
|
26
|
+
const VERSION_TOKEN = /(\d{1,9}\.\d{1,9}\.\d{1,9})/;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Extract the first X.Y.Z-shaped version token from a string.
|
|
30
|
+
*
|
|
31
|
+
* @param line - A single line of --version output (already trimmed).
|
|
32
|
+
* @returns The first version token, or `null` if none found.
|
|
33
|
+
*/
|
|
34
|
+
function parseFirstVersion(line: string): string | null {
|
|
35
|
+
const m = VERSION_TOKEN.exec(line);
|
|
36
|
+
return m ? m[1] : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Discriminated union for binary probe results. */
|
|
40
|
+
type DepProbeResult = { status: 'present'; version: string | null } | { status: 'not-installed' };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Probe a binary by running `bin --version` and parsing the first output line.
|
|
44
|
+
* Returns a DepProbeResult: present (with optional version token) or
|
|
45
|
+
* not-installed (ENOENT). Non-ENOENT errors are treated as present with no
|
|
46
|
+
* version (D-03: "never FAIL on unexpected --version output").
|
|
47
|
+
*
|
|
48
|
+
* @param bin - The binary name to probe (e.g. `gh` or `curl`).
|
|
49
|
+
* @param run - Injectable subprocess runner; defaults to `execFileSync`.
|
|
50
|
+
*/
|
|
51
|
+
function probeOptionalDep(bin: string, run: SpawnSyncFn): DepProbeResult {
|
|
52
|
+
try {
|
|
53
|
+
const firstLine = run(bin, ['--version'], { stdio: ['ignore', 'pipe', 'pipe'] })
|
|
54
|
+
.toString()
|
|
55
|
+
.split('\n')[0]
|
|
56
|
+
.trim();
|
|
57
|
+
const version = parseFirstVersion(firstLine);
|
|
58
|
+
return { status: 'present', version };
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
61
|
+
return { status: 'not-installed' };
|
|
62
|
+
}
|
|
63
|
+
// Non-ENOENT: binary may exist but --version misbehaved; report as present.
|
|
64
|
+
return { status: 'present', version: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Emit presence rows for the optional `gh` and `curl` CLIs into the given
|
|
70
|
+
* doctor section. Each row shows the binary's install status and version (if
|
|
71
|
+
* parseable). Absent binaries emit a WARN naming the features they enable.
|
|
72
|
+
* Never sets `process.exitCode` (D-02): both deps are optional.
|
|
73
|
+
*
|
|
74
|
+
* @param section - The Version Checks section to append rows to.
|
|
75
|
+
* @param run - Injectable subprocess runner; defaults to `execFileSync`.
|
|
76
|
+
*/
|
|
77
|
+
export function reportOptionalDeps(section: DoctorSection, run: SpawnSyncFn = execFileSync): void {
|
|
78
|
+
const gh = probeOptionalDep('gh', run);
|
|
79
|
+
if (gh.status === 'present') {
|
|
80
|
+
addItem(section, `${green(okGlyph)} gh: ${gh.version ?? 'present'}`);
|
|
81
|
+
} else {
|
|
82
|
+
addItem(
|
|
83
|
+
section,
|
|
84
|
+
`${yellow(warnGlyph)} gh: not installed (optional; needed for nomad init Actions auto-disable + mirror-Actions drift check)`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const curl = probeOptionalDep('curl', run);
|
|
89
|
+
if (curl.status === 'present') {
|
|
90
|
+
addItem(section, `${green(okGlyph)} curl: ${curl.version ?? 'present'}`);
|
|
91
|
+
} else {
|
|
92
|
+
addItem(
|
|
93
|
+
section,
|
|
94
|
+
`${yellow(warnGlyph)} curl: not installed (optional; needed for release-version staleness check + nomad doctor --check-schema)`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/commands.doctor.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { REPO_HOME, type PathMap } from './config.ts';
|
|
|
25
25
|
import { reportNodeEngineCheck } from './commands.doctor.engine.ts';
|
|
26
26
|
import { readJsonSafe, renderDoctor, section } from './commands.doctor.format.ts';
|
|
27
27
|
import { reportGitleaksVersionCheck } from './commands.doctor.gitleaks-version.ts';
|
|
28
|
+
import { reportOptionalDeps } from './commands.doctor.checks.deps.ts';
|
|
28
29
|
import { reportMirrorActions } from './commands.doctor.mirror-actions.ts';
|
|
29
30
|
import { reportVersionCheck } from './commands.doctor.version.ts';
|
|
30
31
|
|
|
@@ -85,6 +86,7 @@ export function cmdDoctor(opts: { checkShared?: boolean; checkSchema?: boolean }
|
|
|
85
86
|
reportVersionCheck(version);
|
|
86
87
|
reportNodeEngineCheck(version);
|
|
87
88
|
reportGitleaksVersionCheck(version);
|
|
89
|
+
reportOptionalDeps(version);
|
|
88
90
|
|
|
89
91
|
const sharedScan = section('Shared scan');
|
|
90
92
|
// Reuse the Repository-section readiness probe so reportCheckShared does not
|
|
@@ -13,12 +13,12 @@ const SHARED_PROJECT_LOGICAL = /^shared\/projects\/([^/]+)\//;
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* After a successful drop, remind the operator that the unstage is per-push
|
|
16
|
-
* only: the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* only: the local source still contains the secret, so the next `nomad push`
|
|
17
|
+
* re-copies it (via `remapPush`) and `nomad doctor --check-shared` keeps
|
|
18
|
+
* reporting it (it scans the live `~/.claude/projects/` source, not the repo
|
|
19
|
+
* index). Full remediation requires rotating the credential, then running
|
|
20
|
+
* `nomad redact <id>` (or scrubbing the local transcript manually). Advisory
|
|
21
|
+
* output only; never mutates state.
|
|
22
22
|
*
|
|
23
23
|
* @param id Already-validated session id.
|
|
24
24
|
* @param matches Repo-relative paths collected by `collectMatches`.
|
|
@@ -27,10 +27,12 @@ export function reportScrubHint(id: string, matches: string[]): void {
|
|
|
27
27
|
const live = resolveLiveTranscript(id, matches);
|
|
28
28
|
const target = live ?? `~/.claude/projects/<encoded>/${id}.jsonl`;
|
|
29
29
|
log(
|
|
30
|
-
'note: this only un-stages the session from the next push
|
|
31
|
-
'
|
|
32
|
-
' doctor --check-shared keeps reporting it
|
|
33
|
-
|
|
30
|
+
'note: this only un-stages the session from the next push.\n' +
|
|
31
|
+
' The local source still contains the secret, so nomad push re-stages it\n' +
|
|
32
|
+
' on the next run and nomad doctor --check-shared keeps reporting it.\n' +
|
|
33
|
+
' To fully remediate: rotate the credential, then run:\n' +
|
|
34
|
+
` nomad redact ${id}\n` +
|
|
35
|
+
` (or scrub ${target} manually)`,
|
|
34
36
|
);
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* I/O action dispatchers for the push-time recovery menu: `applyAllow`,
|
|
3
|
+
* `applyRedact`, `collectActions`, `dispatchActions`, `redactAllFindings`.
|
|
4
|
+
* Pure seams live in `commands.push.recovery.seams.ts`; lock-free drop
|
|
5
|
+
* helper in `commands.push.recovery.drop.ts`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PathMap } from './config.ts';
|
|
9
|
+
import { appendGitleaksIgnore } from './commands.redact.ts';
|
|
10
|
+
import { applyRedact } from './commands.push.recovery.redact.ts';
|
|
11
|
+
import { dropSessionFromStaged } from './commands.push.recovery.drop.ts';
|
|
12
|
+
import type { Finding } from './push-gitleaks.scan.ts';
|
|
13
|
+
import { scanFile } from './push-gitleaks.scan.ts';
|
|
14
|
+
import { log } from './utils.ts';
|
|
15
|
+
import {
|
|
16
|
+
type FindingAction,
|
|
17
|
+
type PromptFn,
|
|
18
|
+
findingKey,
|
|
19
|
+
parseAction,
|
|
20
|
+
sessionIdFromFinding,
|
|
21
|
+
} from './commands.push.recovery.seams.ts';
|
|
22
|
+
|
|
23
|
+
export type { FindingAction, PromptFn };
|
|
24
|
+
export { dropSessionFromStaged, findingKey, parseAction, sessionIdFromFinding };
|
|
25
|
+
|
|
26
|
+
/** Apply the Allow action: append the finding's fingerprint to .gitleaksignore. */
|
|
27
|
+
export function applyAllow(f: Finding): void {
|
|
28
|
+
appendGitleaksIgnore(f.Fingerprint);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Walk all findings and prompt the user for one action each. Returns a map
|
|
33
|
+
* from `findingKey` to the chosen action, defaulting to `'skip'` on empty
|
|
34
|
+
* input.
|
|
35
|
+
*
|
|
36
|
+
* @param findings The findings to present.
|
|
37
|
+
* @param prompt An injectable prompt function (one question per call).
|
|
38
|
+
* @returns Populated actions map.
|
|
39
|
+
*/
|
|
40
|
+
export async function collectActions(
|
|
41
|
+
findings: Finding[],
|
|
42
|
+
prompt: PromptFn,
|
|
43
|
+
): Promise<Map<string, FindingAction>> {
|
|
44
|
+
const actions = new Map<string, FindingAction>();
|
|
45
|
+
for (const f of findings) {
|
|
46
|
+
const sid = sessionIdFromFinding(f);
|
|
47
|
+
const header =
|
|
48
|
+
`\nFinding: ${f.RuleID} in ${f.File} line ${f.StartLine}` +
|
|
49
|
+
(sid !== null ? ` (session: ${sid})` : '') +
|
|
50
|
+
'\n [R]edact [A]llow [D]rop session [S]kip (default)\n';
|
|
51
|
+
actions.set(findingKey(f), parseAction(await prompt(header + '> ')));
|
|
52
|
+
}
|
|
53
|
+
return actions;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Apply one finding's triaged action against local state. Extracted from
|
|
58
|
+
* `dispatchActions` so each function stays under the cognitive-complexity gate.
|
|
59
|
+
* `redactedSids` and `droppedSids` are mutated in place so per-session
|
|
60
|
+
* de-duplication is maintained across the caller's loop. Drop wins: once a
|
|
61
|
+
* session id appears in `droppedSids`, subsequent redact or allow actions for
|
|
62
|
+
* findings in that session are skipped.
|
|
63
|
+
*
|
|
64
|
+
* @param f The finding to act on.
|
|
65
|
+
* @param findings Full findings list (passed to `applyRedact` for per-session redaction).
|
|
66
|
+
* @param actions The action map returned by `collectActions`.
|
|
67
|
+
* @param ts Backup timestamp.
|
|
68
|
+
* @param map Parsed path-map.
|
|
69
|
+
* @param nowMs Injectable clock.
|
|
70
|
+
* @param scan Injectable scan function for `applyRedact`.
|
|
71
|
+
* @param drop Injectable staged-copy remover for the Drop action.
|
|
72
|
+
* @param redactedSids Set of already-redacted session ids (mutated in place).
|
|
73
|
+
* @param droppedSids Set of already-dropped session ids (mutated in place).
|
|
74
|
+
*/
|
|
75
|
+
function dispatchOne(
|
|
76
|
+
f: Finding,
|
|
77
|
+
findings: Finding[],
|
|
78
|
+
actions: Map<string, FindingAction>,
|
|
79
|
+
ts: string,
|
|
80
|
+
map: PathMap,
|
|
81
|
+
nowMs: () => number,
|
|
82
|
+
scan: (p: string) => Finding[] | null,
|
|
83
|
+
drop: (sid: string, map: PathMap) => boolean,
|
|
84
|
+
redactedSids: Set<string>,
|
|
85
|
+
droppedSids: Set<string>,
|
|
86
|
+
): void {
|
|
87
|
+
const action = actions.get(findingKey(f)) ?? 'skip';
|
|
88
|
+
if (action === 'skip') return;
|
|
89
|
+
if (action === 'allow') {
|
|
90
|
+
applyAllow(f);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const sid = sessionIdFromFinding(f);
|
|
94
|
+
if (sid === null) return;
|
|
95
|
+
if (droppedSids.has(sid)) return;
|
|
96
|
+
if (action === 'drop') {
|
|
97
|
+
droppedSids.add(sid);
|
|
98
|
+
if (drop(sid, map)) {
|
|
99
|
+
log(
|
|
100
|
+
`dropped session ${sid} from this push (local transcript kept; the secret remains in your local copy)`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (action === 'redact' && !redactedSids.has(sid)) {
|
|
106
|
+
if (applyRedact(f, findings, ts, map, nowMs, scan)) redactedSids.add(sid);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Dispatch all non-skip actions from the triage map against local state.
|
|
112
|
+
* Redacted sessions are de-duplicated: the first finding for a given session
|
|
113
|
+
* triggers the in-place rewrite; subsequent findings for the same session are
|
|
114
|
+
* skipped (the rewrite already covered all findings in one pass).
|
|
115
|
+
*
|
|
116
|
+
* @param findings Full findings list from the current verdict.
|
|
117
|
+
* @param actions The action map returned by `collectActions`.
|
|
118
|
+
* @param ts Backup timestamp.
|
|
119
|
+
* @param map Parsed path-map.
|
|
120
|
+
* @param nowMs Injectable clock.
|
|
121
|
+
* @param scan Injectable scan function for `applyRedact` (default: `scanFile`).
|
|
122
|
+
* @param drop Injectable staged-copy remover for the Drop action (default: `dropSessionFromStaged`).
|
|
123
|
+
*/
|
|
124
|
+
export function dispatchActions(
|
|
125
|
+
findings: Finding[],
|
|
126
|
+
actions: Map<string, FindingAction>,
|
|
127
|
+
ts: string,
|
|
128
|
+
map: PathMap,
|
|
129
|
+
nowMs: () => number,
|
|
130
|
+
scan: (p: string) => Finding[] | null = scanFile,
|
|
131
|
+
drop: (sid: string, map: PathMap) => boolean = dropSessionFromStaged,
|
|
132
|
+
): void {
|
|
133
|
+
const redactedSids = new Set<string>();
|
|
134
|
+
const droppedSids = new Set<string>();
|
|
135
|
+
for (const f of findings) {
|
|
136
|
+
dispatchOne(f, findings, actions, ts, map, nowMs, scan, drop, redactedSids, droppedSids);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Batch-redact all findings non-interactively (the `--redact-all` path).
|
|
142
|
+
* Does not require a TTY. Findings with no resolvable session id are skipped.
|
|
143
|
+
* Sessions are de-duplicated: the first finding per session triggers the
|
|
144
|
+
* rewrite.
|
|
145
|
+
*
|
|
146
|
+
* @param findings All findings from the current verdict.
|
|
147
|
+
* @param ts Backup timestamp.
|
|
148
|
+
* @param map Parsed path-map.
|
|
149
|
+
* @param nowMs Injectable clock.
|
|
150
|
+
* @param scan Injectable scan function for `applyRedact` (default: `scanFile`).
|
|
151
|
+
*/
|
|
152
|
+
export function redactAllFindings(
|
|
153
|
+
findings: Finding[],
|
|
154
|
+
ts: string,
|
|
155
|
+
map: PathMap,
|
|
156
|
+
nowMs: () => number,
|
|
157
|
+
scan: (p: string) => Finding[] | null = scanFile,
|
|
158
|
+
): void {
|
|
159
|
+
const redactedSids = new Set<string>();
|
|
160
|
+
for (const f of findings) {
|
|
161
|
+
const sid = sessionIdFromFinding(f);
|
|
162
|
+
if (sid === null || redactedSids.has(sid)) continue;
|
|
163
|
+
if (applyRedact(f, findings, ts, map, nowMs, scan)) redactedSids.add(sid);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lock-free session drop helper for the push-time recovery menu.
|
|
3
|
+
* `dropSessionFromStaged` removes a session's generated copies from the
|
|
4
|
+
* `REPO_HOME/shared/projects/` tree so the recovery loop's subsequent
|
|
5
|
+
* `git add -A` stages the deletion rather than re-staging the file.
|
|
6
|
+
*
|
|
7
|
+
* Kept separate from `commands.push.recovery.actions.ts` to respect the
|
|
8
|
+
* ~220-line module cap.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { rmSync } from 'node:fs';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
import type { PathMap } from './config.ts';
|
|
15
|
+
import { REPO_HOME } from './config.ts';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Remove the session's generated copies from the staged tree under
|
|
19
|
+
* `REPO_HOME/shared/projects/<logical>/` so the subsequent `git add -A` in
|
|
20
|
+
* the recovery loop stages the deletion rather than re-staging the file.
|
|
21
|
+
*
|
|
22
|
+
* Removes both the flat `<sid>.jsonl` transcript and the sibling subagent
|
|
23
|
+
* directory `<sid>/` (if present) for every logical project in `map`. These
|
|
24
|
+
* are generated copies produced by `remapPush`; the originals under
|
|
25
|
+
* `~/.claude/projects/` are never touched.
|
|
26
|
+
*
|
|
27
|
+
* Lock-free by design: the caller (`dispatchActions`) runs inside a `push`
|
|
28
|
+
* that already holds the global nomad lock. Calling `cmdDropSession` here
|
|
29
|
+
* would deadlock on the lock it already owns.
|
|
30
|
+
*
|
|
31
|
+
* @param sid Session id to drop from the staged tree.
|
|
32
|
+
* @param map Parsed path-map; provides the logical project names.
|
|
33
|
+
* @returns True when `map.projects` has at least one logical entry (the
|
|
34
|
+
* session copies were targeted for removal), false when the map is empty
|
|
35
|
+
* and no paths were evaluated.
|
|
36
|
+
*/
|
|
37
|
+
export function dropSessionFromStaged(sid: string, map: PathMap): boolean {
|
|
38
|
+
const logicals = Object.keys(map.projects);
|
|
39
|
+
if (logicals.length === 0) return false;
|
|
40
|
+
for (const logical of logicals) {
|
|
41
|
+
const jsonl = join(REPO_HOME, 'shared', 'projects', logical, `${sid}.jsonl`);
|
|
42
|
+
const dir = join(REPO_HOME, 'shared', 'projects', logical, sid);
|
|
43
|
+
rmSync(jsonl, { force: true });
|
|
44
|
+
rmSync(dir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|