himaya 0.0.0-stage → 0.1.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/CHANGELOG.md +26 -0
- package/LICENSE +201 -0
- package/PRIVACY.md +64 -0
- package/README.md +283 -2
- package/SECURITY.md +29 -0
- package/agent/AGENTS.section.md +11 -0
- package/agent/skill/SKILL.md +118 -0
- package/dist/ci/codeowners.js +62 -0
- package/dist/ci/reviews.js +62 -0
- package/dist/ci/run.js +347 -0
- package/dist/ci/workflow.js +150 -0
- package/dist/cli/answer.js +77 -0
- package/dist/cli/args.js +53 -0
- package/dist/cli/ci.js +77 -0
- package/dist/cli/diff.js +21 -0
- package/dist/cli/explain.js +62 -0
- package/dist/cli/feedback.js +59 -0
- package/dist/cli/fix.js +184 -0
- package/dist/cli/history.js +36 -0
- package/dist/cli/hunt.js +116 -0
- package/dist/cli/index.js +36 -0
- package/dist/cli/init.js +36 -0
- package/dist/cli/main.js +243 -0
- package/dist/cli/promise.js +100 -0
- package/dist/cli/shield.js +93 -0
- package/dist/cli/threats.js +129 -0
- package/dist/cli/tripwire.js +94 -0
- package/dist/cli/watch.js +77 -0
- package/dist/copy/checks.js +422 -0
- package/dist/copy/ci.js +65 -0
- package/dist/copy/data.js +68 -0
- package/dist/copy/feedback.js +36 -0
- package/dist/copy/fix-steps.js +229 -0
- package/dist/copy/fixes.js +64 -0
- package/dist/copy/guard.js +20 -0
- package/dist/copy/init.js +92 -0
- package/dist/copy/mcp.js +34 -0
- package/dist/copy/platforms.js +93 -0
- package/dist/copy/promises.js +108 -0
- package/dist/copy/report.js +81 -0
- package/dist/copy/shields.js +68 -0
- package/dist/copy/threats.js +231 -0
- package/dist/copy/watch.js +69 -0
- package/dist/data/index.js +25 -0
- package/dist/data/known-bad-packages.json +56 -0
- package/dist/data/popular-packages.json +712 -0
- package/dist/data/shields/GHSA-f82v-jwr5-mffw.json +25 -0
- package/dist/data/shields.js +22 -0
- package/dist/data/tripwire-decoys.json +37 -0
- package/dist/diff/accessmap.js +202 -0
- package/dist/diff/compare.js +107 -0
- package/dist/diff/render.js +38 -0
- package/dist/diff/run.js +124 -0
- package/dist/diff/snapshot.js +163 -0
- package/dist/engine/basis.js +26 -0
- package/dist/engine/checks-list.js +234 -0
- package/dist/engine/code.js +400 -0
- package/dist/engine/configs.js +130 -0
- package/dist/engine/context.js +1 -0
- package/dist/engine/discover.js +212 -0
- package/dist/engine/files.js +151 -0
- package/dist/engine/finding.js +10 -0
- package/dist/engine/git-branch.js +212 -0
- package/dist/engine/git.js +160 -0
- package/dist/engine/gitignore.js +156 -0
- package/dist/engine/hash.js +7 -0
- package/dist/engine/himaya-guards.js +50 -0
- package/dist/engine/invisible.js +187 -0
- package/dist/engine/links.js +18 -0
- package/dist/engine/lockfile.js +75 -0
- package/dist/engine/make-finding.js +37 -0
- package/dist/engine/mask.js +68 -0
- package/dist/engine/package-names.js +143 -0
- package/dist/engine/packs.js +1 -0
- package/dist/engine/pg-worker.js +112 -0
- package/dist/engine/pool.js +16 -0
- package/dist/engine/profile.js +340 -0
- package/dist/engine/project.js +283 -0
- package/dist/engine/rank.js +185 -0
- package/dist/engine/safe-db.js +307 -0
- package/dist/engine/scan.js +412 -0
- package/dist/engine/schema.js +317 -0
- package/dist/engine/secret-formats.js +133 -0
- package/dist/engine/secrets-names.js +71 -0
- package/dist/engine/shipped.js +14 -0
- package/dist/engine/specifiers.js +27 -0
- package/dist/engine/sql-split.js +87 -0
- package/dist/engine/supabase-shim.js +111 -0
- package/dist/engine/text.js +19 -0
- package/dist/engine/tripwire-lures.js +15 -0
- package/dist/engine/versions.js +103 -0
- package/dist/fixes/code-access.js +944 -0
- package/dist/fixes/code-ai.js +1094 -0
- package/dist/fixes/code-common.js +145 -0
- package/dist/fixes/code-edit.js +164 -0
- package/dist/fixes/code-pay.js +933 -0
- package/dist/fixes/data.js +779 -0
- package/dist/fixes/diff.js +166 -0
- package/dist/fixes/registry.js +13 -0
- package/dist/fixes/secrets.js +32 -0
- package/dist/fixes/static.js +1159 -0
- package/dist/guard/bash.js +252 -0
- package/dist/guard/index.js +158 -0
- package/dist/guard/install.js +17 -0
- package/dist/guard/redlines.js +345 -0
- package/dist/guard/rules.js +18 -0
- package/dist/guard/stop.js +194 -0
- package/dist/history/git.js +40 -0
- package/dist/history/replay.js +403 -0
- package/dist/history/report.js +146 -0
- package/dist/history/since.js +36 -0
- package/dist/hunt/candidates.js +119 -0
- package/dist/hunt/merge.js +290 -0
- package/dist/hunt/surfaces.js +129 -0
- package/dist/init/init.js +456 -0
- package/dist/mcp/server.js +230 -0
- package/dist/net/registry.js +116 -0
- package/dist/packs/core/checks/agent.js +831 -0
- package/dist/packs/core/checks/ai.js +1219 -0
- package/dist/packs/core/checks/deps.js +455 -0
- package/dist/packs/core/checks/hard08.js +258 -0
- package/dist/packs/core/checks/hard09.js +192 -0
- package/dist/packs/core/checks/sec02.js +337 -0
- package/dist/packs/core/pack.js +16 -0
- package/dist/packs/index.js +15 -0
- package/dist/packs/nextjs/auth.js +312 -0
- package/dist/packs/nextjs/checks/access.js +612 -0
- package/dist/packs/nextjs/checks/hard.js +783 -0
- package/dist/packs/nextjs/checks/inj01.js +774 -0
- package/dist/packs/nextjs/checks/sec01.js +254 -0
- package/dist/packs/nextjs/pack.js +13 -0
- package/dist/packs/payments/checks.js +678 -0
- package/dist/packs/razorpay/pack.js +10 -0
- package/dist/packs/stripe/pack.js +11 -0
- package/dist/packs/supabase/checks/data.js +1213 -0
- package/dist/packs/supabase/checks/sec03.js +94 -0
- package/dist/packs/supabase/pack.js +11 -0
- package/dist/packs/supabase/sql.js +269 -0
- package/dist/packs/vite/pack.js +18 -0
- package/dist/promises/changes.js +187 -0
- package/dist/promises/check.js +253 -0
- package/dist/promises/code.js +159 -0
- package/dist/promises/db.js +921 -0
- package/dist/promises/readback.js +58 -0
- package/dist/promises/schema.js +277 -0
- package/dist/promises/world.js +395 -0
- package/dist/proofs/code.js +118 -0
- package/dist/proofs/db.js +248 -0
- package/dist/proofs/engine.js +235 -0
- package/dist/proofs/file.js +129 -0
- package/dist/proofs/harness/mocks.js +573 -0
- package/dist/proofs/harness/run.js +316 -0
- package/dist/proofs/promise-test.js +99 -0
- package/dist/proofs/promise.js +122 -0
- package/dist/proofs/runtime.js +50 -0
- package/dist/proofs/together.js +131 -0
- package/dist/proofs/tree.js +77 -0
- package/dist/proofs/types.js +2 -0
- package/dist/report/gate.js +63 -0
- package/dist/report/json.js +64 -0
- package/dist/report/sarif.js +165 -0
- package/dist/report/terminal.js +182 -0
- package/dist/report/threats.js +134 -0
- package/dist/rules/security-rules.js +52 -0
- package/dist/shields/manager.js +762 -0
- package/dist/shields/record.js +45 -0
- package/dist/shields/schema.js +212 -0
- package/dist/shields/templates/app.js +197 -0
- package/dist/threats/evaluate.js +107 -0
- package/dist/threats/tracks.js +108 -0
- package/dist/threats/tracks.yaml +281 -0
- package/dist/tripwires/manager.js +415 -0
- package/dist/tripwires/routes.js +47 -0
- package/dist/tripwires/templates/app.js +140 -0
- package/dist/universal/budget.js +44 -0
- package/dist/universal/commands.js +169 -0
- package/dist/universal/datastores.js +30 -0
- package/dist/universal/egress.js +209 -0
- package/dist/universal/entrypoints.js +568 -0
- package/dist/universal/gate.js +331 -0
- package/dist/universal/manifests.js +89 -0
- package/dist/universal/map.js +202 -0
- package/dist/universal/merge.js +118 -0
- package/dist/universal/parsers.js +60 -0
- package/dist/universal/roles.js +110 -0
- package/dist/universal/run.js +291 -0
- package/dist/universal/runner.js +113 -0
- package/dist/universal/schemas.js +149 -0
- package/dist/universal/serve.js +61 -0
- package/dist/universal/settings.js +96 -0
- package/dist/universal/workspace.js +67 -0
- package/dist/version.js +2 -0
- package/dist/watch/manager.js +816 -0
- package/dist/watch/templates/app.js +407 -0
- package/package.json +55 -4
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `himaya init --ci` writes (ARCHITECTURE: Deployment gate): the workflow and the CODEOWNERS
|
|
3
|
+
* lines for Himaya-protected files. The workflow runs on pull requests and reviews only (never
|
|
4
|
+
* `pull_request_target`), uses no secrets, pins every action to a full commit, and gives write
|
|
5
|
+
* access only where one job needs it. Himaya is installed from the pull request's BASE commit and
|
|
6
|
+
* the pull request's own code is checked out beside it only as data to scan: a pull request can't
|
|
7
|
+
* change the copy of Himaya that judges it. Reviews are fetched by `gh` inside the workflow;
|
|
8
|
+
* Himaya itself never uses the network.
|
|
9
|
+
*/
|
|
10
|
+
export const WORKFLOW_FILE = ".github/workflows/himaya.yml";
|
|
11
|
+
export const COMMENT_MARKER = "<!-- himaya-consequences -->";
|
|
12
|
+
const CHECKOUT = "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1";
|
|
13
|
+
const SETUP_NODE = "actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0";
|
|
14
|
+
const UPLOAD_SARIF = "github/codeql-action/upload-sarif@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5";
|
|
15
|
+
const SETUP = ` - uses: ${CHECKOUT}
|
|
16
|
+
with:
|
|
17
|
+
ref: \${{ github.event.pull_request.base.sha }}
|
|
18
|
+
path: himaya-base
|
|
19
|
+
persist-credentials: false
|
|
20
|
+
- uses: ${CHECKOUT}
|
|
21
|
+
with:
|
|
22
|
+
ref: \${{ github.event.pull_request.head.sha }}
|
|
23
|
+
path: pr
|
|
24
|
+
fetch-depth: 0
|
|
25
|
+
persist-credentials: false
|
|
26
|
+
- uses: ${SETUP_NODE}
|
|
27
|
+
with:
|
|
28
|
+
node-version: "22"
|
|
29
|
+
- name: Install Himaya from the base branch
|
|
30
|
+
working-directory: himaya-base
|
|
31
|
+
run: npm ci --ignore-scripts`;
|
|
32
|
+
/** Runs the base branch's Himaya on the pull request's files (in pr/). */
|
|
33
|
+
const himaya = (args) => `|
|
|
34
|
+
himaya="$GITHUB_WORKSPACE/himaya-base/node_modules/.bin/himaya"
|
|
35
|
+
if [ ! -x "$himaya" ]; then
|
|
36
|
+
echo "Himaya is not on the base branch yet: these checks start working once the pull request that adds it is merged."
|
|
37
|
+
exit 1
|
|
38
|
+
fi
|
|
39
|
+
"$himaya" ci pr ${args}`;
|
|
40
|
+
const REVIEWS = ` - name: Read the pull request's reviews
|
|
41
|
+
env:
|
|
42
|
+
GH_TOKEN: \${{ github.token }}
|
|
43
|
+
REPO: \${{ github.repository }}
|
|
44
|
+
PR: \${{ github.event.pull_request.number }}
|
|
45
|
+
run: gh api --paginate --slurp "repos/$REPO/pulls/$PR/reviews" > "$RUNNER_TEMP/reviews.json"`;
|
|
46
|
+
const SHAS = ` BASE_SHA: \${{ github.event.pull_request.base.sha }}
|
|
47
|
+
HEAD_SHA: \${{ github.event.pull_request.head.sha }}
|
|
48
|
+
AUTHOR: \${{ github.event.pull_request.user.login }}`;
|
|
49
|
+
const approvalJob = (id) => ` ${id}:
|
|
50
|
+
name: himaya/${id}
|
|
51
|
+
runs-on: ubuntu-latest
|
|
52
|
+
timeout-minutes: 15
|
|
53
|
+
permissions:
|
|
54
|
+
contents: read
|
|
55
|
+
pull-requests: read
|
|
56
|
+
steps:
|
|
57
|
+
${SETUP}
|
|
58
|
+
${REVIEWS}
|
|
59
|
+
- name: Himaya ${id}
|
|
60
|
+
env:
|
|
61
|
+
${SHAS}
|
|
62
|
+
run: ${himaya(`--only ${id} --base "$BASE_SHA" --head "$HEAD_SHA" --author "$AUTHOR" --reviews "$RUNNER_TEMP/reviews.json"`)}`;
|
|
63
|
+
export const WORKFLOW = `# Himaya's checks on every pull request (written by \`himaya init --ci\`).
|
|
64
|
+
# Changing this file needs a human code owner's approval (himaya/protected-files).
|
|
65
|
+
name: Himaya
|
|
66
|
+
|
|
67
|
+
on:
|
|
68
|
+
pull_request:
|
|
69
|
+
# "edited" re-runs the checks when the pull request is pointed at another base branch.
|
|
70
|
+
types: [opened, synchronize, reopened, edited]
|
|
71
|
+
pull_request_review:
|
|
72
|
+
types: [submitted, dismissed]
|
|
73
|
+
|
|
74
|
+
permissions:
|
|
75
|
+
contents: read
|
|
76
|
+
|
|
77
|
+
jobs:
|
|
78
|
+
security:
|
|
79
|
+
name: himaya/security
|
|
80
|
+
runs-on: ubuntu-latest
|
|
81
|
+
timeout-minutes: 15
|
|
82
|
+
permissions:
|
|
83
|
+
contents: read
|
|
84
|
+
security-events: write
|
|
85
|
+
steps:
|
|
86
|
+
${SETUP}
|
|
87
|
+
- name: Himaya security
|
|
88
|
+
env:
|
|
89
|
+
${SHAS}
|
|
90
|
+
run: ${himaya('--only security --base "$BASE_SHA" --head "$HEAD_SHA" --sarif-file "$GITHUB_WORKSPACE/himaya.sarif"')}
|
|
91
|
+
- uses: ${UPLOAD_SARIF}
|
|
92
|
+
# Fork pull requests can't upload; that never decides the check.
|
|
93
|
+
if: always() && hashFiles('himaya.sarif') != ''
|
|
94
|
+
continue-on-error: true
|
|
95
|
+
with:
|
|
96
|
+
sarif_file: himaya.sarif
|
|
97
|
+
checkout_path: pr
|
|
98
|
+
|
|
99
|
+
${approvalJob("protected-files")}
|
|
100
|
+
|
|
101
|
+
${approvalJob("access-changes")}
|
|
102
|
+
|
|
103
|
+
consequences:
|
|
104
|
+
name: himaya/consequences
|
|
105
|
+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
|
|
106
|
+
runs-on: ubuntu-latest
|
|
107
|
+
timeout-minutes: 15
|
|
108
|
+
permissions:
|
|
109
|
+
contents: read
|
|
110
|
+
pull-requests: write
|
|
111
|
+
steps:
|
|
112
|
+
${SETUP}
|
|
113
|
+
- name: Write what this change does
|
|
114
|
+
env:
|
|
115
|
+
${SHAS}
|
|
116
|
+
run: ${himaya('--comment --base "$BASE_SHA" --head "$HEAD_SHA" > "$RUNNER_TEMP/comment.md"')}
|
|
117
|
+
- name: Post it, or update the earlier comment
|
|
118
|
+
env:
|
|
119
|
+
GH_TOKEN: \${{ github.token }}
|
|
120
|
+
REPO: \${{ github.repository }}
|
|
121
|
+
PR: \${{ github.event.pull_request.number }}
|
|
122
|
+
run: |
|
|
123
|
+
id=$(gh api --paginate "repos/$REPO/issues/$PR/comments" --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("${COMMENT_MARKER}"))) | .id' | head -n 1)
|
|
124
|
+
if [ -n "$id" ]; then
|
|
125
|
+
gh api --method PATCH "repos/$REPO/issues/comments/$id" -F "body=@$RUNNER_TEMP/comment.md" > /dev/null
|
|
126
|
+
else
|
|
127
|
+
gh api --method POST "repos/$REPO/issues/$PR/comments" -F "body=@$RUNNER_TEMP/comment.md" > /dev/null
|
|
128
|
+
fi
|
|
129
|
+
`;
|
|
130
|
+
/**
|
|
131
|
+
* The CODEOWNERS paths for Himaya-protected files (ARCHITECTURE: Deployment gate), plus every
|
|
132
|
+
* workflow (a new one could report a check under Himaya's name) and `.npmrc` (it decides where
|
|
133
|
+
* packages, Himaya included, come from). The CODEOWNERS file itself is added by `codeownersLines`
|
|
134
|
+
* at the path the project actually uses.
|
|
135
|
+
*/
|
|
136
|
+
export const PROTECTED_PATTERNS = [
|
|
137
|
+
"/himaya.md",
|
|
138
|
+
"/tests/himaya/",
|
|
139
|
+
"/.himaya/",
|
|
140
|
+
"/himaya/",
|
|
141
|
+
"/src/himaya/",
|
|
142
|
+
"/.claude/settings.json",
|
|
143
|
+
"/.claude/settings.local.json",
|
|
144
|
+
"/.github/workflows/",
|
|
145
|
+
"/.npmrc",
|
|
146
|
+
];
|
|
147
|
+
export const CODEOWNERS_HEADER = "# Himaya-protected files: changes need this owner's approval (written by himaya init --ci).";
|
|
148
|
+
export function codeownersLines(owner, codeownersPath) {
|
|
149
|
+
return [...PROTECTED_PATTERNS, `/${codeownersPath}`].map((p) => `${p} @${owner}`);
|
|
150
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `himaya answer <finding-id> yes|no [folder] [--reason TEXT]`: the owner answers a "Needs your
|
|
3
|
+
* answer" question (docs/DECISIONS.md, Dec 2026). The finding is re-found by a fresh scan, never
|
|
4
|
+
* trusted from a stored ID, and must be a database rule. The answer goes into himaya.md under
|
|
5
|
+
* `answers:` (a protected file: CI needs a code owner's approval to change it).
|
|
6
|
+
*/
|
|
7
|
+
import { flagString } from "./args.js";
|
|
8
|
+
import { scan } from "../engine/scan.js";
|
|
9
|
+
import { stripControl } from "../engine/text.js";
|
|
10
|
+
import { addToProfileList, HuntRefused } from "../hunt/merge.js";
|
|
11
|
+
import { ANSWER_TEXT } from "../copy/report.js";
|
|
12
|
+
import { ruleFingerprint } from "../engine/rank.js";
|
|
13
|
+
const out = (s) => void process.stdout.write(`${stripControl(s)}\n`);
|
|
14
|
+
const err = (s) => void process.stderr.write(`${stripControl(s)}\n`);
|
|
15
|
+
export async function answerCommand(args) {
|
|
16
|
+
const [id, said, folder = "."] = args.positionals;
|
|
17
|
+
const intended = said === "yes" ? true : said === "no" ? false : null;
|
|
18
|
+
if (!id || intended === null) {
|
|
19
|
+
err(ANSWER_TEXT.usage);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
const m = /^([A-Z]+-\d{2}):[0-9a-f]{6,}$/.exec(id);
|
|
23
|
+
const check = m?.[1];
|
|
24
|
+
if (!check) {
|
|
25
|
+
err(ANSWER_TEXT.badId);
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
const reason = (flagString(args, "reason") ?? "").trim().slice(0, 300);
|
|
29
|
+
if (intended && !reason) {
|
|
30
|
+
err(ANSWER_TEXT.needReason);
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
// With promises, so a finding that already breaks a confirmed promise is known as such.
|
|
34
|
+
const r = await scan(folder, { online: false, checks: [check], promises: true });
|
|
35
|
+
const hidden = r.ranked.ignored.find((x) => x.finding.id === id);
|
|
36
|
+
if (hidden) {
|
|
37
|
+
// Answered already for this version of the rule (a stale "intended" answer is asked again),
|
|
38
|
+
// or on the ignore list.
|
|
39
|
+
err(hidden.reason.startsWith("You answered") ? ANSWER_TEXT.already(id) : ANSWER_TEXT.ignored(id));
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
const items = [
|
|
43
|
+
...r.ranked.fixNow,
|
|
44
|
+
...r.ranked.needsAnswer,
|
|
45
|
+
...r.ranked.worthALook,
|
|
46
|
+
...r.ranked.later,
|
|
47
|
+
];
|
|
48
|
+
const item = items.find((i) => i.findings.some((f) => f.id === id));
|
|
49
|
+
const finding = item?.findings.find((f) => f.id === id);
|
|
50
|
+
if (!finding || finding.basis !== "database") {
|
|
51
|
+
err(ANSWER_TEXT.notAQuestion(id));
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
if (item?.bucket === "fix-now") {
|
|
55
|
+
// Answered "not intended" already, or it breaks a promise you confirmed: nothing to ask.
|
|
56
|
+
err(finding.breaksPromises?.length ? ANSWER_TEXT.breaksPromise(id) : ANSWER_TEXT.already(id));
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
const question = finding.question ?? finding.title;
|
|
60
|
+
try {
|
|
61
|
+
addToProfileList(folder, "answers", {
|
|
62
|
+
id,
|
|
63
|
+
intended,
|
|
64
|
+
...(reason ? { reason } : {}),
|
|
65
|
+
rule: ruleFingerprint(finding),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e instanceof HuntRefused) {
|
|
70
|
+
err(e.message);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
out(intended ? ANSWER_TEXT.savedYes(question) : ANSWER_TEXT.savedNo(question));
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
package/dist/cli/args.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function parseArgs(argv) {
|
|
2
|
+
const positionals = [];
|
|
3
|
+
const flags = new Map();
|
|
4
|
+
const valued = new Set([
|
|
5
|
+
"checks",
|
|
6
|
+
"fail-on",
|
|
7
|
+
"since",
|
|
8
|
+
"base",
|
|
9
|
+
"head",
|
|
10
|
+
"reviews",
|
|
11
|
+
"max-surfaces",
|
|
12
|
+
"test",
|
|
13
|
+
"run",
|
|
14
|
+
"replay",
|
|
15
|
+
"brief",
|
|
16
|
+
"lure",
|
|
17
|
+
"reason",
|
|
18
|
+
"together",
|
|
19
|
+
"owner",
|
|
20
|
+
"only",
|
|
21
|
+
"author",
|
|
22
|
+
"sarif-file",
|
|
23
|
+
]);
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const a = argv[i] ?? "";
|
|
26
|
+
if (a === "--") {
|
|
27
|
+
positionals.push(...argv.slice(i + 1));
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (a.startsWith("--")) {
|
|
31
|
+
const eq = a.indexOf("=");
|
|
32
|
+
if (eq !== -1)
|
|
33
|
+
flags.set(a.slice(2, eq), a.slice(eq + 1));
|
|
34
|
+
else {
|
|
35
|
+
const key = a.slice(2);
|
|
36
|
+
const next = argv[i + 1];
|
|
37
|
+
if (valued.has(key) && next !== undefined && !next.startsWith("--")) {
|
|
38
|
+
flags.set(key, next);
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
flags.set(key, true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
positionals.push(a);
|
|
47
|
+
}
|
|
48
|
+
return { positionals, flags };
|
|
49
|
+
}
|
|
50
|
+
export function flagString(args, key) {
|
|
51
|
+
const v = args.flags.get(key);
|
|
52
|
+
return typeof v === "string" ? v : undefined;
|
|
53
|
+
}
|
package/dist/cli/ci.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `himaya ci [folder] [--only security|protected-files|access-changes] [--base REF] [--head REF]
|
|
3
|
+
* [--reviews FILE] [--author LOGIN] [--sarif-file FILE] [--json] | --comment`.
|
|
4
|
+
* Exit 0 when every check run passes, 1 when one blocks, 2 for a usage problem.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, lstatSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { flagString } from "./args.js";
|
|
8
|
+
import { CI_CHECKS, CiRefused, accessChanges, consequenceComment, outcomeText, protectedFiles, resolveSides, reviewsFrom, security, } from "../ci/run.js";
|
|
9
|
+
import { defaultBaseCommit } from "../diff/run.js";
|
|
10
|
+
import { resolveCommit } from "../diff/snapshot.js";
|
|
11
|
+
import { toSarif } from "../report/sarif.js";
|
|
12
|
+
import { VERSION } from "../version.js";
|
|
13
|
+
import { CI_TEXT } from "../copy/ci.js";
|
|
14
|
+
import { stripControl } from "../engine/text.js";
|
|
15
|
+
export async function ciCommand(args) {
|
|
16
|
+
const root = args.positionals[0] ?? ".";
|
|
17
|
+
const only = flagString(args, "only");
|
|
18
|
+
if (only !== undefined && !CI_CHECKS.includes(only)) {
|
|
19
|
+
process.stderr.write(CI_TEXT.badOnly + "\n");
|
|
20
|
+
return 2;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const baseRef = flagString(args, "base") ?? defaultBaseCommit(root);
|
|
24
|
+
if (!baseRef)
|
|
25
|
+
throw new CiRefused(CI_TEXT.noBase);
|
|
26
|
+
const { base, head } = resolveSides(root, baseRef, flagString(args, "head") ?? "HEAD");
|
|
27
|
+
if (args.flags.has("comment")) {
|
|
28
|
+
process.stdout.write(await consequenceComment(root, base, head));
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
const reviewsPath = flagString(args, "reviews");
|
|
32
|
+
let reviews = null;
|
|
33
|
+
if (reviewsPath !== undefined) {
|
|
34
|
+
if (!existsSync(reviewsPath) || !lstatSync(reviewsPath).isFile())
|
|
35
|
+
throw new CiRefused(CI_TEXT.noReviews);
|
|
36
|
+
if (flagString(args, "author") === undefined)
|
|
37
|
+
throw new CiRefused(CI_TEXT.needAuthor);
|
|
38
|
+
reviews = reviewsFrom(readFileSync(reviewsPath, "utf8"));
|
|
39
|
+
if (!reviews)
|
|
40
|
+
throw new CiRefused(CI_TEXT.badReviews);
|
|
41
|
+
}
|
|
42
|
+
const input = { root, base, head, reviews, author: flagString(args, "author") ?? "" };
|
|
43
|
+
const run = (only ? [only] : CI_CHECKS);
|
|
44
|
+
const outcomes = [];
|
|
45
|
+
for (const check of run) {
|
|
46
|
+
if (check === "security") {
|
|
47
|
+
// The scan reads the files that are checked out, so they must be the head's.
|
|
48
|
+
if (resolveCommit(root, "HEAD") !== head)
|
|
49
|
+
throw new CiRefused(CI_TEXT.headNotCheckedOut(head));
|
|
50
|
+
const { outcome, result } = await security(root);
|
|
51
|
+
const sarif = flagString(args, "sarif-file");
|
|
52
|
+
if (sarif !== undefined) {
|
|
53
|
+
if (existsSync(sarif) && lstatSync(sarif).isSymbolicLink())
|
|
54
|
+
throw new CiRefused(CI_TEXT.isLink(stripControl(sarif)));
|
|
55
|
+
writeFileSync(sarif, toSarif(result, VERSION) + "\n");
|
|
56
|
+
}
|
|
57
|
+
outcomes.push(outcome);
|
|
58
|
+
}
|
|
59
|
+
else if (check === "protected-files")
|
|
60
|
+
outcomes.push(protectedFiles(input));
|
|
61
|
+
else
|
|
62
|
+
outcomes.push(await accessChanges(input));
|
|
63
|
+
}
|
|
64
|
+
process.stdout.write(args.flags.has("json")
|
|
65
|
+
? JSON.stringify({ passed: outcomes.every((o) => o.passed), checks: outcomes }, null, 2) +
|
|
66
|
+
"\n"
|
|
67
|
+
: outcomes.map(outcomeText).join("\n"));
|
|
68
|
+
return outcomes.every((o) => o.passed) ? 0 : 1;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof CiRefused) {
|
|
72
|
+
process.stderr.write(`${e.message}\n`);
|
|
73
|
+
return 2;
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/cli/diff.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** `himaya diff [folder] [--base REF] [--head REF] [--json]`. */
|
|
2
|
+
import { flagString } from "./args.js";
|
|
3
|
+
import { DiffRefused, consequenceDiff } from "../diff/run.js";
|
|
4
|
+
import { diffToJson, diffToText } from "../diff/render.js";
|
|
5
|
+
export async function diffCommand(args) {
|
|
6
|
+
const folder = args.positionals[0] ?? ".";
|
|
7
|
+
try {
|
|
8
|
+
const r = await consequenceDiff(folder, flagString(args, "base"), flagString(args, "head"));
|
|
9
|
+
process.stdout.write(args.flags.has("json")
|
|
10
|
+
? diffToJson(r.changes, r.unknown) + "\n"
|
|
11
|
+
: diffToText(r.changes, r.unknown));
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
if (e instanceof DiffRefused) {
|
|
16
|
+
process.stderr.write(`${e.message}\n`);
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { scan } from "../engine/scan.js";
|
|
2
|
+
import { CHECKS } from "../engine/checks-list.js";
|
|
3
|
+
import { stripControl } from "../engine/text.js";
|
|
4
|
+
import { maskSecrets } from "../engine/mask.js";
|
|
5
|
+
import { EXPLAIN_TEXT, PROFILE_TEMPLATE } from "../copy/init.js";
|
|
6
|
+
const clean = (s) => maskSecrets(stripControl(s));
|
|
7
|
+
export async function explainText(id, folder) {
|
|
8
|
+
const wanted = id.trim();
|
|
9
|
+
// Only the check the ID names needs to run (with the promises, which may share its cause).
|
|
10
|
+
const check = wanted.split(":")[0]?.toUpperCase() ?? "";
|
|
11
|
+
const known = CHECKS.some((c) => c.id === check);
|
|
12
|
+
const r = await scan(folder, {
|
|
13
|
+
online: false,
|
|
14
|
+
...(known ? { checks: [check], promises: true } : {}),
|
|
15
|
+
});
|
|
16
|
+
const byId = r.findings.find((f) => f.id.toLowerCase() === wanted.toLowerCase());
|
|
17
|
+
const ofCheck = r.findings.filter((f) => f.checkId === wanted.toUpperCase());
|
|
18
|
+
const f = byId ?? ofCheck[0];
|
|
19
|
+
if (!f)
|
|
20
|
+
return null;
|
|
21
|
+
const lines = [
|
|
22
|
+
`${f.id} · ${clean(f.title)}`,
|
|
23
|
+
EXPLAIN_TEXT.where(f.location.file, f.location.line),
|
|
24
|
+
EXPLAIN_TEXT.severity(f.severity, f.severityReason ? clean(f.severityReason) : undefined),
|
|
25
|
+
"",
|
|
26
|
+
clean(f.explanation),
|
|
27
|
+
"",
|
|
28
|
+
EXPLAIN_TEXT.evidence(f.evidence.text),
|
|
29
|
+
];
|
|
30
|
+
if (f.breaksPromises?.length)
|
|
31
|
+
lines.push(EXPLAIN_TEXT.breaks(f.breaksPromises));
|
|
32
|
+
if (f.fix.humanStep)
|
|
33
|
+
lines.push(EXPLAIN_TEXT.human(clean(f.fix.humanStep)));
|
|
34
|
+
lines.push(f.fix.available ? EXPLAIN_TEXT.fix(f.id) : EXPLAIN_TEXT.noFix);
|
|
35
|
+
if (!byId && ofCheck.length > 1)
|
|
36
|
+
lines.push(EXPLAIN_TEXT.others(ofCheck.length - 1));
|
|
37
|
+
return lines.join("\n") + "\n";
|
|
38
|
+
}
|
|
39
|
+
export async function explainCommand(args) {
|
|
40
|
+
const [id, folder] = args.positionals;
|
|
41
|
+
if (!id) {
|
|
42
|
+
process.stderr.write(EXPLAIN_TEXT.usage + "\n");
|
|
43
|
+
return 2;
|
|
44
|
+
}
|
|
45
|
+
const text = await explainText(id, folder ?? ".");
|
|
46
|
+
if (text === null) {
|
|
47
|
+
const check = CHECKS.find((c) => c.id === id.split(":")[0]?.toUpperCase());
|
|
48
|
+
process.stdout.write(EXPLAIN_TEXT.notFound(stripControl(id), check && !id.includes(":") ? check.title : null) +
|
|
49
|
+
"\n");
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
process.stdout.write(text);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
export function profileCommand(args) {
|
|
56
|
+
if (!args.flags.has("template")) {
|
|
57
|
+
process.stderr.write(EXPLAIN_TEXT.templateUsage + "\n");
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
process.stdout.write(PROFILE_TEMPLATE);
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { scan, ScanError } from "../engine/scan.js";
|
|
2
|
+
import { stripControl } from "../engine/text.js";
|
|
3
|
+
import { CHECKS } from "../engine/checks-list.js";
|
|
4
|
+
import { VERSION } from "../version.js";
|
|
5
|
+
import { FEEDBACK_TEXT as T } from "../copy/feedback.js";
|
|
6
|
+
/** The catalogue title for a check ID: shipped text, never the finding's own wording. */
|
|
7
|
+
function titleOf(id) {
|
|
8
|
+
return CHECKS.find((c) => c.id === id)?.title ?? "Promise or hunt rule";
|
|
9
|
+
}
|
|
10
|
+
/** A check ID as shown on the sheet: catalogue IDs only (promise IDs are the owner's own words). */
|
|
11
|
+
function idOf(id) {
|
|
12
|
+
return CHECKS.some((c) => c.id === id) ? id : "PROMISE";
|
|
13
|
+
}
|
|
14
|
+
export function feedbackSheet(r) {
|
|
15
|
+
const finished = !r.notes.some((n) => n.kind === "time-limit");
|
|
16
|
+
const lines = [
|
|
17
|
+
T.title,
|
|
18
|
+
"",
|
|
19
|
+
...T.nothingSent,
|
|
20
|
+
...T.forms,
|
|
21
|
+
"",
|
|
22
|
+
T.scanLine(VERSION, finished, Math.round(r.durationMs / 1000)),
|
|
23
|
+
T.counts(r.ranked.fixNow.length, r.ranked.needsAnswer.length, r.ranked.worthALook.length, r.ranked.later.length),
|
|
24
|
+
"",
|
|
25
|
+
T.fixNowHeading,
|
|
26
|
+
];
|
|
27
|
+
r.ranked.fixNow.forEach((item, i) => lines.push(T.fixNowRow(i + 1, idOf(item.checkId), titleOf(item.checkId))));
|
|
28
|
+
if (!r.ranked.fixNow.length)
|
|
29
|
+
lines.push(T.none);
|
|
30
|
+
lines.push("", T.questionsHeading);
|
|
31
|
+
r.ranked.needsAnswer.forEach((item, i) => lines.push(T.questionRow(i + 1, idOf(item.checkId), titleOf(item.checkId))));
|
|
32
|
+
if (!r.ranked.needsAnswer.length)
|
|
33
|
+
lines.push(T.none);
|
|
34
|
+
lines.push("", T.worthHeading, T.worthLine(r.ranked.worthALook.length));
|
|
35
|
+
lines.push("", T.missedHeading, T.missedLine, "", T.consent, "");
|
|
36
|
+
return lines.join("\n");
|
|
37
|
+
}
|
|
38
|
+
export async function feedbackCommand(args) {
|
|
39
|
+
for (const flag of args.flags.keys()) {
|
|
40
|
+
process.stderr.write(T.unknownFlag(stripControl(flag)) + "\n");
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
if (args.positionals.length > 1) {
|
|
44
|
+
process.stderr.write(T.extraFolder + "\n");
|
|
45
|
+
return 2;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const r = await scan(args.positionals[0] ?? ".", { online: false });
|
|
49
|
+
process.stdout.write(feedbackSheet(r));
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
if (e instanceof ScanError) {
|
|
54
|
+
process.stderr.write(stripControl(e.message) + "\n");
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
}
|