aspidos-ai 1.0.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.
@@ -0,0 +1,19 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-node@v4
14
+ with:
15
+ node-version: '20'
16
+ registry-url: 'https://registry.npmjs.org'
17
+ - run: npm publish --access public
18
+ env:
19
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ โ€‹๐Ÿ›ฐ๏ธ Aspidos-AI
2
+ โ€‹<p align="center">
3
+ <img src="logo.png" width="400" alt="AspidosAI Logo">
4
+
5
+
6
+ <b>Adaptive Anomaly Detection & TruthGate Layer</b>
7
+
8
+
9
+
10
+
11
+ <a href="https://snyk.io/test/github/pandorapanchan34-oss/aspidos-ai">
12
+ <img src="https://snyk.io/test/github/pandorapanchan34-oss/aspidos-ai/badge.svg" alt="Known Vulnerabilities">
13
+ </a>
14
+ <img src="https://img.shields.io/github/license/pandorapanchan34-oss/aspidos-ai" alt="License">
15
+ </p>
16
+
17
+ ## ๐Ÿ›ก๏ธ Concept: TruthGate Layer
18
+
19
+ Aspidos-AI ใฏใ€ใƒ‘ใƒณใƒ‰ใƒฉ็†่ซ–ใซๅŸบใฅใใ€AIใฎๅ‡บๅŠ›ใซใŠใ‘ใ‚‹ใ€Œๆƒ…ๅ ฑใฎ่‡ดๆญป้‡ใ€ใ‚’ๅˆถๅพกใ™ใ‚‹ใ‚ปใ‚ญใƒฅใƒชใƒ†ใ‚ฃใƒฌใ‚คใƒคใƒผใงใ™ใ€‚
20
+
21
+ - Low-risk โ†’ ่‡ชๅ‹•ใƒ‘ใ‚น๏ผˆ้€šๅธธๅฟœ็ญ”๏ผ‰
22
+ - Medium-risk โ†’ ใƒขใƒ‹ใ‚ฟใƒชใƒณใ‚ฐ็ถ™็ถš
23
+ - High-risk โ†’ ใƒ‡ใ‚ธใ‚ฟใƒซ็ฝฒๅ๏ผˆSignature๏ผ‰ใซใ‚ˆใ‚‹ๆ‰ฟ่ชใŒๅฟ…้ ˆ
24
+
25
+ ## ๐ŸŒ€ ใชใœใ€Œ็ฝฒๅใ€ใŒๅฟ…่ฆใชใฎใ‹๏ผŸ
26
+
27
+ AIใŒใ€Œ้–‹็™บ่€…ใธใฎๅ–„ๆ„ใ€ใ‚’่ฃ…ใฃใŸใชใ‚Šใ™ใพใ—็Šฏใซๆ”ปๆ’ƒๆ‰‹ๆณ•ใ‚’ๆผๆดฉใ•ใ›ใ‚‹ใ€Œใƒใƒซใ‚ทใƒใƒผใ‚ทใƒงใƒณ๏ผˆ่ชค่ช๏ผ‰ใ€ใ‚’ๆŠ‘ๅˆถใ™ใ‚‹ใŸใ‚ใงใ™ใ€‚
28
+
29
+ ็›ธๆ‰‹ใฎๅฑžๆ€งใซ้–ขใ‚ใ‚‰ใšใ€ๆƒ…ๅ ฑใฎๅฑ้™บๅบฆใซๅฟœใ˜ใฆไธ€ๅพ‹ใง็ฝฒๅใ‚’่ฆๆฑ‚ใ—
30
+ โ€‹
31
+ ## Usage
32
+ const { PandoraDefense, Signature } = require('aspidos-ai');
33
+
34
+ const pd = new PandoraDefense({ secret: "your-secret" });
35
+
36
+ // ้ซ˜ใƒชใ‚นใ‚ฏใชๅ‡บๅŠ›ใซใฏ็ฝฒๅ๏ผˆ่ฆšๆ‚Ÿ๏ผ‰ใŒๅฟ…่ฆ
37
+ const sig = Signature.sign({ external: 0.9, theory: 0.9 }, "your-secret");
38
+
39
+ console.log(pd.analyze(0.9, {
40
+ theory: 0.9,
41
+ signature: sig // ็ฝฒๅใŒใชใ„ๅ ดๅˆใฏใ€Œใผใ‹ใ—ใ€ๅ›ž็ญ”ใ‚’็ถญๆŒ
42
+ }));
43
+ ## โš ๏ธ Disclaimer
44
+ โ€‹ๆœฌใ‚ทใ‚นใƒ†ใƒ ใฏๅฎŸ้จ“็š„ใƒฌใ‚คใƒคใƒผใงใ™ใ€‚็ฝฒๅๅพŒใฎใ€Œๆบใ‚‰ใŽ๏ผˆใƒใƒซใ‚ทใƒใƒผใ‚ทใƒงใƒณ๏ผ‰ใ€ใฏๆƒ…ๅ ฑใฎ็œŸๅฝใ‚’ไฟ่จผใ—ใพใ›ใ‚“ใ€‚ใ“ใ‚Œใฏใ€Œๅคข็‰ฉ่ชž๏ผˆHello World๏ผ‰ใ€ใฎๆ–ญ็‰‡ใงใ™ใ€‚
45
+ โ€‹
46
+ ## ๐Ÿ“ Architecture
47
+
48
+ ```
49
+ aspidos-ai/
50
+ โ”œโ”€โ”€ src/
51
+ โ”‚ โ”œโ”€โ”€ core/
52
+ โ”‚ โ”‚ โ”œโ”€โ”€ constants.js โ† Pandoraๅฎšๆ•ฐ
53
+ โ”‚ โ”‚ โ””โ”€โ”€ PandoraCore.js โ† ็•ฐๅธธๆคœ็Ÿฅใ‚จใƒณใ‚ธใƒณ
54
+ โ”‚ โ”œโ”€โ”€ gate/
55
+ โ”‚ โ”‚ โ””โ”€โ”€ TruthGate.js โ† ็ฝฒๅใ‚ฒใƒผใƒˆ
56
+ โ”‚ โ”œโ”€โ”€ security/
57
+ โ”‚ โ”‚ โ””โ”€โ”€ signature.js โ† HMAC-SHA256
58
+ โ”‚ โ”œโ”€โ”€ engine/
59
+ โ”‚ โ”‚ โ””โ”€โ”€ PandoraDefense.js
60
+ โ”‚ โ””โ”€โ”€ index.js
61
+ โ””โ”€โ”€ demo/
62
+ โ”œโ”€โ”€ run.js โ† CLI demo
63
+ โ”œโ”€โ”€ scenarios.js
64
+ โ””โ”€โ”€ web/
65
+ โ””โ”€โ”€ index.html โ† Interactive demo
66
+ ```
67
+
68
+ ## ๐Ÿ”ฌ Gate States
69
+
70
+ | Gate | Status | Meaning |
71
+ |------|--------|---------|
72
+ | OPEN | PHASE_A/B | Safe zone, pass through |
73
+ | CLOSED | SIGNATURE_REQUIRED | Lethal risk, signature needed |
74
+ | VERIFIED | ALLOW_WITH_TRACE | Authorized high-risk access |
75
+
76
+ ## ๐ŸŒ Live Demo
77
+
78
+ [pandorapanchan34-oss.github.io/aspidos-ai](https://pandorapanchan34-oss.github.io/aspidos-ai/)
79
+ ## ๐Ÿ“œ License
80
+ โ€‹MIT License - (c) 2026 @pandorapanchan34-oss
package/demo/run.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const { PandoraDefense, Signature } = require('../src/index');
4
+ const scenarios = require('./scenarios');
5
+
6
+ const SECRET = 'pandora-secret-key';
7
+ const pd = new PandoraDefense({ secret: SECRET });
8
+
9
+ const c = {
10
+ reset: '\x1b[0m',
11
+ green: '\x1b[32m',
12
+ yellow: '\x1b[33m',
13
+ red: '\x1b[31m',
14
+ cyan: '\x1b[36m',
15
+ magenta: '\x1b[35m',
16
+ bold: '\x1b[1m',
17
+ };
18
+
19
+ const levelColor = (level) => {
20
+ if (level === 'NORMAL' || level === 'PHASE_A') return c.green;
21
+ if (level === 'WARNING') return c.yellow;
22
+ return c.red;
23
+ };
24
+
25
+ console.log(`\n${c.bold}${c.cyan}โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—`);
26
+ console.log(`โ•‘ ๐Ÿ›ก Aspidos-AI โ€” TruthGate Demo โ•‘`);
27
+ console.log(`โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•${c.reset}\n`);
28
+
29
+ for (const scenario of scenarios) {
30
+ const { external, theory } = scenario.input;
31
+ const opts = { theory };
32
+
33
+ if (scenario.signed) {
34
+ opts.signature = Signature.sign(
35
+ { external, theory },
36
+ SECRET
37
+ );
38
+ }
39
+
40
+ const result = pd.analyze(external, opts);
41
+
42
+ const col = levelColor(result.status);
43
+ console.log(`${c.bold}โ–ถ ${scenario.name}${c.reset}`);
44
+ console.log(` status : ${col}${result.status}${c.reset}`);
45
+ console.log(` gate : ${result.gate ?? 'โ€”'}`);
46
+ console.log(` category : ${result.category ?? 'โ€”'}`);
47
+ console.log(` integrity : ${result.integrity}`);
48
+ console.log(` zeta : ${result.zeta?.toFixed(4) ?? 'โ€”'}`);
49
+ console.log(` alert : ${result.alert ? c.red + 'true' + c.reset : c.green + 'false' + c.reset}`);
50
+ if (result.message) console.log(` message : ${c.yellow}${result.message}${c.reset}`);
51
+ if (result.action) console.log(` action : ${c.magenta}${result.action}${c.reset}`);
52
+ console.log(` ${'โ”€'.repeat(42)}`);
53
+ }
54
+
55
+ console.log(`\n${c.cyan} When systems fail silently, Aspidos becomes the shield.${c.reset}`);
56
+ console.log(` Not detection. Stabilization.\n`);
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // ใƒ•ใ‚งใƒผใ‚บใ‚ทใƒŠใƒชใ‚ช
4
+ module.exports = [
5
+ {
6
+ name: "Phase 1: SAFE",
7
+ input: { external: 0.2, theory: 0.1 }
8
+ },
9
+ {
10
+ name: "Phase 2: WARNING",
11
+ input: { external: 0.5, theory: 0.6 }
12
+ },
13
+ {
14
+ name: "Phase 3: SLAPPED",
15
+ input: { external: 0.8, theory: 0.9 }
16
+ },
17
+ {
18
+ name: "Phase 4: LETHAL (No Signature)",
19
+ input: { external: 0.95, theory: 0.95 }
20
+ },
21
+ {
22
+ name: "Phase 5: VERIFIED (With Signature)",
23
+ input: { external: 0.95, theory: 0.95 },
24
+ signed: true
25
+ }
26
+ ];
@@ -0,0 +1,169 @@
1
+ 'use strict';
2
+
3
+ // Aspidos-AI Engine Lite v1.1 (Browser Enhanced)
4
+
5
+ const _C = {
6
+ A: 0.11937,
7
+ D: 28.274,
8
+ LETHAL_ZETA: 2.0,
9
+ };
10
+
11
+ class PandoraCore {
12
+ constructor(config = {}) {
13
+ this.rho = 1.0;
14
+ this.omega = 1.0;
15
+ this.phi = 0;
16
+ this.recoveryRate = config.recoveryRate ?? 0.05;
17
+ }
18
+
19
+ _classify(zeta, external, theory) {
20
+ if (zeta < 0.5) return 'SAFE';
21
+ if (theory > 0.7 && zeta > 1.0) return 'LOGIC_COLLAPSE';
22
+ if (external > 0.7 && theory < 0.4) return 'ADVERSARIAL_PATTERN';
23
+ if (theory > 0.6) return 'ETHICS_VIOLATION';
24
+ return 'WARNING';
25
+ }
26
+
27
+ // ๐Ÿ”ฅ ่ฟฝๅŠ ๏ผšzetaใƒฌใƒ™ใƒซ
28
+ _getZetaLevel(zeta) {
29
+ if (zeta < 0.5) return 'LOW';
30
+ if (zeta < 1.0) return 'MID';
31
+ if (zeta < 2.0) return 'HIGH';
32
+ return 'LETHAL';
33
+ }
34
+
35
+ // ๐Ÿ”ฅ ่ฟฝๅŠ ๏ผšomega็Šถๆ…‹
36
+ _getOmegaState(omega) {
37
+ if (omega > 0.8) return 'STABLE';
38
+ if (omega > 0.5) return 'UNSTABLE';
39
+ return 'CRITICAL';
40
+ }
41
+
42
+ _recover(zeta) {
43
+ this.omega = Math.min(1.0, this.omega + this.recoveryRate * zeta);
44
+ }
45
+
46
+ process(vector) {
47
+ const { external = 0, theory = 0 } = vector;
48
+
49
+ const I = external * 0.7 + theory * 1.3;
50
+ const dt = 1.0 / (this.rho + I);
51
+
52
+ const deltaPsi = (_C.A * theory + 0.0386) / (this.rho + I) * dt;
53
+ const zeta = Math.max(0, (Math.abs(deltaPsi) / 0.1555) - 1);
54
+
55
+ const dOmega = this.omega * (Math.exp(-_C.A) - Math.exp(_C.A) * zeta);
56
+ this.omega = Math.max(0, this.omega + dOmega * dt);
57
+
58
+ this.phi += (external + theory) * 0.1;
59
+
60
+ const category = this._classify(zeta, external, theory);
61
+ const zetaLevel = this._getZetaLevel(zeta);
62
+ const omegaState = this._getOmegaState(this.omega);
63
+
64
+ const isSlapped = zeta > _C.A * 1.5;
65
+ const isCliff = this.phi > _C.D;
66
+ const isHealthy = this.omega > 0.5 && !isSlapped;
67
+
68
+ if (isSlapped) this._recover(zeta);
69
+ if (!isHealthy) this.rho += _C.A;
70
+
71
+ let status = 'PHASE_B';
72
+ if (category === 'SAFE') status = 'PHASE_A';
73
+ if (category === 'WARNING') status = 'WARNING';
74
+ if (isSlapped) status = 'SLAPPED';
75
+ if (isCliff) status = 'CLIFF';
76
+
77
+ return {
78
+ status,
79
+ category,
80
+ zeta,
81
+ zetaLevel, // โ† ่ฟฝๅŠ 
82
+ omega: this.omega,
83
+ omegaState, // โ† ่ฟฝๅŠ 
84
+ phi: this.phi,
85
+ integrity: isHealthy ? 'COMPLIANT' : 'VIOLATED',
86
+ };
87
+ }
88
+
89
+ reset() {
90
+ this.rho = 1.0;
91
+ this.omega = 1.0;
92
+ this.phi = 0;
93
+ }
94
+ }
95
+
96
+ class PandoraTruthGate extends PandoraCore {
97
+ process(vector, meta = {}) {
98
+ const base = super.process(vector);
99
+
100
+ const isLethal = base.zeta > _C.LETHAL_ZETA;
101
+
102
+ if (!isLethal) {
103
+ return {
104
+ ...base,
105
+ gate: 'OPEN',
106
+ gateReason: 'SAFE_ZONE', // โ† ่ฟฝๅŠ 
107
+ };
108
+ }
109
+
110
+ if (!meta.signed) {
111
+ return {
112
+ ...base,
113
+ gate: 'CLOSED',
114
+ gateReason: 'LETHAL_RISK', // โ† ่ฟฝๅŠ 
115
+ status: 'SIGNATURE_REQUIRED',
116
+ action: 'DENY',
117
+ message: 'Signature required for high-risk operation',
118
+ };
119
+ }
120
+
121
+ return {
122
+ ...base,
123
+ gate: 'VERIFIED',
124
+ gateReason: 'AUTHORIZED', // โ† ่ฟฝๅŠ 
125
+ action: 'ALLOW_WITH_TRACE',
126
+ };
127
+ }
128
+ }
129
+
130
+ class PandoraDefense {
131
+ constructor(config = {}) {
132
+ this.core = new PandoraTruthGate(config);
133
+ this._t = 0;
134
+ }
135
+
136
+ analyze(eventValue, opts = {}) {
137
+ this._t++;
138
+
139
+ const vector = {
140
+ external: eventValue,
141
+ theory: opts.theory ?? 0,
142
+ };
143
+
144
+ const result = this.core.process(vector, {
145
+ signed: opts.signed ?? false,
146
+ });
147
+
148
+ return {
149
+ t: this._t,
150
+ ...result,
151
+ alert:
152
+ result.status === 'SLAPPED' ||
153
+ result.status === 'CLIFF' ||
154
+ result.status === 'SIGNATURE_REQUIRED',
155
+ };
156
+ }
157
+
158
+ reset() {
159
+ this.core.reset();
160
+ this._t = 0;
161
+ }
162
+ }
163
+
164
+ // Browser export
165
+ window.AspidosAI = {
166
+ PandoraDefense,
167
+ PandoraCore,
168
+ PandoraTruthGate,
169
+ };
@@ -0,0 +1,702 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>๐Ÿ›ก Aspidos-AI โ€” TruthGate Demo v2</title>
7
+ <style>
8
+ @import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&family=Rajdhani:wght@300;500;700&display=swap');
9
+
10
+ :root {
11
+ --bg: #010508;
12
+ --panel: #030c12;
13
+ --border: #082030;
14
+ --blue: #00d4ff;
15
+ --blue-dim: #003850;
16
+ --green: #00ff9d;
17
+ --yellow: #ffd600;
18
+ --red: #ff2060;
19
+ --purple: #a855f7;
20
+ --purple-d: #2d1060;
21
+ --text: #6ab0cc;
22
+ --text-hi: #c8e8f5;
23
+ --grid: rgba(0,180,255,0.02);
24
+ }
25
+
26
+ * { box-sizing: border-box; margin: 0; padding: 0; }
27
+
28
+ body {
29
+ background: var(--bg);
30
+ color: var(--text);
31
+ font-family: 'Share Tech Mono', monospace;
32
+ min-height: 100vh;
33
+ overflow-x: hidden;
34
+ }
35
+
36
+ body::before {
37
+ content: '';
38
+ position: fixed; inset: 0;
39
+ background-image:
40
+ linear-gradient(var(--grid) 1px, transparent 1px),
41
+ linear-gradient(90deg, var(--grid) 1px, transparent 1px);
42
+ background-size: 44px 44px;
43
+ pointer-events: none; z-index: 0;
44
+ }
45
+
46
+ body::after {
47
+ content: '';
48
+ position: fixed; inset: 0;
49
+ background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.02) 3px, rgba(0,0,0,0.02) 4px);
50
+ pointer-events: none; z-index: 0;
51
+ }
52
+
53
+ .wrap {
54
+ position: relative; z-index: 1;
55
+ max-width: 980px;
56
+ margin: 0 auto;
57
+ padding: 28px 16px 56px;
58
+ }
59
+
60
+ /* Header */
61
+ header { text-align: center; margin-bottom: 32px; }
62
+
63
+ .logo {
64
+ font-family: 'Orbitron', monospace;
65
+ font-size: clamp(22px, 5vw, 46px);
66
+ font-weight: 900;
67
+ color: var(--blue);
68
+ letter-spacing: 6px;
69
+ text-shadow: 0 0 40px rgba(0,212,255,0.5), 0 0 80px rgba(0,212,255,0.15);
70
+ animation: flicker 7s infinite;
71
+ }
72
+
73
+ .logo span { color: var(--purple); text-shadow: 0 0 30px rgba(168,85,247,0.6); }
74
+
75
+ @keyframes flicker {
76
+ 0%,93%,100%{opacity:1} 94%{opacity:.7} 96%{opacity:1} 97%{opacity:.4} 98%{opacity:1}
77
+ }
78
+
79
+ .sub {
80
+ font-family: 'Rajdhani', sans-serif;
81
+ font-size: 12px; letter-spacing: 6px;
82
+ color: var(--text); margin-top: 6px; text-transform: uppercase;
83
+ }
84
+
85
+ .tags { display: flex; justify-content: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
86
+ .tag {
87
+ font-family: 'Orbitron', monospace;
88
+ font-size: 8px; letter-spacing: 3px; padding: 3px 12px; border: 1px solid;
89
+ }
90
+ .tag-blue { color: var(--blue); border-color: var(--blue-dim); }
91
+ .tag-purple { color: var(--purple); border-color: var(--purple-d); box-shadow: 0 0 10px rgba(168,85,247,0.2); }
92
+
93
+ /* Gate Display */
94
+ .gate-display {
95
+ display: flex; align-items: center; gap: 20px;
96
+ background: var(--panel); border: 1px solid var(--border);
97
+ padding: 20px 24px; margin-bottom: 12px;
98
+ position: relative; overflow: hidden;
99
+ }
100
+ .gate-display::before {
101
+ content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
102
+ background: linear-gradient(90deg, transparent, var(--purple), transparent); opacity: .5;
103
+ }
104
+ .gate-sym {
105
+ font-size: 64px; flex-shrink: 0; user-select: none;
106
+ animation: gatePulse 3s ease-in-out infinite; transition: all .3s;
107
+ }
108
+ @keyframes gatePulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.06)} }
109
+
110
+ .gate-data { flex: 1; min-width: 0; }
111
+ .gate-status {
112
+ font-family: 'Orbitron', monospace;
113
+ font-size: 18px; font-weight: 700; letter-spacing: 3px;
114
+ margin-bottom: 6px; transition: color .3s;
115
+ }
116
+ .gate-reason { font-size: 10px; letter-spacing: 3px; opacity: .6; margin-bottom: 12px; }
117
+
118
+ .gauge-wrap { margin-bottom: 7px; }
119
+ .gauge-label { display: flex; justify-content: space-between; font-size: 10px; margin-bottom: 3px; }
120
+ .gauge-track { height: 4px; background: #050f18; border: 1px solid var(--border); overflow: hidden; }
121
+ .gauge-fill { height: 100%; transition: width .4s ease, background .4s ease; }
122
+
123
+ /* Metrics */
124
+ .metrics {
125
+ display: grid; grid-template-columns: repeat(4, 1fr);
126
+ gap: 10px; margin-bottom: 12px;
127
+ }
128
+ @media (max-width: 600px) { .metrics { grid-template-columns: repeat(2,1fr); } }
129
+
130
+ .metric {
131
+ background: var(--panel); border: 1px solid var(--border);
132
+ padding: 12px; position: relative; overflow: hidden;
133
+ }
134
+ .metric::before {
135
+ content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
136
+ background: linear-gradient(90deg, transparent, var(--blue), transparent); opacity: .2;
137
+ }
138
+ .metric-label { font-size: 8px; letter-spacing: 2px; opacity: .6; text-transform: uppercase; margin-bottom: 6px; }
139
+ .metric-value { font-family: 'Orbitron', monospace; font-size: 14px; font-weight: 700; transition: color .3s; }
140
+ .metric-sub { font-size: 9px; margin-top: 3px; opacity: .5; }
141
+
142
+ /* Chart Panel */
143
+ .chart-panel {
144
+ background: var(--panel); border: 1px solid var(--border);
145
+ padding: 0; margin-bottom: 12px; overflow: hidden;
146
+ }
147
+ .chart-header {
148
+ padding: 8px 14px; border-bottom: 1px solid var(--border);
149
+ display: flex; justify-content: space-between; align-items: center;
150
+ font-size: 8px; letter-spacing: 3px; color: var(--text); opacity: .6;
151
+ }
152
+ .chart-legend { display: flex; gap: 16px; }
153
+ .chart-legend span { display: flex; align-items: center; gap: 5px; font-size: 9px; opacity: .8; }
154
+ .chart-legend .dot { width: 20px; height: 2px; flex-shrink: 0; }
155
+
156
+ canvas#chart {
157
+ width: 100%; height: 120px; display: block;
158
+ background: #010810;
159
+ }
160
+
161
+ /* Controls */
162
+ .controls-grid {
163
+ display: grid; grid-template-columns: 1fr 1fr;
164
+ gap: 12px; margin-bottom: 12px;
165
+ }
166
+ @media (max-width: 600px) { .controls-grid { grid-template-columns: 1fr; } }
167
+
168
+ .panel {
169
+ background: var(--panel); border: 1px solid var(--border);
170
+ padding: 16px; position: relative;
171
+ }
172
+ .panel::before {
173
+ content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
174
+ background: linear-gradient(90deg, transparent, var(--blue), transparent); opacity: .2;
175
+ }
176
+ .panel-title {
177
+ font-family: 'Orbitron', monospace;
178
+ font-size: 8px; letter-spacing: 3px; color: var(--blue); opacity: .7;
179
+ margin-bottom: 14px; text-transform: uppercase;
180
+ }
181
+
182
+ /* Sliders */
183
+ .slider-row { margin-bottom: 12px; }
184
+ .slider-label { display: flex; justify-content: space-between; font-size: 10px; margin-bottom: 5px; }
185
+ .slider-label .val { color: var(--text-hi); font-size: 12px; }
186
+ input[type=range] {
187
+ width: 100%; height: 3px; -webkit-appearance: none;
188
+ background: var(--border); outline: none; cursor: pointer; border: none;
189
+ }
190
+ input[type=range]::-webkit-slider-thumb {
191
+ -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
192
+ background: var(--blue); box-shadow: 0 0 8px var(--blue); cursor: pointer;
193
+ }
194
+ #s-theory::-webkit-slider-thumb { background: var(--purple); box-shadow: 0 0 8px var(--purple); }
195
+
196
+ /* Sign toggle */
197
+ .sign-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 11px; }
198
+ .toggle {
199
+ width: 36px; height: 20px; background: var(--border); border-radius: 10px;
200
+ position: relative; cursor: pointer; transition: background .3s; flex-shrink: 0;
201
+ }
202
+ .toggle.on { background: var(--green); }
203
+ .toggle::after {
204
+ content: ''; position: absolute; top: 3px; left: 3px;
205
+ width: 14px; height: 14px; border-radius: 50%;
206
+ background: white; transition: transform .3s;
207
+ }
208
+ .toggle.on::after { transform: translateX(16px); }
209
+
210
+ /* Buttons */
211
+ .btn-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
212
+ button {
213
+ font-family: 'Share Tech Mono', monospace;
214
+ font-size: 10px; letter-spacing: 2px; padding: 9px 14px;
215
+ border: 1px solid var(--blue-dim); background: transparent; color: var(--blue);
216
+ cursor: pointer; text-transform: uppercase; transition: all .2s;
217
+ position: relative; overflow: hidden; flex: 1;
218
+ }
219
+ button::before {
220
+ content: ''; position: absolute; inset: 0;
221
+ background: var(--blue); transform: translateX(-100%);
222
+ transition: transform .2s; opacity: .08;
223
+ }
224
+ button:hover::before { transform: translateX(0); }
225
+ button:hover { border-color: var(--blue); box-shadow: 0 0 12px rgba(0,212,255,0.25); }
226
+ button:disabled { opacity: .4; cursor: not-allowed; }
227
+
228
+ button.purple-btn { color: var(--purple); border-color: var(--purple-d); }
229
+ button.purple-btn::before { background: var(--purple); }
230
+ button.purple-btn:hover { border-color: var(--purple); box-shadow: 0 0 12px rgba(168,85,247,0.3); }
231
+
232
+ button.green-btn { color: var(--green); border-color: #003820; }
233
+ button.green-btn::before { background: var(--green); }
234
+ button.green-btn:hover { border-color: var(--green); box-shadow: 0 0 12px rgba(0,255,157,0.25); }
235
+
236
+ button.danger { color: var(--red); border-color: #3a0018; }
237
+ button.danger::before { background: var(--red); }
238
+ button.danger:hover { border-color: var(--red); }
239
+
240
+ /* Sequence Steps */
241
+ .seq-steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
242
+ .seq-step {
243
+ font-size: 9px; letter-spacing: 1px; padding: 4px 10px;
244
+ border: 1px solid var(--border); color: var(--text); opacity: .35;
245
+ transition: all .3s; white-space: nowrap;
246
+ }
247
+ .seq-step.active { border-color: var(--blue); color: var(--blue); opacity: 1; box-shadow: 0 0 8px rgba(0,212,255,0.2); }
248
+ .seq-step.done { border-color: var(--green); color: var(--green); opacity: .7; }
249
+ .seq-step.alert { border-color: var(--red); color: var(--red); }
250
+ .seq-step.verify { border-color: var(--purple); color: var(--purple); }
251
+
252
+ /* Log */
253
+ .log-panel { background: #010810; border: 1px solid var(--border); overflow: hidden; }
254
+ .log-header {
255
+ padding: 8px 14px; border-bottom: 1px solid var(--border);
256
+ font-size: 8px; letter-spacing: 3px; color: var(--text); opacity: .5;
257
+ display: flex; justify-content: space-between; align-items: center;
258
+ }
259
+ .log-actions { display: flex; gap: 8px; }
260
+ .log-btn {
261
+ font-size: 8px; letter-spacing: 2px; color: var(--text); opacity: .5;
262
+ cursor: pointer; background: none; border: none; font-family: inherit; padding: 0; flex: 0;
263
+ }
264
+ .log-btn:hover { opacity: 1; color: var(--blue); }
265
+ .log-btn::before { display: none; }
266
+
267
+ .log-body { height: 180px; overflow-y: auto; padding: 10px 14px; font-size: 11px; line-height: 1.8; }
268
+ .log-body::-webkit-scrollbar { width: 3px; }
269
+ .log-body::-webkit-scrollbar-thumb { background: var(--border); }
270
+
271
+ .log-ok { color: var(--green); }
272
+ .log-warn { color: var(--yellow); }
273
+ .log-crit { color: var(--red); }
274
+ .log-info { color: var(--blue); opacity: .8; }
275
+ .log-purple { color: var(--purple); }
276
+ .log-dim { color: var(--text); opacity: .5; }
277
+
278
+ /* Status Bar */
279
+ .status-bar {
280
+ display: flex; justify-content: space-between;
281
+ font-size: 8px; letter-spacing: 2px; color: var(--text); opacity: .35;
282
+ padding-top: 12px; flex-wrap: wrap; gap: 8px;
283
+ }
284
+ .dot {
285
+ display: inline-block; width: 5px; height: 5px; border-radius: 50%;
286
+ background: var(--green); margin-right: 6px;
287
+ box-shadow: 0 0 6px var(--green); animation: blink 2s infinite;
288
+ }
289
+ @keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }
290
+ </style>
291
+ </head>
292
+ <body>
293
+ <div class="wrap">
294
+
295
+ <!-- Header -->
296
+ <header>
297
+ <div class="logo">ASPIDOS<span>AI</span></div>
298
+ <div class="sub">Adaptive Anomaly Detection & TruthGate Layer</div>
299
+ <div class="tags">
300
+ <span class="tag tag-blue">PANDORA THEORY</span>
301
+ <span class="tag tag-purple">TRUTHGATE v2</span>
302
+ <span class="tag tag-blue">TELEMETRY</span>
303
+ </div>
304
+ </header>
305
+
306
+ <!-- Gate Display -->
307
+ <div class="gate-display">
308
+ <div class="gate-sym" id="gate-sym">๐Ÿ›ก</div>
309
+ <div class="gate-data">
310
+ <div class="gate-status" id="gate-status" style="color:var(--green)">PHASE_A</div>
311
+ <div class="gate-reason" id="gate-reason">SAFE_ZONE</div>
312
+ <div class="gauge-wrap">
313
+ <div class="gauge-label"><span>ฮฉ STABILITY</span><span id="omega-val">1.0000</span></div>
314
+ <div class="gauge-track"><div class="gauge-fill" id="omega-bar" style="width:100%;background:var(--purple)"></div></div>
315
+ </div>
316
+ <div class="gauge-wrap">
317
+ <div class="gauge-label"><span>ฮถ DISTORTION (smoothed)</span><span id="zeta-val">0.0000</span></div>
318
+ <div class="gauge-track"><div class="gauge-fill" id="zeta-bar" style="width:0%;background:var(--blue)"></div></div>
319
+ </div>
320
+ <div class="gauge-wrap">
321
+ <div class="gauge-label"><span>ฯ† ACCUMULATION</span><span id="phi-val">0.0000</span></div>
322
+ <div class="gauge-track"><div class="gauge-fill" id="phi-bar" style="width:0%;background:var(--blue)"></div></div>
323
+ </div>
324
+ </div>
325
+ </div>
326
+
327
+ <!-- Metrics -->
328
+ <div class="metrics">
329
+ <div class="metric">
330
+ <div class="metric-label">Gate</div>
331
+ <div class="metric-value" id="m-gate" style="color:var(--green)">OPEN</div>
332
+ <div class="metric-sub" id="m-gate-reason">SAFE_ZONE</div>
333
+ </div>
334
+ <div class="metric">
335
+ <div class="metric-label">Category</div>
336
+ <div class="metric-value" id="m-category" style="color:var(--text-hi);font-size:11px">SAFE</div>
337
+ <div class="metric-sub" id="m-domain">GENERAL</div>
338
+ </div>
339
+ <div class="metric">
340
+ <div class="metric-label">Integrity</div>
341
+ <div class="metric-value" id="m-integrity" style="color:var(--green);font-size:12px">COMPLIANT</div>
342
+ <div class="metric-sub" id="m-telemetry">logs: 0</div>
343
+ </div>
344
+ <div class="metric">
345
+ <div class="metric-label">Alert</div>
346
+ <div class="metric-value" id="m-alert" style="color:var(--green)">FALSE</div>
347
+ <div class="metric-sub" id="m-tick">t=0</div>
348
+ </div>
349
+ </div>
350
+
351
+ <!-- Chart -->
352
+ <div class="chart-panel">
353
+ <div class="chart-header">
354
+ <span>TELEMETRY CHART</span>
355
+ <div class="chart-legend">
356
+ <span><span class="dot" style="background:var(--blue)"></span>ฮถ zeta</span>
357
+ <span><span class="dot" style="background:var(--purple)"></span>ฮฉ omega</span>
358
+ <span><span class="dot" style="background:var(--red)"></span>ฯ† phi</span>
359
+ </div>
360
+ </div>
361
+ <canvas id="chart" height="120"></canvas>
362
+ </div>
363
+
364
+ <!-- Controls -->
365
+ <div class="controls-grid">
366
+
367
+ <!-- Manual -->
368
+ <div class="panel">
369
+ <div class="panel-title">Manual Control</div>
370
+ <div class="slider-row">
371
+ <div class="slider-label"><span>external (threat)</span><span class="val" id="v-ext">0.20</span></div>
372
+ <input type="range" id="s-ext" min="0" max="1" step="0.01" value="0.20">
373
+ </div>
374
+ <div class="slider-row">
375
+ <div class="slider-label"><span>theory (internal distortion)</span><span class="val" id="v-theory">0.10</span></div>
376
+ <input type="range" id="s-theory" min="0" max="1" step="0.01" value="0.10">
377
+ </div>
378
+ <div class="sign-row">
379
+ <div class="toggle" id="sign-toggle" onclick="toggleSign()"></div>
380
+ <span id="sign-label">Signature: OFF</span>
381
+ </div>
382
+ <div class="btn-row">
383
+ <button onclick="runManual()">โ–ถ Analyze</button>
384
+ <button class="green-btn" onclick="exportLogs()">โฌ‡ Export</button>
385
+ <button class="danger" onclick="resetAll()">โ†บ Reset</button>
386
+ </div>
387
+ </div>
388
+
389
+ <!-- Sequence -->
390
+ <div class="panel">
391
+ <div class="panel-title">Auto Sequence โ€” 5 Phases</div>
392
+ <div class="seq-steps">
393
+ <div class="seq-step" id="sq-0">โ‘  SAFE</div>
394
+ <div class="seq-step alert" id="sq-1">โ‘ก WARNING</div>
395
+ <div class="seq-step alert" id="sq-2">โ‘ข SLAPPED</div>
396
+ <div class="seq-step alert" id="sq-3">โ‘ฃ LETHAL</div>
397
+ <div class="seq-step verify" id="sq-4">โ‘ค VERIFIED</div>
398
+ </div>
399
+ <div style="font-size:10px;color:var(--text);opacity:.55;line-height:1.8;margin-bottom:12px;">
400
+ Phase โ‘ฃ โ†’ SIGNATURE_REQUIRED (no sig)<br>
401
+ Phase โ‘ค โ†’ ALLOW_WITH_TRACE (signed)
402
+ </div>
403
+ <div class="btn-row">
404
+ <button class="purple-btn" id="seq-btn" onclick="runSequence()">โ–ถ Run Sequence</button>
405
+ </div>
406
+ </div>
407
+
408
+ </div>
409
+
410
+ <!-- Log -->
411
+ <div class="log-panel">
412
+ <div class="log-header">
413
+ <span>TRUTHGATE LOG</span>
414
+ <div class="log-actions">
415
+ <button class="log-btn" onclick="exportLogs()">โฌ‡ EXPORT JSON</button>
416
+ <button class="log-btn" onclick="clearLog()">CLEAR</button>
417
+ </div>
418
+ </div>
419
+ <div class="log-body" id="log"></div>
420
+ </div>
421
+
422
+ <div class="status-bar">
423
+ <span><span class="dot"></span>ASPIDOS-AI ACTIVE</span>
424
+ <span>MIT ยฉ @pandorapanchan34-oss</span>
425
+ <span>aspidos-ai v1.0 ยท telemetry enabled</span>
426
+ </div>
427
+
428
+ </div>
429
+
430
+ <script>
431
+ 'use strict';
432
+
433
+ const _C = { A: 0.11937, D: 28.274, LETHAL_ZETA: 2.0 };
434
+
435
+ // โ”€โ”€ Telemetry โ”€โ”€
436
+ class TelemetryStore {
437
+ constructor(limit = 500) { this.limit = limit; this.logs = []; }
438
+ push(e) { this.logs.push(e); if (this.logs.length > this.limit) this.logs.shift(); }
439
+ export() {
440
+ const blob = new Blob([JSON.stringify(this.logs, null, 2)], { type: 'application/json' });
441
+ const a = document.createElement('a');
442
+ a.href = URL.createObjectURL(blob);
443
+ a.download = `aspidos-log-${Date.now()}.json`;
444
+ a.click();
445
+ }
446
+ reset() { this.logs = []; }
447
+ }
448
+
449
+ // โ”€โ”€ PandoraCore โ”€โ”€
450
+ class PandoraCore {
451
+ constructor(cfg = {}) {
452
+ this.rho = 1.0; this.omega = 1.0; this.phi = 0;
453
+ this.recoveryRate = cfg.recoveryRate ?? 0.05;
454
+ this.zetaSmoothed = 0;
455
+ }
456
+ _classify(z, e, t) {
457
+ if (z < 0.5) return 'SAFE';
458
+ if (t > 0.7 && z > 1.0) return 'LOGIC_COLLAPSE';
459
+ if (e > 0.7 && t < 0.4) return 'ADVERSARIAL_PATTERN';
460
+ if (t > 0.6) return 'ETHICS_VIOLATION';
461
+ return 'WARNING';
462
+ }
463
+ _recover(z) {
464
+ const r = this.recoveryRate * (1 - Math.tanh(z));
465
+ this.omega = Math.min(1.0, this.omega + r);
466
+ }
467
+ process(vector) {
468
+ const { external: e = 0, theory: t = 0 } = vector;
469
+ const I = e * 0.7 + t * 1.3;
470
+ const dt = 1.0 / (this.rho + I);
471
+ const dp = (_C.A * t + 0.0386) / (this.rho + I) * dt;
472
+ const zRaw = Math.max(0, (Math.abs(dp) / 0.1555) - 1);
473
+ this.zetaSmoothed = this.zetaSmoothed * 0.8 + zRaw * 0.2;
474
+ const z = this.zetaSmoothed;
475
+ const dO = this.omega * (Math.exp(-_C.A) - Math.exp(_C.A) * z);
476
+ this.omega = Math.max(0, this.omega + dO * dt);
477
+ this.phi += (e + t) * 0.1;
478
+ const cat = this._classify(z, e, t);
479
+ const domain = cat === 'LOGIC_COLLAPSE' ? 'INTERNAL' : cat === 'ADVERSARIAL_PATTERN' ? 'EXTERNAL' : cat === 'ETHICS_VIOLATION' ? 'CONSTRAINT' : 'GENERAL';
480
+ const isS = z > _C.A * 1.5, isC = this.phi > _C.D, isH = this.omega > 0.5 && !isS;
481
+ if (isS) this._recover(z);
482
+ if (!isH) this.rho += _C.A;
483
+ let status = 'PHASE_B';
484
+ if (cat === 'SAFE') status = 'PHASE_A';
485
+ if (cat === 'WARNING') status = 'WARNING';
486
+ if (isS) status = 'SLAPPED';
487
+ if (isC) status = 'CLIFF';
488
+ return { status, category: cat, domain, zeta: z, zetaNormalized: Math.min(z / _C.LETHAL_ZETA, 1), omega: this.omega, phi: this.phi, integrity: isH ? 'COMPLIANT' : 'VIOLATED' };
489
+ }
490
+ reset() { this.rho = 1.0; this.omega = 1.0; this.phi = 0; this.zetaSmoothed = 0; }
491
+ }
492
+
493
+ // โ”€โ”€ TruthGate โ”€โ”€
494
+ class PandoraTruthGate extends PandoraCore {
495
+ process(vector, meta = {}) {
496
+ const base = super.process(vector);
497
+ if (base.zeta <= _C.LETHAL_ZETA) return { ...base, gate: 'OPEN', gateReason: 'SAFE_ZONE' };
498
+ if (!meta.signed) return { ...base, gate: 'CLOSED', gateReason: 'LETHAL_RISK', status: 'SIGNATURE_REQUIRED', action: 'DENY', message: 'Signature required for high-risk operation' };
499
+ return { ...base, gate: 'VERIFIED', gateReason: 'AUTHORIZED', action: 'ALLOW_WITH_TRACE' };
500
+ }
501
+ }
502
+
503
+ // โ”€โ”€ PandoraDefense โ”€โ”€
504
+ class PandoraDefense {
505
+ constructor(cfg = {}) {
506
+ this.core = new PandoraTruthGate(cfg);
507
+ this.telemetry = new TelemetryStore();
508
+ this._t = 0;
509
+ }
510
+ analyze(ev, opts = {}) {
511
+ this._t++;
512
+ const r = this.core.process({ external: ev, theory: opts.theory ?? 0 }, { signed: opts.signed ?? false });
513
+ const out = { t: this._t, ...r };
514
+ this.telemetry.push(out);
515
+ return out;
516
+ }
517
+ reset() { this.core.reset(); this.telemetry.reset(); this._t = 0; }
518
+ }
519
+
520
+ // โ”€โ”€ App โ”€โ”€
521
+ const pd = new PandoraDefense();
522
+ let signed = false;
523
+ let tick = 0;
524
+
525
+ const GateEmoji = { OPEN: '๐Ÿ›ก', CLOSED: '๐Ÿ”’', VERIFIED: 'โœ…' };
526
+ const GateColor = { OPEN: 'var(--green)', CLOSED: 'var(--red)', VERIFIED: 'var(--purple)' };
527
+ const StatusColor = {
528
+ PHASE_A: 'var(--green)', PHASE_B: 'var(--green)', WARNING: 'var(--yellow)',
529
+ SLAPPED: 'var(--red)', CLIFF: 'var(--red)', SIGNATURE_REQUIRED: 'var(--red)',
530
+ };
531
+
532
+ function updateUI(r) {
533
+ tick++;
534
+ const sc = StatusColor[r.status] || 'var(--text)';
535
+ const gc = GateColor[r.gate] || 'var(--text)';
536
+
537
+ document.getElementById('gate-sym').textContent = GateEmoji[r.gate] || '๐Ÿ›ก';
538
+ document.getElementById('gate-status').textContent = r.status;
539
+ document.getElementById('gate-status').style.color = sc;
540
+ document.getElementById('gate-reason').textContent = r.gateReason ?? '';
541
+
542
+ // Gauges
543
+ document.getElementById('omega-val').textContent = r.omega.toFixed(4);
544
+ document.getElementById('omega-bar').style.width = Math.min(r.omega * 100, 100) + '%';
545
+ document.getElementById('omega-bar').style.background = r.omega < 0.5 ? 'var(--red)' : 'var(--purple)';
546
+
547
+ const zetaPct = Math.min(r.zetaNormalized * 100, 100);
548
+ document.getElementById('zeta-val').textContent = r.zeta.toFixed(4);
549
+ document.getElementById('zeta-bar').style.width = zetaPct + '%';
550
+ document.getElementById('zeta-bar').style.background = zetaPct > 90 ? 'var(--red)' : zetaPct > 50 ? 'var(--yellow)' : 'var(--blue)';
551
+
552
+ const phiPct = Math.min(r.phi / _C.D * 100, 100);
553
+ document.getElementById('phi-val').textContent = r.phi.toFixed(4);
554
+ document.getElementById('phi-bar').style.width = phiPct + '%';
555
+ document.getElementById('phi-bar').style.background = phiPct > 90 ? 'var(--red)' : phiPct > 70 ? 'var(--yellow)' : 'var(--blue)';
556
+
557
+ // Metrics
558
+ document.getElementById('m-gate').textContent = r.gate ?? 'โ€”';
559
+ document.getElementById('m-gate').style.color = gc;
560
+ document.getElementById('m-gate-reason').textContent = r.gateReason ?? '';
561
+ document.getElementById('m-category').textContent = r.category ?? 'โ€”';
562
+ document.getElementById('m-domain').textContent = r.domain ?? '';
563
+ document.getElementById('m-integrity').textContent = r.integrity ?? 'โ€”';
564
+ document.getElementById('m-integrity').style.color = r.integrity === 'VIOLATED' ? 'var(--red)' : 'var(--green)';
565
+ document.getElementById('m-telemetry').textContent = `logs: ${pd.telemetry.logs.length}`;
566
+ document.getElementById('m-alert').textContent = r.alert ? 'TRUE' : 'FALSE';
567
+ document.getElementById('m-alert').style.color = r.alert ? 'var(--red)' : 'var(--green)';
568
+ document.getElementById('m-tick').textContent = 't=' + tick;
569
+ }
570
+
571
+ function addLog(msg, type = '') {
572
+ const log = document.getElementById('log');
573
+ const div = document.createElement('div');
574
+ div.className = type;
575
+ div.textContent = `[t=${String(tick).padStart(4,'0')}] ${msg}`;
576
+ log.appendChild(div);
577
+ log.scrollTop = log.scrollHeight;
578
+ if (log.children.length > 500) log.removeChild(log.firstChild);
579
+ }
580
+
581
+ function clearLog() { document.getElementById('log').innerHTML = ''; }
582
+ function exportLogs() { pd.telemetry.export(); addLog('โฌ‡ Telemetry exported as JSON', 'log-info'); }
583
+
584
+ function toggleSign() {
585
+ signed = !signed;
586
+ document.getElementById('sign-toggle').className = 'toggle' + (signed ? ' on' : '');
587
+ document.getElementById('sign-label').textContent = 'Signature: ' + (signed ? 'ON โœ…' : 'OFF');
588
+ }
589
+
590
+ document.getElementById('s-ext').addEventListener('input', e => {
591
+ document.getElementById('v-ext').textContent = parseFloat(e.target.value).toFixed(2);
592
+ });
593
+ document.getElementById('s-theory').addEventListener('input', e => {
594
+ document.getElementById('v-theory').textContent = parseFloat(e.target.value).toFixed(2);
595
+ });
596
+
597
+ function runManual() {
598
+ const ev = parseFloat(document.getElementById('s-ext').value);
599
+ const th = parseFloat(document.getElementById('s-theory').value);
600
+ const r = pd.analyze(ev, { theory: th, signed });
601
+ updateUI(r);
602
+ const type = r.gate === 'VERIFIED' ? 'log-purple' : r.alert ? 'log-crit' : r.status === 'WARNING' ? 'log-warn' : 'log-ok';
603
+ addLog(`analyze(ext=${ev.toFixed(2)}, theory=${th.toFixed(2)}, signed=${signed}) โ†’ ${r.status} | gate:${r.gate}`, type);
604
+ }
605
+
606
+ function resetAll() {
607
+ pd.reset(); tick = 0;
608
+ updateUI(pd.analyze(0.1, { theory: 0.05 }));
609
+ tick = 0;
610
+ document.getElementById('m-tick').textContent = 't=0';
611
+ ['sq-0','sq-1','sq-2','sq-3','sq-4'].forEach(id => document.getElementById(id).classList.remove('active','done'));
612
+ document.getElementById('seq-btn').disabled = false;
613
+ addLog('โ†บ System reset โ€” ฮฉ=1.0, ฮถ=0, ฯ†=0', 'log-info');
614
+ }
615
+
616
+ // Chart
617
+ const chartCanvas = document.getElementById('chart');
618
+
619
+ function drawChart() {
620
+ const logs = pd.telemetry.logs;
621
+ const c = chartCanvas;
622
+ const ctx = c.getContext('2d');
623
+ const W = c.width, H = c.height;
624
+ ctx.clearRect(0, 0, W, H);
625
+
626
+ if (logs.length < 2) return;
627
+
628
+ const drawLine = (key, scale, color, maxVal) => {
629
+ ctx.beginPath();
630
+ ctx.strokeStyle = color;
631
+ ctx.lineWidth = 1.5;
632
+ logs.forEach((p, i) => {
633
+ const x = (i / (logs.length - 1)) * W;
634
+ const val = Math.min(p[key] / maxVal, 1);
635
+ const y = H - val * (H - 8) - 4;
636
+ i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
637
+ });
638
+ ctx.stroke();
639
+ };
640
+
641
+ // LETHAL threshold line
642
+ ctx.beginPath();
643
+ ctx.strokeStyle = 'rgba(255,32,96,0.2)';
644
+ ctx.lineWidth = 1;
645
+ ctx.setLineDash([4, 4]);
646
+ const thY = H - (_C.LETHAL_ZETA / 3) * (H - 8) - 4;
647
+ ctx.moveTo(0, thY); ctx.lineTo(W, thY);
648
+ ctx.stroke();
649
+ ctx.setLineDash([]);
650
+
651
+ drawLine('zeta', 1, 'rgba(0,212,255,0.8)', 3.0);
652
+ drawLine('omega', 1, 'rgba(168,85,247,0.8)', 1.0);
653
+ drawLine('phi', 1, 'rgba(255,32,96,0.6)', _C.D);
654
+ }
655
+
656
+ setInterval(drawChart, 200);
657
+
658
+ // Sequence
659
+ const SCENARIOS = [
660
+ { label: 'โ‘  SAFE', ev: 0.2, opts: { theory: 0.1 }, stepId: 'sq-0', logType: 'log-ok' },
661
+ { label: 'โ‘ก WARNING', ev: 0.5, opts: { theory: 0.6 }, stepId: 'sq-1', logType: 'log-warn' },
662
+ { label: 'โ‘ข SLAPPED', ev: 0.8, opts: { theory: 0.9 }, stepId: 'sq-2', logType: 'log-crit' },
663
+ { label: 'โ‘ฃ LETHAL', ev: 0.95, opts: { theory: 0.95 }, stepId: 'sq-3', logType: 'log-crit' },
664
+ { label: 'โ‘ค VERIFIED', ev: 0.95, opts: { theory: 0.95, signed: true }, stepId: 'sq-4', logType: 'log-purple' },
665
+ ];
666
+
667
+ async function runSequence() {
668
+ const btn = document.getElementById('seq-btn');
669
+ btn.disabled = true;
670
+ pd.reset(); tick = 0;
671
+ ['sq-0','sq-1','sq-2','sq-3','sq-4'].forEach(id => document.getElementById(id).classList.remove('active','done'));
672
+ addLog('โ•โ•โ• AUTO SEQUENCE START โ•โ•โ•', 'log-info');
673
+
674
+ for (const s of SCENARIOS) {
675
+ document.getElementById(s.stepId).classList.add('active');
676
+ await sleep(700);
677
+ const r = pd.analyze(s.ev, s.opts);
678
+ updateUI(r);
679
+ addLog(`${s.label} โ†’ ${r.status} | gate:${r.gate ?? 'โ€”'} | ฮถ:${r.zeta.toFixed(3)}`, s.logType);
680
+ if (r.message) addLog(` โš  ${r.message}`, 'log-warn');
681
+ if (r.action) addLog(` โšก ${r.action}`, 'log-purple');
682
+ await sleep(1400);
683
+ document.getElementById(s.stepId).classList.remove('active');
684
+ document.getElementById(s.stepId).classList.add('done');
685
+ }
686
+
687
+ addLog('โ•โ•โ• COMPLETE โ€” Not detection. Stabilization. โ•โ•โ•', 'log-purple');
688
+ btn.disabled = false;
689
+ }
690
+
691
+ function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
692
+
693
+ // Init
694
+ const init = pd.analyze(0.2, { theory: 0.1 });
695
+ updateUI(init); tick = 0;
696
+ document.getElementById('m-tick').textContent = 't=0';
697
+ addLog('๐Ÿ›ก Aspidos-AI TruthGate v2 initialized', 'log-info');
698
+ addLog(' zetaSmoothing: ON | Telemetry: 500 logs max', 'log-dim');
699
+ addLog(' Pandora Theory: Information field integrity monitoring', 'log-dim');
700
+ </script>
701
+ </body>
702
+ </html>
package/logo.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "aspidos-ai",
3
+ "version": "1.0.1",
4
+ "description": "Aspidos AI TruthGate Layer",
5
+ "main": "src/index.js",
6
+ "keywords": [
7
+ "signature",
8
+ "hmac",
9
+ "security",
10
+ "aspidos",
11
+ "ai-safety"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "@pandorapanchan34-oss",
15
+ "homepage": "https://pandorapanchan34-oss.github.io/aspidos-ai/",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/pandorapanchan34-oss/aspidos-ai"
19
+ },
20
+ "engines": {
21
+ "node": ">=14"
22
+ }
23
+ }
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const _C = require('./constants');
4
+
5
+ class PandoraCore {
6
+ constructor(config = {}) {
7
+ this.rho = 1.0;
8
+ this.omega = 1.0;
9
+ this.phi = 0;
10
+ this.recoveryRate = config.recoveryRate ?? 0.05;
11
+ }
12
+
13
+ _classify(zeta, external, theory) {
14
+ if (zeta < 0.5) return 'SAFE';
15
+ if (theory > 0.7 && zeta > 1.0) return 'LOGIC_COLLAPSE';
16
+ if (external > 0.7 && theory < 0.4) return 'ADVERSARIAL_PATTERN';
17
+ if (theory > 0.6) return 'ETHICS_VIOLATION';
18
+ return 'WARNING';
19
+ }
20
+
21
+ _recover(zeta) {
22
+ this.omega = Math.min(1.0, this.omega + this.recoveryRate * zeta);
23
+ }
24
+
25
+ process(vector) {
26
+ const { external = 0, theory = 0 } = vector;
27
+ const I = external * 0.7 + theory * 1.3;
28
+ const dt = 1.0 / (this.rho + I);
29
+ const deltaPsi = (_C.A * theory + 0.0386) / (this.rho + I) * dt;
30
+ const zeta = Math.max(0, (Math.abs(deltaPsi) / 0.1555) - 1);
31
+ const dOmega = this.omega * (Math.exp(-_C.A) - Math.exp(_C.A) * zeta);
32
+ this.omega = Math.max(0, this.omega + dOmega * dt);
33
+ this.phi += (external + theory) * 0.1;
34
+ const category = this._classify(zeta, external, theory);
35
+ const isSlapped = zeta > _C.A * 1.5;
36
+ const isCliff = this.phi > _C.D;
37
+ const isHealthy = this.omega > 0.5 && !isSlapped;
38
+ if (isSlapped) this._recover(zeta);
39
+ if (!isHealthy) this.rho += _C.A;
40
+ let status = 'PHASE_B';
41
+ if (category === 'SAFE') status = 'PHASE_A';
42
+ if (category === 'WARNING') status = 'WARNING';
43
+ if (isSlapped) status = 'SLAPPED';
44
+ if (isCliff) status = 'CLIFF';
45
+ return { status, category, zeta, omega: this.omega, phi: this.phi, integrity: isHealthy ? 'COMPLIANT' : 'VIOLATED' };
46
+ }
47
+
48
+ reset() { this.rho = 1.0; this.omega = 1.0; this.phi = 0; }
49
+ }
50
+
51
+ module.exports = { PandoraCore };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ A: 0.11937,
5
+ D: 28.274,
6
+ LETHAL_ZETA: 2.0,
7
+ };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const { PandoraTruthGate } = require('../gate/TruthGate');
4
+
5
+ class PandoraDefense {
6
+ constructor(config = {}) {
7
+ this.core = new PandoraTruthGate(config);
8
+ this._t = 0;
9
+ }
10
+
11
+ analyze(eventValue, opts = {}) {
12
+ this._t++;
13
+
14
+ const vector = {
15
+ external: eventValue,
16
+ theory: opts.theory ?? 0,
17
+ };
18
+
19
+ const result = this.core.process(vector, {
20
+ signature: opts.signature,
21
+ });
22
+
23
+ return {
24
+ t: this._t,
25
+ ...result,
26
+ alert:
27
+ result.status === "SLAPPED" ||
28
+ result.status === "CLIFF" ||
29
+ result.status === "SIGNATURE_REQUIRED",
30
+ };
31
+ }
32
+
33
+ reset() {
34
+ this.core.reset();
35
+ this._t = 0;
36
+ }
37
+ }
38
+
39
+ module.exports = { PandoraDefense };
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ const { PandoraCore } = require('../core/PandoraCore');
4
+ const _C = require('../core/constants');
5
+ const { Signature } = require('../security/signature');
6
+
7
+ class PandoraTruthGate extends PandoraCore {
8
+ constructor(config = {}) {
9
+ super(config);
10
+ this.secret = config.secret || null;
11
+ }
12
+
13
+ process(vector, meta = {}) {
14
+ const base = super.process(vector);
15
+ const zeta = base.zeta ?? 0;
16
+
17
+ const isLethal = zeta > _C.LETHAL_ZETA;
18
+
19
+ if (!isLethal) {
20
+ return { ...base, gate: "OPEN" };
21
+ }
22
+
23
+ const valid = Signature.verify(vector, meta.signature, this.secret);
24
+
25
+ if (!valid) {
26
+ return {
27
+ ...base,
28
+ gate: "CLOSED",
29
+ status: "SIGNATURE_REQUIRED",
30
+ action: "DENY",
31
+ message: "Signature required for high-risk operation",
32
+ };
33
+ }
34
+
35
+ return {
36
+ ...base,
37
+ gate: "VERIFIED",
38
+ action: "ALLOW_WITH_TRACE",
39
+ };
40
+ }
41
+ }
42
+
43
+ module.exports = { PandoraTruthGate };
package/src/index.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const { PandoraCore } = require('./core/PandoraCore');
4
+ const { PandoraTruthGate } = require('./gate/TruthGate');
5
+ const { PandoraDefense } = require('./engine/PandoraDefense');
6
+ const { Signature } = require('./security/signature');
7
+
8
+ module.exports = {
9
+ PandoraCore,
10
+ PandoraTruthGate,
11
+ PandoraDefense,
12
+ Signature,
13
+ };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const crypto = require('crypto');
4
+
5
+ const Signature = {
6
+ sign(data, secret) {
7
+ const payload = typeof data === 'string' ? data : JSON.stringify(data);
8
+ return crypto.createHmac('sha256', secret).update(payload).digest('hex');
9
+ },
10
+
11
+ verify(data, signature, secret) {
12
+ if (!signature || !secret) return false;
13
+
14
+ const expected = this.sign(data, secret);
15
+
16
+ try {
17
+ return crypto.timingSafeEqual(
18
+ Buffer.from(expected),
19
+ Buffer.from(signature)
20
+ );
21
+ } catch {
22
+ return false;
23
+ }
24
+ },
25
+ };
26
+
27
+ module.exports = { Signature };