chatroom-cli 1.39.1 → 1.40.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/dist/index.js CHANGED
@@ -71238,6 +71238,286 @@ function readFileContent(filePath, optionName) {
71238
71238
  }
71239
71239
  var init_file_content = () => {};
71240
71240
 
71241
+ // src/commands/workflow/templates/code-review.ts
71242
+ function getCodeReviewTemplate(role) {
71243
+ return {
71244
+ key: "code-review",
71245
+ steps: [
71246
+ {
71247
+ stepKey: "pillar-1-simplification",
71248
+ description: "Simplification: functions/classes, dead code, monolithic patterns",
71249
+ dependsOn: [],
71250
+ order: 1,
71251
+ assigneeRole: role,
71252
+ specification: {
71253
+ goal: `## Pillar 1 — Simplification (Highest Priority)
71254
+
71255
+ AI generates more code than needed. The average developer checked in 75% more code in 2025
71256
+ than in 2022 — volume that the team now has to maintain. AI agents never suggest refactoring,
71257
+ so complexity accumulates silently.
71258
+
71259
+ Look for:
71260
+ - Functions over ~40 lines or classes over ~200 lines with no clear single responsibility
71261
+ - Monolithic architecture: 40–50% of AI code defaults to tightly-coupled structures that
71262
+ reverse a decade of modular progress (OX Security, 2025)
71263
+ - Phantom Bugs: logic handling highly improbable edge cases, adding complexity with no benefit
71264
+ (found in 20–30% of AI code)
71265
+ - Dead code, unused imports, or leftover scaffolding from generation
71266
+ - PRs that touch services, libraries, infrastructure, and tests in a single change
71267
+
71268
+ Ask: Is there a simpler path to the same outcome? Would a new team member understand this
71269
+ without help? Can this function be split without losing meaning?
71270
+
71271
+ Action: Flag any function over ~40 lines. Require decomposition or written justification
71272
+ before merge.`,
71273
+ requirements: REVIEW_REQUIREMENTS
71274
+ }
71275
+ },
71276
+ {
71277
+ stepKey: "pillar-2-type-drift",
71278
+ description: "Type Drift: any usage, unsafe assertions, null checks, boundary drift",
71279
+ dependsOn: ["pillar-1-simplification"],
71280
+ order: 2,
71281
+ assigneeRole: role,
71282
+ specification: {
71283
+ goal: `## Pillar 2 — Type Drift (High Priority)
71284
+
71285
+ AI generates code in isolation from the broader type system. Type inconsistencies introduced
71286
+ here surface later as null pointer exceptions, silent failures, and cross-service contract
71287
+ mismatches. A University of Naples study of 500k+ samples (Aug 2025) confirmed these are the
71288
+ most reliably catchable issues via static analysis — meaning they should never reach review.
71289
+
71290
+ Look for:
71291
+ - \`any\` usage: defeats TypeScript entirely; AI reaches for it when uncertain
71292
+ - Unsafe \`as\` assertions: suppresses the compiler rather than satisfying it
71293
+ - Missing \`strictNullChecks\` compliance — null/undefined slipping through unchecked
71294
+ - Boundary drift: API endpoints returning different shapes across execution paths
71295
+ - Configuration drift: divergent \`tsconfig\` settings or ESLint rules added incrementally
71296
+ - Leaked internals: AI exposing implementation details that should be encapsulated
71297
+
71298
+ Ask: Are all return types and parameters explicitly typed? Are API contract types shared and
71299
+ stable? Does this match existing type conventions, or introduce a new pattern?
71300
+
71301
+ Action: \`strict: true\` in \`tsconfig.json\` is a hard gate. Any PR disabling strict settings
71302
+ requires explicit team sign-off.`,
71303
+ requirements: REVIEW_REQUIREMENTS
71304
+ }
71305
+ },
71306
+ {
71307
+ stepKey: "pillar-3-duplication",
71308
+ description: "Duplication: shared abstractions, copy-paste, vanilla rebuilds",
71309
+ dependsOn: ["pillar-2-type-drift"],
71310
+ order: 3,
71311
+ assigneeRole: role,
71312
+ specification: {
71313
+ goal: `## Pillar 3 — Duplication (High Priority)
71314
+
71315
+ GitClear's 2025 analysis of 211 million changed lines found duplicated code blocks grew 8x
71316
+ in one year, and copy/pasted code surpassed refactored code for the first time in history.
71317
+ OX Security found "Bugs Déjà-Vu" in 70–80% of AI codebases: identical bugs recurring in
71318
+ multiple locations because logic was never abstracted.
71319
+
71320
+ Look for:
71321
+ - Duplicate utility logic across files — each instance works, but no shared abstraction exists
71322
+ - "Vanilla Style" rebuilds: AI reconstructing functionality from scratch instead of using
71323
+ existing libraries, SDKs, or internal utilities (40–50% of AI code, OX Security)
71324
+ - Duplicated validation, auth checks, and input sanitization
71325
+ - Copy-pasted try/catch blocks instead of centralised error handling
71326
+ - New dependencies that the existing codebase already covers
71327
+
71328
+ Ask: Does an equivalent utility already exist? Is this logic duplicated anywhere else?
71329
+ Use AST-level search, not just grep.
71330
+
71331
+ Action: Require a codebase search before approving any new utility function. Run SonarQube,
71332
+ CodeClimate, or Codacy as a PR gate for duplication thresholds.`,
71333
+ requirements: REVIEW_REQUIREMENTS
71334
+ }
71335
+ },
71336
+ {
71337
+ stepKey: "pillar-4-design-patterns",
71338
+ description: "Design Patterns: SOLID compliance, pattern violations, context blindness",
71339
+ dependsOn: ["pillar-3-duplication"],
71340
+ order: 4,
71341
+ assigneeRole: role,
71342
+ specification: {
71343
+ goal: `## Pillar 4 — Design Pattern Compliance (Standard Priority)
71344
+
71345
+ AI implements the prompt. It does not check the ADR log, existing service patterns, or
71346
+ architectural conventions. OX Security identified "By-The-Book Fixation" in 80–90% of AI
71347
+ code: rigid application of generic best practices, missing the better solution for this
71348
+ specific context.
71349
+
71350
+ Look for:
71351
+ - Pattern violations: raw \`fetch\` where an API service layer exists; new state patterns where
71352
+ a store convention is already established
71353
+ - SOLID violations:
71354
+ - Single Responsibility: see Pillar 1
71355
+ - Open/Closed: code requiring modification rather than extension to add new behaviour
71356
+ - Dependency Inversion: hard-coded dependencies instead of injection
71357
+ - No refactoring suggestions — AI never proposes that a feature should trigger a refactor
71358
+ - Context blindness: ignoring ADRs, versioning strategy, or team-level conventions
71359
+
71360
+ Ask: Does this follow the patterns in this area of the codebase? Can this be extended without
71361
+ modification? Are dependencies injected?
71362
+
71363
+ Action: Maintain a living \`ARCHITECTURE.md\` or ADR log. Pass it as context to AI tools before
71364
+ generation, not after.`,
71365
+ requirements: REVIEW_REQUIREMENTS
71366
+ }
71367
+ },
71368
+ {
71369
+ stepKey: "pillar-5-security",
71370
+ description: "Security: OWASP Top 10, auth checks, secrets, env awareness",
71371
+ dependsOn: ["pillar-4-design-patterns"],
71372
+ order: 5,
71373
+ assigneeRole: role,
71374
+ specification: {
71375
+ goal: `## Pillar 5 — Security (Standard Priority)
71376
+
71377
+ 45% of AI-generated code samples introduced OWASP Top 10 vulnerabilities in Veracode's 2025
71378
+ test of 100+ LLMs. CodeRabbit found AI code is 2.74x more likely to introduce XSS, 1.88x more
71379
+ likely to mishandle passwords, 1.82x more likely to implement insecure deserialization.
71380
+ OX Security calls this "insecure by dumbness" — not malicious, but structurally blind to
71381
+ security requirements that were not in the prompt.
71382
+
71383
+ Look for:
71384
+ - OWASP Top 10: injection (SQL, XSS, command), broken auth, insecure deserialization
71385
+ - "Worked on My Machine" syndrome (60–70% of AI code): missing environment awareness,
71386
+ hard-coded localhost references, assumed-present secrets
71387
+ - Missing auth/ownership checks — AI assumes the happy path; role gates rarely appear unprompted
71388
+ - Secrets, tokens, or credentials in source code
71389
+ - Deprecated API patterns from the model's training data
71390
+ - Excessive I/O (~8x human rate) and concurrency misuse (~2x human rate)
71391
+
71392
+ Ask: Are all inputs validated before use? Are auth checks present at every trust boundary?
71393
+ Does this code behave differently across environments?
71394
+
71395
+ Action: Run SAST tooling (Snyk, Semgrep, SonarQube) on every AI-generated PR as a CI gate.
71396
+ Manual review alone cannot keep pace with AI generation velocity.`,
71397
+ requirements: REVIEW_REQUIREMENTS
71398
+ }
71399
+ },
71400
+ {
71401
+ stepKey: "pillar-6-test-quality",
71402
+ description: "Test Quality: edge cases, coverage theater, integration tests",
71403
+ dependsOn: ["pillar-5-security"],
71404
+ order: 6,
71405
+ assigneeRole: role,
71406
+ specification: {
71407
+ goal: `## Pillar 6 — Test Quality (Standard Priority)
71408
+
71409
+ AI generates tests that look comprehensive but frequently are not. OX Security found "Fake
71410
+ Test Coverage" in 40–50% of AI codebases: inflated metrics, low signal. The failure mode is
71411
+ precise: AI tests its own assumptions, not the developer's intent. University of Naples (2025)
71412
+ confirmed that even code passing all functional benchmarks averaged 1.45–1.77 static issues
71413
+ per task.
71414
+
71415
+ Look for:
71416
+ - Tests that verify AI output is stable, not that it is correct by domain rules
71417
+ - Missing edge cases: empty inputs, boundary values, null handling, race conditions,
71418
+ business-rule violations
71419
+ - Coverage theater: tests that assert no exception was thrown and nothing more
71420
+ - No integration or contract tests — AI generates unit tests almost exclusively
71421
+ - Tests coupled to implementation: must be updated every time the code changes
71422
+
71423
+ Ask: Do these tests verify the domain intent? Would they catch a logic regression in the
71424
+ next PR? Are cross-service interactions tested?
71425
+
71426
+ Action: Test review is a separate pass from code review. Use mutation testing (Stryker,
71427
+ PITest) to validate whether tests catch real defects — coverage percentage is not sufficient.`,
71428
+ requirements: REVIEW_REQUIREMENTS
71429
+ }
71430
+ },
71431
+ {
71432
+ stepKey: "pillar-7-ownership",
71433
+ description: "Ownership & Observability: named owner, logging, error handling, health checks",
71434
+ dependsOn: ["pillar-6-test-quality"],
71435
+ order: 7,
71436
+ assigneeRole: role,
71437
+ specification: {
71438
+ goal: `## Pillar 7 — Ownership, Observability, Deployment (Standard Priority)
71439
+
71440
+ The most consistently missed category. ISACA's 2026 incident review found that the biggest
71441
+ AI failures of 2025 were organisational, not technical: weak controls and unclear ownership.
71442
+ Bright Security (2026) identified unclear ownership as one of the most dangerous patterns:
71443
+ code that works well enough that no one feels responsible for it. IBM's 2025 breach data found
71444
+ shadow AI added $670,000 average to breach costs.
71445
+
71446
+ Look for:
71447
+ - No named human owner — every AI-generated module needs someone who can explain it in a
71448
+ postmortem without reading it fresh
71449
+ - Missing structured logs, metrics emission, or tracing hooks
71450
+ - Swallowed exceptions: retry logic with no alerting; fallback paths invisible to operators
71451
+ - No environment-specific configuration, secrets management, or health check endpoints
71452
+ - Model versioning chaos: inconsistencies from team members using different AI tool versions
71453
+ - Shadow AI: code with no record of which tool or prompt produced it
71454
+
71455
+ Ask: Who owns this? Will production failures surface to operators? Does this behave
71456
+ differently across environments?
71457
+
71458
+ Action: Require every AI-generated module to have a named owner in CODEOWNERS. Add logging
71459
+ requirements to the PR template. Establish a team AI governance policy that tracks tools
71460
+ and model versions — treat this like any other dependency.`,
71461
+ requirements: REVIEW_REQUIREMENTS
71462
+ }
71463
+ },
71464
+ {
71465
+ stepKey: "pillar-8-dead-code",
71466
+ description: "Dead Code: unreachable code, unused imports, orphaned config",
71467
+ dependsOn: ["pillar-7-ownership"],
71468
+ order: 8,
71469
+ assigneeRole: role,
71470
+ specification: {
71471
+ goal: `## Pillar 8 — Dead Code Elimination (Standard Priority)
71472
+
71473
+ AI generates code speculatively. It adds helper functions "just in case", creates abstractions
71474
+ for paths that never materialise, and leaves behind scaffolding from earlier generation
71475
+ attempts. GitClear's 2025 data showed a 75% increase in total code volume, much of it never
71476
+ executed. Dead code is not harmless — it misleads future readers, inflates bundle sizes, creates
71477
+ false positive search results, and adds surface area for bugs and security vulnerabilities
71478
+ in code that serves no purpose.
71479
+
71480
+ Look for:
71481
+ - Unreachable code: functions, methods, or branches that no call site ever invokes
71482
+ - Unused imports: modules imported but never referenced — common in AI-generated files
71483
+ - Commented-out code: old implementations left inline instead of being removed; version
71484
+ control already preserves history
71485
+ - Feature flags that are permanently off: conditional paths that were never enabled or have
71486
+ been superseded but not cleaned up
71487
+ - Orphaned configuration: environment variables, constants, or config entries with no consumer
71488
+ - Stale types and interfaces: type definitions for data shapes that no longer exist in the
71489
+ system
71490
+ - Unused dependencies: packages listed in \`package.json\` (or equivalent) that no source file
71491
+ imports
71492
+ - Vestigial error handling: catch blocks or fallback paths for conditions that can no longer
71493
+ occur due to upstream changes
71494
+ - Test helpers and fixtures for tests that have been deleted
71495
+
71496
+ Ask: Is every function called? Is every import used? Is every dependency exercised?
71497
+ Would removing this code change any observable behaviour?
71498
+
71499
+ Action: Run tree-shaking analysis and dead code detection tools (e.g., \`ts-prune\`,
71500
+ \`knip\`, \`depcheck\`, IDE unused-symbol highlighting) as part of CI. Treat dead code
71501
+ the same as duplication — it compounds over time and must be actively managed.`,
71502
+ requirements: REVIEW_REQUIREMENTS
71503
+ }
71504
+ }
71505
+ ]
71506
+ };
71507
+ }
71508
+ var REVIEW_REQUIREMENTS = "Review the code against this pillar. Mark this step complete when you have finished reviewing and noting all findings for this pillar.";
71509
+
71510
+ // src/commands/workflow/templates/index.ts
71511
+ function getTemplate(name, role) {
71512
+ switch (name.toLowerCase()) {
71513
+ case "code-review":
71514
+ return getCodeReviewTemplate(role);
71515
+ default:
71516
+ return null;
71517
+ }
71518
+ }
71519
+ var init_templates = () => {};
71520
+
71241
71521
  // src/commands/workflow/index.ts
71242
71522
  var exports_workflow = {};
71243
71523
  __export(exports_workflow, {
@@ -71247,6 +71527,7 @@ __export(exports_workflow, {
71247
71527
  getWorkflowStatus: () => getWorkflowStatus,
71248
71528
  exitWorkflow: () => exitWorkflow,
71249
71529
  executeWorkflow: () => executeWorkflow,
71530
+ createWorkflowFromTemplate: () => createWorkflowFromTemplate,
71250
71531
  createWorkflow: () => createWorkflow,
71251
71532
  completeStep: () => completeStep
71252
71533
  });
@@ -71599,17 +71880,33 @@ async function completeStep(chatroomId, options, deps) {
71599
71880
  const sessionId = await requireAuth3(d);
71600
71881
  validateChatroomId2(chatroomId);
71601
71882
  try {
71602
- await d.backend.mutation(api.workflows.completeStep, {
71883
+ const result = await d.backend.mutation(api.workflows.completeStep, {
71603
71884
  sessionId,
71604
71885
  chatroomId,
71605
71886
  workflowKey: options.workflowKey,
71606
71887
  stepKey: options.stepKey
71607
71888
  });
71608
71889
  console.log("");
71609
- console.log("✅ Step completed");
71890
+ console.log("✅ Step complete!");
71610
71891
  console.log(` Workflow: ${options.workflowKey}`);
71611
71892
  console.log(` Step: ${options.stepKey}`);
71612
71893
  console.log("");
71894
+ if (result.workflowComplete) {
71895
+ console.log("\uD83C\uDF89 All steps complete — the workflow is done.");
71896
+ console.log("");
71897
+ } else if (result.nextStep) {
71898
+ if (result.nextStep.assigneeRole === options.role) {
71899
+ console.log(`⏭️ Next step unlocked: "${result.nextStep.description}"`);
71900
+ console.log(" Run this to view it:");
71901
+ console.log(` chatroom workflow step-view --chatroom-id=${chatroomId} --role=${options.role} --workflow-key=${options.workflowKey} --step-key=${result.nextStep.stepKey}`);
71902
+ console.log("");
71903
+ } else {
71904
+ const assignee = result.nextStep.assigneeRole ?? "unknown";
71905
+ console.log(`⏭️ Next step unlocked: "${result.nextStep.description}"`);
71906
+ console.log(` Assigned to: ${assignee}`);
71907
+ console.log("");
71908
+ }
71909
+ }
71613
71910
  } catch (error) {
71614
71911
  console.error(`❌ Failed to complete step: ${getErrorMessage(error)}`);
71615
71912
  process.exit(1);
@@ -71732,12 +72029,77 @@ async function viewStep(chatroomId, options, deps) {
71732
72029
  return;
71733
72030
  }
71734
72031
  }
72032
+ async function createWorkflowFromTemplate(chatroomId, options, deps) {
72033
+ const d = deps ?? await createDefaultDeps12();
72034
+ const sessionId = await requireAuth3(d);
72035
+ validateChatroomId2(chatroomId);
72036
+ const template = getTemplate(options.template, options.role);
72037
+ if (!template) {
72038
+ console.error(`❌ Unknown template: "${options.template}"`);
72039
+ console.error(" Available templates: code-review");
72040
+ process.exit(1);
72041
+ return;
72042
+ }
72043
+ const workflowKey = `${template.key}-${Date.now()}`;
72044
+ try {
72045
+ const stepsForCreate = template.steps.map((s) => ({
72046
+ stepKey: s.stepKey,
72047
+ description: s.description,
72048
+ dependsOn: s.dependsOn,
72049
+ order: s.order
72050
+ }));
72051
+ const createResult = await d.backend.mutation(api.workflows.createWorkflow, {
72052
+ sessionId,
72053
+ chatroomId,
72054
+ workflowKey,
72055
+ steps: stepsForCreate,
72056
+ createdBy: options.role
72057
+ });
72058
+ console.log("");
72059
+ console.log(`✅ Workflow created from template "${options.template}"`);
72060
+ console.log(` Key: ${workflowKey}`);
72061
+ console.log(` Steps: ${template.steps.length} (one pillar revealed at a time)`);
72062
+ for (const step4 of template.steps) {
72063
+ if (step4.specification) {
72064
+ await d.backend.mutation(api.workflows.specifyStep, {
72065
+ sessionId,
72066
+ chatroomId,
72067
+ workflowKey,
72068
+ stepKey: step4.stepKey,
72069
+ assigneeRole: step4.assigneeRole,
72070
+ goal: step4.specification.goal,
72071
+ requirements: step4.specification.requirements,
72072
+ warnings: step4.specification.warnings
72073
+ });
72074
+ }
72075
+ }
72076
+ console.log(` Specifications: ${template.steps.length} steps specified`);
72077
+ await d.backend.mutation(api.workflows.executeWorkflow, {
72078
+ sessionId,
72079
+ chatroomId,
72080
+ workflowKey
72081
+ });
72082
+ console.log(` Status: active`);
72083
+ console.log("");
72084
+ console.log("Next steps:");
72085
+ const firstStep = template.steps[0];
72086
+ console.log(` 1. View first step: chatroom workflow step-view --chatroom-id=${chatroomId} --role=${options.role} --workflow-key=${workflowKey} --step-key=${firstStep.stepKey}`);
72087
+ console.log(` 2. When done reviewing: chatroom workflow step-complete --chatroom-id=${chatroomId} --role=${options.role} --workflow-key=${workflowKey} --step-key=${firstStep.stepKey}`);
72088
+ console.log(" 3. Proceed to next pillar as each step unlocks");
72089
+ console.log("");
72090
+ } catch (error) {
72091
+ console.error(`❌ Failed to start workflow: ${getErrorMessage(error)}`);
72092
+ process.exit(1);
72093
+ return;
72094
+ }
72095
+ }
71735
72096
  var VALID_CHATROOM_SKILLS;
71736
72097
  var init_workflow = __esm(() => {
71737
72098
  init_api3();
71738
72099
  init_storage();
71739
72100
  init_client2();
71740
72101
  init_convex_error();
72102
+ init_templates();
71741
72103
  VALID_CHATROOM_SKILLS = ["backlog", "software-engineering", "code-review", "workflow"];
71742
72104
  });
71743
72105
 
@@ -79084,6 +79446,14 @@ backlogCommand.command("import").description("Import backlog items from a JSON e
79084
79446
  await importBacklog2(options.chatroomId, { role: options.role, path: options.path });
79085
79447
  });
79086
79448
  var workflowCommand = program2.command("workflow").description("Manage structured workflows");
79449
+ workflowCommand.command("create-from-template").description("Create a workflow from a built-in template with all steps pre-filled").requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role").requiredOption("--template <name>", "Template name (e.g. code-review)").action(async (options) => {
79450
+ await maybeRequireAuth();
79451
+ const { createWorkflowFromTemplate: createWorkflowFromTemplate2 } = await Promise.resolve().then(() => (init_workflow(), exports_workflow));
79452
+ await createWorkflowFromTemplate2(options.chatroomId, {
79453
+ role: options.role,
79454
+ template: options.template
79455
+ });
79456
+ });
79087
79457
  workflowCommand.command("create").description("Create a new workflow with steps (reads JSON from stdin)").requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role (creator)").requiredOption("--workflow-key <key>", "Unique workflow key").action(async (options) => {
79088
79458
  await maybeRequireAuth();
79089
79459
  const stdinContent = await readStdin();
@@ -79339,5 +79709,5 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
79339
79709
  });
79340
79710
  program2.parse();
79341
79711
 
79342
- //# debugId=F3CC073413306D7A64756E2164756E21
79712
+ //# debugId=CC4268FCAB22FC9D64756E2164756E21
79343
79713
  //# sourceMappingURL=index.js.map