@stmcw1/dacw 1.0.2 → 1.1.1

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,41 +1,45 @@
1
1
  import * as fs from 'fs/promises';
2
2
  import * as path from 'path';
3
3
  import * as crypto from 'crypto';
4
+ function serializeChecksumBody(state) {
5
+ const { taskId, round, status, taskPrompt, writtenFiles, testResult, reviewResult, reviewExcluded, secretScanHits, rollbackPoint, rollback, lastError } = state;
6
+ return JSON.stringify({
7
+ taskId,
8
+ round,
9
+ status,
10
+ taskPrompt,
11
+ writtenFiles,
12
+ testResult,
13
+ reviewResult,
14
+ reviewExcluded: reviewExcluded ?? null,
15
+ secretScanHits: secretScanHits ?? null,
16
+ rollbackPoint: rollbackPoint ?? null,
17
+ rollback: rollback ?? null,
18
+ lastError
19
+ });
20
+ }
21
+ const DEFAULT_CHECKSUM_FN = (body)=>crypto.createHash('sha256').update(body).digest('hex');
4
22
  export class StateManager {
5
23
  stateDir;
6
24
  stateFilePath;
7
25
  taskId;
8
- macSecret;
26
+ checksumFn;
9
27
  writeChain = Promise.resolve();
10
28
  authoritative = null;
11
29
  tmpSeq = 0;
12
- constructor(stateDir, rawTaskId, workspaceDir, macSecret){
30
+ constructor(stateDir, rawTaskId, workspaceDir, checksumFn){
13
31
  const safeTaskId = rawTaskId.replace(/[^a-zA-Z0-9_\-]/g, '_');
14
32
  const idHash = crypto.createHash('sha256').update(String(rawTaskId) + '\n' + String(workspaceDir)).digest('hex').slice(0, 8);
15
33
  this.taskId = safeTaskId;
16
- this.macSecret = macSecret ?? null;
34
+ this.checksumFn = checksumFn ?? DEFAULT_CHECKSUM_FN;
17
35
  this.stateDir = path.resolve(stateDir);
18
36
  this.stateFilePath = path.join(this.stateDir, `state_${safeTaskId}_${idHash}.json`);
19
37
  }
20
- macOf(body) {
21
- if (this.macSecret !== null) {
22
- return crypto.createHmac('sha256', this.macSecret).update(body).digest('hex');
23
- }
24
- return crypto.createHash('sha256').update(body).digest('hex');
38
+ static computeChecksum(state) {
39
+ return DEFAULT_CHECKSUM_FN(serializeChecksumBody(state));
25
40
  }
26
41
  checksumOf(state) {
27
- const { taskId, round, status, taskPrompt, writtenFiles, testResult, reviewResult, lastError } = state;
28
- const body = JSON.stringify({
29
- taskId,
30
- round,
31
- status,
32
- taskPrompt,
33
- writtenFiles,
34
- testResult,
35
- reviewResult,
36
- lastError
37
- });
38
- return this.macOf(body);
42
+ return this.checksumFn(serializeChecksumBody(state));
39
43
  }
40
44
  async persist(state) {
41
45
  await fs.mkdir(this.stateDir, {
@@ -108,6 +112,10 @@ export class StateManager {
108
112
  writtenFiles: null,
109
113
  testResult: null,
110
114
  reviewResult: null,
115
+ reviewExcluded: null,
116
+ secretScanHits: null,
117
+ rollbackPoint: null,
118
+ rollback: null,
111
119
  lastError: null
112
120
  };
113
121
  await this.persist(initial);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stmcw1/dacw",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Defensive Agent Coding Workflow (DACW) as a DSH Host plugin: an AI writer proposes code, a deterministic runner tests it, a separate reviewer audits it, and a human gate decides the merge.",
5
5
  "keywords": [
6
6
  "dacw",
@@ -30,10 +30,7 @@
30
30
  "./icon": "./icon.png"
31
31
  },
32
32
  "files": [
33
- "dist/index.js",
34
- "dist/plugin.js",
35
- "dist/runner.js",
36
- "dist/state_manager.js",
33
+ "dist/",
37
34
  "cordis.patch.yml",
38
35
  "locale/*.json",
39
36
  "icon.png",