@stackbilt/aegis-core 0.1.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/package.json +96 -0
- package/schema.sql +586 -0
- package/src/adapters/voice/cloudflare-agent.ts +34 -0
- package/src/auth.ts +124 -0
- package/src/bluesky.ts +464 -0
- package/src/claude-tools/content.ts +188 -0
- package/src/claude-tools/email.ts +69 -0
- package/src/claude-tools/github.ts +440 -0
- package/src/claude-tools/goals.ts +116 -0
- package/src/claude-tools/index.ts +353 -0
- package/src/claude-tools/web.ts +59 -0
- package/src/claude.ts +406 -0
- package/src/codebeast.ts +200 -0
- package/src/composite.ts +715 -0
- package/src/content/column.ts +80 -0
- package/src/content/hero-image.ts +47 -0
- package/src/content/index.ts +27 -0
- package/src/content/journal.ts +91 -0
- package/src/content/roundtable.ts +163 -0
- package/src/core.ts +309 -0
- package/src/dashboard.ts +620 -0
- package/src/decision-docs.ts +284 -0
- package/src/dispatch.ts +13 -0
- package/src/edge-env.ts +58 -0
- package/src/email.ts +850 -0
- package/src/exports.ts +156 -0
- package/src/github-projects.ts +312 -0
- package/src/github.ts +670 -0
- package/src/groq.ts +247 -0
- package/src/health-page.ts +578 -0
- package/src/index.ts +89 -0
- package/src/kernel/argus-actions.ts +397 -0
- package/src/kernel/argus-correlation.ts +639 -0
- package/src/kernel/board.ts +91 -0
- package/src/kernel/briefing.ts +177 -0
- package/src/kernel/classify-memory-topic.ts +166 -0
- package/src/kernel/cognition.ts +377 -0
- package/src/kernel/court-cards.ts +163 -0
- package/src/kernel/dispatch.ts +587 -0
- package/src/kernel/domain.ts +50 -0
- package/src/kernel/dynamic-tools.ts +322 -0
- package/src/kernel/executor-port.ts +45 -0
- package/src/kernel/executors/claude.ts +73 -0
- package/src/kernel/executors/direct.ts +237 -0
- package/src/kernel/executors/groq.ts +18 -0
- package/src/kernel/executors/index.ts +87 -0
- package/src/kernel/executors/tarotscript.ts +104 -0
- package/src/kernel/executors/workers-ai.ts +54 -0
- package/src/kernel/insight-cache.ts +76 -0
- package/src/kernel/memory/agenda.ts +200 -0
- package/src/kernel/memory/blocks.ts +188 -0
- package/src/kernel/memory/consolidation.ts +194 -0
- package/src/kernel/memory/episodic.ts +241 -0
- package/src/kernel/memory/goals.ts +156 -0
- package/src/kernel/memory/graph.ts +290 -0
- package/src/kernel/memory/index.ts +11 -0
- package/src/kernel/memory/insights.ts +316 -0
- package/src/kernel/memory/procedural.ts +467 -0
- package/src/kernel/memory/pruning.ts +67 -0
- package/src/kernel/memory/recall.ts +367 -0
- package/src/kernel/memory/semantic.ts +315 -0
- package/src/kernel/memory/synthesis.ts +161 -0
- package/src/kernel/memory-adapter.ts +369 -0
- package/src/kernel/memory-guardrails.ts +76 -0
- package/src/kernel/port.ts +23 -0
- package/src/kernel/resilience.ts +322 -0
- package/src/kernel/router.ts +471 -0
- package/src/kernel/scheduled/agent-dispatch.ts +252 -0
- package/src/kernel/scheduled/argus-analytics.ts +247 -0
- package/src/kernel/scheduled/argus-heartbeat.ts +320 -0
- package/src/kernel/scheduled/argus-notify.ts +348 -0
- package/src/kernel/scheduled/board-sync.ts +110 -0
- package/src/kernel/scheduled/ci-watcher.ts +125 -0
- package/src/kernel/scheduled/cognitive-metrics.ts +377 -0
- package/src/kernel/scheduled/consolidation.ts +229 -0
- package/src/kernel/scheduled/content-drip.ts +47 -0
- package/src/kernel/scheduled/content.ts +6 -0
- package/src/kernel/scheduled/conversation-facts.ts +204 -0
- package/src/kernel/scheduled/cost-report.ts +84 -0
- package/src/kernel/scheduled/curiosity.ts +219 -0
- package/src/kernel/scheduled/dev-activity.ts +44 -0
- package/src/kernel/scheduled/digest.ts +317 -0
- package/src/kernel/scheduled/dreaming/agenda-triage.ts +115 -0
- package/src/kernel/scheduled/dreaming/facts.ts +239 -0
- package/src/kernel/scheduled/dreaming/index.ts +8 -0
- package/src/kernel/scheduled/dreaming/llm.ts +33 -0
- package/src/kernel/scheduled/dreaming/pattern-synthesis.ts +124 -0
- package/src/kernel/scheduled/dreaming/persona.ts +75 -0
- package/src/kernel/scheduled/dreaming/symbolic.ts +31 -0
- package/src/kernel/scheduled/dreaming/task-proposals.ts +80 -0
- package/src/kernel/scheduled/dreaming.ts +66 -0
- package/src/kernel/scheduled/entropy.ts +149 -0
- package/src/kernel/scheduled/escalation.ts +192 -0
- package/src/kernel/scheduled/feed-watcher.ts +206 -0
- package/src/kernel/scheduled/goals.ts +214 -0
- package/src/kernel/scheduled/governance.ts +41 -0
- package/src/kernel/scheduled/heartbeat.ts +220 -0
- package/src/kernel/scheduled/inbox-processor.ts +174 -0
- package/src/kernel/scheduled/index.ts +245 -0
- package/src/kernel/scheduled/issue-proposer.ts +478 -0
- package/src/kernel/scheduled/issue-watcher.ts +128 -0
- package/src/kernel/scheduled/pr-automerge.ts +213 -0
- package/src/kernel/scheduled/product-health.ts +107 -0
- package/src/kernel/scheduled/reflection.ts +373 -0
- package/src/kernel/scheduled/self-improvement.ts +114 -0
- package/src/kernel/scheduled/social-engage.ts +175 -0
- package/src/kernel/scheduled/task-audit.ts +60 -0
- package/src/kernel/symbolic.ts +156 -0
- package/src/kernel/types.ts +145 -0
- package/src/landing.ts +1190 -0
- package/src/lib/audit-chain/chain.ts +28 -0
- package/src/lib/audit-chain/types.ts +12 -0
- package/src/lib/observability/errors.ts +55 -0
- package/src/markdown.ts +164 -0
- package/src/mcp/handlers.ts +647 -0
- package/src/mcp/server.ts +184 -0
- package/src/mcp/tools.ts +316 -0
- package/src/mcp-client.ts +275 -0
- package/src/mcp-server.ts +2 -0
- package/src/operator/config.example.ts +60 -0
- package/src/operator/config.ts +60 -0
- package/src/operator/index.ts +46 -0
- package/src/operator/persona.example.ts +34 -0
- package/src/operator/persona.ts +34 -0
- package/src/operator/prompt-builder.ts +190 -0
- package/src/operator/types.ts +43 -0
- package/src/pulse.ts +1179 -0
- package/src/routes/bluesky.ts +116 -0
- package/src/routes/cc-tasks.ts +328 -0
- package/src/routes/codebeast.ts +1 -0
- package/src/routes/content.ts +194 -0
- package/src/routes/conversations.ts +25 -0
- package/src/routes/dynamic-tools.ts +111 -0
- package/src/routes/feedback.ts +192 -0
- package/src/routes/health.ts +147 -0
- package/src/routes/messages.ts +228 -0
- package/src/routes/observability.ts +82 -0
- package/src/routes/operator-logs.ts +42 -0
- package/src/routes/pages.ts +96 -0
- package/src/routes/sessions.ts +54 -0
- package/src/sanitize.ts +73 -0
- package/src/schema-enums.ts +155 -0
- package/src/search.ts +112 -0
- package/src/task-intelligence.ts +497 -0
- package/src/types.ts +194 -0
- package/src/ui.ts +5 -0
- package/src/version.ts +3 -0
- package/src/workers-ai-chat.ts +333 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core hash chain logic.
|
|
3
|
+
*
|
|
4
|
+
* SHA-256(prev_hash_bytes + record_bytes) forms the chain link.
|
|
5
|
+
* Uses the Web Crypto API -- zero external dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compute a SHA-256 chain link.
|
|
10
|
+
*
|
|
11
|
+
* Concatenates the UTF-8 bytes of `prevHash` with `recordBytes`,
|
|
12
|
+
* then returns the hex-encoded SHA-256 digest.
|
|
13
|
+
*/
|
|
14
|
+
export async function computeHash(
|
|
15
|
+
prevHash: string,
|
|
16
|
+
recordBytes: Uint8Array
|
|
17
|
+
): Promise<string> {
|
|
18
|
+
const encoder = new TextEncoder();
|
|
19
|
+
const prevBytes = encoder.encode(prevHash);
|
|
20
|
+
|
|
21
|
+
const combined = new Uint8Array(prevBytes.length + recordBytes.length);
|
|
22
|
+
combined.set(prevBytes, 0);
|
|
23
|
+
combined.set(recordBytes, prevBytes.length);
|
|
24
|
+
|
|
25
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', combined);
|
|
26
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
27
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* audit-chain type definitions.
|
|
3
|
+
*
|
|
4
|
+
* Generic, domain-agnostic types for tamper-evident audit logging.
|
|
5
|
+
* D1-only mode (no R2). Hash chain provides tamper evidence.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Chain genesis sentinel -- 64 hex zeros.
|
|
10
|
+
* The first record in any chain uses this as its prev_hash.
|
|
11
|
+
*/
|
|
12
|
+
export const GENESIS_HASH = '0'.repeat(64);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// In-memory error tracker for per-cron-run error aggregation.
|
|
2
|
+
// Deduplicates errors by type and tracks occurrence counts.
|
|
3
|
+
|
|
4
|
+
interface ErrorDetails {
|
|
5
|
+
name: string;
|
|
6
|
+
message: string;
|
|
7
|
+
stack?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface TrackedError {
|
|
11
|
+
id: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
error: ErrorDetails;
|
|
14
|
+
occurrences: number;
|
|
15
|
+
firstSeen: number;
|
|
16
|
+
lastSeen: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ErrorStats {
|
|
20
|
+
total: number;
|
|
21
|
+
unique: number;
|
|
22
|
+
byType: Record<string, number>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class InMemoryErrorTracker {
|
|
26
|
+
private errors: Map<string, TrackedError> = new Map();
|
|
27
|
+
|
|
28
|
+
track(error: Error): void {
|
|
29
|
+
const errorId = `${error.name}:${error.message.slice(0, 100)}`;
|
|
30
|
+
const existing = this.errors.get(errorId);
|
|
31
|
+
if (existing) {
|
|
32
|
+
existing.occurrences++;
|
|
33
|
+
existing.lastSeen = Date.now();
|
|
34
|
+
} else {
|
|
35
|
+
this.errors.set(errorId, {
|
|
36
|
+
id: errorId,
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
error: { name: error.name, message: error.message, stack: error.stack },
|
|
39
|
+
occurrences: 1,
|
|
40
|
+
firstSeen: Date.now(),
|
|
41
|
+
lastSeen: Date.now(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getErrorStats(): ErrorStats {
|
|
47
|
+
const byType: Record<string, number> = {};
|
|
48
|
+
let total = 0;
|
|
49
|
+
for (const tracked of this.errors.values()) {
|
|
50
|
+
total += tracked.occurrences;
|
|
51
|
+
byType[tracked.error.name] = (byType[tracked.error.name] ?? 0) + tracked.occurrences;
|
|
52
|
+
}
|
|
53
|
+
return { total, unique: this.errors.size, byType };
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/markdown.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side markdown renderer — pure functions (no DOM access).
|
|
3
|
+
* Extracted from ui.ts as part of Operation Atheist (#127).
|
|
4
|
+
*
|
|
5
|
+
* Returns JS source code for embedding in the chat page <script> tag.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function markdownRendererScript(): string {
|
|
9
|
+
return `
|
|
10
|
+
// ── Markdown renderer (pure — no DOM access) ─────
|
|
11
|
+
function escapeHtml(s) {
|
|
12
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function renderMarkdown(text) {
|
|
16
|
+
// Phase 1: Extract fenced code blocks to protect them from markdown processing
|
|
17
|
+
const codeBlocks = [];
|
|
18
|
+
let processed = text.replace(/\`\`\`(\\w*)\\n([\\s\\S]*?)\`\`\`/g, function(_, lang, code) {
|
|
19
|
+
const idx = codeBlocks.length;
|
|
20
|
+
codeBlocks.push('<pre><code' + (lang ? ' data-lang="' + lang + '"' : '') + '>' + escapeHtml(code.trim()) + '</code></pre>');
|
|
21
|
+
return '\\x00CODEBLOCK' + idx + '\\x00';
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Phase 2: Split into lines and process block elements
|
|
25
|
+
const lines = processed.split('\\n');
|
|
26
|
+
const output = [];
|
|
27
|
+
let i = 0;
|
|
28
|
+
|
|
29
|
+
while (i < lines.length) {
|
|
30
|
+
const line = lines[i];
|
|
31
|
+
|
|
32
|
+
// Code block placeholder
|
|
33
|
+
const cbMatch = line.match(/^\\x00CODEBLOCK(\\d+)\\x00$/);
|
|
34
|
+
if (cbMatch) {
|
|
35
|
+
output.push(codeBlocks[parseInt(cbMatch[1])]);
|
|
36
|
+
i++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Table: detect header row + separator row
|
|
41
|
+
if (i + 1 < lines.length && lines[i + 1].match(/^\\s*\\|?[\\s:]*-{2,}[\\s:]*(?:\\|[\\s:]*-{2,}[\\s:]*)*\\|?\\s*$/)) {
|
|
42
|
+
const tableLines = [];
|
|
43
|
+
tableLines.push(line);
|
|
44
|
+
i++; // skip separator
|
|
45
|
+
i++; // move past separator
|
|
46
|
+
while (i < lines.length && lines[i].includes('|') && lines[i].trim() !== '') {
|
|
47
|
+
tableLines.push(lines[i]);
|
|
48
|
+
i++;
|
|
49
|
+
}
|
|
50
|
+
output.push(renderTable(tableLines));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Horizontal rule
|
|
55
|
+
if (line.match(/^\\s*(-{3,}|\\*{3,}|_{3,})\\s*$/)) {
|
|
56
|
+
output.push('<hr>');
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Headers
|
|
62
|
+
const hMatch = line.match(/^(#{1,4})\\s+(.+)$/);
|
|
63
|
+
if (hMatch) {
|
|
64
|
+
const level = hMatch[1].length;
|
|
65
|
+
output.push('<h' + level + '>' + renderInline(hMatch[2]) + '</h' + level + '>');
|
|
66
|
+
i++;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Unordered list
|
|
71
|
+
if (line.match(/^\\s*[-*+]\\s+/)) {
|
|
72
|
+
const listItems = [];
|
|
73
|
+
while (i < lines.length && lines[i].match(/^\\s*[-*+]\\s+/)) {
|
|
74
|
+
listItems.push(lines[i].replace(/^\\s*[-*+]\\s+/, ''));
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
output.push('<ul>' + listItems.map(li => '<li>' + renderInline(li) + '</li>').join('') + '</ul>');
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Ordered list
|
|
82
|
+
if (line.match(/^\\s*\\d+[.)\\s]\\s*/)) {
|
|
83
|
+
const listItems = [];
|
|
84
|
+
while (i < lines.length && lines[i].match(/^\\s*\\d+[.)\\s]\\s*/)) {
|
|
85
|
+
listItems.push(lines[i].replace(/^\\s*\\d+[.)\\s]\\s*/, ''));
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
output.push('<ol>' + listItems.map(li => '<li>' + renderInline(li) + '</li>').join('') + '</ol>');
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Blockquote
|
|
93
|
+
if (line.match(/^>\\s?/)) {
|
|
94
|
+
const quoteLines = [];
|
|
95
|
+
while (i < lines.length && lines[i].match(/^>\\s?/)) {
|
|
96
|
+
quoteLines.push(lines[i].replace(/^>\\s?/, ''));
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
output.push('<blockquote>' + renderInline(quoteLines.join('<br>')) + '</blockquote>');
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Empty line
|
|
104
|
+
if (line.trim() === '') {
|
|
105
|
+
output.push('<br>');
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Regular paragraph line
|
|
111
|
+
output.push(renderInline(line) + '<br>');
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return output.join('');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Render inline markdown (bold, italic, code, links, strikethrough)
|
|
119
|
+
function renderInline(text) {
|
|
120
|
+
let html = escapeHtml(text);
|
|
121
|
+
|
|
122
|
+
// Inline code (before other transforms to protect code content)
|
|
123
|
+
html = html.replace(/\`([^\`]+)\`/g, '<code>$1</code>');
|
|
124
|
+
|
|
125
|
+
// Bold + italic: ***text***
|
|
126
|
+
html = html.replace(/\\*\\*\\*(.+?)\\*\\*\\*/g, '<strong><em>$1</em></strong>');
|
|
127
|
+
|
|
128
|
+
// Bold: **text**
|
|
129
|
+
html = html.replace(/\\*\\*(.+?)\\*\\*/g, '<strong>$1</strong>');
|
|
130
|
+
|
|
131
|
+
// Italic: *text*
|
|
132
|
+
html = html.replace(/(?<![\\w*])\\*([^*]+?)\\*(?![\\w*])/g, '<em>$1</em>');
|
|
133
|
+
|
|
134
|
+
// Strikethrough: ~~text~~
|
|
135
|
+
html = html.replace(/~~(.+?)~~/g, '<del>$1</del>');
|
|
136
|
+
|
|
137
|
+
// Links: [text](url)
|
|
138
|
+
html = html.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href="$2" target="_blank" rel="noopener">$1</a>');
|
|
139
|
+
|
|
140
|
+
// Auto-link bare URLs (but not inside href attributes)
|
|
141
|
+
html = html.replace(/(?<!href="|">)(https?:\\/\\/[^\\s<]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>');
|
|
142
|
+
|
|
143
|
+
return html;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Render a markdown table (first row = header, rest = body)
|
|
147
|
+
function renderTable(rows) {
|
|
148
|
+
if (rows.length === 0) return '';
|
|
149
|
+
const parseRow = (row) => row.replace(/^\\s*\\|/, '').replace(/\\|\\s*$/, '').split('|').map(c => c.trim());
|
|
150
|
+
const headers = parseRow(rows[0]);
|
|
151
|
+
const bodyRows = rows.slice(1).map(parseRow);
|
|
152
|
+
|
|
153
|
+
let html = '<table><thead><tr>';
|
|
154
|
+
headers.forEach(h => { html += '<th>' + renderInline(h) + '</th>'; });
|
|
155
|
+
html += '</tr></thead><tbody>';
|
|
156
|
+
bodyRows.forEach(row => {
|
|
157
|
+
html += '<tr>';
|
|
158
|
+
row.forEach((cell, ci) => { html += '<td>' + renderInline(cell || '') + '</td>'; });
|
|
159
|
+
html += '</tr>';
|
|
160
|
+
});
|
|
161
|
+
html += '</tbody></table>';
|
|
162
|
+
return html;
|
|
163
|
+
}`;
|
|
164
|
+
}
|