ai-saas-guard 0.11.0 → 0.12.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/README.md CHANGED
@@ -73,8 +73,8 @@ The CLI is published on npm as `ai-saas-guard`, and the GitHub Action is availab
73
73
  | JSON and SARIF output | Available |
74
74
  | Composite GitHub Action | Available |
75
75
  | Project config | `.ai-saas-guard.json` rule toggles, severity overrides, and fail thresholds |
76
- | Versioned Action tags | `v0.11.0`, `v0` |
77
- | npm package | `ai-saas-guard@0.11.0` |
76
+ | Versioned Action tags | `v0.12.0`, `v0` |
77
+ | npm package | `ai-saas-guard@0.12.0` |
78
78
  | npm publishing | Trusted Publisher/OIDC, no long-lived publish token |
79
79
 
80
80
  ## Quick Start
@@ -214,13 +214,13 @@ Hosted uninstall and data deletion behavior is documented in [docs/hosted-uninst
214
214
 
215
215
  Hosted pricing and packaging boundaries are documented in [docs/hosted-pricing-packaging.md](docs/hosted-pricing-packaging.md). Core local scanning stays useful without an account; hosted plans may add workflow convenience, saved reports, team policy, and optional human review, but they do not gate local CLI scanning.
216
216
 
217
- Hosted pre-implementation pure contracts are documented in [docs/hosted-preimplementation-contracts.md](docs/hosted-preimplementation-contracts.md). They now include a pull request webhook intake planner that verifies signatures before parsing or queueing, builds trusted scan identity, authorizes selected-repository scope, and defaults to check-run-only output. They also cover queue-safe webhook event parsing, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, and other service-free helpers exported from `ai-saas-guard/hosted/contracts`.
217
+ Hosted pre-implementation pure contracts are documented in [docs/hosted-preimplementation-contracts.md](docs/hosted-preimplementation-contracts.md). They now include a pull request webhook intake planner that verifies signatures before parsing or queueing, plus a durable scan queue planner that reuses queued, running, and completed jobs for the same trusted scan key. They also cover queue-safe webhook event parsing, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, and other service-free helpers exported from `ai-saas-guard/hosted/contracts`.
218
218
 
219
219
  A public hosted compact report schema fixture is available at [examples/hosted-compact-report.json](examples/hosted-compact-report.json). It is synthetic and public-safe: compact evidence only, no raw source, raw diffs, secrets, webhook payload bodies, customer payloads, private URLs, or worker checkout paths.
220
220
 
221
221
  The proposed hosted app permission boundary is intentionally narrow: repository contents read, pull requests read, checks write, and metadata read for the first version. Optional PR comments require repository policy opt-in, and broad permissions such as administration, deployments, Actions write, and repository secrets are out of scope.
222
222
 
223
- The repository also includes pure pre-implementation hosted contract helpers and tests for webhook intake order, webhook verification, installation token scoping, queue idempotency, compact reports, and retention limits. These helpers do not implement or deploy a hosted service.
223
+ The repository also includes pure pre-implementation hosted contract helpers and tests for webhook intake order, webhook verification, installation token scoping, durable queue idempotency, compact reports, and retention limits. These helpers do not implement or deploy a hosted service.
224
224
 
225
225
  Users should prefer the local CLI for private repositories, offline review, or no-account workflows where hosted code processing is not acceptable.
226
226
 
@@ -254,7 +254,7 @@ Use `suppressions` for narrower false-positive handling when one rule is noisy o
254
254
 
255
255
  ## GitHub Action
256
256
 
257
- The repo includes a composite Action. Use `v0` for the latest compatible pre-1.0 Action, a specific release tag such as `v0.11.0` for controlled upgrades, or pin a reviewed commit SHA for stricter supply-chain control:
257
+ The repo includes a composite Action. Use `v0` for the latest compatible pre-1.0 Action, a specific release tag such as `v0.12.0` for controlled upgrades, or pin a reviewed commit SHA for stricter supply-chain control:
258
258
 
259
259
  ```yaml
260
260
  name: ai-saas-guard
package/README.zh-CN.md CHANGED
@@ -55,7 +55,7 @@ AI 能很快把一个 SaaS 从想法做成可运行的产品。真正难的是
55
55
 
56
56
  这个仓库是公开 GitHub 仓库。
57
57
 
58
- CLI 已发布到 npm:`ai-saas-guard@0.11.0`。GitHub Action 支持 `v0` 浮动标签,也支持固定版本标签,例如 `v0.11.0`。
58
+ CLI 已发布到 npm:`ai-saas-guard@0.12.0`。GitHub Action 支持 `v0` 浮动标签,也支持固定版本标签,例如 `v0.12.0`。
59
59
 
60
60
  | 模块 | 状态 |
61
61
  | --- | --- |
@@ -66,8 +66,8 @@ CLI 已发布到 npm:`ai-saas-guard@0.11.0`。GitHub Action 支持 `v0` 浮动
66
66
  | Markdown PR summary | 已可用 |
67
67
  | GitHub Action | 已可用 |
68
68
  | 项目配置 | `.ai-saas-guard.json` 支持规则开关、severity 覆盖和 fail threshold |
69
- | 当前版本 | `0.11.0` |
70
- | Action 标签 | `v0.11.0`、`v0` |
69
+ | 当前版本 | `0.12.0` |
70
+ | Action 标签 | `v0.12.0`、`v0` |
71
71
  | npm 发布 | GitHub Actions Trusted Publisher/OIDC,无需长期 npm token |
72
72
 
73
73
  ## 快速开始
@@ -253,6 +253,7 @@ jobs:
253
253
  已经实现的 hosted 预实现纯契约包括:
254
254
 
255
255
  - pull request webhook intake planner:先验签,再解析 payload、生成可信 identity、校验 selected-repository scope,并默认只走 check-run-only 输出
256
+ - durable scan queue planner:同一个 trusted scan key 的 queued/running/completed job 会复用,不重复排 worker,也不会把源码、diff、secret 或 PR 正文放进队列 payload
256
257
  - webhook event parser
257
258
  - check-run summary renderer
258
259
  - queue cleanup planner
@@ -114,6 +114,57 @@ export interface HostedScanJobDecision {
114
114
  shouldCreatePrComment: boolean;
115
115
  }
116
116
  export type HostedQueueJobStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
117
+ export interface HostedScanQueueRecord {
118
+ key: string;
119
+ identity: HostedScanIdentity;
120
+ status: HostedQueueJobStatus;
121
+ attempt: number;
122
+ deliveryIds: string[];
123
+ createdAt: string;
124
+ updatedAt: string;
125
+ reportId?: string;
126
+ }
127
+ export interface HostedScanQueuePayload {
128
+ key: string;
129
+ identity: HostedScanIdentity;
130
+ deliveryId: string;
131
+ attempt: number;
132
+ requestedAt: string;
133
+ source: "github_pull_request";
134
+ }
135
+ export interface HostedScanQueueUpsertInput {
136
+ identity: HostedScanIdentity;
137
+ deliveryId: string;
138
+ requestedAt: string;
139
+ queue: Map<string, HostedScanQueueRecord>;
140
+ manualRerun?: boolean;
141
+ rawSource?: string;
142
+ rawDiff?: string;
143
+ secretValues?: string[];
144
+ untrustedPrText?: string;
145
+ customerPayload?: unknown;
146
+ }
147
+ export interface HostedScanQueueUpsertDecision {
148
+ key: string;
149
+ idempotent: true;
150
+ created: boolean;
151
+ reusedExistingJob: boolean;
152
+ existingStatus?: HostedQueueJobStatus;
153
+ attempt: number;
154
+ queueRecord: HostedScanQueueRecord;
155
+ queuePayload: HostedScanQueuePayload;
156
+ shouldEnqueueWorker: boolean;
157
+ shouldReuseCompletedReport: boolean;
158
+ shouldCreateCheckRun: boolean;
159
+ shouldCreatePrComment: false;
160
+ privacy: {
161
+ includesRawSource: false;
162
+ includesRawDiffs: false;
163
+ includesSecrets: false;
164
+ includesUntrustedPrText: false;
165
+ includesCustomerPayloads: false;
166
+ };
167
+ }
117
168
  export type HostedQueueCleanupTrigger = "repository_removed" | "installation_deleted" | "repeated_cleanup";
118
169
  export interface HostedQueueCleanupJobState {
119
170
  key: string;
@@ -303,6 +354,7 @@ export declare function parseHostedPullRequestEvent(input: HostedPullRequestEven
303
354
  export declare function authorizeInstallationTokenScope(input: InstallationScopeInput): InstallationScopeDecision;
304
355
  export declare function getHostedScanIdempotencyKey(identity: HostedScanIdentity): string;
305
356
  export declare function upsertHostedScanJob(queue: Map<string, HostedScanJobState>, input: HostedScanJobInput): HostedScanJobDecision;
357
+ export declare function planHostedScanQueueUpsert(input: HostedScanQueueUpsertInput): HostedScanQueueUpsertDecision;
306
358
  export declare function getHostedQueueCleanupIdempotencyKey(input: {
307
359
  trigger: HostedQueueCleanupTrigger;
308
360
  installationId: number;
@@ -222,6 +222,76 @@ export function upsertHostedScanJob(queue, input) {
222
222
  shouldCreatePrComment: false
223
223
  };
224
224
  }
225
+ export function planHostedScanQueueUpsert(input) {
226
+ const key = getHostedScanIdempotencyKey(input.identity);
227
+ const existing = input.queue.get(key);
228
+ if (!existing) {
229
+ const record = {
230
+ key,
231
+ identity: input.identity,
232
+ status: "queued",
233
+ attempt: 1,
234
+ deliveryIds: [input.deliveryId],
235
+ createdAt: input.requestedAt,
236
+ updatedAt: input.requestedAt
237
+ };
238
+ input.queue.set(key, record);
239
+ return {
240
+ key,
241
+ idempotent: true,
242
+ created: true,
243
+ reusedExistingJob: false,
244
+ attempt: record.attempt,
245
+ queueRecord: { ...record, deliveryIds: [...record.deliveryIds] },
246
+ queuePayload: createHostedScanQueuePayload(record, input.deliveryId, input.requestedAt),
247
+ shouldEnqueueWorker: true,
248
+ shouldReuseCompletedReport: false,
249
+ shouldCreateCheckRun: true,
250
+ shouldCreatePrComment: false,
251
+ privacy: hostedScanQueuePrivacy()
252
+ };
253
+ }
254
+ if (!existing.deliveryIds.includes(input.deliveryId)) {
255
+ existing.deliveryIds.push(input.deliveryId);
256
+ }
257
+ const existingStatus = existing.status;
258
+ if (input.manualRerun) {
259
+ existing.attempt += 1;
260
+ existing.status = "queued";
261
+ existing.updatedAt = input.requestedAt;
262
+ return {
263
+ key,
264
+ idempotent: true,
265
+ created: false,
266
+ reusedExistingJob: false,
267
+ existingStatus,
268
+ attempt: existing.attempt,
269
+ queueRecord: cloneHostedScanQueueRecord(existing),
270
+ queuePayload: createHostedScanQueuePayload(existing, input.deliveryId, input.requestedAt),
271
+ shouldEnqueueWorker: true,
272
+ shouldReuseCompletedReport: false,
273
+ shouldCreateCheckRun: true,
274
+ shouldCreatePrComment: false,
275
+ privacy: hostedScanQueuePrivacy()
276
+ };
277
+ }
278
+ existing.updatedAt = input.requestedAt;
279
+ return {
280
+ key,
281
+ idempotent: true,
282
+ created: false,
283
+ reusedExistingJob: true,
284
+ existingStatus,
285
+ attempt: existing.attempt,
286
+ queueRecord: cloneHostedScanQueueRecord(existing),
287
+ queuePayload: createHostedScanQueuePayload(existing, input.deliveryId, input.requestedAt),
288
+ shouldEnqueueWorker: false,
289
+ shouldReuseCompletedReport: existingStatus === "completed",
290
+ shouldCreateCheckRun: false,
291
+ shouldCreatePrComment: false,
292
+ privacy: hostedScanQueuePrivacy()
293
+ };
294
+ }
225
295
  export function getHostedQueueCleanupIdempotencyKey(input) {
226
296
  return ["queue-cleanup", input.trigger, input.installationId, input.repositoryId ?? "all"].join(":");
227
297
  }
@@ -441,6 +511,32 @@ function hostedWebhookIntakePrivacy() {
441
511
  includesCustomerPayloads: false
442
512
  };
443
513
  }
514
+ function createHostedScanQueuePayload(record, deliveryId, requestedAt) {
515
+ return {
516
+ key: record.key,
517
+ identity: record.identity,
518
+ deliveryId,
519
+ attempt: record.attempt,
520
+ requestedAt,
521
+ source: "github_pull_request"
522
+ };
523
+ }
524
+ function cloneHostedScanQueueRecord(record) {
525
+ return {
526
+ ...record,
527
+ identity: { ...record.identity },
528
+ deliveryIds: [...record.deliveryIds]
529
+ };
530
+ }
531
+ function hostedScanQueuePrivacy() {
532
+ return {
533
+ includesRawSource: false,
534
+ includesRawDiffs: false,
535
+ includesSecrets: false,
536
+ includesUntrustedPrText: false,
537
+ includesCustomerPayloads: false
538
+ };
539
+ }
444
540
  function parseJsonPayload(payload) {
445
541
  try {
446
542
  return JSON.parse(Buffer.isBuffer(payload) ? payload.toString("utf8") : payload);
@@ -2,7 +2,7 @@
2
2
 
3
3
  `ai-saas-guard` ships as a composite GitHub Action for pull request and code scanning workflows.
4
4
 
5
- Use `zr9959/ai-saas-guard@v0` for the latest compatible pre-1.0 Action. Use a specific tag such as `v0.11.0` or a reviewed commit SHA when reproducibility is more important than automatic minor updates.
5
+ Use `zr9959/ai-saas-guard@v0` for the latest compatible pre-1.0 Action. Use a specific tag such as `v0.12.0` or a reviewed commit SHA when reproducibility is more important than automatic minor updates.
6
6
 
7
7
  ## PR Summary
8
8
 
@@ -26,6 +26,27 @@ Privacy boundaries:
26
26
 
27
27
  The exported helper is `planHostedPullRequestWebhookIntake`. It is intentionally service-free: callers still need a real webhook server, queue provider, installation token lookup, worker checkout, scanner execution, compact report storage, and GitHub Checks API writer before any hosted environment exists.
28
28
 
29
+ ## Durable Scan Queue Planner
30
+
31
+ The durable scan queue planner defines how the future hosted service should create or reuse scan jobs once a signed pull request webhook has produced trusted scan identity. It is a pure planner only: it does not connect to a queue provider, run a worker, fetch source, write reports, or call GitHub APIs.
32
+
33
+ Default behavior:
34
+
35
+ - compute the same logical scan key from installation ID, repository ID, pull request number, head SHA, and scanner version
36
+ - create one queued job when no matching job exists
37
+ - reuse existing queued, running, or completed jobs for duplicate deliveries
38
+ - reuse completed compact reports instead of enqueueing duplicate worker work
39
+ - allow manual reruns to increment `attempt` while keeping the same logical scan key
40
+ - keep the first hosted slice check-run-only; PR comments remain disabled
41
+
42
+ Queue payload boundaries:
43
+
44
+ - include only scan identity, job key, delivery ID, attempt, requested time, and source
45
+ - do not include raw source, raw diffs, secret values, untrusted PR text, webhook payload bodies, customer payloads, private URLs, or worker checkout paths
46
+ - return safe queue metadata that can be stored by a durable queue without leaking source code
47
+
48
+ The exported helper is `planHostedScanQueueUpsert`. It is intended to be the queue-provider-independent contract for the first real hosted queue implementation.
49
+
29
50
  ## Webhook Event Parser
30
51
 
31
52
  The webhook event parser runs after webhook signature verification. It converts a reduced GitHub `pull_request` webhook payload into a queue-safe scan request identity.
@@ -164,6 +185,10 @@ Automated tests must cover:
164
185
  - signed pull request webhook intake verifies signatures before JSON parsing or queueing
165
186
  - accepted pull request webhook intake queues one check-run-only scan request from trusted fields
166
187
  - rejected installation scope stops before repository fetch planning
188
+ - durable scan queue planning creates one queued job for a new trusted scan key
189
+ - duplicate deliveries reuse queued, running, and completed jobs without enqueueing duplicate worker work
190
+ - completed duplicate jobs reuse compact reports
191
+ - manual reruns increment attempt without changing the logical scan key
167
192
  - accepted pull request events build the expected trusted scan identity
168
193
  - unsupported actions are rejected
169
194
  - draft pull requests are rejected by default
@@ -5,10 +5,10 @@
5
5
  ## Current State
6
6
 
7
7
  - Package name: `ai-saas-guard`
8
- - Current version: `0.11.0`
8
+ - Current version: `0.12.0`
9
9
  - npm registry state: published at <https://www.npmjs.com/package/ai-saas-guard>
10
10
  - First npm-published version: `0.1.1`
11
- - GitHub Release: `v0.11.0`
11
+ - GitHub Release: `v0.12.0`
12
12
  - Publish workflow: `.github/workflows/npm-publish.yml`
13
13
  - Trusted Publisher: GitHub Actions, `zr9959/ai-saas-guard`, workflow `npm-publish.yml`, allowed action `npm publish`
14
14
  - Long-lived npm publish token: not required
@@ -17,7 +17,7 @@
17
17
 
18
18
  Use GitHub Actions with npm Trusted Publisher/OIDC:
19
19
 
20
- 1. Create and review a release tag such as `v0.11.0`.
20
+ 1. Create and review a release tag such as `v0.12.0`.
21
21
  2. Publish from the GitHub Release or run the `Publish npm` workflow manually with `ref` set to that tag.
22
22
  3. Keep `permissions.id-token: write` in the workflow so npm can exchange the GitHub Actions OIDC identity for a short-lived publish credential.
23
23
  4. Run `npm publish --access public` from the workflow. Trusted publishing automatically generates provenance for this public package from this public repository.
@@ -57,9 +57,9 @@ Implemented surfaces:
57
57
  - hosted operational release gate document requiring hosted CI, webhook replay, dependency and container scanning, privacy and retention verification, worker cleanup, monitoring and alerting, manual rollback, and incident response evidence before exposure
58
58
  - hosted uninstall and data deletion document defining repository removal, full app uninstall, compact report deletion, queue cancellation, audit record retention, repeated cleanup idempotency, and user-facing deletion wording
59
59
  - hosted pricing and packaging document defining open-source CLI boundaries, free/public repo hosted behavior, private repo hosted behavior, PR comments, saved reports, team policy, optional Launch Review, and no pentest/certification/full-audit claims
60
- - hosted pre-implementation contracts document, hosted compact report fixture, and pure helpers for pull request webhook intake planning, queue-safe pull request event parsing from trusted GitHub event fields, bounded check-run summary rendering, idempotent queue cleanup planning, and worker checkout cleanup planning
60
+ - hosted pre-implementation contracts document, hosted compact report fixture, and pure helpers for pull request webhook intake planning, durable scan queue upsert planning, queue-safe pull request event parsing from trusted GitHub event fields, bounded check-run summary rendering, idempotent queue cleanup planning, and worker checkout cleanup planning
61
61
  - implementation-ready hosted GitHub App permission contract for required permissions, optional PR comment permissions, selected repository installation, and out-of-scope broad permissions
62
- - pure hosted GitHub App contract helpers and tests for webhook intake order, webhook verification, installation token scoping, scan queue idempotency, compact reports, and retention limits
62
+ - pure hosted GitHub App contract helpers and tests for webhook intake order, webhook verification, installation token scoping, durable scan queue idempotency, compact reports, and retention limits
63
63
  - GitHub issue templates for bug reports, false positives, false negatives, rule requests, and public-safe security reports
64
64
  - CODEOWNERS for source, tests, docs, workflows, Action, and package metadata
65
65
  - JSON output
@@ -113,7 +113,8 @@ GitHub Project:
113
113
 
114
114
  Current issue set:
115
115
 
116
- - Open hosted MVP roadmap issues: #24 webhook intake, #25 idempotent queue contract, #26 read-only worker checkout, #27 Check summaries, #28 retention/uninstall cleanup, and #29 hosted operational release gate.
116
+ - Closed hosted MVP issue: #24 webhook intake.
117
+ - Open hosted MVP roadmap issues: #25 idempotent queue contract, #26 read-only worker checkout, #27 Check summaries, #28 retention/uninstall cleanup, and #29 hosted operational release gate.
117
118
 
118
119
  CI:
119
120
 
@@ -125,7 +126,7 @@ CI:
125
126
  Publishing:
126
127
 
127
128
  - npm package: `ai-saas-guard`
128
- - Current release line: `v0.11.0`
129
+ - Current release line: `v0.12.0`
129
130
  - Publish workflow: `.github/workflows/npm-publish.yml`
130
131
  - Trusted Publisher: GitHub Actions for `zr9959/ai-saas-guard`, workflow `npm-publish.yml`
131
132
  - Long-lived npm publish tokens should not be required.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-saas-guard",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Repo-local launch-readiness scanner for AI-built SaaS apps.",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/zr9959/ai-saas-guard#readme",