DSLO commited on
Commit
24bda31
·
verified ·
1 Parent(s): f5adefe

Update engine.js

Browse files
Files changed (1) hide show
  1. engine.js +22 -19
engine.js CHANGED
@@ -1,5 +1,7 @@
1
  // engine.js
2
 
 
 
3
  // Invariant set F1–F9
4
  const INVARIANTS = {
5
  F1_NO_SEMANTIC_INTERPRETATION: true,
@@ -13,7 +15,6 @@ const INVARIANTS = {
13
  F9_NO_CROSS_SIGNAL_CONTAMINATION: true,
14
  };
15
 
16
- // Simple invariant check function
17
  function checkInvariants(input) {
18
  const report = {
19
  inputType: typeof input,
@@ -22,44 +23,46 @@ function checkInvariants(input) {
22
  violations: [],
23
  };
24
 
25
- // F1: no semantic interpretation → we only treat input as opaque string
26
  if (typeof input !== 'string') {
27
  report.violations.push('F1: input must be a string (opaque signal)');
28
  }
29
 
30
- // F4: no autonomous state mutation → engine must be stateless
31
- // (we just assert; no external state is touched here)
32
-
33
- // F9: no cross-signal contamination → single input per call
34
- // (enforced by API: one input argument)
35
-
36
  return report;
37
  }
38
 
39
- // Deterministic processing function
40
  function processSignal(input) {
41
  const invariantReport = checkInvariants(input);
42
 
 
43
  if (invariantReport.violations.length > 0) {
44
- return {
45
  input,
46
  output: null,
47
  timestamp: 0,
48
  invariants: invariantReport,
49
  status: 'error',
50
  };
 
 
 
 
 
 
 
 
 
51
  }
52
 
53
- // Opaque, deterministic transform (no semantics)
54
- const output = `processed:${input}`;
 
 
 
 
 
 
55
 
56
- return {
57
- input,
58
- output,
59
- timestamp: 0,
60
- invariants: invariantReport,
61
- status: 'ok',
62
- };
63
  }
64
 
65
  module.exports = { processSignal };
 
1
  // engine.js
2
 
3
+ const { writeLedgerEntry } = require('./ledger');
4
+
5
  // Invariant set F1–F9
6
  const INVARIANTS = {
7
  F1_NO_SEMANTIC_INTERPRETATION: true,
 
15
  F9_NO_CROSS_SIGNAL_CONTAMINATION: true,
16
  };
17
 
 
18
  function checkInvariants(input) {
19
  const report = {
20
  inputType: typeof input,
 
23
  violations: [],
24
  };
25
 
 
26
  if (typeof input !== 'string') {
27
  report.violations.push('F1: input must be a string (opaque signal)');
28
  }
29
 
 
 
 
 
 
 
30
  return report;
31
  }
32
 
 
33
  function processSignal(input) {
34
  const invariantReport = checkInvariants(input);
35
 
36
+ let result;
37
  if (invariantReport.violations.length > 0) {
38
+ result = {
39
  input,
40
  output: null,
41
  timestamp: 0,
42
  invariants: invariantReport,
43
  status: 'error',
44
  };
45
+ } else {
46
+ const output = `processed:${input}`;
47
+ result = {
48
+ input,
49
+ output,
50
+ timestamp: 0,
51
+ invariants: invariantReport,
52
+ status: 'ok',
53
+ };
54
  }
55
 
56
+ // Write ledger entry (deterministic, append-only)
57
+ const ledgerPath = writeLedgerEntry({
58
+ input: result.input,
59
+ output: result.output,
60
+ timestamp: result.timestamp,
61
+ status: result.status,
62
+ invariants: result.invariants,
63
+ });
64
 
65
+ return { ...result, ledgerPath };
 
 
 
 
 
 
66
  }
67
 
68
  module.exports = { processSignal };