mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 06:36:49 +09:00
🔖 Checkpoint: Edit /workspaces/claude-code-flow/src/cli/simple-commands/train-and-stream.js
This commit is contained in:
1 parent
ccd8a31281
commit
fbc78e5f77
31 files changed
+26373
No files matched your search
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "conservative",
|
||||
"executionTime": 1870,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.519999999999996,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:32.104Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "balanced",
|
||||
"executionTime": 1888,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.448,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:33.992Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "aggressive",
|
||||
"executionTime": 1688,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 43.248,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:35.680Z"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "conservative",
|
||||
"executionTime": 1938,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.248000000000005,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:41.318Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "balanced",
|
||||
"executionTime": 1872,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.512,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:43.190Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "aggressive",
|
||||
"executionTime": 1687,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 43.252,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:44.877Z"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "conservative",
|
||||
"executionTime": 1942,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.232,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:50.348Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "balanced",
|
||||
"executionTime": 1810,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.76,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:52.158Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "aggressive",
|
||||
"executionTime": 1656,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 43.376000000000005,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:53.814Z"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "conservative",
|
||||
"executionTime": 1887,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.452,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:23:59.331Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "balanced",
|
||||
"executionTime": 1947,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.212,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:24:01.278Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "aggressive",
|
||||
"executionTime": 1665,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 43.34,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:24:02.943Z"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,65 @@
|
||||
[
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "conservative",
|
||||
"executionTime": 1922,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.312,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:24:08.406Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "balanced",
|
||||
"executionTime": 1889,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 42.444,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:24:10.295Z"
|
||||
},
|
||||
{
|
||||
"task": "Implement efficient sorting",
|
||||
"type": "algorithm",
|
||||
"strategy": "aggressive",
|
||||
"executionTime": 1675,
|
||||
"successRate": 0.5,
|
||||
"checks": {
|
||||
"test": {
|
||||
"passed": true,
|
||||
"score": 1,
|
||||
"output": "\n> sortAlgorithm@1.0.0 test\n> jest --silent\n\n"
|
||||
},
|
||||
"lint": {
|
||||
"passed": false,
|
||||
"score": 0.5
|
||||
}
|
||||
},
|
||||
"score": 43.3,
|
||||
"real": true,
|
||||
"timestamp": "2025-08-12T17:24:11.970Z"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
const users = [];
|
||||
|
||||
app.get('/users', (req, res) => {
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
app.post('/users', (req, res) => {
|
||||
const { name, email } = req.body;
|
||||
if (!name || !email) {
|
||||
return res.status(400).json({ error: 'Name and email required' });
|
||||
}
|
||||
const user = { id: users.length + 1, name, email };
|
||||
users.push(user);
|
||||
res.status(201).json(user);
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
const request = require('supertest');
|
||||
const app = require('./index');
|
||||
|
||||
describe('User API', () => {
|
||||
test('GET /users returns empty array initially', async () => {
|
||||
const res = await request(app).get('/users');
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual([]);
|
||||
});
|
||||
|
||||
test('POST /users creates a user', async () => {
|
||||
const res = await request(app)
|
||||
.post('/users')
|
||||
.send({ name: 'Test', email: 'test@test.com' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.name).toBe('Test');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "userApi",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.18.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
function quickSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const pivot = arr[Math.floor(arr.length / 2)];
|
||||
const left = arr.filter(x => x < pivot);
|
||||
const middle = arr.filter(x => x === pivot);
|
||||
const right = arr.filter(x => x > pivot);
|
||||
|
||||
return [...quickSort(left), ...middle, ...quickSort(right)];
|
||||
}
|
||||
|
||||
function mergeSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const mid = Math.floor(arr.length / 2);
|
||||
const left = mergeSort(arr.slice(0, mid));
|
||||
const right = mergeSort(arr.slice(mid));
|
||||
|
||||
const result = [];
|
||||
let i = 0, j = 0;
|
||||
|
||||
while (i < left.length && j < right.length) {
|
||||
if (left[i] < right[j]) {
|
||||
result.push(left[i++]);
|
||||
} else {
|
||||
result.push(right[j++]);
|
||||
}
|
||||
}
|
||||
|
||||
return result.concat(left.slice(i)).concat(right.slice(j));
|
||||
}
|
||||
|
||||
module.exports = { quickSort, mergeSort };
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
const { quickSort, mergeSort } = require('./index');
|
||||
|
||||
describe('Sorting Algorithms', () => {
|
||||
const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
|
||||
const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
|
||||
|
||||
test('quickSort sorts correctly', () => {
|
||||
expect(quickSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('mergeSort sorts correctly', () => {
|
||||
expect(mergeSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('handles empty arrays', () => {
|
||||
expect(quickSort([])).toEqual([]);
|
||||
expect(mergeSort([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
+5057
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sortAlgorithm",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
function quickSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const pivot = arr[Math.floor(arr.length / 2)];
|
||||
const left = arr.filter(x => x < pivot);
|
||||
const middle = arr.filter(x => x === pivot);
|
||||
const right = arr.filter(x => x > pivot);
|
||||
|
||||
return [...quickSort(left), ...middle, ...quickSort(right)];
|
||||
}
|
||||
|
||||
function mergeSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const mid = Math.floor(arr.length / 2);
|
||||
const left = mergeSort(arr.slice(0, mid));
|
||||
const right = mergeSort(arr.slice(mid));
|
||||
|
||||
const result = [];
|
||||
let i = 0, j = 0;
|
||||
|
||||
while (i < left.length && j < right.length) {
|
||||
if (left[i] < right[j]) {
|
||||
result.push(left[i++]);
|
||||
} else {
|
||||
result.push(right[j++]);
|
||||
}
|
||||
}
|
||||
|
||||
return result.concat(left.slice(i)).concat(right.slice(j));
|
||||
}
|
||||
|
||||
module.exports = { quickSort, mergeSort };
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
const { quickSort, mergeSort } = require('./index');
|
||||
|
||||
describe('Sorting Algorithms', () => {
|
||||
const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
|
||||
const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
|
||||
|
||||
test('quickSort sorts correctly', () => {
|
||||
expect(quickSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('mergeSort sorts correctly', () => {
|
||||
expect(mergeSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('handles empty arrays', () => {
|
||||
expect(quickSort([])).toEqual([]);
|
||||
expect(mergeSort([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
+5057
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sortAlgorithm",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
function quickSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const pivot = arr[Math.floor(arr.length / 2)];
|
||||
const left = arr.filter(x => x < pivot);
|
||||
const middle = arr.filter(x => x === pivot);
|
||||
const right = arr.filter(x => x > pivot);
|
||||
|
||||
return [...quickSort(left), ...middle, ...quickSort(right)];
|
||||
}
|
||||
|
||||
function mergeSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const mid = Math.floor(arr.length / 2);
|
||||
const left = mergeSort(arr.slice(0, mid));
|
||||
const right = mergeSort(arr.slice(mid));
|
||||
|
||||
const result = [];
|
||||
let i = 0, j = 0;
|
||||
|
||||
while (i < left.length && j < right.length) {
|
||||
if (left[i] < right[j]) {
|
||||
result.push(left[i++]);
|
||||
} else {
|
||||
result.push(right[j++]);
|
||||
}
|
||||
}
|
||||
|
||||
return result.concat(left.slice(i)).concat(right.slice(j));
|
||||
}
|
||||
|
||||
module.exports = { quickSort, mergeSort };
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
const { quickSort, mergeSort } = require('./index');
|
||||
|
||||
describe('Sorting Algorithms', () => {
|
||||
const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
|
||||
const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
|
||||
|
||||
test('quickSort sorts correctly', () => {
|
||||
expect(quickSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('mergeSort sorts correctly', () => {
|
||||
expect(mergeSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('handles empty arrays', () => {
|
||||
expect(quickSort([])).toEqual([]);
|
||||
expect(mergeSort([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
+5057
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sortAlgorithm",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
function quickSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const pivot = arr[Math.floor(arr.length / 2)];
|
||||
const left = arr.filter(x => x < pivot);
|
||||
const middle = arr.filter(x => x === pivot);
|
||||
const right = arr.filter(x => x > pivot);
|
||||
|
||||
return [...quickSort(left), ...middle, ...quickSort(right)];
|
||||
}
|
||||
|
||||
function mergeSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const mid = Math.floor(arr.length / 2);
|
||||
const left = mergeSort(arr.slice(0, mid));
|
||||
const right = mergeSort(arr.slice(mid));
|
||||
|
||||
const result = [];
|
||||
let i = 0, j = 0;
|
||||
|
||||
while (i < left.length && j < right.length) {
|
||||
if (left[i] < right[j]) {
|
||||
result.push(left[i++]);
|
||||
} else {
|
||||
result.push(right[j++]);
|
||||
}
|
||||
}
|
||||
|
||||
return result.concat(left.slice(i)).concat(right.slice(j));
|
||||
}
|
||||
|
||||
module.exports = { quickSort, mergeSort };
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
const { quickSort, mergeSort } = require('./index');
|
||||
|
||||
describe('Sorting Algorithms', () => {
|
||||
const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
|
||||
const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
|
||||
|
||||
test('quickSort sorts correctly', () => {
|
||||
expect(quickSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('mergeSort sorts correctly', () => {
|
||||
expect(mergeSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('handles empty arrays', () => {
|
||||
expect(quickSort([])).toEqual([]);
|
||||
expect(mergeSort([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
+5057
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sortAlgorithm",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
function quickSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const pivot = arr[Math.floor(arr.length / 2)];
|
||||
const left = arr.filter(x => x < pivot);
|
||||
const middle = arr.filter(x => x === pivot);
|
||||
const right = arr.filter(x => x > pivot);
|
||||
|
||||
return [...quickSort(left), ...middle, ...quickSort(right)];
|
||||
}
|
||||
|
||||
function mergeSort(arr) {
|
||||
if (arr.length <= 1) return arr;
|
||||
|
||||
const mid = Math.floor(arr.length / 2);
|
||||
const left = mergeSort(arr.slice(0, mid));
|
||||
const right = mergeSort(arr.slice(mid));
|
||||
|
||||
const result = [];
|
||||
let i = 0, j = 0;
|
||||
|
||||
while (i < left.length && j < right.length) {
|
||||
if (left[i] < right[j]) {
|
||||
result.push(left[i++]);
|
||||
} else {
|
||||
result.push(right[j++]);
|
||||
}
|
||||
}
|
||||
|
||||
return result.concat(left.slice(i)).concat(right.slice(j));
|
||||
}
|
||||
|
||||
module.exports = { quickSort, mergeSort };
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
const { quickSort, mergeSort } = require('./index');
|
||||
|
||||
describe('Sorting Algorithms', () => {
|
||||
const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
|
||||
const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
|
||||
|
||||
test('quickSort sorts correctly', () => {
|
||||
expect(quickSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('mergeSort sorts correctly', () => {
|
||||
expect(mergeSort(unsorted)).toEqual(sorted);
|
||||
});
|
||||
|
||||
test('handles empty arrays', () => {
|
||||
expect(quickSort([])).toEqual([]);
|
||||
expect(mergeSort([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
+5057
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sortAlgorithm",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest --silent",
|
||||
"lint": "eslint index.js || true",
|
||||
"typecheck": "echo 'No TypeScript' || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"supertest": "^6.0.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"branch": "checkpoint/pre-edit-20250812-172234", "file": "/workspaces/claude-code-flow/demo-stream-chain.sh", "timestamp": "2025-08-12T17:22:34Z", "type": "pre-edit", "original_branch": "alpha-89"}
|
||||
@@ -0,0 +1 @@
|
||||
{"tag": "checkpoint-20250812-172236", "file": "/workspaces/claude-code-flow/demo-stream-chain.sh", "timestamp": "2025-08-12T17:22:36Z", "type": "post-edit", "branch": "alpha-89", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 120 +++++++++++++++++++++++++++++++ .claude-flow/metrics/task-metrics.json | 8 +-- .claude/checkpoints/task-1755019061.json | 1 + claude-flow-wiki | 0 demo-stream-chain.sh | 31 ++++++++ 6 files changed, 157 insertions(+), 5 deletions(-) "}
|
||||
@@ -0,0 +1,357 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Integrated Training and Stream Chaining System
|
||||
* Combines real code training with stream-based agent chaining
|
||||
*/
|
||||
|
||||
import fs from 'fs/promises';
|
||||
import { spawn } from 'child_process';
|
||||
import { TrainingPipeline } from './training-pipeline.js';
|
||||
|
||||
export class TrainAndStreamSystem {
|
||||
constructor() {
|
||||
this.trainingPipeline = new TrainingPipeline();
|
||||
this.streamConfig = '.claude-flow/stream-config.json';
|
||||
}
|
||||
|
||||
/**
|
||||
* Train agents and then use them in a stream chain
|
||||
*/
|
||||
async trainAndExecute(task, options = {}) {
|
||||
console.log('🎯 Integrated Training & Stream Execution');
|
||||
console.log('━'.repeat(50));
|
||||
|
||||
// Step 1: Run training to improve agent profiles
|
||||
console.log('\n📚 Phase 1: Training Agents with Real Code');
|
||||
console.log('─'.repeat(40));
|
||||
|
||||
await this.trainingPipeline.initialize();
|
||||
const trainingResult = await this.trainingPipeline.runFullPipeline({
|
||||
complexity: options.complexity || 'medium',
|
||||
iterations: options.iterations || 2,
|
||||
validate: true
|
||||
});
|
||||
|
||||
// Step 2: Load trained profiles
|
||||
const profiles = JSON.parse(
|
||||
await fs.readFile('.claude-flow/agents/profiles.json', 'utf8')
|
||||
);
|
||||
|
||||
// Step 3: Select best strategy based on task requirements
|
||||
const strategy = this.selectOptimalStrategy(profiles, options);
|
||||
console.log(`\n🎯 Selected Strategy: ${strategy.name}`);
|
||||
console.log(` Success Rate: ${(strategy.profile.successRate * 100).toFixed(1)}%`);
|
||||
console.log(` Avg Score: ${strategy.profile.avgScore.toFixed(2)}`);
|
||||
console.log(` Execution Time: ${strategy.profile.avgExecutionTime.toFixed(0)}ms`);
|
||||
|
||||
// Step 4: Execute stream chain with trained agents
|
||||
console.log('\n🔗 Phase 2: Stream Chain Execution');
|
||||
console.log('─'.repeat(40));
|
||||
|
||||
const result = await this.executeStreamChain(task, strategy, options);
|
||||
|
||||
// Step 5: Learn from execution results
|
||||
await this.updateProfilesFromExecution(strategy.name, result);
|
||||
|
||||
return {
|
||||
training: trainingResult,
|
||||
execution: result,
|
||||
strategy: strategy.name,
|
||||
performance: {
|
||||
trainingImprovement: trainingResult.improvements,
|
||||
executionTime: result.duration,
|
||||
success: result.success
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Select optimal strategy based on task requirements
|
||||
*/
|
||||
selectOptimalStrategy(profiles, options) {
|
||||
const priorities = options.priorities || {
|
||||
reliability: 0.4,
|
||||
speed: 0.3,
|
||||
score: 0.3
|
||||
};
|
||||
|
||||
let bestScore = -1;
|
||||
let bestStrategy = null;
|
||||
|
||||
for (const [name, profile] of Object.entries(profiles)) {
|
||||
const score =
|
||||
(profile.successRate * priorities.reliability) +
|
||||
((1 - profile.avgExecutionTime / 5000) * priorities.speed) +
|
||||
(profile.avgScore / 100 * priorities.score);
|
||||
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
bestStrategy = { name, profile, score };
|
||||
}
|
||||
}
|
||||
|
||||
return bestStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a stream chain with multiple agents
|
||||
*/
|
||||
async executeStreamChain(task, strategy, options) {
|
||||
const startTime = Date.now();
|
||||
const steps = this.decomposeTask(task, strategy.name);
|
||||
|
||||
console.log(`\n📝 Task decomposed into ${steps.length} steps:`);
|
||||
steps.forEach((step, i) => {
|
||||
console.log(` ${i + 1}. ${step.description}`);
|
||||
});
|
||||
|
||||
let inputStream = null;
|
||||
let lastOutput = null;
|
||||
const results = [];
|
||||
|
||||
for (let i = 0; i < steps.length; i++) {
|
||||
const step = steps[i];
|
||||
console.log(`\n🔄 Executing Step ${i + 1}: ${step.description}`);
|
||||
|
||||
const output = await this.executeStreamStep(
|
||||
step,
|
||||
inputStream,
|
||||
i === steps.length - 1 // isLast
|
||||
);
|
||||
|
||||
results.push({
|
||||
step: i + 1,
|
||||
description: step.description,
|
||||
output: output.summary,
|
||||
duration: output.duration
|
||||
});
|
||||
|
||||
inputStream = output.stream;
|
||||
lastOutput = output;
|
||||
}
|
||||
|
||||
const totalDuration = Date.now() - startTime;
|
||||
|
||||
console.log('\n✅ Stream Chain Complete');
|
||||
console.log(` Total Duration: ${totalDuration}ms`);
|
||||
console.log(` Steps Completed: ${results.length}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
duration: totalDuration,
|
||||
steps: results,
|
||||
finalOutput: lastOutput.summary
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a single step in the stream chain
|
||||
*/
|
||||
async executeStreamStep(step, inputStream, isLast) {
|
||||
return new Promise((resolve) => {
|
||||
const startTime = Date.now();
|
||||
|
||||
// Build command arguments
|
||||
const args = ['-p'];
|
||||
if (inputStream) {
|
||||
args.push('--input-format', 'stream-json');
|
||||
}
|
||||
if (!isLast) {
|
||||
args.push('--output-format', 'stream-json');
|
||||
}
|
||||
args.push(step.prompt);
|
||||
|
||||
// Spawn Claude process
|
||||
const claudeProcess = spawn('claude', args, {
|
||||
stdio: inputStream ? ['pipe', 'pipe', 'pipe'] : ['inherit', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
let output = '';
|
||||
let streamOutput = '';
|
||||
|
||||
// Pipe input if available
|
||||
if (inputStream && claudeProcess.stdin) {
|
||||
inputStream.pipe(claudeProcess.stdin);
|
||||
}
|
||||
|
||||
// Capture output
|
||||
claudeProcess.stdout.on('data', (data) => {
|
||||
const chunk = data.toString();
|
||||
output += chunk;
|
||||
if (!isLast) {
|
||||
streamOutput += chunk;
|
||||
}
|
||||
});
|
||||
|
||||
claudeProcess.on('close', (code) => {
|
||||
const duration = Date.now() - startTime;
|
||||
|
||||
// Parse output for summary
|
||||
let summary = 'Step completed';
|
||||
try {
|
||||
if (output.includes('"type":"message"')) {
|
||||
const lines = output.split('\n');
|
||||
for (const line of lines) {
|
||||
if (line.includes('"type":"message"')) {
|
||||
const parsed = JSON.parse(line);
|
||||
if (parsed.content && parsed.content[0]) {
|
||||
summary = parsed.content[0].text?.slice(0, 100) || summary;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
summary = output.slice(0, 100);
|
||||
}
|
||||
} catch (e) {
|
||||
// Fallback to raw output
|
||||
summary = output.slice(0, 100);
|
||||
}
|
||||
|
||||
resolve({
|
||||
success: code === 0,
|
||||
duration,
|
||||
summary,
|
||||
stream: !isLast ? streamOutput : null
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Decompose task into stream chain steps
|
||||
*/
|
||||
decomposeTask(task, strategy) {
|
||||
// Different decomposition based on strategy
|
||||
if (strategy === 'conservative') {
|
||||
return [
|
||||
{
|
||||
description: 'Thorough analysis and validation',
|
||||
prompt: `Analyze this task thoroughly and identify all requirements: ${task}`
|
||||
},
|
||||
{
|
||||
description: 'Detailed planning with error handling',
|
||||
prompt: 'Create a detailed implementation plan with comprehensive error handling'
|
||||
},
|
||||
{
|
||||
description: 'Safe implementation with validation',
|
||||
prompt: 'Implement the solution with extensive validation and safety checks'
|
||||
}
|
||||
];
|
||||
} else if (strategy === 'aggressive') {
|
||||
return [
|
||||
{
|
||||
description: 'Quick analysis',
|
||||
prompt: `Quickly analyze and implement: ${task}`
|
||||
},
|
||||
{
|
||||
description: 'Optimization pass',
|
||||
prompt: 'Optimize the implementation for maximum performance'
|
||||
}
|
||||
];
|
||||
} else {
|
||||
// Balanced
|
||||
return [
|
||||
{
|
||||
description: 'Analysis and design',
|
||||
prompt: `Analyze and design a solution for: ${task}`
|
||||
},
|
||||
{
|
||||
description: 'Implementation',
|
||||
prompt: 'Implement the designed solution'
|
||||
},
|
||||
{
|
||||
description: 'Review and refinement',
|
||||
prompt: 'Review the implementation and make necessary refinements'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update profiles based on execution results
|
||||
*/
|
||||
async updateProfilesFromExecution(strategy, result) {
|
||||
const profiles = JSON.parse(
|
||||
await fs.readFile('.claude-flow/agents/profiles.json', 'utf8')
|
||||
);
|
||||
|
||||
if (profiles[strategy]) {
|
||||
const profile = profiles[strategy];
|
||||
const executionScore = result.success ? 80 : 20;
|
||||
const timeScore = Math.max(0, 100 - result.duration / 100);
|
||||
const overallScore = (executionScore + timeScore) / 2;
|
||||
|
||||
// Update with learning
|
||||
const learningRate = 0.2;
|
||||
profile.avgScore = profile.avgScore * (1 - learningRate) + overallScore * learningRate;
|
||||
profile.avgExecutionTime = profile.avgExecutionTime * (1 - learningRate) + result.duration * learningRate;
|
||||
profile.uses++;
|
||||
|
||||
// Add to trend
|
||||
if (!profile.trend) profile.trend = [];
|
||||
profile.trend.push({
|
||||
score: overallScore,
|
||||
timestamp: new Date().toISOString(),
|
||||
streamExecution: true
|
||||
});
|
||||
|
||||
await fs.writeFile(
|
||||
'.claude-flow/agents/profiles.json',
|
||||
JSON.stringify(profiles, null, 2)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CLI Command Handler
|
||||
*/
|
||||
export async function trainAndStreamCommand(args, flags) {
|
||||
const system = new TrainAndStreamSystem();
|
||||
const task = args.join(' ') || 'Create a function to validate email addresses';
|
||||
|
||||
console.log('🚀 Train & Stream System');
|
||||
console.log(`📋 Task: ${task}`);
|
||||
console.log('');
|
||||
|
||||
const options = {
|
||||
complexity: flags.complexity || 'medium',
|
||||
iterations: parseInt(flags.iterations) || 2,
|
||||
priorities: {
|
||||
reliability: parseFloat(flags.reliability) || 0.4,
|
||||
speed: parseFloat(flags.speed) || 0.3,
|
||||
score: parseFloat(flags.score) || 0.3
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await system.trainAndExecute(task, options);
|
||||
|
||||
console.log('\n' + '═'.repeat(50));
|
||||
console.log('📊 Final Report');
|
||||
console.log('═'.repeat(50));
|
||||
|
||||
console.log('\n🎯 Strategy Used:', result.strategy);
|
||||
console.log('⏱️ Total Execution Time:', result.performance.executionTime + 'ms');
|
||||
console.log('✅ Success:', result.performance.success ? 'Yes' : 'No');
|
||||
|
||||
if (result.performance.trainingImprovement) {
|
||||
console.log('\n📈 Training Improvements:');
|
||||
console.log(` Success Rate: ${result.performance.trainingImprovement.successRate > 0 ? '+' : ''}${result.performance.trainingImprovement.successRate.toFixed(1)}%`);
|
||||
console.log(` Score: ${result.performance.trainingImprovement.score > 0 ? '+' : ''}${result.performance.trainingImprovement.score.toFixed(1)}%`);
|
||||
}
|
||||
|
||||
console.log('\n🔗 Stream Chain Steps:');
|
||||
for (const step of result.execution.steps) {
|
||||
console.log(` ${step.step}. ${step.description} (${step.duration}ms)`);
|
||||
console.log(` Output: ${step.output.slice(0, 60)}...`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export default TrainAndStreamSystem;
|
||||
Reference in new issue
Block a user