scalix 0.0.1 → 1.0.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +122 -0
  2. package/LICENSE +100 -0
  3. package/README.md +300 -2
  4. package/app.py +55 -0
  5. package/bin/scalix.js +19 -0
  6. package/dist/agent-replay.js +166 -0
  7. package/dist/agent.js +852 -0
  8. package/dist/auto-verify.js +136 -0
  9. package/dist/change-tracker.js +53 -0
  10. package/dist/cli.js +2329 -0
  11. package/dist/commands.js +71 -0
  12. package/dist/config.js +16 -0
  13. package/dist/constants.js +324 -0
  14. package/dist/context-builder.js +151 -0
  15. package/dist/context-manager.js +148 -0
  16. package/dist/cost-tracker.js +85 -0
  17. package/dist/diff.js +140 -0
  18. package/dist/git-context.js +180 -0
  19. package/dist/git-undo.js +67 -0
  20. package/dist/headless.js +654 -0
  21. package/dist/hooks.js +94 -0
  22. package/dist/ipc-server.js +228 -0
  23. package/dist/logger.js +45 -0
  24. package/dist/markdown.js +41 -0
  25. package/dist/mcp.js +49 -0
  26. package/dist/model-router.js +68 -0
  27. package/dist/plugins.js +132 -0
  28. package/dist/project-index.js +374 -0
  29. package/dist/project-memory.js +165 -0
  30. package/dist/safe-math.js +194 -0
  31. package/dist/sandbox.js +279 -0
  32. package/dist/scoped-rules.js +82 -0
  33. package/dist/sessions.js +71 -0
  34. package/dist/settings.js +155 -0
  35. package/dist/sub-agent.js +79 -0
  36. package/dist/token-counter.js +47 -0
  37. package/dist/tool-helper.js +97 -0
  38. package/dist/tool-selector.js +77 -0
  39. package/dist/tools-advanced.js +232 -0
  40. package/dist/tools-browser.js +273 -0
  41. package/dist/tools-extra.js +383 -0
  42. package/dist/tools-vision.js +115 -0
  43. package/dist/tools-voice.js +147 -0
  44. package/dist/tools-web.js +346 -0
  45. package/dist/tools.js +370 -0
  46. package/dist/types.js +1 -0
  47. package/docs/DISTRIBUTION.md +301 -0
  48. package/package.json +67 -6
@@ -0,0 +1,166 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { USER_CONFIG_DIR } from './constants.js';
4
+ const REPLAYS_DIR = path.join(process.env.HOME || process.env.USERPROFILE || '.', USER_CONFIG_DIR, 'replays');
5
+ export class AgentReplay {
6
+ session;
7
+ stepCounter = 0;
8
+ startTime;
9
+ recording = true;
10
+ constructor(sessionId, model) {
11
+ this.startTime = Date.now();
12
+ this.session = {
13
+ id: sessionId,
14
+ model,
15
+ startedAt: new Date().toISOString(),
16
+ steps: [],
17
+ totalTokens: 0,
18
+ totalCost: 0,
19
+ forkPoints: [],
20
+ };
21
+ }
22
+ record(kind, data = {}) {
23
+ if (!this.recording)
24
+ return { id: -1, kind, timestamp: 0, elapsed: 0, data };
25
+ const step = {
26
+ id: this.stepCounter++,
27
+ kind,
28
+ timestamp: Date.now(),
29
+ elapsed: Date.now() - this.startTime,
30
+ data,
31
+ };
32
+ this.session.steps.push(step);
33
+ if (kind === 'user_message') {
34
+ this.session.forkPoints.push(step.id);
35
+ }
36
+ return step;
37
+ }
38
+ recordUsage(tokens, cost) {
39
+ this.session.totalTokens += tokens;
40
+ this.session.totalCost += cost;
41
+ }
42
+ pause() {
43
+ this.recording = false;
44
+ }
45
+ resume() {
46
+ this.recording = true;
47
+ }
48
+ getSteps() {
49
+ return [...this.session.steps];
50
+ }
51
+ getStepsSince(stepId) {
52
+ const idx = this.session.steps.findIndex((s) => s.id === stepId);
53
+ if (idx === -1)
54
+ return [];
55
+ return this.session.steps.slice(idx);
56
+ }
57
+ getForkPoints() {
58
+ return this.session.forkPoints.map((id) => {
59
+ const step = this.session.steps.find((s) => s.id === id);
60
+ return {
61
+ stepId: id,
62
+ message: step?.data?.content || '(unknown)',
63
+ };
64
+ });
65
+ }
66
+ getTimeline() {
67
+ const lines = [];
68
+ let toolCallCount = 0;
69
+ for (const step of this.session.steps) {
70
+ const time = formatElapsed(step.elapsed);
71
+ switch (step.kind) {
72
+ case 'user_message':
73
+ lines.push(`\n[${time}] YOU: ${truncate(step.data.content, 60)}`);
74
+ toolCallCount = 0;
75
+ break;
76
+ case 'thinking_start':
77
+ lines.push(`[${time}] Thinking...`);
78
+ break;
79
+ case 'thinking_end':
80
+ lines.push(`[${time}] Done thinking`);
81
+ break;
82
+ case 'stream_end':
83
+ lines.push(`[${time}] AI: ${truncate(step.data.text, 80)}`);
84
+ break;
85
+ case 'tool_call':
86
+ toolCallCount++;
87
+ lines.push(`[${time}] Tool #${toolCallCount}: ${step.data.name} → ${truncate(JSON.stringify(step.data.args), 50)}`);
88
+ break;
89
+ case 'tool_result':
90
+ lines.push(`[${time}] Result: ${truncate(step.data.result, 60)}`);
91
+ break;
92
+ case 'tool_blocked':
93
+ lines.push(`[${time}] BLOCKED: ${step.data.reason}`);
94
+ break;
95
+ case 'error':
96
+ lines.push(`[${time}] ERROR: ${step.data.message}`);
97
+ break;
98
+ case 'context_compress':
99
+ lines.push(`[${time}] Context compressed (${step.data.saved} tokens saved)`);
100
+ break;
101
+ case 'model_switch':
102
+ lines.push(`[${time}] Model: ${step.data.from} → ${step.data.to}`);
103
+ break;
104
+ }
105
+ }
106
+ lines.push('');
107
+ lines.push(`Total: ${this.session.steps.length} steps, ${this.session.totalTokens.toLocaleString()} tokens`);
108
+ return lines.join('\n');
109
+ }
110
+ async save() {
111
+ await fs.mkdir(REPLAYS_DIR, { recursive: true });
112
+ const filePath = path.join(REPLAYS_DIR, `${this.session.id}.json`);
113
+ await fs.writeFile(filePath, JSON.stringify(this.session, null, 2), 'utf-8');
114
+ return filePath;
115
+ }
116
+ static async load(sessionId) {
117
+ const filePath = path.join(REPLAYS_DIR, `${sessionId}.json`);
118
+ const raw = await fs.readFile(filePath, 'utf-8');
119
+ const data = JSON.parse(raw);
120
+ const replay = new AgentReplay(data.id, data.model);
121
+ replay.session = data;
122
+ replay.stepCounter = data.steps.length;
123
+ replay.recording = false;
124
+ return replay;
125
+ }
126
+ static async listReplays() {
127
+ try {
128
+ await fs.mkdir(REPLAYS_DIR, { recursive: true });
129
+ const files = await fs.readdir(REPLAYS_DIR);
130
+ const replays = [];
131
+ for (const file of files) {
132
+ if (!file.endsWith('.json'))
133
+ continue;
134
+ try {
135
+ const raw = await fs.readFile(path.join(REPLAYS_DIR, file), 'utf-8');
136
+ const data = JSON.parse(raw);
137
+ replays.push({
138
+ id: data.id,
139
+ model: data.model,
140
+ date: data.startedAt,
141
+ steps: data.steps.length,
142
+ });
143
+ }
144
+ catch {
145
+ console.error(`Warning: corrupted replay file skipped: ${file}`);
146
+ }
147
+ }
148
+ return replays.sort((a, b) => b.date.localeCompare(a.date));
149
+ }
150
+ catch {
151
+ return [];
152
+ }
153
+ }
154
+ }
155
+ function formatElapsed(ms) {
156
+ const seconds = Math.floor(ms / 1000);
157
+ const minutes = Math.floor(seconds / 60);
158
+ const s = seconds % 60;
159
+ return minutes > 0 ? `${minutes}m${s.toString().padStart(2, '0')}s` : `${s}s`;
160
+ }
161
+ function truncate(s, max) {
162
+ if (!s)
163
+ return '';
164
+ const clean = s.replace(/\n/g, ' ').trim();
165
+ return clean.length > max ? clean.slice(0, max - 1) + '\u2026' : clean;
166
+ }