filegrc 0.7.0 → 0.8.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.
@@ -1,6 +1,93 @@
1
1
  import { currentPartyPeople } from "./parties.js";
2
+ import { modelSupports } from "../model/index.js";
2
3
 
3
- export function obligationProgramStatus(obligation, byId, asOf) {
4
+ const requiredDocumentsByControlCache = new WeakMap();
5
+
6
+ export function auditSpecificDocumentKinds(model) {
7
+ return new Set([
8
+ ...(model?.auditReadiness?.managementDocuments || []).map(({ kind }) => kind),
9
+ "soc2-engagement-terms"
10
+ ]);
11
+ }
12
+
13
+ export function documentIsAuditSpecific(document, model) {
14
+ if (document?.type !== "document") return false;
15
+ if (modelSupports(model, "document-workflow-scope")) {
16
+ return document.workflowScope === "engagement";
17
+ }
18
+ return auditSpecificDocumentKinds(model).has(document.documentKind);
19
+ }
20
+
21
+ export function governedDocumentIsOperating(document, asOf, model) {
22
+ if (document?.type !== "document" || document.status !== "active") return false;
23
+ if (!document.effectiveOn || document.effectiveOn > asOf) return false;
24
+ if (!modelSupports(model, "governed-document-activation")) return true;
25
+ if (document.activationBasis === "legacy-v4") {
26
+ return document.workflowScope === "engagement"
27
+ && Boolean(document.approvedOn && document.approvedContentRevisions);
28
+ }
29
+ return Boolean(
30
+ document.activationBasis === "recorded"
31
+ && document.approvedOn
32
+ && document.approvedContentRevisions
33
+ && document.activatedOn
34
+ && document.activatedOn <= asOf
35
+ && (document.activatedByIds || []).length
36
+ && document.activatedContentRevisions
37
+ && contentRevisionBindingsMatch(document.approvedContentRevisions, document.activatedContentRevisions)
38
+ );
39
+ }
40
+
41
+ export function contentRevisionBindingsMatch(left, right) {
42
+ if (!left || !right || Array.isArray(left) || Array.isArray(right)) return false;
43
+ const normalize = (value) => Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)));
44
+ return JSON.stringify(normalize(left)) === JSON.stringify(normalize(right));
45
+ }
46
+
47
+ export function obligationGovernedDocuments(obligation, byId, model) {
48
+ if (!modelSupports(model, "governed-document-activation")) return [];
49
+ const policyDocumentIds = (obligation.policyIds || []).flatMap((id) => {
50
+ const policy = byId.get(id);
51
+ return policy?.type === "policy" ? policy.relatedDocumentIds || [] : [];
52
+ });
53
+ const directDocumentIds = [
54
+ ...(obligation.scopeResourceIds || []),
55
+ ...(obligation.templateResourceId ? [obligation.templateResourceId] : [])
56
+ ];
57
+ const requiredDocumentsByControl = indexRequiredDocumentsByControl(byId, model);
58
+ const controlDocumentIds = (obligation.controlIds || [])
59
+ .flatMap((id) => requiredDocumentsByControl.get(id) || []);
60
+ return [...new Set([...policyDocumentIds, ...directDocumentIds, ...controlDocumentIds])]
61
+ .map((id) => byId.get(id))
62
+ .filter((record) => (
63
+ record?.type === "document"
64
+ && !["superseded", "retired"].includes(record.status)
65
+ && !documentIsAuditSpecific(record, model)
66
+ ));
67
+ }
68
+
69
+ function indexRequiredDocumentsByControl(byId, model) {
70
+ const modelVersion = String(model?.modelVersion || "");
71
+ const cached = requiredDocumentsByControlCache.get(byId);
72
+ if (cached?.modelVersion === modelVersion) return cached.index;
73
+ const index = new Map();
74
+ for (const record of byId.values()) {
75
+ if (
76
+ record.type !== "document"
77
+ || record.programRole !== "required"
78
+ || ["superseded", "retired"].includes(record.status)
79
+ || documentIsAuditSpecific(record, model)
80
+ ) continue;
81
+ for (const controlId of record.controlIds || []) {
82
+ if (!index.has(controlId)) index.set(controlId, []);
83
+ index.get(controlId).push(record.id);
84
+ }
85
+ }
86
+ requiredDocumentsByControlCache.set(byId, { modelVersion, index });
87
+ return index;
88
+ }
89
+
90
+ export function obligationProgramStatus(obligation, byId, asOf, model) {
4
91
  if (obligation.status !== "active") return "proposed";
5
92
  if (currentPartyPeople(obligation.ownerIds || [], byId).size === 0) return "proposed";
6
93
  const policyIds = obligation.policyIds || [];
@@ -12,6 +99,9 @@ export function obligationProgramStatus(obligation, byId, asOf) {
12
99
  && policy.effectiveOn <= asOf;
13
100
  });
14
101
  if (!policiesReady) return "proposed";
102
+ const governedDocumentsReady = obligationGovernedDocuments(obligation, byId, model)
103
+ .every((document) => governedDocumentIsOperating(document, asOf, model));
104
+ if (!governedDocumentsReady) return "proposed";
15
105
  const controlIds = obligation.controlIds || [];
16
106
  if (!controlIds.length) return "accepted";
17
107
  return controlIds.some((id) => byId.get(id)?.type === "control" && byId.get(id).status === "implemented")
@@ -19,10 +109,10 @@ export function obligationProgramStatus(obligation, byId, asOf) {
19
109
  : "proposed";
20
110
  }
21
111
 
22
- export function obligationIsRunning(obligation, byId, asOf) {
112
+ export function obligationIsRunning(obligation, byId, asOf, model) {
23
113
  return obligation?.type === "obligation"
24
114
  && obligation.status === "active"
25
- && obligationProgramStatus(obligation, byId, asOf) === "accepted";
115
+ && obligationProgramStatus(obligation, byId, asOf, model) === "accepted";
26
116
  }
27
117
 
28
118
  export function obligationIsEnabled(obligation) {
@@ -12,7 +12,7 @@ export const RESOURCE_INSTRUCTIONS = {
12
12
  requirement: "Keep the published criterion as catalog content. Record management applicability and rationale on the selected Program.",
13
13
  commitment: "Record supplemental customer promises and service requirements that shape the scope or control design. The Commitment’s systemIds and controlIds are authoritative for what fulfills it.",
14
14
  policy: "Tailor each Policy to match what the company is committing to. Clear placeholders, assign an owner and separate approver, then bind approval to the reviewed content. Approval does not prove implementation. Activate the Policy during the Step 3 cutover after reviewing its implementation gaps.",
15
- document: "Tailor the governed plans and other supporting documents the program needs. Assign owners and approvers, then keep the approved Markdown in Git.",
15
+ document: "Complete required governed plans and schedules in Step 2, assign an owner and separate approver, and bind approval to the intended values and exact Markdown. Implement the linked requirements and activate that approved revision in Step 3. Prepare audit-specific Documents in Step 5.",
16
16
  control: "Finish each applicable starter Control with the procedure people follow, its owner, bounded System scope, operating Components, authoritative evidence-source Components, governing Policy and Requirement mappings, and implementation date. Put calendar and event schedules in Obligations.",
17
17
  "complementary-control": "Review whether any in-scope Control depends on a customer or carved-out provider action. Record each real dependency, or confirm that the current scope has none.",
18
18
  evidence: "Create an Evidence Artifact when a real export, report, screenshot, signed file, or approved external reference exists. Select its authoritative source Component, link the Controls and operating records it supports, retain the fixed artifact or reference, and have another person verify it before audit use.",
@@ -98,16 +98,20 @@ export const PROGRAM_PATH = [
98
98
  {
99
99
  id: "policies",
100
100
  number: 2,
101
- title: "Approve Policies",
102
- description: "Tailor, review, and approve",
103
- summary: "Adapt and approve the starter policies.",
101
+ title: "Approve Policies and Plans",
102
+ description: "Tailor requirements, intended values, and approvals",
103
+ summary: "Adapt and independently approve Policies and required governed Documents.",
104
104
  sections: [
105
- { id: "library", title: "Policy Library", description: "Review and approve Policy requirements without treating approval as proof of technical implementation.", steps: ["Review Policy Markdown and replace every organization placeholder.", "Confirm the owner, separate approver, audience, review Obligation, and Controls that point to the Policy.", "Record approval against the exact reviewed content. Leave the Policy approved and inactive until the Step 3 implementation cutover."], types: ["policy"], defaultOpen: true }
105
+ { id: "library", title: "Policy Library", description: "Review and approve Policy requirements without treating approval as proof of technical implementation.", steps: ["Review Policy Markdown and replace every organization placeholder.", "Confirm the owner, separate approver, audience, review Obligation, and Controls that point to the Policy.", "Record approval against the exact reviewed content. Leave the Policy approved and inactive until the Step 3 implementation cutover."], types: ["policy"], defaultOpen: true },
106
+ { id: "governed-documents", title: "Governed Plans and Schedules", description: "Complete the intended values in each required program plan or schedule and obtain independent approval of the exact revision before implementation.", steps: ["Review each required plan or schedule and replace every organization placeholder with the intended owner, timing, threshold, scope, or response value.", "Confirm the Document owner, separate approver, linked Controls, and review schedule.", "Record approval and its date against the exact Markdown revision. Leave the Document approved until its linked requirements are implemented in Step 3."], types: [], relatedLinks: [{ type: "document", label: "Governed plans and schedules", href: "#/resources/document?stage=policies&documentScope=program" }], defaultOpen: true }
106
107
  ],
107
108
  resourceTypes: ["policy"],
109
+ supportingResourceTypes: ["document"],
108
110
  commands: [
109
111
  "filegrc guide policy --json",
112
+ "filegrc guide document --json",
110
113
  "filegrc list policy --json",
114
+ "filegrc list document --json",
111
115
  "filegrc get POLICY_ID --mutation"
112
116
  ]
113
117
  },
@@ -118,14 +122,15 @@ export const PROGRAM_PATH = [
118
122
  description: "Finish controls and their evidence sources",
119
123
  summary: "Describe each Control and connect its evidence source.",
120
124
  sections: [
121
- { id: "catalog", title: "Control Catalog", description: "Finish the starter Controls, governed plans, schedules, and authoritative evidence sources, then review the approved Policies together at implementation cutover.", steps: ["Open every planned Control and confirm its mappings and operation pattern.", "Write the real procedure in Record Markdown, add bounded System scope, and map the operating and authoritative evidence-source Components.", "Create or enable every calendar and event schedule as an Obligation. Enabled work remains dormant until its governing Policy is active.", "Confirm each source Component is active, has an evidence-source role and rationale in the Control's System scope, has current access owners, and includes repeatable retrieval instructions in Record Markdown.", "Complete required governed plans, then use Review policy activation on the Controls page to inspect each Policy’s planned or partial Controls, missing Components or sources, missing schedules, and unresolved Exceptions.", "Choose the approved Policies that should take effect, set the real effective date, and confirm the Step 3 cutover. You can activate with a documented gap or approved Exception, but Evidence Readiness still requires active and operating Policies."], types: ["control", "complementary-control", "document"], defaultOpen: true }
125
+ { id: "catalog", title: "Control Catalog", description: "Implement the approved requirements, activate required governed Documents, finish the authoritative evidence sources, then review the approved Policies together at implementation cutover.", steps: ["Open every planned Control and confirm its mappings and operation pattern.", "Write the real procedure in Record Markdown, add bounded System scope, and map the operating and authoritative evidence-source Components.", "Create or enable every calendar and event schedule as an Obligation. Enabled work remains dormant until its governing Policy is active.", "Confirm each source Component is active, has an evidence-source role and rationale in the Control's System scope, has current access owners, and includes repeatable retrieval instructions in Record Markdown.", "Implement every requirement linked from an approved governed plan or schedule, then activate the unchanged approved Document with a separate activation date and revision.", "Use Review policy activation on the Controls page to inspect each Policy’s planned or partial Controls, inactive governed Documents, missing Components or sources, missing schedules, and unresolved Exceptions.", "Choose the approved Policies that should take effect, set the real effective date, and confirm the Step 3 cutover. You can activate with a documented gap or approved Exception, but Evidence Readiness still requires active and operating Policies and Documents."], types: ["control", "complementary-control"], relatedLinks: [{ type: "document", label: "Activate governed plans and schedules", href: "#/resources/document?stage=controls&documentScope=program" }], defaultOpen: true }
122
126
  ],
123
- resourceTypes: ["control", "complementary-control", "document"],
127
+ resourceTypes: ["control", "complementary-control"],
124
128
  commands: [
125
129
  "filegrc guide control --json",
126
130
  "filegrc list control --json",
127
131
  "filegrc get CONTROL_ID --mutation",
128
132
  "filegrc review-collection complementary-control --scaffold",
133
+ "filegrc activate-documents --scaffold",
129
134
  "filegrc activate-policies --scaffold",
130
135
  "filegrc evidence-map --json",
131
136
  "filegrc program-readiness --json"
@@ -144,7 +149,7 @@ export const PROGRAM_PATH = [
144
149
  { id: "governance", title: "Governance", description: "Record formal reviews, oversight meetings, and approved policy or control exceptions.", steps: ["Complete scheduled policy reviews and oversight meetings.", "Record decisions, attendees, follow-up work, and evidence.", "Approve time-bound exceptions before the departure begins."], types: ["policy-review", "meeting", "exception"], defaultOpen: false },
145
150
  { id: "inventories", title: "Assets and Vendors", description: "Maintain the asset inventory and recurring reviews of supplier relationships during operation.", steps: ["Keep ownership, custody, status, and lifecycle current for important assets.", "Perform vendor reviews on schedule and after material supplier changes.", "Link fixed reports and review evidence to the operating records."], types: ["asset", "vendor-review"], defaultOpen: false },
146
151
  { id: "access-training", title: "Access and Training", description: "Inventory service accounts before recording access decisions, periodic reviews, assignments, and acknowledgements.", steps: ["Catalog service accounts that need separate tracking.", "Preserve access approvals and removals as they occur, then complete periodic access reviews and resolve exceptions.", "Assign training and retain acknowledgement evidence for the exact content revision."], types: ["service-account", "access-grant", "access-review", "training", "attestation"], defaultOpen: false },
147
- { id: "security", title: "Security Operations", description: "Record vulnerability work, independent testing, and incident response activity for the period.", steps: ["Retain scan scope, results, vulnerabilities, remediation, and exceptions.", "Track penetration testing and follow-up findings.", "Start the incident workflow when a qualifying event occurs."], types: ["vulnerability-scan", "vulnerability", "penetration-test", "incident"], defaultOpen: false },
152
+ { id: "security", title: "Security Operations", description: "Record vulnerability work, applicable penetration testing, and incident response activity for the period.", steps: ["Retain scan scope, results, vulnerabilities, remediation, and exceptions.", "When the approved applicability review requires penetration testing, record the test and follow-up findings.", "Start the incident workflow when a qualifying event occurs."], types: ["vulnerability-scan", "vulnerability", "penetration-test", "incident"], defaultOpen: false },
148
153
  { id: "resilience", title: "Resilience", description: "Preserve proof that backups, restoration, continuity, and incident exercises work as designed.", steps: ["Record backup restoration tests and their results.", "Run continuity and incident exercises on schedule.", "Assign and close follow-up work from failed objectives or lessons learned."], types: ["backup-test", "exercise"], defaultOpen: false },
149
154
  { id: "issues", title: "Issues and Remediation", description: "Keep observations in the source report and track only confirmed gaps that need a separate remediation lifecycle.", steps: ["Create a Finding only when a confirmed gap needs its own owner, due date, status, or verified closure.", "Use the Finding itself for straightforward remediation; create Action Items only for separate assigned tasks.", "Work Action Items from Work Queue and close the Finding only after remediation is independently verified."], types: ["finding"], defaultOpen: false }
150
155
  ],
@@ -217,7 +222,7 @@ export const PROGRAM_PATH = [
217
222
  summary: "Track the CPA engagement, fieldwork, and evidence packet.",
218
223
  sections: [
219
224
  { id: "engagement", title: "Engagement", description: "Record the actual CPA engagement, formal scope and dates, requests, and management responses.", steps: ["Create the Audit after the CPA firm is engaged.", "Record the firm-agreed type, scope, systems, criteria, and dates.", "Track incoming requests and approved response material."], types: ["audit", "audit-request"], defaultOpen: true },
220
- { id: "fieldwork", title: "Fieldwork", description: "Prepare management documents, reconcile Type 2 populations, review both evidence paths, support testing, and build the indexed packet.", steps: ["Initialize engagement-specific management documents and populations.", "Review dated FileGRC operating records and verified Evidence Artifacts for the formal period.", "Reconcile complete populations, link samples, and resolve fieldwork requests and Findings.", "Build the packet from a clean Git revision; it includes FileGRC records, Markdown, Evidence Artifacts, attachments, indexes, history, and checksums."], types: ["audit-population", "control-test"], utility: "audit-packet", defaultOpen: true }
225
+ { id: "fieldwork", title: "Fieldwork", description: "Prepare audit-specific Documents, reconcile Type 2 populations, review both evidence paths, support testing, and build the indexed packet.", steps: ["Initialize and complete engagement-specific management Documents and populations.", "Approve and activate each audit-specific Document only when its engagement facts and timing are final.", "Review dated FileGRC operating records and verified Evidence Artifacts for the formal period.", "Reconcile complete populations, link samples, and resolve fieldwork requests and Findings.", "Build the packet from a clean Git revision; it includes FileGRC records, Markdown, Evidence Artifacts, attachments, indexes, history, and checksums."], types: ["audit-population", "control-test"], relatedLinks: [{ type: "document", label: "Audit-specific Documents", href: "#/resources/document?stage=audit&documentScope=audit" }], utility: "audit-packet", defaultOpen: true }
221
226
  ],
222
227
  resourceTypes: ["audit", "audit-request", "audit-population", "control-test"],
223
228
  utilities: [