@abdulr7man/pensieve 0.0.0-stage → 1.2.2
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/LICENSE +684 -0
- package/README.md +180 -2
- package/VERSION +1 -0
- package/agents/README.md +16 -0
- package/agents/pensieve-code-auditor.md +58 -0
- package/agents/pensieve-mapper.md +46 -0
- package/agents/pensieve-planner.md +67 -0
- package/agents/pensieve-reconner.md +76 -0
- package/agents/pensieve-reporter.md +61 -0
- package/agents/pensieve-roe-checker.md +46 -0
- package/agents/pensieve-scoper.md +77 -0
- package/agents/pensieve-tester.md +83 -0
- package/agents/pensieve-validator.md +62 -0
- package/bin/pensieve +452 -0
- package/bin/pensieve-installer.cjs +5 -0
- package/commands/pensieve-close.md +6 -0
- package/commands/pensieve-map.md +6 -0
- package/commands/pensieve-new-engagement.md +6 -0
- package/commands/pensieve-pause.md +15 -0
- package/commands/pensieve-plan.md +6 -0
- package/commands/pensieve-progress.md +34 -0
- package/commands/pensieve-quick.md +8 -0
- package/commands/pensieve-recon.md +6 -0
- package/commands/pensieve-report.md +6 -0
- package/commands/pensieve-resume.md +6 -0
- package/commands/pensieve-retest.md +10 -0
- package/commands/pensieve-scope.md +49 -0
- package/commands/pensieve-surface.md +8 -0
- package/commands/pensieve-test.md +6 -0
- package/commands/pensieve-validate.md +6 -0
- package/docker/Dockerfile.pensieve-toolbox +75 -0
- package/docker/compose.pensieve-net.yml +37 -0
- package/docker/squid.conf.template +21 -0
- package/package.json +39 -4
- package/packs/ad/ad-killchain/checklist.md +64 -0
- package/packs/ad/ad-killchain/pack.yaml +19 -0
- package/packs/cloud/cloud-cis/checklist.md +66 -0
- package/packs/cloud/cloud-cis/pack.yaml +20 -0
- package/packs/fintech/practice-core/checklist.md +33 -0
- package/packs/fintech/practice-core/learnings.md +5 -0
- package/packs/fintech/practice-core/pack.yaml +18 -0
- package/packs/infra/ptes-infra/checklist.md +22 -0
- package/packs/infra/ptes-infra/pack.yaml +19 -0
- package/packs/mobile/owasp-masvs/checklist.md +80 -0
- package/packs/mobile/owasp-masvs/pack.yaml +20 -0
- package/packs/owasp-api-v4/checklist.md +85 -0
- package/packs/owasp-api-v4/learnings.md +6 -0
- package/packs/owasp-api-v4/pack.yaml +23 -0
- package/packs/owasp-api-v4/runbooks/API1/SKILL.md +66 -0
- package/packs/owasp-api-v4/runbooks/API10/SKILL.md +67 -0
- package/packs/owasp-api-v4/runbooks/API2/SKILL.md +129 -0
- package/packs/owasp-api-v4/runbooks/API3/SKILL.md +55 -0
- package/packs/owasp-api-v4/runbooks/API4/SKILL.md +59 -0
- package/packs/owasp-api-v4/runbooks/API5/SKILL.md +60 -0
- package/packs/owasp-api-v4/runbooks/API6/SKILL.md +63 -0
- package/packs/owasp-api-v4/runbooks/API7/SKILL.md +70 -0
- package/packs/owasp-api-v4/runbooks/API8/SKILL.md +72 -0
- package/packs/owasp-api-v4/runbooks/API9/SKILL.md +66 -0
- package/packs/thickclient/thickclient-core/checklist.md +60 -0
- package/packs/thickclient/thickclient-core/pack.yaml +24 -0
- package/packs/web/asvs-l2/checklist.md +50 -0
- package/packs/web/asvs-l2/learnings.md +6 -0
- package/packs/web/asvs-l2/pack.yaml +19 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-ENUM/SKILL.md +75 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-LIVE/SKILL.md +78 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-MFA/SKILL.md +76 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-RATE/SKILL.md +72 -0
- package/packs/web/owasp-testing-checklist/checklist.md +52 -0
- package/packs/web/owasp-testing-checklist/learnings.md +47 -0
- package/packs/web/owasp-testing-checklist/pack.yaml +21 -0
- package/packs/web/unauth-perimeter/checklist.md +72 -0
- package/packs/web/unauth-perimeter/pack.yaml +18 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-01/SKILL.md +60 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-02/SKILL.md +63 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-03/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-04/SKILL.md +75 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-05/SKILL.md +66 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-06/SKILL.md +59 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-07/SKILL.md +56 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-08/SKILL.md +57 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-09/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-10/SKILL.md +60 -0
- package/packs/whitebox/code-audit-core/checklist.md +36 -0
- package/packs/whitebox/code-audit-core/learnings.md +6 -0
- package/packs/whitebox/code-audit-core/pack.yaml +14 -0
- package/prompts/orchestrator-core.md +52 -0
- package/reference/attack-playbooks.md +57 -0
- package/reference/otp-relay.md +98 -0
- package/reference/param-profiles.md +48 -0
- package/reference/templates/FINDING.md +97 -0
- package/reference/tool-selection.md +64 -0
- package/reference/vulnerability-finding-standard.md +80 -0
- package/runtimes/hermes/hooks/injection-scan.py +290 -0
- package/runtimes/hermes/hooks/scope-guard.py +136 -0
- package/skills/pensieve/SKILL.md +134 -0
- package/skills/pensieve-close/SKILL.md +31 -0
- package/skills/pensieve-map/SKILL.md +25 -0
- package/skills/pensieve-new-engagement/SKILL.md +28 -0
- package/skills/pensieve-pause/SKILL.md +22 -0
- package/skills/pensieve-plan/SKILL.md +39 -0
- package/skills/pensieve-progress/SKILL.md +35 -0
- package/skills/pensieve-quick/SKILL.md +47 -0
- package/skills/pensieve-recon/SKILL.md +30 -0
- package/skills/pensieve-report/SKILL.md +46 -0
- package/skills/pensieve-resume/SKILL.md +33 -0
- package/skills/pensieve-retest/SKILL.md +35 -0
- package/skills/pensieve-scope/SKILL.md +35 -0
- package/skills/pensieve-surface/SKILL.md +36 -0
- package/skills/pensieve-test/SKILL.md +35 -0
- package/skills/pensieve-validate/SKILL.md +28 -0
- package/skills/pensieve-wiki/SKILL.md +39 -0
- package/src/installer/cli.cjs +209 -0
- package/src/installer/home.cjs +155 -0
- package/src/installer/runtimes.cjs +276 -0
- package/src/installer/uninstall.cjs +342 -0
- package/src/pensieve-sdk/bin/pensieve-sdk.cjs +1045 -0
- package/src/pensieve-sdk/lib/agent-translate.cjs +50 -0
- package/src/pensieve-sdk/lib/approvals.cjs +408 -0
- package/src/pensieve-sdk/lib/audit.cjs +290 -0
- package/src/pensieve-sdk/lib/checklist.cjs +337 -0
- package/src/pensieve-sdk/lib/clientlist.cjs +814 -0
- package/src/pensieve-sdk/lib/close.cjs +133 -0
- package/src/pensieve-sdk/lib/config.cjs +156 -0
- package/src/pensieve-sdk/lib/cvss.cjs +91 -0
- package/src/pensieve-sdk/lib/env.cjs +272 -0
- package/src/pensieve-sdk/lib/evidence.cjs +217 -0
- package/src/pensieve-sdk/lib/findings.cjs +1096 -0
- package/src/pensieve-sdk/lib/frontmatter.cjs +178 -0
- package/src/pensieve-sdk/lib/graph.cjs +607 -0
- package/src/pensieve-sdk/lib/ids.cjs +63 -0
- package/src/pensieve-sdk/lib/init.cjs +79 -0
- package/src/pensieve-sdk/lib/liveness.cjs +176 -0
- package/src/pensieve-sdk/lib/loop.cjs +619 -0
- package/src/pensieve-sdk/lib/migrate.cjs +57 -0
- package/src/pensieve-sdk/lib/monitor.cjs +69 -0
- package/src/pensieve-sdk/lib/pack.cjs +607 -0
- package/src/pensieve-sdk/lib/paths.cjs +73 -0
- package/src/pensieve-sdk/lib/pdf.cjs +291 -0
- package/src/pensieve-sdk/lib/recon.cjs +296 -0
- package/src/pensieve-sdk/lib/renderers/__pycache__/formal_report.cpython-314.pyc +0 -0
- package/src/pensieve-sdk/lib/renderers/formal_report.py +608 -0
- package/src/pensieve-sdk/lib/report.cjs +1135 -0
- package/src/pensieve-sdk/lib/runbook.cjs +124 -0
- package/src/pensieve-sdk/lib/sarif.cjs +154 -0
- package/src/pensieve-sdk/lib/scope.cjs +621 -0
- package/src/pensieve-sdk/lib/security.cjs +61 -0
- package/src/pensieve-sdk/lib/skills.cjs +193 -0
- package/src/pensieve-sdk/lib/state.cjs +610 -0
- package/src/pensieve-sdk/lib/subagent.cjs +658 -0
- package/src/pensieve-sdk/lib/target.cjs +149 -0
- package/src/pensieve-sdk/lib/tools.cjs +66 -0
- package/src/pensieve-sdk/lib/vault.cjs +122 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.LICENSE +22 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.js +1208 -0
- package/src/pensieve-sdk/package.json +11 -0
- package/templates/ACCOUNTS.md +35 -0
- package/templates/ATTACK-SURFACE.md +30 -0
- package/templates/FINDING.md +43 -0
- package/templates/PLAN.md +33 -0
- package/templates/PROJECT.md +29 -0
- package/templates/ROE.md +50 -0
- package/templates/RUN-LOG.md +19 -0
- package/templates/SCOPE.md +32 -0
- package/templates/VALIDATION.md +62 -0
- package/templates/report/REPORT.md +49 -0
- package/workflows/close.md +34 -0
- package/workflows/map.md +39 -0
- package/workflows/new-engagement.md +37 -0
- package/workflows/plan.md +45 -0
- package/workflows/progress.md +28 -0
- package/workflows/quick.md +67 -0
- package/workflows/recon.md +87 -0
- package/workflows/report.md +51 -0
- package/workflows/resume.md +26 -0
- package/workflows/retest.md +53 -0
- package/workflows/scope.md +47 -0
- package/workflows/surface.md +29 -0
- package/workflows/test.md +95 -0
- package/workflows/validate.md +34 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* init.cjs — engagement scaffolding (ADR-006).
|
|
4
|
+
* Creates <cwd>/<id>/ with the full FLAT layout: skeleton files and dirs live
|
|
5
|
+
* directly at the engagement root (the .pentest/ layer is gone, v0.6 01-01).
|
|
6
|
+
* The rich templates/ directory (repo) overrides these skeletons at install time;
|
|
7
|
+
* the sdk stays self-contained so `pensieve-sdk init` always works.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
const { engagementId } = require('./ids.cjs');
|
|
13
|
+
const config = require('./config.cjs');
|
|
14
|
+
const state = require('./state.cjs');
|
|
15
|
+
const fm = require('./frontmatter.cjs');
|
|
16
|
+
const paths = require('./paths.cjs');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* REACH-04 (v1.1): the SCOPE.md asset line carries the HOST only (the
|
|
20
|
+
* scope parser rejects scheme-prefixed tokens). Accepts a URL, host[:port],
|
|
21
|
+
* or bare host and returns the hostname.
|
|
22
|
+
*/
|
|
23
|
+
function extractTargetHost(target) {
|
|
24
|
+
const t = String(target || '').trim();
|
|
25
|
+
try { return new URL(t).hostname || t; } catch { /* not a full URL */ }
|
|
26
|
+
const m = /^([A-Za-z0-9.-]+)(?::\d+)?/.exec(t);
|
|
27
|
+
return m ? m[1] : t;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function skeletons(id, client, target, methodology) {
|
|
31
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
32
|
+
// REACH-04 (v1.1): the skeleton asset line must be the CANONICAL parser
|
|
33
|
+
// form from day one — the ai-approve gate rejected the old scheme-prefixed
|
|
34
|
+
// skeleton line twice in the live walkthrough (2026-12-04). HOST only,
|
|
35
|
+
// single line, ports in the parenthetical.
|
|
36
|
+
const targetHostOnly = extractTargetHost(target);
|
|
37
|
+
return {
|
|
38
|
+
'PROJECT.md': `# ${id}\n\n- Client: ${client}\n- Primary target: ${target}\n- Methodology: ${methodology}\n- Created: ${today}\n\n_Engagement overview, objectives, constraints._\n`,
|
|
39
|
+
'SCOPE.md': `# Scope — ${id}\n\n## In Scope\n\n- AST-001 ${targetHostOnly} (primary target, ports 80,443)\n\n## Out of Scope\n\n- _to be confirmed at /pensieve-scope checkpoint_\n`,
|
|
40
|
+
'ROE.md': `# Rules of Engagement — ${id}\n\n_Authorization reference, allowed techniques, blackout windows, emergency contacts._\n\n## Layer notes (from spike 001)\n\nThe scope-guard hook sees command text only; redirects/CNAME chains are\nenforced at the network layer (squid sees the real destination).\nRaw-socket scanning lanes are deferred (M2); web/API tooling runs proxied.\n`,
|
|
41
|
+
'STATE.md': fm.stringify({ status: 'initialized', engagement: id, methodology, updated: today },
|
|
42
|
+
`\n## Phase Notes\n\n_engagement initialized; awaiting /pensieve-scope_\n`),
|
|
43
|
+
'ATTACK-SURFACE.md': `# Attack Surface — ${id}\n\n_pending /pensieve-recon_ \n`,
|
|
44
|
+
'ACCOUNTS.md': `# Accounts — ${id}\n\n| Account | Role | Source | Created by | Status |\n|---------|------|--------|------------|--------|\n\n_provided credentials and self-provisioned test accounts (ADR-010)_\n`,
|
|
45
|
+
// Phase 23 (VAULT-01): the credential vault lives at <engagement>/.env —
|
|
46
|
+
// a 0600 JSON slot file the SDK writes atomically. The scaffold ships a
|
|
47
|
+
// .gitignore entry for it from day one so the vault NEVER lands in git,
|
|
48
|
+
// even when the engagement root sits inside a repository.
|
|
49
|
+
'.gitignore': '# Engagement-local secrets — never commit\n.env\n',
|
|
50
|
+
// methodology is per-engagement metadata: override the schema default
|
|
51
|
+
// with the value the operator gave at /pensieve-new-engagement (VIZ-05).
|
|
52
|
+
'config.yaml': Object.entries({ ...config.defaults(), methodology }).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join('\n') + '\n',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function initEngagement({ client, target, methodology = 'web', cwd, date }) {
|
|
57
|
+
if (!client || !target) throw new Error('init requires client and target');
|
|
58
|
+
if (typeof methodology !== 'string' || !methodology.trim()) {
|
|
59
|
+
throw new Error('init requires a non-empty methodology (e.g. web, api) — it is engagement metadata (VIZ-05)');
|
|
60
|
+
}
|
|
61
|
+
methodology = methodology.trim();
|
|
62
|
+
const id = engagementId(client, target, date);
|
|
63
|
+
const root = path.resolve(cwd || process.cwd());
|
|
64
|
+
const engPath = path.join(root, id);
|
|
65
|
+
if (fs.existsSync(engPath)) throw new Error(`engagement dir already exists: ${engPath}`);
|
|
66
|
+
|
|
67
|
+
fs.mkdirSync(engPath, { recursive: true });
|
|
68
|
+
for (const d of paths.DIRS) fs.mkdirSync(paths.resolve(engPath, d), { recursive: true });
|
|
69
|
+
for (const [name, content] of Object.entries(skeletons(id, client, target, methodology))) {
|
|
70
|
+
fs.writeFileSync(paths.resolve(engPath, name), content);
|
|
71
|
+
}
|
|
72
|
+
fs.writeFileSync(paths.findingsIndex(engPath), '# Findings Index\n\n_(empty)_\n');
|
|
73
|
+
fs.writeFileSync(paths.evidenceIndex(engPath), '# Evidence Index (JSONL — one record per line)\n');
|
|
74
|
+
|
|
75
|
+
state.register(engPath, id);
|
|
76
|
+
return { id, path: engPath, methodology };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { initEngagement };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* liveness.cjs — REACH-01 (v1.1): the contained reachability pre-check.
|
|
4
|
+
*
|
|
5
|
+
* The dogfood walkthrough (2026-12-04) walked six phases and built a full
|
|
6
|
+
* report to close an engagement whose target never existed — nobody checked
|
|
7
|
+
* liveness first. scope.liveness probes every in-scope host THROUGH the
|
|
8
|
+
* engagement proxy (the only lane that can resolve external names under
|
|
9
|
+
* containment — spike 001c), classifies the squid error ids, writes the raw
|
|
10
|
+
* exchanges into the evidence ledger, and records the verdict in
|
|
11
|
+
* recon/LIVENESS.md. That file is the checkpoint input (unreachable → the
|
|
12
|
+
* native question form: amend / close early / continue with a recorded
|
|
13
|
+
* override) and the close gate's evidence-backed input for
|
|
14
|
+
* engagement.close --reason unreachable — no fabrication lane: the verdict
|
|
15
|
+
* must exist and its evidence ids must verify.
|
|
16
|
+
*/
|
|
17
|
+
const fs = require('node:fs');
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
const { execFileSync } = require('node:child_process');
|
|
20
|
+
const scope = require('./scope.cjs');
|
|
21
|
+
const evidence = require('./evidence.cjs');
|
|
22
|
+
const paths = require('./paths.cjs');
|
|
23
|
+
const fm = require('./frontmatter.cjs');
|
|
24
|
+
|
|
25
|
+
function livenessFile(dir) {
|
|
26
|
+
return path.join(paths.reconDir(dir), 'LIVENESS.md');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Map one proxied curl header dump to a host state. Squid marks its own
|
|
31
|
+
* error pages with an X-Squid-Error header; anything without it that
|
|
32
|
+
* carries an HTTP status line is a real application response. Fail-closed:
|
|
33
|
+
* empty/blank text is NOT live.
|
|
34
|
+
*/
|
|
35
|
+
function classify(headersText) {
|
|
36
|
+
const text = String(headersText || '');
|
|
37
|
+
const m = /X-Squid-Error:\s*([A-Za-z_]+)/i.exec(text);
|
|
38
|
+
if (m) {
|
|
39
|
+
const err = m[1].toUpperCase();
|
|
40
|
+
return { live: false, resolved: err !== 'ERR_DNS_FAIL', squidError: err };
|
|
41
|
+
}
|
|
42
|
+
const answered = /^HTTP\/\d(?:\.\d)?\s+\d{3}/.test(text.trim());
|
|
43
|
+
return { live: answered, resolved: answered, squidError: null };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function probeCmd(host, scheme) {
|
|
47
|
+
// -D - dumps headers to stdout; body discarded; the toolbox env carries
|
|
48
|
+
// the proxy vars (compose environment), so curl transits squid. The
|
|
49
|
+
// trailing `; true` is load-bearing: an unreachable host makes curl exit
|
|
50
|
+
// non-zero (e.g. CONNECT tunnel failure) and execFileSync would THROW on
|
|
51
|
+
// the exit code — the failure IS the probe's data, never a runner error.
|
|
52
|
+
return `curl -sS -D - -o /dev/null --max-time 15 -w '\\nCURL_HTTP=%{http_code}\\n' ${scheme}://${host}/ 2>&1; true`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function composeExecToolbox(dir, cmd) {
|
|
56
|
+
const composeFile = path.join(paths.envDir(dir), 'compose.pensieve-net.yml');
|
|
57
|
+
if (!fs.existsSync(composeFile)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'scope.liveness: no env/ compose file — run pensieve-sdk env.render + env.up first '
|
|
60
|
+
+ '(liveness probes through the contained network only, never the host)'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return execFileSync(
|
|
65
|
+
'docker',
|
|
66
|
+
['compose', '-f', composeFile, 'exec', '-T', 'toolbox', 'sh', '-c', cmd],
|
|
67
|
+
{ stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', timeout: 60 * 1000 },
|
|
68
|
+
);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
'scope.liveness: toolbox exec failed — is the stack up? (pensieve-sdk env.up --engagement <dir>): '
|
|
72
|
+
+ String(e.message || e).split('\n')[0]
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function inScopeHosts(dir) {
|
|
78
|
+
const file = paths.scopeFile(dir);
|
|
79
|
+
if (!fs.existsSync(file)) throw new Error('scope.liveness: SCOPE.md not found');
|
|
80
|
+
const ast = scope.parse(fs.readFileSync(file, 'utf8'));
|
|
81
|
+
const hosts = [...new Set(ast.assets.map((a) => a.host).filter((h) => !h.includes('/')))];
|
|
82
|
+
if (!hosts.length) throw new Error('scope.liveness: no in-scope hosts in SCOPE.md');
|
|
83
|
+
return hosts;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The live runner: probe every in-scope host through the contained proxy. */
|
|
87
|
+
function liveness(dir) {
|
|
88
|
+
const probes = inScopeHosts(dir).map((host) => ({
|
|
89
|
+
host,
|
|
90
|
+
http: composeExecToolbox(dir, probeCmd(host, 'http')),
|
|
91
|
+
https: composeExecToolbox(dir, probeCmd(host, 'https')),
|
|
92
|
+
}));
|
|
93
|
+
return livenessFromProbes(dir, probes);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The deterministic core (probe outputs → verdict + ledger + LIVENESS.md).
|
|
98
|
+
* Split from the runner so tests inject probe outputs with no docker.
|
|
99
|
+
*/
|
|
100
|
+
function livenessFromProbes(dir, probes) {
|
|
101
|
+
if (!Array.isArray(probes) || !probes.length) {
|
|
102
|
+
throw new Error('scope.liveness: no probes to classify');
|
|
103
|
+
}
|
|
104
|
+
const results = [];
|
|
105
|
+
for (const p of probes) {
|
|
106
|
+
const cH = classify(p.http);
|
|
107
|
+
const cS = classify(p.https);
|
|
108
|
+
const resolved = cH.resolved || cS.resolved;
|
|
109
|
+
const live = cH.live || cS.live;
|
|
110
|
+
const squidError = cH.squidError || cS.squidError || null;
|
|
111
|
+
|
|
112
|
+
const raw = [
|
|
113
|
+
`# scope.liveness probe — ${p.host}`,
|
|
114
|
+
'',
|
|
115
|
+
`## http://${p.host}/`,
|
|
116
|
+
'```',
|
|
117
|
+
String(p.http),
|
|
118
|
+
'```',
|
|
119
|
+
`## https://${p.host}/`,
|
|
120
|
+
'```',
|
|
121
|
+
String(p.https),
|
|
122
|
+
'```',
|
|
123
|
+
'',
|
|
124
|
+
].join('\n');
|
|
125
|
+
const rawPath = path.join(paths.runsDir(dir), `liveness-${p.host.replace(/[^a-z0-9.-]/gi, '_')}.txt`);
|
|
126
|
+
fs.mkdirSync(path.dirname(rawPath), { recursive: true });
|
|
127
|
+
fs.writeFileSync(rawPath, raw);
|
|
128
|
+
const rec = evidence.store(dir, rawPath, { note: `scope.liveness probe: ${p.host}` });
|
|
129
|
+
results.push({ host: p.host, resolved, live, squidError, evidence: [rec.id] });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const verdict = results.some((r) => r.live) ? 'live' : 'unreachable';
|
|
133
|
+
const checkedAt = new Date().toISOString();
|
|
134
|
+
const lines = results.map((r) => {
|
|
135
|
+
const state = r.live
|
|
136
|
+
? 'LIVE'
|
|
137
|
+
: (r.resolved ? `NO-ANSWER (${r.squidError})` : `UNRESOLVED (${r.squidError || 'no answer'})`);
|
|
138
|
+
return `- ${r.host} — ${state} — ${r.evidence.join(', ')}`;
|
|
139
|
+
});
|
|
140
|
+
const body = [
|
|
141
|
+
`# Liveness — ${path.basename(dir)}`,
|
|
142
|
+
'',
|
|
143
|
+
...lines,
|
|
144
|
+
'',
|
|
145
|
+
'Probes ran through the engagement proxy (squid) from the toolbox, per',
|
|
146
|
+
'REACH-01. An unreachable verdict is the checkpoint input: present the',
|
|
147
|
+
'unreachable options (amend target / close early / continue with a',
|
|
148
|
+
'recorded override) — never probe on silently. engagement.close',
|
|
149
|
+
'--reason unreachable trusts this verdict and verifies its evidence ids.',
|
|
150
|
+
'',
|
|
151
|
+
].join('\n');
|
|
152
|
+
fs.mkdirSync(path.dirname(livenessFile(dir)), { recursive: true });
|
|
153
|
+
fs.writeFileSync(livenessFile(dir), fm.stringify(
|
|
154
|
+
{ verdict, checked_at: checkedAt, hosts: results.length, evidence: results.flatMap((r) => r.evidence) },
|
|
155
|
+
body,
|
|
156
|
+
));
|
|
157
|
+
return { verdict, checked_at: checkedAt, hosts: results };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The close gate's input: { verdict, evidence[] } from LIVENESS.md. */
|
|
161
|
+
function readLiveness(dir) {
|
|
162
|
+
const file = livenessFile(dir);
|
|
163
|
+
if (!fs.existsSync(file)) {
|
|
164
|
+
throw new Error(
|
|
165
|
+
'close --reason unreachable refused: scope.liveness has not run — recon/LIVENESS.md is absent '
|
|
166
|
+
+ '(run pensieve-sdk scope.liveness --engagement <dir> first; the reason must be evidence-backed)'
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
170
|
+
const verdict = fm.get(text, 'verdict');
|
|
171
|
+
let evidenceIds = fm.get(text, 'evidence') || [];
|
|
172
|
+
if (!Array.isArray(evidenceIds)) evidenceIds = [evidenceIds];
|
|
173
|
+
return { verdict, evidence: evidenceIds };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = { classify, liveness, livenessFromProbes, readLiveness };
|