vibeman 0.0.5 → 0.0.7
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/dist/api.js +43 -0
- package/dist/index.js +227 -104
- package/dist/ui/assets/index-C_kQPI1m.js +9 -0
- package/dist/ui/index.html +12 -0
- package/package.json +13 -46
- package/README.md +0 -12
- package/dist/runtime/api/.tsbuildinfo +0 -1
- package/dist/runtime/api/agent/agent-service.d.ts +0 -229
- package/dist/runtime/api/agent/agent-service.js +0 -963
- package/dist/runtime/api/agent/ai-providers/amp-cli-provider.d.ts +0 -38
- package/dist/runtime/api/agent/ai-providers/amp-cli-provider.js +0 -268
- package/dist/runtime/api/agent/ai-providers/claude-code-adapter.d.ts +0 -61
- package/dist/runtime/api/agent/ai-providers/claude-code-adapter.js +0 -362
- package/dist/runtime/api/agent/ai-providers/codex-cli-provider.d.ts +0 -36
- package/dist/runtime/api/agent/ai-providers/codex-cli-provider.js +0 -375
- package/dist/runtime/api/agent/ai-providers/gemini-cli-provider.d.ts +0 -24
- package/dist/runtime/api/agent/ai-providers/gemini-cli-provider.js +0 -291
- package/dist/runtime/api/agent/ai-providers/index.d.ts +0 -9
- package/dist/runtime/api/agent/ai-providers/index.js +0 -9
- package/dist/runtime/api/agent/ai-providers/types.d.ts +0 -185
- package/dist/runtime/api/agent/ai-providers/types.js +0 -5
- package/dist/runtime/api/agent/amp-cli-provider.test.d.ts +0 -1
- package/dist/runtime/api/agent/amp-cli-provider.test.js +0 -99
- package/dist/runtime/api/agent/codex-cli-provider.test.d.ts +0 -1
- package/dist/runtime/api/agent/codex-cli-provider.test.js +0 -172
- package/dist/runtime/api/agent/core-agent-service.d.ts +0 -119
- package/dist/runtime/api/agent/core-agent-service.js +0 -267
- package/dist/runtime/api/agent/parsers.d.ts +0 -16
- package/dist/runtime/api/agent/parsers.js +0 -308
- package/dist/runtime/api/agent/prompt-service.d.ts +0 -30
- package/dist/runtime/api/agent/prompt-service.js +0 -452
- package/dist/runtime/api/agent/prompt-service.test.d.ts +0 -1
- package/dist/runtime/api/agent/prompt-service.test.js +0 -265
- package/dist/runtime/api/agent/routing-policy.d.ts +0 -171
- package/dist/runtime/api/agent/routing-policy.js +0 -196
- package/dist/runtime/api/agent/routing-policy.test.d.ts +0 -1
- package/dist/runtime/api/agent/routing-policy.test.js +0 -63
- package/dist/runtime/api/api/router-helpers.d.ts +0 -32
- package/dist/runtime/api/api/router-helpers.js +0 -31
- package/dist/runtime/api/api/routers/ai.d.ts +0 -200
- package/dist/runtime/api/api/routers/ai.js +0 -396
- package/dist/runtime/api/api/routers/executions.d.ts +0 -93
- package/dist/runtime/api/api/routers/executions.js +0 -94
- package/dist/runtime/api/api/routers/git.d.ts +0 -45
- package/dist/runtime/api/api/routers/git.js +0 -35
- package/dist/runtime/api/api/routers/provider-config.d.ts +0 -199
- package/dist/runtime/api/api/routers/provider-config.js +0 -252
- package/dist/runtime/api/api/routers/settings.d.ts +0 -158
- package/dist/runtime/api/api/routers/settings.js +0 -129
- package/dist/runtime/api/api/routers/tasks.d.ts +0 -141
- package/dist/runtime/api/api/routers/tasks.js +0 -238
- package/dist/runtime/api/api/routers/workflows.d.ts +0 -275
- package/dist/runtime/api/api/routers/workflows.js +0 -311
- package/dist/runtime/api/api/routers/worktrees.d.ts +0 -101
- package/dist/runtime/api/api/routers/worktrees.js +0 -80
- package/dist/runtime/api/api/trpc.d.ts +0 -118
- package/dist/runtime/api/api/trpc.js +0 -34
- package/dist/runtime/api/index.d.ts +0 -9
- package/dist/runtime/api/index.js +0 -117
- package/dist/runtime/api/lib/id-generator.d.ts +0 -70
- package/dist/runtime/api/lib/id-generator.js +0 -123
- package/dist/runtime/api/lib/local-config.d.ts +0 -335
- package/dist/runtime/api/lib/local-config.js +0 -304
- package/dist/runtime/api/lib/logger.d.ts +0 -11
- package/dist/runtime/api/lib/logger.js +0 -188
- package/dist/runtime/api/lib/provider-detection.d.ts +0 -61
- package/dist/runtime/api/lib/provider-detection.js +0 -326
- package/dist/runtime/api/lib/server/agent-service-singleton.d.ts +0 -6
- package/dist/runtime/api/lib/server/agent-service-singleton.js +0 -27
- package/dist/runtime/api/lib/server/bootstrap.d.ts +0 -38
- package/dist/runtime/api/lib/server/bootstrap.js +0 -197
- package/dist/runtime/api/lib/server/git-service-singleton.d.ts +0 -6
- package/dist/runtime/api/lib/server/git-service-singleton.js +0 -47
- package/dist/runtime/api/lib/server/project-root.d.ts +0 -2
- package/dist/runtime/api/lib/server/project-root.js +0 -61
- package/dist/runtime/api/lib/server/task-service-singleton.d.ts +0 -7
- package/dist/runtime/api/lib/server/task-service-singleton.js +0 -58
- package/dist/runtime/api/lib/server/vibeman-info.d.ts +0 -5
- package/dist/runtime/api/lib/server/vibeman-info.js +0 -85
- package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.d.ts +0 -7
- package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.js +0 -57
- package/dist/runtime/api/lib/trpc/server.d.ts +0 -965
- package/dist/runtime/api/lib/trpc/server.js +0 -11
- package/dist/runtime/api/lib/trpc/ws-server.d.ts +0 -8
- package/dist/runtime/api/lib/trpc/ws-server.js +0 -33
- package/dist/runtime/api/persistence/database-service.d.ts +0 -14
- package/dist/runtime/api/persistence/database-service.js +0 -74
- package/dist/runtime/api/persistence/execution-log-persistence.d.ts +0 -90
- package/dist/runtime/api/persistence/execution-log-persistence.js +0 -426
- package/dist/runtime/api/persistence/execution-log-persistence.test.d.ts +0 -1
- package/dist/runtime/api/persistence/execution-log-persistence.test.js +0 -170
- package/dist/runtime/api/router.d.ts +0 -968
- package/dist/runtime/api/router.js +0 -34
- package/dist/runtime/api/settings-service.d.ts +0 -110
- package/dist/runtime/api/settings-service.js +0 -678
- package/dist/runtime/api/tasks/file-watcher.d.ts +0 -23
- package/dist/runtime/api/tasks/file-watcher.js +0 -88
- package/dist/runtime/api/tasks/task-file-parser.d.ts +0 -14
- package/dist/runtime/api/tasks/task-file-parser.js +0 -180
- package/dist/runtime/api/tasks/task-service.d.ts +0 -36
- package/dist/runtime/api/tasks/task-service.js +0 -173
- package/dist/runtime/api/tasks/task-updater.d.ts +0 -62
- package/dist/runtime/api/tasks/task-updater.js +0 -260
- package/dist/runtime/api/tasks/task-updater.test.d.ts +0 -1
- package/dist/runtime/api/tasks/task-updater.test.js +0 -303
- package/dist/runtime/api/types/index.d.ts +0 -186
- package/dist/runtime/api/types/index.js +0 -1
- package/dist/runtime/api/types/settings.d.ts +0 -105
- package/dist/runtime/api/types/settings.js +0 -2
- package/dist/runtime/api/types.d.ts +0 -2
- package/dist/runtime/api/types.js +0 -1
- package/dist/runtime/api/utils/env.d.ts +0 -6
- package/dist/runtime/api/utils/env.js +0 -12
- package/dist/runtime/api/utils/stripNextEnv.d.ts +0 -7
- package/dist/runtime/api/utils/stripNextEnv.js +0 -22
- package/dist/runtime/api/utils/title-slug.d.ts +0 -6
- package/dist/runtime/api/utils/title-slug.js +0 -77
- package/dist/runtime/api/utils/url.d.ts +0 -2
- package/dist/runtime/api/utils/url.js +0 -19
- package/dist/runtime/api/vcs/git-history-service.d.ts +0 -57
- package/dist/runtime/api/vcs/git-history-service.js +0 -228
- package/dist/runtime/api/vcs/git-service.d.ts +0 -136
- package/dist/runtime/api/vcs/git-service.js +0 -307
- package/dist/runtime/api/vcs/worktree-service.d.ts +0 -93
- package/dist/runtime/api/vcs/worktree-service.js +0 -518
- package/dist/runtime/api/vcs/worktree-service.test.d.ts +0 -1
- package/dist/runtime/api/vcs/worktree-service.test.js +0 -20
- package/dist/runtime/api/workflows/quality-pipeline.d.ts +0 -58
- package/dist/runtime/api/workflows/quality-pipeline.js +0 -401
- package/dist/runtime/api/workflows/vibing-orchestrator.d.ts +0 -406
- package/dist/runtime/api/workflows/vibing-orchestrator.js +0 -2462
- package/dist/runtime/api/workflows/workflow-effects.d.ts +0 -45
- package/dist/runtime/api/workflows/workflow-effects.js +0 -49
- package/dist/runtime/api/workflows/workflow-reconciler.d.ts +0 -65
- package/dist/runtime/api/workflows/workflow-reconciler.js +0 -226
- package/dist/runtime/api/workflows/workflow-reducer.d.ts +0 -26
- package/dist/runtime/api/workflows/workflow-reducer.js +0 -288
- package/dist/runtime/api/workflows/workflow-reducer.test.d.ts +0 -1
- package/dist/runtime/api/workflows/workflow-reducer.test.js +0 -247
- package/dist/runtime/api/workflows/workflow-schema.d.ts +0 -546
- package/dist/runtime/api/workflows/workflow-schema.js +0 -256
- package/dist/runtime/web/.next/BUILD_ID +0 -1
- package/dist/runtime/web/.next/app-build-manifest.json +0 -66
- package/dist/runtime/web/.next/app-path-routes-manifest.json +0 -8
- package/dist/runtime/web/.next/build-manifest.json +0 -33
- package/dist/runtime/web/.next/package.json +0 -1
- package/dist/runtime/web/.next/prerender-manifest.json +0 -61
- package/dist/runtime/web/.next/react-loadable-manifest.json +0 -8
- package/dist/runtime/web/.next/required-server-files.json +0 -334
- package/dist/runtime/web/.next/routes-manifest.json +0 -70
- package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route.js +0 -1
- package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app/_not-found/page.js +0 -2
- package/dist/runtime/web/.next/server/app/_not-found/page.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/_not-found/page_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app/_not-found.html +0 -7
- package/dist/runtime/web/.next/server/app/_not-found.meta +0 -8
- package/dist/runtime/web/.next/server/app/_not-found.rsc +0 -22
- package/dist/runtime/web/.next/server/app/api/health/route.js +0 -1
- package/dist/runtime/web/.next/server/app/api/health/route.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/api/health/route_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js +0 -1
- package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/api/images/[...path]/route_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app/api/upload/route.js +0 -1
- package/dist/runtime/web/.next/server/app/api/upload/route.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/api/upload/route_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app/index.html +0 -7
- package/dist/runtime/web/.next/server/app/index.meta +0 -7
- package/dist/runtime/web/.next/server/app/index.rsc +0 -27
- package/dist/runtime/web/.next/server/app/page.js +0 -112
- package/dist/runtime/web/.next/server/app/page.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/app/page_client-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/app-paths-manifest.json +0 -8
- package/dist/runtime/web/.next/server/chunks/210.js +0 -1
- package/dist/runtime/web/.next/server/chunks/291.js +0 -18
- package/dist/runtime/web/.next/server/chunks/552.js +0 -22
- package/dist/runtime/web/.next/server/chunks/780.js +0 -1
- package/dist/runtime/web/.next/server/chunks/905.js +0 -6
- package/dist/runtime/web/.next/server/chunks/98.js +0 -1
- package/dist/runtime/web/.next/server/functions-config-manifest.json +0 -4
- package/dist/runtime/web/.next/server/middleware-build-manifest.js +0 -1
- package/dist/runtime/web/.next/server/middleware-manifest.json +0 -6
- package/dist/runtime/web/.next/server/middleware-react-loadable-manifest.js +0 -1
- package/dist/runtime/web/.next/server/next-font-manifest.js +0 -1
- package/dist/runtime/web/.next/server/next-font-manifest.json +0 -1
- package/dist/runtime/web/.next/server/pages/404.html +0 -7
- package/dist/runtime/web/.next/server/pages/500.html +0 -1
- package/dist/runtime/web/.next/server/pages/_app.js +0 -1
- package/dist/runtime/web/.next/server/pages/_app.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/pages/_document.js +0 -1
- package/dist/runtime/web/.next/server/pages/_document.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/pages/_error.js +0 -19
- package/dist/runtime/web/.next/server/pages/_error.js.nft.json +0 -1
- package/dist/runtime/web/.next/server/pages-manifest.json +0 -6
- package/dist/runtime/web/.next/server/server-reference-manifest.js +0 -1
- package/dist/runtime/web/.next/server/server-reference-manifest.json +0 -1
- package/dist/runtime/web/.next/server/webpack-runtime.js +0 -1
- package/dist/runtime/web/.next/static/LJFZk_8tvKFN_Ee4HqUuM/_buildManifest.js +0 -1
- package/dist/runtime/web/.next/static/LJFZk_8tvKFN_Ee4HqUuM/_ssgManifest.js +0 -1
- package/dist/runtime/web/.next/static/chunks/05c91ade-7d09b2b280adffd1.js +0 -1
- package/dist/runtime/web/.next/static/chunks/201-51bef3fa8c832e2e.js +0 -1
- package/dist/runtime/web/.next/static/chunks/524-89747ed9b0294f8a.js +0 -1
- package/dist/runtime/web/.next/static/chunks/554-8bec6e9cca6acc67.js +0 -1
- package/dist/runtime/web/.next/static/chunks/764.86e9503a69d45a85.js +0 -1
- package/dist/runtime/web/.next/static/chunks/7ab4dc20-239138e0ae7af24a.js +0 -1
- package/dist/runtime/web/.next/static/chunks/905-342391e3d3a3678f.js +0 -20
- package/dist/runtime/web/.next/static/chunks/a8a5ce16-4edea7df2d9b544a.js +0 -79
- package/dist/runtime/web/.next/static/chunks/ad74d572-4c1b162e2c15acaa.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/.vibeman/assets/images/[...path]/route-7b752a8641f96c1f.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/_not-found/page-34e66b251c2b5044.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/api/health/route-7b752a8641f96c1f.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/api/images/[...path]/route-7b752a8641f96c1f.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/api/upload/route-7b752a8641f96c1f.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/layout-df9ac93cb02b2385.js +0 -1
- package/dist/runtime/web/.next/static/chunks/app/page-6610743f7de5f92a.js +0 -1
- package/dist/runtime/web/.next/static/chunks/c25e0690-e9b798b8de667da1.js +0 -1
- package/dist/runtime/web/.next/static/chunks/framework-57157ec4d37f64aa.js +0 -1
- package/dist/runtime/web/.next/static/chunks/main-app-156cc0c60371bd78.js +0 -1
- package/dist/runtime/web/.next/static/chunks/main-df25d367c47b1fec.js +0 -1
- package/dist/runtime/web/.next/static/chunks/pages/_app-9f629a5e1131d19f.js +0 -1
- package/dist/runtime/web/.next/static/chunks/pages/_error-9238238274c7efcd.js +0 -1
- package/dist/runtime/web/.next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
- package/dist/runtime/web/.next/static/chunks/webpack-cd50e39b423d1808.js +0 -1
- package/dist/runtime/web/.next/static/css/2728291c68f99cb1.css +0 -3
- package/dist/runtime/web/.next/static/css/4fbf378a264bd4ea.css +0 -1
- package/dist/runtime/web/.next/static/css/521bd69cc298cd1a.css +0 -1
- package/dist/runtime/web/.next/static/css/537e22821e101b87.css +0 -1
- package/dist/runtime/web/.next/static/media/19cfc7226ec3afaa-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/21350d82a1f187e9-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/8e9860b6e62d6359-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/ba9851c3c22cd980-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/c5fe6dc8356a8c31-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/df0a9ae256c0569c-s.woff2 +0 -0
- package/dist/runtime/web/.next/static/media/e4af272ccee01ff0-s.p.woff2 +0 -0
- package/dist/runtime/web/package.json +0 -65
- package/dist/runtime/web/server.js +0 -44
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { publicProcedure } from '../trpc.js';
|
|
3
|
-
import { TaskIdSchema, WorktreePathSchema, withErrors } from '../router-helpers.js';
|
|
4
|
-
import { log } from '../../lib/logger.js';
|
|
5
|
-
export function buildWorktreeRoutes({ vibingOrchestrator }) {
|
|
6
|
-
return {
|
|
7
|
-
listWorktrees: publicProcedure.query(withErrors('list worktrees', 'router:listWorktrees', async () => {
|
|
8
|
-
const orchestrator = vibingOrchestrator;
|
|
9
|
-
return await orchestrator.listWorktrees();
|
|
10
|
-
})),
|
|
11
|
-
syncWorktreeState: publicProcedure.mutation(withErrors('sync worktree state', 'router:syncWorktreeState', async () => {
|
|
12
|
-
const orchestrator = vibingOrchestrator;
|
|
13
|
-
await orchestrator.syncWorktreeState();
|
|
14
|
-
return { success: true, message: 'Worktree state synchronized' };
|
|
15
|
-
})),
|
|
16
|
-
getWorktreeInfo: publicProcedure.input(TaskIdSchema).query(async ({ input }) => {
|
|
17
|
-
const orchestrator = vibingOrchestrator;
|
|
18
|
-
const worktree = orchestrator.getWorktreeInfo(input.taskId);
|
|
19
|
-
if (!worktree)
|
|
20
|
-
return null;
|
|
21
|
-
const { git, ...serializableWorktree } = worktree;
|
|
22
|
-
return serializableWorktree;
|
|
23
|
-
}),
|
|
24
|
-
createWorktree: publicProcedure.input(TaskIdSchema).mutation(async ({ input }) => {
|
|
25
|
-
const orchestrator = vibingOrchestrator;
|
|
26
|
-
const worktree = await orchestrator.createWorktree(input.taskId);
|
|
27
|
-
const { git, ...serializableWorktree } = worktree;
|
|
28
|
-
return serializableWorktree;
|
|
29
|
-
}),
|
|
30
|
-
deleteWorktree: publicProcedure
|
|
31
|
-
.input(z.object({ taskId: z.string(), force: z.coerce.boolean().optional() }))
|
|
32
|
-
.mutation(async ({ input }) => {
|
|
33
|
-
const orchestrator = vibingOrchestrator;
|
|
34
|
-
await orchestrator.deleteWorktree(input.taskId, input.force || false);
|
|
35
|
-
if (orchestrator) {
|
|
36
|
-
await orchestrator.removeWorkflowsByTask(input.taskId);
|
|
37
|
-
}
|
|
38
|
-
return { success: true };
|
|
39
|
-
}),
|
|
40
|
-
openInEditor: publicProcedure.input(WorktreePathSchema).mutation(withErrors('open in editor', 'router:openInEditor', async ({ input }) => {
|
|
41
|
-
const orchestrator = vibingOrchestrator;
|
|
42
|
-
await orchestrator.openInEditor(input.worktreePath);
|
|
43
|
-
// Ensure we return a clean, serializable object
|
|
44
|
-
return { success: true };
|
|
45
|
-
})),
|
|
46
|
-
openInTerminal: publicProcedure.input(WorktreePathSchema).mutation(withErrors('open in terminal', 'router:openInTerminal', async ({ input }) => {
|
|
47
|
-
const orchestrator = vibingOrchestrator;
|
|
48
|
-
await orchestrator.openInTerminal(input.worktreePath);
|
|
49
|
-
// Ensure we return a clean, serializable object
|
|
50
|
-
return { success: true };
|
|
51
|
-
})),
|
|
52
|
-
// TODO: Deprecated alias; prefer createPullRequest
|
|
53
|
-
createWorktreePR: publicProcedure
|
|
54
|
-
.input(z.object({ taskId: z.string(), baseBranch: z.string().optional().default('main') }))
|
|
55
|
-
.mutation(async ({ input }) => {
|
|
56
|
-
const orchestrator = vibingOrchestrator;
|
|
57
|
-
log.warn('Deprecated route used: createWorktreePR; prefer createPullRequest', { taskId: input.taskId }, 'router:createWorktreePR');
|
|
58
|
-
return await orchestrator.createPullRequest(input.taskId, input.baseBranch);
|
|
59
|
-
}),
|
|
60
|
-
createPullRequest: publicProcedure
|
|
61
|
-
.input(z.object({ taskId: z.string(), baseBranch: z.string().optional().default('main') }))
|
|
62
|
-
.mutation(withErrors('create pull request', 'router:createPullRequest', async ({ input }) => {
|
|
63
|
-
const orchestrator = vibingOrchestrator;
|
|
64
|
-
return await orchestrator.createPullRequest(input.taskId, input.baseBranch);
|
|
65
|
-
})),
|
|
66
|
-
cleanupWorktree: publicProcedure
|
|
67
|
-
.input(z.object({
|
|
68
|
-
taskId: z.string().optional(),
|
|
69
|
-
worktreePath: z.string().optional(),
|
|
70
|
-
branchName: z.string().optional(),
|
|
71
|
-
isConnectedToTask: z.boolean(),
|
|
72
|
-
force: z.coerce.boolean().optional().default(false),
|
|
73
|
-
}))
|
|
74
|
-
.mutation(async ({ input }) => {
|
|
75
|
-
const orchestrator = vibingOrchestrator;
|
|
76
|
-
await orchestrator.cleanupWorktree(input);
|
|
77
|
-
return { success: true };
|
|
78
|
-
}),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import superjson from 'superjson';
|
|
3
|
-
import type { TaskService } from '../tasks/task-service.js';
|
|
4
|
-
export interface Context {
|
|
5
|
-
taskService?: TaskService;
|
|
6
|
-
}
|
|
7
|
-
export declare const t: import("@trpc/server").TRPCRootObject<Context, object, {
|
|
8
|
-
transformer: typeof superjson;
|
|
9
|
-
}, {
|
|
10
|
-
ctx: Context;
|
|
11
|
-
meta: object;
|
|
12
|
-
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
13
|
-
transformer: true;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const router: import("@trpc/server").TRPCRouterBuilder<{
|
|
16
|
-
ctx: Context;
|
|
17
|
-
meta: object;
|
|
18
|
-
errorShape: import("@trpc/server").TRPCDefaultErrorShape;
|
|
19
|
-
transformer: true;
|
|
20
|
-
}>;
|
|
21
|
-
export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<Context, object, object, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
|
|
22
|
-
export declare const TaskCreateSchema: z.ZodObject<{
|
|
23
|
-
id: z.ZodOptional<z.ZodString>;
|
|
24
|
-
title: z.ZodString;
|
|
25
|
-
type: z.ZodEnum<["feature", "bug", "chore", "refactor", "test", "doc"]>;
|
|
26
|
-
status: z.ZodDefault<z.ZodEnum<["backlog", "in-progress", "review", "done"]>>;
|
|
27
|
-
tags: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
28
|
-
due_date: z.ZodOptional<z.ZodString>;
|
|
29
|
-
assignee: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
30
|
-
priority: z.ZodDefault<z.ZodEnum<["low", "medium", "high"]>>;
|
|
31
|
-
comments: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
32
|
-
content: z.ZodString;
|
|
33
|
-
}, "strip", z.ZodTypeAny, {
|
|
34
|
-
type: "feature" | "bug" | "chore" | "refactor" | "test" | "doc";
|
|
35
|
-
status: "backlog" | "in-progress" | "review" | "done";
|
|
36
|
-
priority: "low" | "medium" | "high";
|
|
37
|
-
title: string;
|
|
38
|
-
tags: string[];
|
|
39
|
-
assignee: string[];
|
|
40
|
-
comments: string[];
|
|
41
|
-
content: string;
|
|
42
|
-
id?: string | undefined;
|
|
43
|
-
due_date?: string | undefined;
|
|
44
|
-
}, {
|
|
45
|
-
type: "feature" | "bug" | "chore" | "refactor" | "test" | "doc";
|
|
46
|
-
title: string;
|
|
47
|
-
content: string;
|
|
48
|
-
status?: "backlog" | "in-progress" | "review" | "done" | undefined;
|
|
49
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
50
|
-
id?: string | undefined;
|
|
51
|
-
tags?: string[] | undefined;
|
|
52
|
-
due_date?: string | undefined;
|
|
53
|
-
assignee?: string[] | undefined;
|
|
54
|
-
comments?: string[] | undefined;
|
|
55
|
-
}>;
|
|
56
|
-
export declare const TaskUpdateSchema: z.ZodObject<{
|
|
57
|
-
title: z.ZodOptional<z.ZodString>;
|
|
58
|
-
type: z.ZodOptional<z.ZodEnum<["feature", "bug", "chore", "refactor", "test", "doc"]>>;
|
|
59
|
-
status: z.ZodOptional<z.ZodDefault<z.ZodEnum<["backlog", "in-progress", "review", "done"]>>>;
|
|
60
|
-
tags: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
|
|
61
|
-
due_date: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
62
|
-
assignee: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
|
|
63
|
-
priority: z.ZodOptional<z.ZodDefault<z.ZodEnum<["low", "medium", "high"]>>>;
|
|
64
|
-
comments: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
|
|
65
|
-
content: z.ZodOptional<z.ZodString>;
|
|
66
|
-
} & {
|
|
67
|
-
id: z.ZodString;
|
|
68
|
-
deleted_at: z.ZodOptional<z.ZodString>;
|
|
69
|
-
}, "strip", z.ZodTypeAny, {
|
|
70
|
-
id: string;
|
|
71
|
-
type?: "feature" | "bug" | "chore" | "refactor" | "test" | "doc" | undefined;
|
|
72
|
-
status?: "backlog" | "in-progress" | "review" | "done" | undefined;
|
|
73
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
74
|
-
title?: string | undefined;
|
|
75
|
-
tags?: string[] | undefined;
|
|
76
|
-
due_date?: string | undefined;
|
|
77
|
-
assignee?: string[] | undefined;
|
|
78
|
-
comments?: string[] | undefined;
|
|
79
|
-
content?: string | undefined;
|
|
80
|
-
deleted_at?: string | undefined;
|
|
81
|
-
}, {
|
|
82
|
-
id: string;
|
|
83
|
-
type?: "feature" | "bug" | "chore" | "refactor" | "test" | "doc" | undefined;
|
|
84
|
-
status?: "backlog" | "in-progress" | "review" | "done" | undefined;
|
|
85
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
86
|
-
title?: string | undefined;
|
|
87
|
-
tags?: string[] | undefined;
|
|
88
|
-
due_date?: string | undefined;
|
|
89
|
-
assignee?: string[] | undefined;
|
|
90
|
-
comments?: string[] | undefined;
|
|
91
|
-
content?: string | undefined;
|
|
92
|
-
deleted_at?: string | undefined;
|
|
93
|
-
}>;
|
|
94
|
-
export declare const TaskFilterSchema: z.ZodObject<{
|
|
95
|
-
status: z.ZodOptional<z.ZodEnum<["backlog", "in-progress", "review", "done"]>>;
|
|
96
|
-
type: z.ZodOptional<z.ZodEnum<["feature", "bug", "chore", "refactor", "test", "doc"]>>;
|
|
97
|
-
priority: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
|
|
98
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
99
|
-
search: z.ZodOptional<z.ZodString>;
|
|
100
|
-
includeDeleted: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
-
onlyDeleted: z.ZodOptional<z.ZodBoolean>;
|
|
102
|
-
}, "strip", z.ZodTypeAny, {
|
|
103
|
-
type?: "feature" | "bug" | "chore" | "refactor" | "test" | "doc" | undefined;
|
|
104
|
-
status?: "backlog" | "in-progress" | "review" | "done" | undefined;
|
|
105
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
106
|
-
search?: string | undefined;
|
|
107
|
-
tags?: string[] | undefined;
|
|
108
|
-
includeDeleted?: boolean | undefined;
|
|
109
|
-
onlyDeleted?: boolean | undefined;
|
|
110
|
-
}, {
|
|
111
|
-
type?: "feature" | "bug" | "chore" | "refactor" | "test" | "doc" | undefined;
|
|
112
|
-
status?: "backlog" | "in-progress" | "review" | "done" | undefined;
|
|
113
|
-
priority?: "low" | "medium" | "high" | undefined;
|
|
114
|
-
search?: string | undefined;
|
|
115
|
-
tags?: string[] | undefined;
|
|
116
|
-
includeDeleted?: boolean | undefined;
|
|
117
|
-
onlyDeleted?: boolean | undefined;
|
|
118
|
-
}>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { initTRPC } from '@trpc/server';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import superjson from 'superjson';
|
|
4
|
-
export const t = initTRPC.context().create({
|
|
5
|
-
transformer: superjson,
|
|
6
|
-
});
|
|
7
|
-
export const router = t.router;
|
|
8
|
-
export const publicProcedure = t.procedure;
|
|
9
|
-
// Input validation schemas
|
|
10
|
-
export const TaskCreateSchema = z.object({
|
|
11
|
-
id: z.string().optional(), // Made optional - will be auto-generated if not provided
|
|
12
|
-
title: z.string(),
|
|
13
|
-
type: z.enum(['feature', 'bug', 'chore', 'refactor', 'test', 'doc']),
|
|
14
|
-
status: z.enum(['backlog', 'in-progress', 'review', 'done']).default('backlog'),
|
|
15
|
-
tags: z.array(z.string()).default([]),
|
|
16
|
-
due_date: z.string().optional(),
|
|
17
|
-
assignee: z.array(z.string()).default([]),
|
|
18
|
-
priority: z.enum(['low', 'medium', 'high']).default('medium'),
|
|
19
|
-
comments: z.array(z.string()).default([]),
|
|
20
|
-
content: z.string(),
|
|
21
|
-
});
|
|
22
|
-
export const TaskUpdateSchema = TaskCreateSchema.partial().extend({
|
|
23
|
-
id: z.string(),
|
|
24
|
-
deleted_at: z.string().optional(),
|
|
25
|
-
});
|
|
26
|
-
export const TaskFilterSchema = z.object({
|
|
27
|
-
status: z.enum(['backlog', 'in-progress', 'review', 'done']).optional(),
|
|
28
|
-
type: z.enum(['feature', 'bug', 'chore', 'refactor', 'test', 'doc']).optional(),
|
|
29
|
-
priority: z.enum(['low', 'medium', 'high']).optional(),
|
|
30
|
-
tags: z.array(z.string()).optional(),
|
|
31
|
-
search: z.string().optional(),
|
|
32
|
-
includeDeleted: z.boolean().optional(),
|
|
33
|
-
onlyDeleted: z.boolean().optional(),
|
|
34
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Starts a standalone HTTP server that serves tRPC over HTTP and WebSocket on the same port.
|
|
3
|
-
* HTTP endpoint: /trpc
|
|
4
|
-
* WebSocket path: /trpc
|
|
5
|
-
*/
|
|
6
|
-
export declare function startApiServer({ port, host }: {
|
|
7
|
-
port: number;
|
|
8
|
-
host: string;
|
|
9
|
-
}): Promise<void>;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'http';
|
|
2
|
-
import { nodeHTTPRequestHandler } from '@trpc/server/adapters/node-http';
|
|
3
|
-
import { applyWSSHandler } from '@trpc/server/adapters/ws';
|
|
4
|
-
import { WebSocketServer } from 'ws';
|
|
5
|
-
import { appRouter } from './lib/trpc/server.js';
|
|
6
|
-
import { getTaskService } from './lib/server/task-service-singleton.js';
|
|
7
|
-
import { log } from './lib/logger.js';
|
|
8
|
-
import { pathToFileURL } from 'url';
|
|
9
|
-
function getNumberEnv(name, fallback) {
|
|
10
|
-
const raw = process.env[name];
|
|
11
|
-
const n = raw ? Number(raw) : NaN;
|
|
12
|
-
return Number.isFinite(n) ? n : fallback;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Starts a standalone HTTP server that serves tRPC over HTTP and WebSocket on the same port.
|
|
16
|
-
* HTTP endpoint: /trpc
|
|
17
|
-
* WebSocket path: /trpc
|
|
18
|
-
*/
|
|
19
|
-
export async function startApiServer({ port, host }) {
|
|
20
|
-
const httpServer = createServer((req, res) => {
|
|
21
|
-
// Basic CORS for local dev
|
|
22
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
23
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
|
|
24
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization');
|
|
25
|
-
if (req.method === 'OPTIONS') {
|
|
26
|
-
res.writeHead(200);
|
|
27
|
-
res.end();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (req.url?.startsWith('/trpc')) {
|
|
31
|
-
const host = req.headers.host || 'localhost';
|
|
32
|
-
const url = new URL(req.url, `http://${host}`);
|
|
33
|
-
// Strip the /trpc prefix and any leading slash; omit query string
|
|
34
|
-
const rawPath = url.pathname.replace(/^\/trpc\/?/, '');
|
|
35
|
-
const trpcPath = rawPath.replace(/^\/+/, '');
|
|
36
|
-
return nodeHTTPRequestHandler({
|
|
37
|
-
router: appRouter,
|
|
38
|
-
createContext: () => ({ taskService: getTaskService() }),
|
|
39
|
-
req: req,
|
|
40
|
-
res: res,
|
|
41
|
-
path: trpcPath,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (req.url === '/api/health') {
|
|
45
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
46
|
-
res.end(JSON.stringify({ status: 'ok', timestamp: new Date().toISOString() }));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
50
|
-
res.end(JSON.stringify({ error: 'Not Found' }));
|
|
51
|
-
});
|
|
52
|
-
// Share same HTTP server for WS, listening on /trpc
|
|
53
|
-
const wss = new WebSocketServer({ noServer: true });
|
|
54
|
-
// Upgrade handler for WebSocket path filtering
|
|
55
|
-
httpServer.on('upgrade', (request, socket, head) => {
|
|
56
|
-
const { url } = request;
|
|
57
|
-
if (!url || !url.startsWith('/trpc')) {
|
|
58
|
-
socket.destroy();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
62
|
-
wss.emit('connection', ws, request);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
// Hook tRPC WS handler
|
|
66
|
-
applyWSSHandler({
|
|
67
|
-
wss,
|
|
68
|
-
router: appRouter,
|
|
69
|
-
createContext: () => ({ taskService: getTaskService() }),
|
|
70
|
-
});
|
|
71
|
-
await new Promise((resolve) => {
|
|
72
|
-
httpServer.listen(port, host, () => resolve());
|
|
73
|
-
});
|
|
74
|
-
const addr = httpServer.address();
|
|
75
|
-
const actualPort = typeof addr === 'object' && addr && 'port' in addr ? addr.port : port;
|
|
76
|
-
log.info('API server listening', { port: actualPort, host, path: '/trpc' }, 'api-server');
|
|
77
|
-
console.log(`📡 API ready at http://${host}:${actualPort}/trpc (HTTP & WS)`);
|
|
78
|
-
// Graceful shutdown
|
|
79
|
-
const shutdown = () => {
|
|
80
|
-
try {
|
|
81
|
-
wss.close();
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
log.error('Failed to close WebSocket server', error, 'api-server');
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
httpServer.close();
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
log.error('Failed to close HTTP server', error, 'api-server');
|
|
91
|
-
}
|
|
92
|
-
process.exit(0);
|
|
93
|
-
};
|
|
94
|
-
process.on('SIGINT', shutdown);
|
|
95
|
-
process.on('SIGTERM', shutdown);
|
|
96
|
-
}
|
|
97
|
-
// Self-executing entry when run directly under ESM (e.g., tsx src/index.ts or node dist/index.js)
|
|
98
|
-
try {
|
|
99
|
-
const isMain = process.argv[1] ? pathToFileURL(process.argv[1]).href === import.meta.url : false;
|
|
100
|
-
if (isMain) {
|
|
101
|
-
const host = process.env.HOST || 'localhost';
|
|
102
|
-
const resolveApiPort = async () => {
|
|
103
|
-
const port = getNumberEnv('PORT', 3000);
|
|
104
|
-
return port + 1;
|
|
105
|
-
};
|
|
106
|
-
(async () => {
|
|
107
|
-
const port = await resolveApiPort();
|
|
108
|
-
startApiServer({ port, host }).catch((err) => {
|
|
109
|
-
console.error('Failed to start API server:', err);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
});
|
|
112
|
-
})();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// ignore
|
|
117
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified ID generation utility for consistent ID creation across the application
|
|
3
|
-
*/
|
|
4
|
-
export type IdPrefix = 'workflow' | 'exec' | 'improve' | 'merge' | 'review' | 'claude' | 'task' | 'session';
|
|
5
|
-
interface IdGeneratorOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Use UUID v4 for guaranteed uniqueness (default: true)
|
|
8
|
-
*/
|
|
9
|
-
useUuid?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Include timestamp for sortability (default: false)
|
|
12
|
-
*/
|
|
13
|
-
includeTimestamp?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Custom separator between parts (default: '_')
|
|
16
|
-
*/
|
|
17
|
-
separator?: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Generate a unique ID with consistent format
|
|
21
|
-
*
|
|
22
|
-
* @param prefix - The prefix to identify the ID type
|
|
23
|
-
* @param options - Configuration options for ID generation
|
|
24
|
-
* @returns A unique identifier string
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* generateId('workflow') // 'workflow_550e8400-e29b-41d4-a716-446655440000'
|
|
28
|
-
* generateId('exec', { includeTimestamp: true }) // 'exec_1703123456789_550e8400-e29b-41d4'
|
|
29
|
-
*/
|
|
30
|
-
export declare function generateId(prefix: IdPrefix | string, options?: IdGeneratorOptions): string;
|
|
31
|
-
/**
|
|
32
|
-
* Generate a short, human-readable ID (less secure, for display purposes)
|
|
33
|
-
*
|
|
34
|
-
* @param prefix - The prefix to identify the ID type
|
|
35
|
-
* @returns A shorter identifier string
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* generateShortId('task') // 'task_a1b2c3d4'
|
|
39
|
-
*/
|
|
40
|
-
export declare function generateShortId(prefix: IdPrefix | string): string;
|
|
41
|
-
/**
|
|
42
|
-
* Parse an ID to extract its components
|
|
43
|
-
*
|
|
44
|
-
* @param id - The ID to parse
|
|
45
|
-
* @param separator - The separator used in the ID
|
|
46
|
-
* @returns Parsed components of the ID
|
|
47
|
-
*/
|
|
48
|
-
export declare function parseId(id: string, separator?: string): {
|
|
49
|
-
prefix: string;
|
|
50
|
-
timestamp?: number;
|
|
51
|
-
uuid?: string;
|
|
52
|
-
full: string;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Validate if a string is a valid UUID v4
|
|
56
|
-
*/
|
|
57
|
-
export declare function isValidUuid(id: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Extract the UUID portion from a prefixed ID
|
|
60
|
-
*/
|
|
61
|
-
export declare function extractUuid(id: string): string | null;
|
|
62
|
-
/**
|
|
63
|
-
* Create a batch of IDs efficiently
|
|
64
|
-
*/
|
|
65
|
-
export declare function generateBatchIds(prefix: IdPrefix | string, count: number, options?: IdGeneratorOptions): string[];
|
|
66
|
-
/**
|
|
67
|
-
* Generate a deterministic ID based on input (useful for idempotency)
|
|
68
|
-
*/
|
|
69
|
-
export declare function generateDeterministicId(prefix: IdPrefix | string, input: string): Promise<string>;
|
|
70
|
-
export {};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
/**
|
|
3
|
-
* Generate a unique ID with consistent format
|
|
4
|
-
*
|
|
5
|
-
* @param prefix - The prefix to identify the ID type
|
|
6
|
-
* @param options - Configuration options for ID generation
|
|
7
|
-
* @returns A unique identifier string
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* generateId('workflow') // 'workflow_550e8400-e29b-41d4-a716-446655440000'
|
|
11
|
-
* generateId('exec', { includeTimestamp: true }) // 'exec_1703123456789_550e8400-e29b-41d4'
|
|
12
|
-
*/
|
|
13
|
-
export function generateId(prefix, options = {}) {
|
|
14
|
-
const { useUuid = true, includeTimestamp = false, separator = '_' } = options;
|
|
15
|
-
const parts = [prefix];
|
|
16
|
-
if (includeTimestamp) {
|
|
17
|
-
// Use high-resolution timestamp for better uniqueness
|
|
18
|
-
parts.push(Date.now().toString());
|
|
19
|
-
}
|
|
20
|
-
if (useUuid) {
|
|
21
|
-
parts.push(uuidv4());
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
// Fallback to crypto.randomUUID if available (browser/Node 19+)
|
|
25
|
-
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
26
|
-
parts.push(crypto.randomUUID());
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
// Legacy fallback with better entropy
|
|
30
|
-
const timestamp = Date.now();
|
|
31
|
-
const random1 = Math.random().toString(36).substring(2, 11);
|
|
32
|
-
const random2 = Math.random().toString(36).substring(2, 7);
|
|
33
|
-
const counter = getCounter();
|
|
34
|
-
parts.push(`${timestamp.toString(36)}${random1}${random2}${counter.toString(36)}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return parts.join(separator);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generate a short, human-readable ID (less secure, for display purposes)
|
|
41
|
-
*
|
|
42
|
-
* @param prefix - The prefix to identify the ID type
|
|
43
|
-
* @returns A shorter identifier string
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* generateShortId('task') // 'task_a1b2c3d4'
|
|
47
|
-
*/
|
|
48
|
-
export function generateShortId(prefix) {
|
|
49
|
-
const timestamp = Date.now().toString(36).slice(-4);
|
|
50
|
-
const random = Math.random().toString(36).substring(2, 6);
|
|
51
|
-
return `${prefix}_${timestamp}${random}`;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Parse an ID to extract its components
|
|
55
|
-
*
|
|
56
|
-
* @param id - The ID to parse
|
|
57
|
-
* @param separator - The separator used in the ID
|
|
58
|
-
* @returns Parsed components of the ID
|
|
59
|
-
*/
|
|
60
|
-
export function parseId(id, separator = '_') {
|
|
61
|
-
const parts = id.split(separator);
|
|
62
|
-
const result = {
|
|
63
|
-
prefix: parts[0] || '',
|
|
64
|
-
full: id,
|
|
65
|
-
};
|
|
66
|
-
// Check if second part is a timestamp (13+ digit number for millisecond timestamps)
|
|
67
|
-
// This avoids treating short numbers like "123" as timestamps
|
|
68
|
-
if (parts[1] && /^\d{13,}$/.test(parts[1])) {
|
|
69
|
-
result.timestamp = parseInt(parts[1], 10);
|
|
70
|
-
// When timestamp is present, UUID is the third part onward
|
|
71
|
-
result.uuid = parts.slice(2).join(separator);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// No timestamp, so UUID is everything after the prefix
|
|
75
|
-
result.uuid = parts.slice(1).join(separator);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Validate if a string is a valid UUID v4
|
|
81
|
-
*/
|
|
82
|
-
export function isValidUuid(id) {
|
|
83
|
-
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
84
|
-
return uuidV4Regex.test(id);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Extract the UUID portion from a prefixed ID
|
|
88
|
-
*/
|
|
89
|
-
export function extractUuid(id) {
|
|
90
|
-
const parts = id.split('_');
|
|
91
|
-
const lastPart = parts[parts.length - 1];
|
|
92
|
-
return isValidUuid(lastPart) ? lastPart : null;
|
|
93
|
-
}
|
|
94
|
-
// Counter for additional entropy in fallback ID generation
|
|
95
|
-
let counter = 0;
|
|
96
|
-
function getCounter() {
|
|
97
|
-
counter = (counter + 1) % 10000;
|
|
98
|
-
return counter;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Create a batch of IDs efficiently
|
|
102
|
-
*/
|
|
103
|
-
export function generateBatchIds(prefix, count, options) {
|
|
104
|
-
return Array.from({ length: count }, () => generateId(prefix, options));
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Generate a deterministic ID based on input (useful for idempotency)
|
|
108
|
-
*/
|
|
109
|
-
export async function generateDeterministicId(prefix, input) {
|
|
110
|
-
// Use Web Crypto API if available
|
|
111
|
-
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
|
112
|
-
const encoder = new TextEncoder();
|
|
113
|
-
const data = encoder.encode(input);
|
|
114
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
115
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
116
|
-
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
117
|
-
return `${prefix}_${hashHex.substring(0, 32)}`;
|
|
118
|
-
}
|
|
119
|
-
// Fallback for Node.js
|
|
120
|
-
const cryptoModule = await import('crypto');
|
|
121
|
-
const hash = cryptoModule.createHash('sha256').update(input).digest('hex');
|
|
122
|
-
return `${prefix}_${hash.substring(0, 32)}`;
|
|
123
|
-
}
|