symphony-forge 1.2.44__py3-none-any.whl
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.
- forge/__init__.py +4 -0
- forge/app_baseline.py +148 -0
- forge/approval.py +298 -0
- forge/autoreview.py +139 -0
- forge/backfill.py +298 -0
- forge/board.py +1197 -0
- forge/board_app/app.js +276 -0
- forge/board_app/assign.css +91 -0
- forge/board_app/assign.js +157 -0
- forge/board_app/insights.js +80 -0
- forge/board_app/item.css +380 -0
- forge/board_app/item.js +594 -0
- forge/board_app/markdown.js +110 -0
- forge/board_app/now.css +417 -0
- forge/board_app/now.js +248 -0
- forge/board_app/pages.css +178 -0
- forge/board_app/releases.js +203 -0
- forge/board_app/shell.html +31 -0
- forge/board_app/tokens.css +220 -0
- forge/board_facts.py +696 -0
- forge/board_graph.py +38 -0
- forge/board_server.py +431 -0
- forge/board_trends.py +105 -0
- forge/box.py +54 -0
- forge/box_ssh.py +209 -0
- forge/checks.py +743 -0
- forge/citime.py +259 -0
- forge/claude_sdk.py +56 -0
- forge/claude_turn.py +62 -0
- forge/cli.py +185 -0
- forge/close.py +1193 -0
- forge/close_remote.py +85 -0
- forge/codex.py +1200 -0
- forge/codex_turn.py +346 -0
- forge/deny.py +253 -0
- forge/design.py +201 -0
- forge/design_skills.py +16 -0
- forge/docskip.py +175 -0
- forge/doctor.py +578 -0
- forge/event_log.py +128 -0
- forge/fasttest.py +846 -0
- forge/feature.py +318 -0
- forge/feature_api.py +593 -0
- forge/feature_python.py +1107 -0
- forge/feature_python_contracts.py +268 -0
- forge/feature_python_tests.py +1134 -0
- forge/feature_python_tools.py +81 -0
- forge/feature_remove.py +189 -0
- forge/feature_schema.py +156 -0
- forge/feature_tests.py +1062 -0
- forge/fullrun.py +166 -0
- forge/gaps.py +109 -0
- forge/githooks.py +251 -0
- forge/github.py +191 -0
- forge/init.py +494 -0
- forge/intake.py +226 -0
- forge/journey.py +126 -0
- forge/known_issues.py +165 -0
- forge/land.py +882 -0
- forge/machine.py +821 -0
- forge/merge.py +530 -0
- forge/merge_review.py +84 -0
- forge/merge_timings.py +46 -0
- forge/migrate.py +673 -0
- forge/migration_warnings.py +108 -0
- forge/mod/.claude-plugin/plugin.json +20 -0
- forge/mod/hooks/hooks.json +3 -0
- forge/mod/hooks/pane.test.ts +608 -0
- forge/mod/hooks/register.ts +413 -0
- forge/mod/tsconfig.json +18 -0
- forge/native.py +306 -0
- forge/nextstep.py +1184 -0
- forge/node_workers.cjs +26 -0
- forge/noise.py +40 -0
- forge/open_decisions.py +205 -0
- forge/owner_choices.py +167 -0
- forge/payback.py +97 -0
- forge/plain_english.py +20 -0
- forge/plan_scope.py +76 -0
- forge/prcheck.py +640 -0
- forge/quicktest.py +198 -0
- forge/records.py +912 -0
- forge/releases.py +100 -0
- forge/repo.py +1154 -0
- forge/review.py +1199 -0
- forge/review_process.py +86 -0
- forge/review_skip.py +116 -0
- forge/roles.py +141 -0
- forge/round_limits.py +7 -0
- forge/score.py +192 -0
- forge/spotted.py +271 -0
- forge/standards.md +318 -0
- forge/story.py +1200 -0
- forge/sync.py +783 -0
- forge/task.py +1082 -0
- forge/templates/adapters/AGENTS.md +98 -0
- forge/templates/brief.md +834 -0
- forge/templates/cold-read.md +324 -0
- forge/templates/conventions/api.md +144 -0
- forge/templates/conventions/backend.md +171 -0
- forge/templates/conventions/database.md +81 -0
- forge/templates/conventions/demo-data.md +61 -0
- forge/templates/conventions/deploy.md +114 -0
- forge/templates/conventions/frontend.md +187 -0
- forge/templates/conventions/python.md +336 -0
- forge/templates/conventions/security.md +44 -0
- forge/templates/conventions/stack.md +96 -0
- forge/templates/conventions/testing.md +165 -0
- forge/templates/delegation.md +3 -0
- forge/templates/design/render-check.d.mts +25 -0
- forge/templates/design/render-check.mjs +113 -0
- forge/templates/design/support.js +159 -0
- forge/templates/design/ui-checks.js +111 -0
- forge/templates/fde.md +218 -0
- forge/templates/feature/kinds.toml +140 -0
- forge/templates/handover.md +26 -0
- forge/templates/migrate-skill.md +87 -0
- forge/templates/records-only-action.yml +16 -0
- forge/templates/review-light.md +48 -0
- forge/templates/review-tests.py +200 -0
- forge/templates/review.md +661 -0
- forge/templates/run-reference.md +328 -0
- forge/templates/skeleton/.dockerignore +18 -0
- forge/templates/skeleton/Dockerfile +10 -0
- forge/templates/skeleton/docs/decisions/README.md +13 -0
- forge/templates/skeleton/docs/product/BRIEF.md +47 -0
- forge/templates/skeleton/docs/product/DISCOVERY.md +46 -0
- forge/templates/skeleton/docs/specs/README.md +41 -0
- forge/templates/skeleton/services.toml +6 -0
- forge/templates/skill.md +2753 -0
- forge/templates/skills/agents/SKILL.md +446 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/app/assistant/README.md +131 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/app/assistant/__init__.py +5 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/app/assistant/chats.py +60 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/app/assistant/cleanup.py +91 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/app/assistant/models.py +57 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/migrations/versions/20261106_assistant.py +90 -0
- forge/templates/skills/agents/assistant-module/python/apps/api/tests/test_assistant_chats.py +173 -0
- forge/templates/skills/agents/assistant-module/typescript/apps/api/prisma/migrations/20261106000000_assistant/migration.sql +17 -0
- forge/templates/skills/agents/assistant-module/typescript/apps/api/prisma/schema/assistant.prisma +19 -0
- forge/templates/skills/agents/assistant-module/typescript/apps/api/test/assistant-api.e2e-spec.ts +185 -0
- forge/templates/skills/agents/assistant-module/typescript/apps/api/test/assistant-chats.e2e-spec.ts +75 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/README.md +107 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/contracts/package.json +10 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/contracts/src/index.ts +66 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/contracts/tsconfig.json +12 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/package.json +23 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/src/assistant.chats.controller.ts +54 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/src/assistant.chats.service.ts +140 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/src/assistant.cleanup.ts +34 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/src/assistant.module.ts +20 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/src/index.ts +3 -0
- forge/templates/skills/agents/assistant-module/typescript/libs/assistant/server/tsconfig.json +15 -0
- forge/templates/skills/app-baseline/SKILL.md +241 -0
- forge/templates/skills/database/SKILL.md +155 -0
- forge/templates/skills/emil-design-eng/FORGE-NOTICE.md +9 -0
- forge/templates/skills/emil-design-eng/LICENSE +21 -0
- forge/templates/skills/emil-design-eng/SKILL.md +674 -0
- forge/templates/skills/impeccable/FORGE-NOTICE.md +10 -0
- forge/templates/skills/impeccable/LICENSE +191 -0
- forge/templates/skills/impeccable/NOTICE.md +11 -0
- forge/templates/skills/impeccable/SKILL.md +88 -0
- forge/templates/skills/impeccable/reference/adapt.md +318 -0
- forge/templates/skills/impeccable/reference/adapt.native.md +58 -0
- forge/templates/skills/impeccable/reference/android.md +46 -0
- forge/templates/skills/impeccable/reference/animate.md +89 -0
- forge/templates/skills/impeccable/reference/audit.md +139 -0
- forge/templates/skills/impeccable/reference/audit.native.md +139 -0
- forge/templates/skills/impeccable/reference/bolder.md +33 -0
- forge/templates/skills/impeccable/reference/clarify.md +94 -0
- forge/templates/skills/impeccable/reference/colorize.md +86 -0
- forge/templates/skills/impeccable/reference/component-review.md +63 -0
- forge/templates/skills/impeccable/reference/craft-floor.md +44 -0
- forge/templates/skills/impeccable/reference/craft.md +5 -0
- forge/templates/skills/impeccable/reference/critique.md +819 -0
- forge/templates/skills/impeccable/reference/degraded/asset-producer.md +42 -0
- forge/templates/skills/impeccable/reference/degraded/documenter.md +24 -0
- forge/templates/skills/impeccable/reference/degraded/finish-reviewer.md +38 -0
- forge/templates/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -0
- forge/templates/skills/impeccable/reference/delight.md +70 -0
- forge/templates/skills/impeccable/reference/distill.md +111 -0
- forge/templates/skills/impeccable/reference/doctor.md +54 -0
- forge/templates/skills/impeccable/reference/document.md +416 -0
- forge/templates/skills/impeccable/reference/extract.md +69 -0
- forge/templates/skills/impeccable/reference/generate.md +101 -0
- forge/templates/skills/impeccable/reference/harden.md +362 -0
- forge/templates/skills/impeccable/reference/hooks.md +114 -0
- forge/templates/skills/impeccable/reference/init.md +131 -0
- forge/templates/skills/impeccable/reference/ios.md +51 -0
- forge/templates/skills/impeccable/reference/layout.md +84 -0
- forge/templates/skills/impeccable/reference/live-setup.md +104 -0
- forge/templates/skills/impeccable/reference/live.md +325 -0
- forge/templates/skills/impeccable/reference/mode-operate.md +21 -0
- forge/templates/skills/impeccable/reference/mode-persuade.md +19 -0
- forge/templates/skills/impeccable/reference/mode-read.md +21 -0
- forge/templates/skills/impeccable/reference/new-work.md +154 -0
- forge/templates/skills/impeccable/reference/onboard.md +234 -0
- forge/templates/skills/impeccable/reference/operate.md +61 -0
- forge/templates/skills/impeccable/reference/optimize.md +257 -0
- forge/templates/skills/impeccable/reference/overdrive.md +127 -0
- forge/templates/skills/impeccable/reference/polish.md +105 -0
- forge/templates/skills/impeccable/reference/quieter.md +99 -0
- forge/templates/skills/impeccable/reference/region-map.md +26 -0
- forge/templates/skills/impeccable/reference/routing.md +24 -0
- forge/templates/skills/impeccable/reference/shape.md +59 -0
- forge/templates/skills/impeccable/reference/typeset.md +90 -0
- forge/templates/skills/impeccable/reference/visualize.md +47 -0
- forge/templates/skills/impeccable/scripts/VERSION +1 -0
- forge/templates/skills/impeccable/scripts/command-metadata.json +98 -0
- forge/templates/skills/impeccable/scripts/data/font-index-failures.json +121 -0
- forge/templates/skills/impeccable/scripts/data/font-index.json +1 -0
- forge/templates/skills/impeccable/scripts/engine-checksums.txt +9 -0
- forge/templates/skills/impeccable/scripts/impeccable +249 -0
- forge/templates/skills/impeccable/scripts/impeccable.cmd +278 -0
- forge/templates/skills/impeccable/scripts/live-browser-dom.js +321 -0
- forge/templates/skills/impeccable/scripts/live-browser-ignores.js +247 -0
- forge/templates/skills/impeccable/scripts/live-browser-session.js +184 -0
- forge/templates/skills/impeccable/scripts/live-browser.js +13646 -0
- forge/templates/skills/impeccable/scripts/modern-screenshot.umd.js +15 -0
- forge/templates/skills/remote-approval/SKILL.md +40 -0
- forge/templates/skills/security-audit/AI-AND-LLM.md +83 -0
- forge/templates/skills/security-audit/ATTACK-CLASSES.md +130 -0
- forge/templates/skills/security-audit/CLIENT-SIDE.md +83 -0
- forge/templates/skills/security-audit/CLOUD-AND-DEPLOYMENT.md +86 -0
- forge/templates/skills/security-audit/DATA-ISOLATION-AND-LIFECYCLE.md +84 -0
- forge/templates/skills/security-audit/DESKTOP-MOBILE-AND-LOCAL-IPC.md +89 -0
- forge/templates/skills/security-audit/HUNTING.md +251 -0
- forge/templates/skills/security-audit/LICENSE +21 -0
- forge/templates/skills/security-audit/MEMORY-SAFETY-AND-BINARY.md +101 -0
- forge/templates/skills/security-audit/NOTICE.md +6 -0
- forge/templates/skills/security-audit/PROTOCOLS-RPC-AND-MESSAGING.md +81 -0
- forge/templates/skills/security-audit/RECONNAISSANCE.md +156 -0
- forge/templates/skills/security-audit/RESOURCE-EXHAUSTION-AND-AVAILABILITY.md +78 -0
- forge/templates/skills/security-audit/SKILL.md +192 -0
- forge/templates/skills/security-audit/SUPPLY-CHAIN-AND-RELEASE.md +73 -0
- forge/templates/skills/security-audit/VALIDATION-AND-REPORTING.md +186 -0
- forge/templates/skills/security-audit/WEB-PROTOCOL-AND-AUTH.md +105 -0
- forge/templates/skills/security-audit/report-schema.json +461 -0
- forge/templates/skills/security-audit/validate-coverage-ledger.cjs +873 -0
- forge/templates/skills/security-audit/validate-findings.cjs +774 -0
- forge/templates/skills/simplified-technical-english/LICENSE +28 -0
- forge/templates/skills/simplified-technical-english/NOTICE.md +33 -0
- forge/templates/skills/simplified-technical-english/SKILL.md +127 -0
- forge/templates/skills/simplified-technical-english/examples/before-after.md +86 -0
- forge/templates/skills/simplified-technical-english/references/substitutions.md +113 -0
- forge/templates/skills/simplified-technical-english/references/writing-rules.md +209 -0
- forge/templates/skills/simplified-technical-english/scripts/ste_check.py +301 -0
- forge/templates/skills/test-audit/NOTICE.md +25 -0
- forge/templates/skills/test-audit/SKILL.md +182 -0
- forge/templates/start.md +27 -0
- forge/templates/starter/.env.example +14 -0
- forge/templates/starter/.gitignore +7 -0
- forge/templates/starter/.npmrc +1 -0
- forge/templates/starter/Dockerfile +23 -0
- forge/templates/starter/README.md +121 -0
- forge/templates/starter/apps/api/package.json +15 -0
- forge/templates/starter/apps/api/prisma/migrations/20261022000000_initial/migration.sql +68 -0
- forge/templates/starter/apps/api/prisma/migrations/20261025000000_organisations/migration.sql +44 -0
- forge/templates/starter/apps/api/prisma/migrations/20261025000100_invites/migration.sql +18 -0
- forge/templates/starter/apps/api/prisma/migrations/20261025000200_history/migration.sql +13 -0
- forge/templates/starter/apps/api/prisma/migrations/20261025000300_soft_delete_only/migration.sql +10 -0
- forge/templates/starter/apps/api/prisma/migrations/20261026000000_extensions/migration.sql +3 -0
- forge/templates/starter/apps/api/prisma/migrations/20261026000100_ids_and_updated_at/migration.sql +31 -0
- forge/templates/starter/apps/api/prisma/migrations/20261026000150_module_schemas/migration.sql +19 -0
- forge/templates/starter/apps/api/prisma/migrations/20261026000200_columns/migration.sql +51 -0
- forge/templates/starter/apps/api/prisma/migrations/20261026000300_history_subjects/migration.sql +11 -0
- forge/templates/starter/apps/api/prisma/migrations/20261027000000_agents/migration.sql +12 -0
- forge/templates/starter/apps/api/prisma/migrations/20261027000100_mcp/migration.sql +20 -0
- forge/templates/starter/apps/api/prisma/migrations/20261028000000_via_agent/migration.sql +7 -0
- forge/templates/starter/apps/api/prisma/migrations/20261102000000_sign_in_attempts/migration.sql +13 -0
- forge/templates/starter/apps/api/prisma/migrations/20261104000000_notifications/migration.sql +23 -0
- forge/templates/starter/apps/api/prisma/migrations/migration_lock.toml +1 -0
- forge/templates/starter/apps/api/prisma/schema/auth.prisma +65 -0
- forge/templates/starter/apps/api/prisma/schema/base.prisma +9 -0
- forge/templates/starter/apps/api/prisma/schema/history.prisma +19 -0
- forge/templates/starter/apps/api/prisma/schema/mcp.prisma +18 -0
- forge/templates/starter/apps/api/prisma/schema/notifications.prisma +20 -0
- forge/templates/starter/apps/api/prisma/schema/organisations.prisma +66 -0
- forge/templates/starter/apps/api/prisma/schema/projects.prisma +23 -0
- forge/templates/starter/apps/api/project.json +35 -0
- forge/templates/starter/apps/api/src/app.module.ts +36 -0
- forge/templates/starter/apps/api/src/health/health.controller.ts +16 -0
- forge/templates/starter/apps/api/src/health/health.module.ts +5 -0
- forge/templates/starter/apps/api/src/main.ts +44 -0
- forge/templates/starter/apps/api/src/setup-company.ts +33 -0
- forge/templates/starter/apps/api/test/agents.e2e-spec.ts +99 -0
- forge/templates/starter/apps/api/test/api.e2e-spec.ts +250 -0
- forge/templates/starter/apps/api/test/auth.e2e-spec.ts +287 -0
- forge/templates/starter/apps/api/test/database.e2e-spec.ts +171 -0
- forge/templates/starter/apps/api/test/environment.e2e-spec.ts +56 -0
- forge/templates/starter/apps/api/test/error-reports.e2e-spec.ts +72 -0
- forge/templates/starter/apps/api/test/exports.e2e-spec.ts +85 -0
- forge/templates/starter/apps/api/test/helpers.ts +103 -0
- forge/templates/starter/apps/api/test/history.e2e-spec.ts +93 -0
- forge/templates/starter/apps/api/test/invites.e2e-spec.ts +262 -0
- forge/templates/starter/apps/api/test/mcp.e2e-spec.ts +269 -0
- forge/templates/starter/apps/api/test/notifications.e2e-spec.ts +117 -0
- forge/templates/starter/apps/api/test/one-company.e2e-spec.ts +154 -0
- forge/templates/starter/apps/api/test/organisations.e2e-spec.ts +210 -0
- forge/templates/starter/apps/api/test/projects.e2e-spec.ts +824 -0
- forge/templates/starter/apps/api/test/soft-delete.e2e-spec.ts +31 -0
- forge/templates/starter/apps/api/tsconfig.json +44 -0
- forge/templates/starter/apps/api/tsconfig.test.json +17 -0
- forge/templates/starter/apps/api/vitest.config.ts +13 -0
- forge/templates/starter/apps/web/e2e/motion.spec.ts +88 -0
- forge/templates/starter/apps/web/e2e/rules/accept-invite.spec.ts +59 -0
- forge/templates/starter/apps/web/e2e/rules/members.spec.ts +212 -0
- forge/templates/starter/apps/web/e2e/rules/reset-password.spec.ts +78 -0
- forge/templates/starter/apps/web/e2e/rules/sign-in.spec.ts +87 -0
- forge/templates/starter/apps/web/e2e/served-app.spec.ts +19 -0
- forge/templates/starter/apps/web/index.html +14 -0
- forge/templates/starter/apps/web/package.json +9 -0
- forge/templates/starter/apps/web/playwright.config.ts +21 -0
- forge/templates/starter/apps/web/project.json +36 -0
- forge/templates/starter/apps/web/src/index.css +166 -0
- forge/templates/starter/apps/web/src/main.tsx +14 -0
- forge/templates/starter/apps/web/src/shared-states.test.tsx +40 -0
- forge/templates/starter/apps/web/tsconfig.json +30 -0
- forge/templates/starter/apps/web/vite.config.ts +19 -0
- forge/templates/starter/apps/web/vitest.config.ts +23 -0
- forge/templates/starter/apps/web/vitest.setup.ts +5 -0
- forge/templates/starter/compose.test.yml +66 -0
- forge/templates/starter/eslint.config.mjs +56 -0
- forge/templates/starter/libs/auth/contracts/package.json +17 -0
- forge/templates/starter/libs/auth/contracts/project.json +15 -0
- forge/templates/starter/libs/auth/contracts/src/index.ts +56 -0
- forge/templates/starter/libs/auth/contracts/tsconfig.json +18 -0
- forge/templates/starter/libs/auth/server/package.json +19 -0
- forge/templates/starter/libs/auth/server/project.json +15 -0
- forge/templates/starter/libs/auth/server/src/agents.controller.ts +24 -0
- forge/templates/starter/libs/auth/server/src/auth.controller.ts +136 -0
- forge/templates/starter/libs/auth/server/src/auth.dto.ts +53 -0
- forge/templates/starter/libs/auth/server/src/auth.module.ts +18 -0
- forge/templates/starter/libs/auth/server/src/auth.service.ts +251 -0
- forge/templates/starter/libs/auth/server/src/index.ts +3 -0
- forge/templates/starter/libs/auth/server/src/invites.controller.ts +37 -0
- forge/templates/starter/libs/auth/server/src/members.controller.ts +47 -0
- forge/templates/starter/libs/auth/server/src/session.guard.ts +52 -0
- forge/templates/starter/libs/auth/server/tsconfig.json +29 -0
- forge/templates/starter/libs/core/server/package.json +17 -0
- forge/templates/starter/libs/core/server/project.json +19 -0
- forge/templates/starter/libs/core/server/src/common/account-principal.ts +8 -0
- forge/templates/starter/libs/core/server/src/common/admin-only.decorator.ts +18 -0
- forge/templates/starter/libs/core/server/src/common/all-exceptions.filter.ts +55 -0
- forge/templates/starter/libs/core/server/src/common/api-envelope.decorator.ts +28 -0
- forge/templates/starter/libs/core/server/src/common/api-response.dto.ts +26 -0
- forge/templates/starter/libs/core/server/src/common/api-zod.decorator.ts +21 -0
- forge/templates/starter/libs/core/server/src/common/authenticated-request.ts +7 -0
- forge/templates/starter/libs/core/server/src/common/common.module.ts +7 -0
- forge/templates/starter/libs/core/server/src/common/correlation.middleware.ts +12 -0
- forge/templates/starter/libs/core/server/src/common/csrf.guard.ts +35 -0
- forge/templates/starter/libs/core/server/src/common/csv.ts +14 -0
- forge/templates/starter/libs/core/server/src/common/current-account.decorator.ts +11 -0
- forge/templates/starter/libs/core/server/src/common/envelope.interceptor.ts +10 -0
- forge/templates/starter/libs/core/server/src/common/error-report.ts +43 -0
- forge/templates/starter/libs/core/server/src/common/json-logger.test.ts +95 -0
- forge/templates/starter/libs/core/server/src/common/json-logger.ts +57 -0
- forge/templates/starter/libs/core/server/src/common/permissions.ts +49 -0
- forge/templates/starter/libs/core/server/src/common/prompts.ts +42 -0
- forge/templates/starter/libs/core/server/src/common/public.decorator.ts +4 -0
- forge/templates/starter/libs/core/server/src/common/request-log.middleware.ts +19 -0
- forge/templates/starter/libs/core/server/src/common/resources.ts +88 -0
- forge/templates/starter/libs/core/server/src/common/retry-keys.ts +31 -0
- forge/templates/starter/libs/core/server/src/common/tools.test.ts +205 -0
- forge/templates/starter/libs/core/server/src/common/tools.ts +266 -0
- forge/templates/starter/libs/core/server/src/common/zod-validation.pipe.ts +22 -0
- forge/templates/starter/libs/core/server/src/config/environment.ts +95 -0
- forge/templates/starter/libs/core/server/src/index.ts +27 -0
- forge/templates/starter/libs/core/server/src/mail/mail.module.ts +19 -0
- forge/templates/starter/libs/core/server/src/mail/mail.provider.ts +22 -0
- forge/templates/starter/libs/core/server/src/prisma/prisma.module.ts +7 -0
- forge/templates/starter/libs/core/server/src/prisma/prisma.service.ts +19 -0
- forge/templates/starter/libs/core/server/tsconfig.json +23 -0
- forge/templates/starter/libs/core/web/package.json +16 -0
- forge/templates/starter/libs/core/web/project.json +15 -0
- forge/templates/starter/libs/core/web/src/api-client.ts +42 -0
- forge/templates/starter/libs/core/web/src/error-report.ts +12 -0
- forge/templates/starter/libs/core/web/src/form-errors.ts +18 -0
- forge/templates/starter/libs/core/web/src/index.ts +4 -0
- forge/templates/starter/libs/core/web/src/permissions.ts +9 -0
- forge/templates/starter/libs/core/web/src/query-client.ts +10 -0
- forge/templates/starter/libs/core/web/tsconfig.json +18 -0
- forge/templates/starter/libs/history/contracts/package.json +14 -0
- forge/templates/starter/libs/history/contracts/project.json +15 -0
- forge/templates/starter/libs/history/contracts/src/index.ts +2 -0
- forge/templates/starter/libs/history/contracts/src/service.ts +21 -0
- forge/templates/starter/libs/history/contracts/tsconfig.json +14 -0
- forge/templates/starter/libs/history/server/package.json +19 -0
- forge/templates/starter/libs/history/server/project.json +19 -0
- forge/templates/starter/libs/history/server/src/history.controller.ts +45 -0
- forge/templates/starter/libs/history/server/src/history.dto.ts +22 -0
- forge/templates/starter/libs/history/server/src/history.module.ts +12 -0
- forge/templates/starter/libs/history/server/src/history.service.test.ts +18 -0
- forge/templates/starter/libs/history/server/src/history.service.ts +42 -0
- forge/templates/starter/libs/history/server/src/index.ts +2 -0
- forge/templates/starter/libs/history/server/tsconfig.json +29 -0
- forge/templates/starter/libs/mcp/server/package.json +18 -0
- forge/templates/starter/libs/mcp/server/project.json +15 -0
- forge/templates/starter/libs/mcp/server/src/index.ts +1 -0
- forge/templates/starter/libs/mcp/server/src/mcp.controller.ts +102 -0
- forge/templates/starter/libs/mcp/server/src/mcp.module.ts +5 -0
- forge/templates/starter/libs/mcp/server/tsconfig.json +26 -0
- forge/templates/starter/libs/notifications/contracts/package.json +14 -0
- forge/templates/starter/libs/notifications/contracts/project.json +12 -0
- forge/templates/starter/libs/notifications/contracts/src/index.ts +1 -0
- forge/templates/starter/libs/notifications/contracts/src/service.ts +19 -0
- forge/templates/starter/libs/notifications/contracts/tsconfig.json +12 -0
- forge/templates/starter/libs/notifications/server/package.json +18 -0
- forge/templates/starter/libs/notifications/server/project.json +12 -0
- forge/templates/starter/libs/notifications/server/src/index.ts +1 -0
- forge/templates/starter/libs/notifications/server/src/notifications.controller.ts +21 -0
- forge/templates/starter/libs/notifications/server/src/notifications.dto.ts +28 -0
- forge/templates/starter/libs/notifications/server/src/notifications.module.ts +12 -0
- forge/templates/starter/libs/notifications/server/src/notifications.service.ts +36 -0
- forge/templates/starter/libs/notifications/server/tsconfig.json +18 -0
- forge/templates/starter/libs/organisations/contracts/package.json +14 -0
- forge/templates/starter/libs/organisations/contracts/project.json +15 -0
- forge/templates/starter/libs/organisations/contracts/src/index.ts +54 -0
- forge/templates/starter/libs/organisations/contracts/src/service.ts +29 -0
- forge/templates/starter/libs/organisations/contracts/tsconfig.json +14 -0
- forge/templates/starter/libs/organisations/server/package.json +20 -0
- forge/templates/starter/libs/organisations/server/project.json +15 -0
- forge/templates/starter/libs/organisations/server/src/index.ts +2 -0
- forge/templates/starter/libs/organisations/server/src/organisations.controller.ts +101 -0
- forge/templates/starter/libs/organisations/server/src/organisations.dto.ts +46 -0
- forge/templates/starter/libs/organisations/server/src/organisations.module.ts +14 -0
- forge/templates/starter/libs/organisations/server/src/organisations.service.ts +221 -0
- forge/templates/starter/libs/organisations/server/tsconfig.json +32 -0
- forge/templates/starter/libs/projects/contracts/package.json +14 -0
- forge/templates/starter/libs/projects/contracts/project.json +15 -0
- forge/templates/starter/libs/projects/contracts/src/index.ts +87 -0
- forge/templates/starter/libs/projects/contracts/tsconfig.json +14 -0
- forge/templates/starter/libs/projects/server/package.json +21 -0
- forge/templates/starter/libs/projects/server/project.json +15 -0
- forge/templates/starter/libs/projects/server/src/index.ts +2 -0
- forge/templates/starter/libs/projects/server/src/projects.controller.ts +165 -0
- forge/templates/starter/libs/projects/server/src/projects.dto.ts +77 -0
- forge/templates/starter/libs/projects/server/src/projects.module.ts +19 -0
- forge/templates/starter/libs/projects/server/src/projects.permissions.ts +7 -0
- forge/templates/starter/libs/projects/server/src/projects.service.ts +314 -0
- forge/templates/starter/libs/projects/server/src/projects.tools.ts +28 -0
- forge/templates/starter/libs/projects/server/tsconfig.json +29 -0
- forge/templates/starter/libs/shared/ui/components.json +21 -0
- forge/templates/starter/libs/shared/ui/package.json +27 -0
- forge/templates/starter/libs/shared/ui/project.json +15 -0
- forge/templates/starter/libs/shared/ui/src/components/states.tsx +73 -0
- forge/templates/starter/libs/shared/ui/src/components/theme-provider.tsx +39 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/LICENSE +21 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/alert-dialog.tsx +196 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/alert.tsx +65 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/avatar.tsx +108 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/badge.tsx +47 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/breadcrumb.tsx +108 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/button.tsx +63 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/card.tsx +91 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/checkbox.tsx +29 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/collapsible.tsx +33 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/command.tsx +184 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/dialog.tsx +158 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/dropdown-menu.tsx +256 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/empty.tsx +103 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/form.tsx +167 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/input.tsx +20 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/label.tsx +23 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/popover.tsx +88 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/select.tsx +189 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/separator.tsx +27 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/sheet.tsx +142 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/sidebar.tsx +726 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/skeleton.tsx +13 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/sonner.tsx +40 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/switch.tsx +32 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/table.tsx +115 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/textarea.tsx +17 -0
- forge/templates/starter/libs/shared/ui/src/components/ui/tooltip.tsx +56 -0
- forge/templates/starter/libs/shared/ui/src/hooks/use-mobile.ts +19 -0
- forge/templates/starter/libs/shared/ui/src/lib/utils.ts +6 -0
- forge/templates/starter/libs/shared/ui/tsconfig.json +23 -0
- forge/templates/starter/libs/shared/util/package.json +14 -0
- forge/templates/starter/libs/shared/util/project.json +19 -0
- forge/templates/starter/libs/shared/util/src/csv-field.ts +6 -0
- forge/templates/starter/libs/shared/util/src/envelope.ts +9 -0
- forge/templates/starter/libs/shared/util/src/format.test.ts +33 -0
- forge/templates/starter/libs/shared/util/src/format.ts +43 -0
- forge/templates/starter/libs/shared/util/src/index.ts +12 -0
- forge/templates/starter/libs/shared/util/tsconfig.json +14 -0
- forge/templates/starter/nx.json +7 -0
- forge/templates/starter/package.json +97 -0
- forge/templates/starter/pnpm-lock.yaml +11587 -0
- forge/templates/starter/pnpm-workspace.yaml +4 -0
- forge/templates/starter/prisma.config.ts +13 -0
- forge/templates/starter/scripts/affected.mjs +27 -0
- forge/templates/starter/scripts/test-build.mjs +29 -0
- forge/templates/starter/scripts/test.mjs +107 -0
- forge/templates/starter/services.toml +7 -0
- forge/templates/starter/tsconfig.base.json +15 -0
- forge/templates/starter-python/.env.example +8 -0
- forge/templates/starter-python/.gitignore +13 -0
- forge/templates/starter-python/Dockerfile +30 -0
- forge/templates/starter-python/README.md +101 -0
- forge/templates/starter-python/apps/api/.python-version +1 -0
- forge/templates/starter-python/apps/api/alembic.ini +38 -0
- forge/templates/starter-python/apps/api/app/__init__.py +1 -0
- forge/templates/starter-python/apps/api/app/auth/__init__.py +27 -0
- forge/templates/starter-python/apps/api/app/auth/models.py +111 -0
- forge/templates/starter-python/apps/api/app/auth/routes.py +398 -0
- forge/templates/starter-python/apps/api/app/auth/schema.py +117 -0
- forge/templates/starter-python/apps/api/app/auth/service.py +453 -0
- forge/templates/starter-python/apps/api/app/core/__init__.py +89 -0
- forge/templates/starter-python/apps/api/app/core/admin.py +23 -0
- forge/templates/starter-python/apps/api/app/core/config.py +83 -0
- forge/templates/starter-python/apps/api/app/core/csv.py +40 -0
- forge/templates/starter-python/apps/api/app/core/database.py +21 -0
- forge/templates/starter-python/apps/api/app/core/envelope.py +40 -0
- forge/templates/starter-python/apps/api/app/core/error_report.py +85 -0
- forge/templates/starter-python/apps/api/app/core/errors.py +153 -0
- forge/templates/starter-python/apps/api/app/core/logging.py +66 -0
- forge/templates/starter-python/apps/api/app/core/mail.py +34 -0
- forge/templates/starter-python/apps/api/app/core/permissions.py +59 -0
- forge/templates/starter-python/apps/api/app/core/principal.py +12 -0
- forge/templates/starter-python/apps/api/app/core/prompts.py +96 -0
- forge/templates/starter-python/apps/api/app/core/resources.py +230 -0
- forge/templates/starter-python/apps/api/app/core/retry_keys.py +101 -0
- forge/templates/starter-python/apps/api/app/core/schema.py +13 -0
- forge/templates/starter-python/apps/api/app/core/security.py +197 -0
- forge/templates/starter-python/apps/api/app/core/tools.py +1117 -0
- forge/templates/starter-python/apps/api/app/history/__init__.py +5 -0
- forge/templates/starter-python/apps/api/app/history/models.py +48 -0
- forge/templates/starter-python/apps/api/app/history/routes.py +65 -0
- forge/templates/starter-python/apps/api/app/history/schema.py +29 -0
- forge/templates/starter-python/apps/api/app/history/service.py +77 -0
- forge/templates/starter-python/apps/api/app/main.py +115 -0
- forge/templates/starter-python/apps/api/app/mcp/__init__.py +3 -0
- forge/templates/starter-python/apps/api/app/mcp/server.py +192 -0
- forge/templates/starter-python/apps/api/app/notifications/__init__.py +5 -0
- forge/templates/starter-python/apps/api/app/notifications/models.py +62 -0
- forge/templates/starter-python/apps/api/app/notifications/routes.py +25 -0
- forge/templates/starter-python/apps/api/app/notifications/schema.py +39 -0
- forge/templates/starter-python/apps/api/app/notifications/service.py +70 -0
- forge/templates/starter-python/apps/api/app/openapi.py +17 -0
- forge/templates/starter-python/apps/api/app/organisations/__init__.py +10 -0
- forge/templates/starter-python/apps/api/app/organisations/models.py +128 -0
- forge/templates/starter-python/apps/api/app/organisations/routes.py +176 -0
- forge/templates/starter-python/apps/api/app/organisations/schema.py +76 -0
- forge/templates/starter-python/apps/api/app/organisations/service.py +403 -0
- forge/templates/starter-python/apps/api/app/projects/__init__.py +14 -0
- forge/templates/starter-python/apps/api/app/projects/models.py +67 -0
- forge/templates/starter-python/apps/api/app/projects/permissions.py +13 -0
- forge/templates/starter-python/apps/api/app/projects/routes.py +246 -0
- forge/templates/starter-python/apps/api/app/projects/schema.py +118 -0
- forge/templates/starter-python/apps/api/app/projects/service.py +359 -0
- forge/templates/starter-python/apps/api/app/projects/tools.py +28 -0
- forge/templates/starter-python/apps/api/app/setup_company.py +56 -0
- forge/templates/starter-python/apps/api/migrations/env.py +51 -0
- forge/templates/starter-python/apps/api/migrations/script.py.mako +25 -0
- forge/templates/starter-python/apps/api/migrations/versions/0001_initial.py +167 -0
- forge/templates/starter-python/apps/api/migrations/versions/0002_soft_delete_only.py +31 -0
- forge/templates/starter-python/apps/api/migrations/versions/0003_organisations.py +115 -0
- forge/templates/starter-python/apps/api/migrations/versions/0004_invites.py +58 -0
- forge/templates/starter-python/apps/api/migrations/versions/0005_history.py +51 -0
- forge/templates/starter-python/apps/api/migrations/versions/0006_extensions.py +22 -0
- forge/templates/starter-python/apps/api/migrations/versions/0007_ids_and_updated_at.py +52 -0
- forge/templates/starter-python/apps/api/migrations/versions/0008_module_schemas.py +42 -0
- forge/templates/starter-python/apps/api/migrations/versions/0009_columns.py +97 -0
- forge/templates/starter-python/apps/api/migrations/versions/0010_history_subjects.py +46 -0
- forge/templates/starter-python/apps/api/migrations/versions/0011_agents.py +44 -0
- forge/templates/starter-python/apps/api/migrations/versions/0012_mcp.py +71 -0
- forge/templates/starter-python/apps/api/migrations/versions/0013_via_agent.py +23 -0
- forge/templates/starter-python/apps/api/migrations/versions/20261103_sign_in_attempts.py +48 -0
- forge/templates/starter-python/apps/api/migrations/versions/20261105_notifications.py +84 -0
- forge/templates/starter-python/apps/api/pyproject.toml +86 -0
- forge/templates/starter-python/apps/api/tests/conftest.py +146 -0
- forge/templates/starter-python/apps/api/tests/test_agents.py +169 -0
- forge/templates/starter-python/apps/api/tests/test_api.py +319 -0
- forge/templates/starter-python/apps/api/tests/test_auth.py +428 -0
- forge/templates/starter-python/apps/api/tests/test_config.py +58 -0
- forge/templates/starter-python/apps/api/tests/test_database.py +204 -0
- forge/templates/starter-python/apps/api/tests/test_error_reports.py +119 -0
- forge/templates/starter-python/apps/api/tests/test_history.py +206 -0
- forge/templates/starter-python/apps/api/tests/test_invites.py +427 -0
- forge/templates/starter-python/apps/api/tests/test_logging.py +56 -0
- forge/templates/starter-python/apps/api/tests/test_mcp.py +556 -0
- forge/templates/starter-python/apps/api/tests/test_module_schemas.py +100 -0
- forge/templates/starter-python/apps/api/tests/test_notifications.py +182 -0
- forge/templates/starter-python/apps/api/tests/test_one_company.py +188 -0
- forge/templates/starter-python/apps/api/tests/test_organisations.py +231 -0
- forge/templates/starter-python/apps/api/tests/test_projects.py +874 -0
- forge/templates/starter-python/apps/api/tests/test_soft_delete.py +80 -0
- forge/templates/starter-python/apps/api/tests/test_tools.py +395 -0
- forge/templates/starter-python/apps/api/uv.lock +1277 -0
- forge/templates/starter-python/compose.test.yml +63 -0
- forge/templates/starter-python/eslint.config.mjs +49 -0
- forge/templates/starter-python/libs/auth/contracts/package.json +17 -0
- forge/templates/starter-python/libs/auth/contracts/src/index.ts +51 -0
- forge/templates/starter-python/libs/auth/contracts/tsconfig.json +16 -0
- forge/templates/starter-python/libs/history/contracts/package.json +17 -0
- forge/templates/starter-python/libs/history/contracts/src/index.ts +3 -0
- forge/templates/starter-python/libs/history/contracts/tsconfig.json +16 -0
- forge/templates/starter-python/libs/organisations/contracts/package.json +17 -0
- forge/templates/starter-python/libs/organisations/contracts/src/index.ts +30 -0
- forge/templates/starter-python/libs/organisations/contracts/tsconfig.json +16 -0
- forge/templates/starter-python/libs/projects/contracts/package.json +17 -0
- forge/templates/starter-python/libs/projects/contracts/src/index.ts +65 -0
- forge/templates/starter-python/libs/projects/contracts/tsconfig.json +16 -0
- forge/templates/starter-python/libs/shared/api-types/package.json +14 -0
- forge/templates/starter-python/libs/shared/api-types/tsconfig.json +14 -0
- forge/templates/starter-python/package.json +71 -0
- forge/templates/starter-python/pnpm-lock.yaml +7574 -0
- forge/templates/starter-python/pnpm-workspace.yaml +4 -0
- forge/templates/starter-python/scripts/affected.mjs +20 -0
- forge/templates/starter-python/scripts/test-browser.mjs +39 -0
- forge/templates/starter-python/scripts/test.mjs +86 -0
- forge/templates/starter-python/services.toml +7 -0
- forge/templates/story.md +89 -0
- forge/time_records.py +1022 -0
- forge/ui_checks.py +97 -0
- forge/upgrade.py +368 -0
- forge/worker.py +876 -0
- symphony_forge-1.2.44.dist-info/METADATA +7 -0
- symphony_forge-1.2.44.dist-info/RECORD +623 -0
- symphony_forge-1.2.44.dist-info/WHEEL +4 -0
- symphony_forge-1.2.44.dist-info/entry_points.txt +2 -0
- symphony_forge-1.2.44.dist-info/licenses/LICENSE +21 -0
forge/__init__.py
ADDED
forge/app_baseline.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Ship client app skills, check shadcn/ui additions and validate services lists."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ast
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import tomllib
|
|
8
|
+
from pathlib import Path, PurePosixPath
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from forge import repo, ui_checks
|
|
12
|
+
|
|
13
|
+
REFUSALS = {
|
|
14
|
+
"design": ("This change fails the design checks: {problems}.",
|
|
15
|
+
"fix them, or add the waiver comment shown under a problem with the reason, "
|
|
16
|
+
"then forge close {item}"),
|
|
17
|
+
"contract": ("These new migrations can break the previous release: {problems}.",
|
|
18
|
+
"add a Contract: comment in each migration explaining why the live release "
|
|
19
|
+
"no longer reads the table or column, then forge close {item}"),
|
|
20
|
+
"services": ("services.toml {problem}.",
|
|
21
|
+
"fix services.toml to match the Dockerfiles, then forge close {item}"),
|
|
22
|
+
"shadcn": ("This app uses shadcn/ui only, and this change adds {problems}.",
|
|
23
|
+
"use the shadcn/ui component (npx shadcn@4.21.4 add <name>) and remove the copy "
|
|
24
|
+
"or the library, then forge close {item}"),
|
|
25
|
+
}
|
|
26
|
+
# Component libraries, not the primitives and utilities used by shadcn/ui itself.
|
|
27
|
+
LIBRARIES = frozenset({
|
|
28
|
+
"@mui/material", "@mui/joy", "@chakra-ui/react", "antd", "@mantine/core",
|
|
29
|
+
"@nextui-org/react", "@heroui/react", "react-bootstrap", "bootstrap",
|
|
30
|
+
"semantic-ui-react", "primereact", "rsuite", "grommet", "evergreen-ui",
|
|
31
|
+
"baseui", "theme-ui", "rebass", "@fluentui/react", "@fluentui/react-components",
|
|
32
|
+
"@blueprintjs/core", "@headlessui/react", "daisyui", "flowbite-react",
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def check(top: Path, cfg: dict[str, Any], base: str, files: list[str]) -> None:
|
|
37
|
+
"""Refuse added UI libraries and design problems in changed client files."""
|
|
38
|
+
if cfg.get("repo") != "client":
|
|
39
|
+
return
|
|
40
|
+
paths = repo.git("ls-tree", "-r", "--name-only", "-z", "HEAD", cwd=top).split("\0")
|
|
41
|
+
shadcn = any(PurePosixPath(path).name == "components.json" for path in paths)
|
|
42
|
+
|
|
43
|
+
def libraries(ref: str) -> set[str]:
|
|
44
|
+
found = set()
|
|
45
|
+
for path in repo.git("ls-tree", "-r", "--name-only", "-z", ref, cwd=top).split("\0"):
|
|
46
|
+
if PurePosixPath(path).name == "package.json":
|
|
47
|
+
package = json.loads(repo.git("show", f"{ref}:{path}", cwd=top))
|
|
48
|
+
for group in ("dependencies", "devDependencies"):
|
|
49
|
+
found.update(LIBRARIES.intersection(package.get(group, {})))
|
|
50
|
+
return found
|
|
51
|
+
|
|
52
|
+
problems = sorted(libraries("HEAD") - libraries(base)) if shadcn else []
|
|
53
|
+
if problems:
|
|
54
|
+
repo.refuse(REFUSALS["shadcn"], problems="; ".join(problems),
|
|
55
|
+
item=repo.current_branch(top).partition("/")[2])
|
|
56
|
+
problems = ui_checks.problems(top, files) + ui_checks.theme(top, files)
|
|
57
|
+
if problems:
|
|
58
|
+
repo.refuse(REFUSALS["design"], problems="\n" + "\n".join(problems),
|
|
59
|
+
item=repo.current_branch(top).partition("/")[2])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def services(top: Path, cfg: dict[str, Any]) -> None:
|
|
63
|
+
"""Check the committed list against this branch's committed Dockerfiles."""
|
|
64
|
+
if cfg.get("repo") != "client":
|
|
65
|
+
return
|
|
66
|
+
paths = set(repo.git("ls-tree", "-r", "--name-only", "-z", "HEAD", cwd=top).split("\0")) - {""}
|
|
67
|
+
if "services.toml" not in paths:
|
|
68
|
+
return
|
|
69
|
+
item = repo.current_branch(top).partition("/")[2]
|
|
70
|
+
try:
|
|
71
|
+
listed = tomllib.loads(repo.git("show", "HEAD:services.toml", cwd=top)).get("service", [])
|
|
72
|
+
except tomllib.TOMLDecodeError as error:
|
|
73
|
+
repo.refuse(REFUSALS["services"], problem=f"is not valid TOML: {error}", item=item)
|
|
74
|
+
if not isinstance(listed, list):
|
|
75
|
+
listed = []
|
|
76
|
+
problems = []
|
|
77
|
+
main = 0
|
|
78
|
+
# ponytail: no port, health, command or subdomain checks; add one when a deploy shows the need.
|
|
79
|
+
for service in listed:
|
|
80
|
+
dockerfile = service.get("dockerfile") if isinstance(service, dict) else None
|
|
81
|
+
if not isinstance(dockerfile, str):
|
|
82
|
+
problems.append("has a service with no dockerfile")
|
|
83
|
+
elif dockerfile not in paths:
|
|
84
|
+
problems.append(f"names {dockerfile}, which this branch does not have")
|
|
85
|
+
main += isinstance(service, dict) and service.get("expose") == "main"
|
|
86
|
+
if main != 1:
|
|
87
|
+
problems.append(f'has {main} services with expose = "main"; it needs exactly one')
|
|
88
|
+
if problems:
|
|
89
|
+
repo.refuse(REFUSALS["services"], problem="; ".join(problems), item=item)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def migrations(top: Path, cfg: dict[str, Any], base: str) -> None:
|
|
93
|
+
"""Hold destructive additions until their migration states the contract decision."""
|
|
94
|
+
if cfg.get("repo") != "client" or repo.is_prototype(top, cfg, refs=(base, "HEAD")):
|
|
95
|
+
return
|
|
96
|
+
destructive_sql = re.compile(
|
|
97
|
+
r"\bDROP\s+TABLE\b|\bALTER\s+TABLE\b.*?\b(?:DROP\s+COLUMN\b|"
|
|
98
|
+
r"RENAME\s+(?:COLUMN\b|TO\b)|ALTER\s+(?:COLUMN\s+)?\S+\s+(?:SET\s+DATA\s+)?TYPE\b)",
|
|
99
|
+
re.I | re.S)
|
|
100
|
+
problems = []
|
|
101
|
+
for path in repo.git("diff", "--name-only", "-z", "--no-renames", "--diff-filter=A",
|
|
102
|
+
base, "HEAD", cwd=top).split("\0"):
|
|
103
|
+
file = PurePosixPath(path)
|
|
104
|
+
sql = file.match("prisma/migrations/*/migration.sql")
|
|
105
|
+
python = (file.suffix == ".py" and file.parent.name == "versions"
|
|
106
|
+
and file.parent.parent.name == "migrations")
|
|
107
|
+
if not (sql or python):
|
|
108
|
+
continue
|
|
109
|
+
text = repo.git("show", f"HEAD:{path}", cwd=top)
|
|
110
|
+
comment = "--" if sql else "#"
|
|
111
|
+
if re.search(rf"^\s*{comment}\s*Contract:[^\S\n]*\S", text, re.M):
|
|
112
|
+
continue
|
|
113
|
+
statements = []
|
|
114
|
+
if sql:
|
|
115
|
+
uncommented = re.sub(r"--[^\n]*|/\*.*?\*/", "", text, flags=re.S)
|
|
116
|
+
statements = [statement.strip() for statement in uncommented.split(";")
|
|
117
|
+
if destructive_sql.search(statement)]
|
|
118
|
+
else:
|
|
119
|
+
for function in ast.parse(text).body:
|
|
120
|
+
if not isinstance(function, (ast.FunctionDef, ast.AsyncFunctionDef)) or function.name != "upgrade":
|
|
121
|
+
continue
|
|
122
|
+
for node in ast.walk(function):
|
|
123
|
+
if not (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)
|
|
124
|
+
and isinstance(node.func.value, ast.Name) and node.func.value.id == "op"):
|
|
125
|
+
continue
|
|
126
|
+
source = ast.get_source_segment(text, node) or ""
|
|
127
|
+
method = node.func.attr
|
|
128
|
+
if (method in {"drop_column", "drop_table", "rename_table"}
|
|
129
|
+
or (method == "alter_column" and any(
|
|
130
|
+
keyword.arg in {"type_", "new_column_name"} for keyword in node.keywords))
|
|
131
|
+
or (method == "execute" and destructive_sql.search(source))):
|
|
132
|
+
statements.append(source)
|
|
133
|
+
problems.extend(f"{path}: {' '.join(statement.split())}" for statement in statements)
|
|
134
|
+
if problems:
|
|
135
|
+
repo.refuse(REFUSALS["contract"], problems="; ".join(problems),
|
|
136
|
+
item=repo.current_branch(top).partition("/")[2])
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def ships(top: Path, cfg: dict[str, Any]) -> dict[str, str]:
|
|
140
|
+
from forge import sync
|
|
141
|
+
|
|
142
|
+
skill = sync._synced_text(".codex/skills/app-baseline/SKILL.md",
|
|
143
|
+
"skills/app-baseline/SKILL.md")
|
|
144
|
+
database = (sync.TEMPLATES / "skills/database/SKILL.md").read_text(encoding="utf-8")
|
|
145
|
+
agents = (sync.TEMPLATES / "skills/agents/SKILL.md").read_text(encoding="utf-8")
|
|
146
|
+
return {f"{host}/skills/{name}/SKILL.md": text
|
|
147
|
+
for host in (".claude", ".codex")
|
|
148
|
+
for name, text in (("app-baseline", skill), ("database", database), ("agents", agents))}
|
forge/approval.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"""v1 approval: one human approval binds a story doc's "What changes for you" and "Done when".
|
|
2
|
+
|
|
3
|
+
`forge hook approval` runs after Claude Code's ExitPlanMode and AskUserQuestion and after Codex's
|
|
4
|
+
request_user_input. It keeps today's trust checks (docs/specs/plan-approval.md), applied to the
|
|
5
|
+
section hash: a completed call, the exact digest, the runtime, the tool, a stable session and event
|
|
6
|
+
identity, replay refusal and exactly one story waiting for that digest. It also holds the client
|
|
7
|
+
sign-off gate, and counts every answered question as a human touch of the item being worked on.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from forge import __version__, design, machine, repo, story
|
|
19
|
+
|
|
20
|
+
REFUSALS = {
|
|
21
|
+
"bad_payload": ("The hook input is not a JSON object.", "forge doctor"),
|
|
22
|
+
"wrong_runtime": ("{tool} is not {runtime}'s approval tool, so nothing was recorded.", "forge next"),
|
|
23
|
+
"not_completed": ("The approval question was cancelled or failed, so nothing was recorded.",
|
|
24
|
+
"forge next"),
|
|
25
|
+
"unsupported": ("The approval doesn't match the approval contract, so nothing was recorded.",
|
|
26
|
+
"forge next"),
|
|
27
|
+
"not_approved": ('The answer was "{answer}", not "Approve plan", so nothing was recorded.',
|
|
28
|
+
"forge next"),
|
|
29
|
+
"no_identity": ("The approval has no session or event id to guard against a replay, so nothing "
|
|
30
|
+
"was recorded.", "forge next"),
|
|
31
|
+
"replay": ("This approval was already recorded once; a replay records nothing.", "forge next"),
|
|
32
|
+
"no_match": ("The approved plan matches no story doc waiting for approval; it may have changed "
|
|
33
|
+
"since it was shown.", "forge next"),
|
|
34
|
+
"several": ("The approved plan matches {count} story docs, so nothing was recorded.",
|
|
35
|
+
'give each a different "What changes for you" or "Done when", then forge next'),
|
|
36
|
+
"no_signoff": ("This client's sign-off isn't recorded yet, so the approval was not recorded.",
|
|
37
|
+
'forge decision new client-signoff, then forge decision accept client-signoff '
|
|
38
|
+
'--by "<client name>"'),
|
|
39
|
+
}
|
|
40
|
+
OTHER_VERSION = ("{repo} pins Forge {pinned}, but {installed} is installed; the approval is recorded "
|
|
41
|
+
"anyway. {advice}")
|
|
42
|
+
|
|
43
|
+
TOOLS = {"claude": "ExitPlanMode", "codex": "request_user_input"}
|
|
44
|
+
QUESTIONS = ("AskUserQuestion", "request_user_input")
|
|
45
|
+
SUCCESS = {"success", "succeeded", "completed"}
|
|
46
|
+
CHOICES = ["Approve plan", "Request changes", "Stop"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def ships(top: Path, cfg: dict[str, Any]) -> dict[str, str]:
|
|
50
|
+
from forge import sync
|
|
51
|
+
|
|
52
|
+
return {".claude/skills/remote-approval/SKILL.md":
|
|
53
|
+
sync._synced_text(".claude/skills/remote-approval/SKILL.md",
|
|
54
|
+
"skills/remote-approval/SKILL.md")}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def hook(args: Any) -> int:
|
|
58
|
+
try:
|
|
59
|
+
payload = json.loads(sys.stdin.read() or "null")
|
|
60
|
+
except ValueError:
|
|
61
|
+
payload = None
|
|
62
|
+
if not isinstance(payload, dict):
|
|
63
|
+
repo.refuse(REFUSALS["bad_payload"])
|
|
64
|
+
tool, answered = payload.get("tool_name"), _answered(payload)
|
|
65
|
+
approving = tool == "ExitPlanMode" or (tool == "request_user_input" and _asks_approval(payload))
|
|
66
|
+
if not approving and not (tool in QUESTIONS and answered):
|
|
67
|
+
return 0 # any other tool (forge doctor's sample among them) records nothing
|
|
68
|
+
cwd = payload.get("cwd")
|
|
69
|
+
top = repo.root(cwd if isinstance(cwd, str) and Path(cwd).is_dir() else None)
|
|
70
|
+
if approving:
|
|
71
|
+
try:
|
|
72
|
+
_approve(top, payload, tool)
|
|
73
|
+
except repo.Refused as refusal:
|
|
74
|
+
if answered:
|
|
75
|
+
_touch(top)
|
|
76
|
+
last_refusal(top).write_text(str(refusal).partition("\nNext: ")[0], encoding="utf-8")
|
|
77
|
+
raise
|
|
78
|
+
last_refusal(top).unlink(missing_ok=True)
|
|
79
|
+
else:
|
|
80
|
+
_touch(top)
|
|
81
|
+
return 0
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def waiting_digest(key: str, top: Path) -> str | None:
|
|
85
|
+
"""The story doc's section hash when the story waits for a first or renewed approval."""
|
|
86
|
+
state, doc = repo.read_state(key, top), top / "plans" / f"{key}.md"
|
|
87
|
+
if state is None or not doc.is_file():
|
|
88
|
+
return None
|
|
89
|
+
text = doc.read_text(encoding="utf-8")
|
|
90
|
+
digest = story.approval_hash(text)
|
|
91
|
+
if (state.get("approval") or {}).get("hash") == digest:
|
|
92
|
+
try:
|
|
93
|
+
design.check(top, text, required=False)
|
|
94
|
+
except (repo.Refused, ValueError):
|
|
95
|
+
return digest
|
|
96
|
+
return None
|
|
97
|
+
return digest
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def last_refusal(top: Path) -> Path:
|
|
101
|
+
"""Why the last approval recorded nothing, for `forge next`. Local, never committed."""
|
|
102
|
+
return repo.forge_dir(top) / "approval-refused.txt"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _approve(top: Path, payload: dict[str, Any], tool: str) -> None:
|
|
106
|
+
runtime = "codex" if "turn_id" in payload else "claude" # ponytail: only Codex payloads carry turn_id
|
|
107
|
+
if tool != TOOLS[runtime]:
|
|
108
|
+
repo.refuse(REFUSALS["wrong_runtime"], tool=tool, runtime=runtime.capitalize())
|
|
109
|
+
if not _completed(payload):
|
|
110
|
+
repo.refuse(REFUSALS["not_completed"])
|
|
111
|
+
digest = _claude_digest(payload) if runtime == "claude" else _codex_digest(payload)
|
|
112
|
+
session, event = _text(payload.get("session_id")), _text(payload.get("tool_use_id"))
|
|
113
|
+
if not session or not event:
|
|
114
|
+
repo.refuse(REFUSALS["no_identity"])
|
|
115
|
+
marker = hashlib.sha256(f"{runtime}\0{session}\0{event}".encode("utf-8")).hexdigest()
|
|
116
|
+
chat_used = repo.forge_dir(top) / "approvals" / marker
|
|
117
|
+
if chat_used.exists():
|
|
118
|
+
repo.refuse(REFUSALS["replay"])
|
|
119
|
+
checkouts = dict.fromkeys([machine.main_checkout(top), *machine.remembered()])
|
|
120
|
+
matches = [(key, path) for checkout in checkouts
|
|
121
|
+
for key, path in story.stories_here(checkout).items()
|
|
122
|
+
if waiting_digest(key, path) == digest]
|
|
123
|
+
if not matches:
|
|
124
|
+
repo.refuse(REFUSALS["no_match"])
|
|
125
|
+
if len(matches) > 1:
|
|
126
|
+
repo.refuse(REFUSALS["several"], count=len(matches))
|
|
127
|
+
key, path = matches[0]
|
|
128
|
+
pinned = repo.config(path)["version"]
|
|
129
|
+
story_used = repo.forge_dir(path) / "approvals" / marker
|
|
130
|
+
if story_used.exists():
|
|
131
|
+
repo.refuse(REFUSALS["replay"])
|
|
132
|
+
doc = (path / "plans" / f"{key}.md").read_text(encoding="utf-8")
|
|
133
|
+
folder = design.check(path, doc)
|
|
134
|
+
story.check_read(key, path)
|
|
135
|
+
if repo.is_prototype(path):
|
|
136
|
+
repo.refuse(REFUSALS["no_signoff"])
|
|
137
|
+
state = repo.read_state(key, path) or {}
|
|
138
|
+
notes = story._record(story._text(path / "plans" / f"{key}.read.md"))[0] # pyright: ignore[reportPrivateUsage]
|
|
139
|
+
# The round it passed, so the story keeps needing a passing round even if its notes go.
|
|
140
|
+
approval = {"by": f"human-via-{runtime.capitalize()}", "at": repo.now(), "hash": digest,
|
|
141
|
+
"runtime": runtime, "session": session, "event": event,
|
|
142
|
+
"round": int(notes.get("round") or 1)}
|
|
143
|
+
state.update(status="approved", approval=approval, touches=state.get("touches", 0) + 1)
|
|
144
|
+
rel = repo.write_state(key, repo.add_step(state, "approved"), path)
|
|
145
|
+
heading = re.search(r"^# (.+)$", doc, re.M)
|
|
146
|
+
title = heading[1] if heading else key
|
|
147
|
+
repo.commit_state(f"Approve the plan: {title}", f"plans/{key}.md", f"plans/{key}.read.md", rel,
|
|
148
|
+
*([folder] if folder else []), top=path)
|
|
149
|
+
for used in dict.fromkeys((chat_used, story_used)):
|
|
150
|
+
used.parent.mkdir(exist_ok=True)
|
|
151
|
+
used.write_text(json.dumps(approval), encoding="utf-8")
|
|
152
|
+
print(f"Recorded the approval of {title}.")
|
|
153
|
+
# A version mismatch warns only after the approval is recorded.
|
|
154
|
+
if pinned.removeprefix("v") != __version__:
|
|
155
|
+
from forge import upgrade
|
|
156
|
+
|
|
157
|
+
installed, checkout = f"v{__version__}", machine.main_checkout(path)
|
|
158
|
+
advice = (f"Ask your agent to install Forge {pinned}."
|
|
159
|
+
if upgrade._numbers(pinned) > upgrade._numbers(installed) # pyright: ignore[reportPrivateUsage]
|
|
160
|
+
else f"Ask your agent to upgrade {checkout} to {installed}.")
|
|
161
|
+
print(OTHER_VERSION.format(repo=checkout, pinned=pinned, installed=installed,
|
|
162
|
+
advice=advice), file=sys.stderr)
|
|
163
|
+
# Tasks start from origin, so the approval must reach it; a failed push never undoes the approval.
|
|
164
|
+
if repo.run("git", "remote", "get-url", "origin", cwd=path).returncode == 0 and repo.run(
|
|
165
|
+
"git", "push", "-q", "origin", f"story/{key}", cwd=path).returncode:
|
|
166
|
+
print(f"Forge couldn't push story/{key}; run git push origin story/{key} so tasks see "
|
|
167
|
+
"this approval.")
|
|
168
|
+
_to_promoted(key, path)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _to_promoted(key: str, path: Path) -> None:
|
|
172
|
+
"""Merge the story branch into a task promoted from a fix, so the approved doc, its notes, the
|
|
173
|
+
story's state and its roadmap entry reach that task's pull request. On any failure, leave the
|
|
174
|
+
task as it was and name the merge to finish."""
|
|
175
|
+
folder = story.worktrees(path).get(f"task/{key}-SPEC")
|
|
176
|
+
state = repo.read_state(f"{key}/SPEC", folder) if folder else None
|
|
177
|
+
if not state or "done_when" not in state: # only a promoted fix's state has a done-when
|
|
178
|
+
return
|
|
179
|
+
if repo.run("git", "rev-parse", "-q", "--verify", "MERGE_HEAD", cwd=folder).returncode == 0:
|
|
180
|
+
print(f"{key}/SPEC's folder has a merge in progress, so Forge left it untouched.\n"
|
|
181
|
+
f"Next: in {folder}, finish that merge, then git merge story/{key}")
|
|
182
|
+
return
|
|
183
|
+
merged = repo.run("git", "merge", "-q", "--no-edit", "-m", "Bring in the approved plan",
|
|
184
|
+
f"story/{key}", cwd=folder)
|
|
185
|
+
if merged.returncode:
|
|
186
|
+
if repo.run("git", "rev-parse", "-q", "--verify", "MERGE_HEAD", cwd=folder).returncode == 0:
|
|
187
|
+
repo.run("git", "merge", "--abort", cwd=folder)
|
|
188
|
+
print(f"Forge couldn't bring the approved plan into {key}/SPEC's branch.\n"
|
|
189
|
+
f"Next: in {folder}, git merge story/{key}, then forge close {key}/SPEC")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _completed(payload: dict[str, Any]) -> bool:
|
|
193
|
+
"""The call finished: it didn't fail or get cancelled, and any status it gives is a success."""
|
|
194
|
+
response = payload.get("tool_response")
|
|
195
|
+
response = response if isinstance(response, dict) else {}
|
|
196
|
+
if any(part.get("is_error") is True or part.get("cancelled") is True for part in (payload, response)):
|
|
197
|
+
return False
|
|
198
|
+
return response.get("status") is None or _text(response.get("status")).lower() in SUCCESS
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _answered(payload: dict[str, Any]) -> bool:
|
|
202
|
+
"""The human answered: the call completed with a response, and a question's response holds an
|
|
203
|
+
answer. A plan that ExitPlanMode completed was accepted by the human."""
|
|
204
|
+
response = payload.get("tool_response")
|
|
205
|
+
if not _completed(payload) or not isinstance(response, dict):
|
|
206
|
+
return False
|
|
207
|
+
if payload.get("tool_name") == "ExitPlanMode":
|
|
208
|
+
return True
|
|
209
|
+
answers = response.get("answers")
|
|
210
|
+
if not isinstance(answers, dict):
|
|
211
|
+
return False
|
|
212
|
+
for answer in answers.values():
|
|
213
|
+
choices = answer.get("answers") if isinstance(answer, dict) else [answer]
|
|
214
|
+
if isinstance(choices, list) and any(isinstance(choice, str) and choice.strip()
|
|
215
|
+
for choice in choices):
|
|
216
|
+
return True
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _claude_digest(payload: dict[str, Any]) -> str:
|
|
221
|
+
"""The section hash of the plan text a successful ExitPlanMode showed."""
|
|
222
|
+
response, tool_input = payload.get("tool_response"), payload.get("tool_input")
|
|
223
|
+
if not isinstance(response, dict):
|
|
224
|
+
repo.refuse(REFUSALS["unsupported"])
|
|
225
|
+
plan = tool_input.get("plan") if isinstance(tool_input, dict) else None
|
|
226
|
+
if plan is None: # a no-argument ExitPlanMode has the plan only in its response
|
|
227
|
+
plan = response.get("plan")
|
|
228
|
+
documented = response.get("plan") == plan and isinstance(response.get("isAgent"), bool)
|
|
229
|
+
if not isinstance(plan, str) or not plan or (response.get("status") is None and not documented):
|
|
230
|
+
repo.refuse(REFUSALS["unsupported"])
|
|
231
|
+
digest = story.approval_hash(plan)
|
|
232
|
+
if digest is None:
|
|
233
|
+
repo.refuse(REFUSALS["no_match"])
|
|
234
|
+
return digest
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _codex_digest(payload: dict[str, Any]) -> str:
|
|
238
|
+
"""The digest a completed Codex approval question carries in its id, when it follows the contract."""
|
|
239
|
+
tool_input, response = payload.get("tool_input"), payload.get("tool_response")
|
|
240
|
+
questions = tool_input.get("questions") if isinstance(tool_input, dict) else None
|
|
241
|
+
answers = response.get("answers") if isinstance(response, dict) else None
|
|
242
|
+
if (payload.get("async") is True or not isinstance(questions, list) or len(questions) != 1
|
|
243
|
+
or not isinstance(questions[0], dict) or not isinstance(answers, dict)):
|
|
244
|
+
repo.refuse(REFUSALS["unsupported"])
|
|
245
|
+
question = questions[0]
|
|
246
|
+
qid = _text(question.get("id"))
|
|
247
|
+
match = re.fullmatch(r"approve_plan_([0-9a-f]{64})", qid)
|
|
248
|
+
options = question.get("options")
|
|
249
|
+
labels = ([option.get("label") if isinstance(option, dict) else option for option in options]
|
|
250
|
+
if isinstance(options, list) else None)
|
|
251
|
+
if (match is None or labels != CHOICES or _text(question.get("question")) != "Approve this plan?"
|
|
252
|
+
or _text(question.get("header")) != "Approve plan" or set(answers) != {qid}):
|
|
253
|
+
repo.refuse(REFUSALS["unsupported"])
|
|
254
|
+
chosen = answers[qid].get("answers") if isinstance(answers[qid], dict) else None
|
|
255
|
+
if not isinstance(chosen, list) or len(chosen) != 1 or not isinstance(chosen[0], str):
|
|
256
|
+
repo.refuse(REFUSALS["unsupported"])
|
|
257
|
+
if chosen[0] != "Approve plan":
|
|
258
|
+
repo.refuse(REFUSALS["not_approved"], answer=chosen[0])
|
|
259
|
+
return match[1]
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _asks_approval(payload: dict[str, Any]) -> bool:
|
|
263
|
+
tool_input = payload.get("tool_input")
|
|
264
|
+
questions = tool_input.get("questions") if isinstance(tool_input, dict) else None
|
|
265
|
+
return isinstance(questions, list) and any(
|
|
266
|
+
isinstance(question, dict) and _text(question.get("id")).startswith("approve_plan_")
|
|
267
|
+
for question in questions)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _touch(top: Path) -> None:
|
|
271
|
+
"""Add a human touch to the story, task or fix this checkout works on; elsewhere, nothing."""
|
|
272
|
+
item = _item_here(top)
|
|
273
|
+
state = repo.read_state(item, top) if item else None
|
|
274
|
+
if state is not None:
|
|
275
|
+
state["touches"] = state.get("touches", 0) + 1
|
|
276
|
+
repo.write_state(item, state, top)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _item_here(top: Path) -> str:
|
|
280
|
+
kind, _, name = repo.current_branch(top).partition("/")
|
|
281
|
+
if kind == "task": # KEY and TASK both hold hyphens, so match the task state files here
|
|
282
|
+
return next((f"{path.parent.parent.name}/{path.stem}"
|
|
283
|
+
for path in (top / ".factory" / "stories").glob("*/tasks/*.json")
|
|
284
|
+
if f"{path.parent.parent.name}-{path.stem}" == name), "")
|
|
285
|
+
ok = {"story": story.KEY, "fix": re.compile(r"[a-z0-9][a-z0-9-]*")}.get(kind)
|
|
286
|
+
return name if ok and ok.fullmatch(name) else ""
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _text(value: object) -> str:
|
|
290
|
+
return str(value).strip() if value is not None else ""
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
COMMANDS = [{
|
|
294
|
+
"words": "hook approval", "run": "hook", "changes_state": True,
|
|
295
|
+
"help": "After a plan or question tool: record approvals and count human touches",
|
|
296
|
+
"args": [], "position": 250,
|
|
297
|
+
"listing": "| `forge hook approval` | After the plan and question tools: records approvals and counts human touches |",
|
|
298
|
+
}]
|
forge/autoreview.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Autoreview's process output and finding schema at the external tool boundary."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import contextlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from forge import machine, repo, score
|
|
14
|
+
|
|
15
|
+
PRIORITIES = ("P0", "P1", "P2", "P3")
|
|
16
|
+
TOKENS = ("input_tokens", "cached_input_tokens", "output_tokens", "reasoning_output_tokens")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def spent(folder: Path) -> dict[str, Any]:
|
|
20
|
+
"""Sum the engine processes' separate streams and keep the first chat."""
|
|
21
|
+
runs: list[dict[str, Any]] = []
|
|
22
|
+
for path in sorted(folder.glob("*.jsonl")):
|
|
23
|
+
with contextlib.suppress(OSError):
|
|
24
|
+
calls: list[dict[str, Any]] = []
|
|
25
|
+
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
26
|
+
try:
|
|
27
|
+
event = json.loads(line)
|
|
28
|
+
except ValueError:
|
|
29
|
+
continue
|
|
30
|
+
if not isinstance(event, dict):
|
|
31
|
+
continue
|
|
32
|
+
usage = event.get("usage")
|
|
33
|
+
if event.get("type") == "thread.started":
|
|
34
|
+
calls.append({"chat": event.get("thread_id")})
|
|
35
|
+
elif event.get("type") == "turn.completed" and isinstance(usage, dict) and calls:
|
|
36
|
+
# Codex's last turn holds this process's running token total.
|
|
37
|
+
calls[-1].update({key: usage.get(key) for key in TOKENS})
|
|
38
|
+
elif event.get("type") == "result" and isinstance(usage, dict):
|
|
39
|
+
calls.append({"chat": event.get("session_id"), **repo.claude_tokens(usage)})
|
|
40
|
+
runs.extend(calls)
|
|
41
|
+
path.unlink()
|
|
42
|
+
if not runs:
|
|
43
|
+
return {}
|
|
44
|
+
return {"chat": runs[0]["chat"], **{key: sum(counts) if (counts := [
|
|
45
|
+
run[key] for run in runs if isinstance(run.get(key), int)]) else None for key in TOKENS}}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def attempt(argv: list[str], cwd: Path, out: Path,
|
|
49
|
+
selected: dict[str, str], top: Path, item: str, run_id: str,
|
|
50
|
+
strict: bool = False) -> tuple[list[dict[str, Any]], str]:
|
|
51
|
+
"""Run Autoreview once: its findings, or the reason the run doesn't count."""
|
|
52
|
+
from forge import codex # importing it here avoids sync's hook-import cycle
|
|
53
|
+
out.unlink(missing_ok=True)
|
|
54
|
+
proc = subprocess.Popen(argv, cwd=cwd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
|
55
|
+
stderr=subprocess.STDOUT, env={**os.environ, "FORGE_WORKER": "1"},
|
|
56
|
+
**codex.GROUP)
|
|
57
|
+
# The run's output file: what a person sees when they open the run from the pane.
|
|
58
|
+
log = repo.forge_dir(top) / f"review-{run_id}.log"
|
|
59
|
+
with proc, log.open("wb") as saved, machine.agent_process(proc, log):
|
|
60
|
+
last = ""
|
|
61
|
+
pending = b""
|
|
62
|
+
for line in proc.stdout or []: # streamed as bytes: its progress is how a person watches it
|
|
63
|
+
line = line.replace(b"\0", b"")
|
|
64
|
+
# Claude's failure trailer contains its result JSON. Hold it until we
|
|
65
|
+
# can name a sign-in failure without printing the raw result first.
|
|
66
|
+
if "claude" in argv and (pending or line.lstrip().startswith(b"{")
|
|
67
|
+
or b"claude engine failed" in line):
|
|
68
|
+
pending += line
|
|
69
|
+
last = line.decode("utf-8", "replace").strip() or last
|
|
70
|
+
continue
|
|
71
|
+
sys.stderr.buffer.write(line)
|
|
72
|
+
sys.stderr.flush()
|
|
73
|
+
saved.write(line)
|
|
74
|
+
saved.flush()
|
|
75
|
+
last = line.decode("utf-8", "replace").strip() or last
|
|
76
|
+
if match := re.fullmatch(r"(model|thinking): (.*)", last):
|
|
77
|
+
selected[{"model": "model", "thinking": "effort"}[match[1]]] = match[2]
|
|
78
|
+
elif match := re.fullmatch(
|
|
79
|
+
r"codex model \S+ is unavailable for this account; retrying with (\S+)", last):
|
|
80
|
+
selected["model"] = match[1]
|
|
81
|
+
if line.strip():
|
|
82
|
+
repo.record_progress(top, item, run_id, step=" ".join(last.split()), **selected)
|
|
83
|
+
code = proc.wait()
|
|
84
|
+
trailer = pending.decode("utf-8", "replace")
|
|
85
|
+
for match in re.finditer(r"(?m)^\s*\{", trailer):
|
|
86
|
+
try:
|
|
87
|
+
result, _ = json.JSONDecoder().raw_decode(trailer[match.end() - 1:])
|
|
88
|
+
except ValueError:
|
|
89
|
+
continue
|
|
90
|
+
if (result.get("is_error") is True and isinstance(result.get("result"), str)
|
|
91
|
+
and result["result"].startswith("Not logged in")):
|
|
92
|
+
raise repo.Refused("Claude is not signed in. Next: run claude and sign in, "
|
|
93
|
+
f"then forge close {item}.", "")
|
|
94
|
+
if pending:
|
|
95
|
+
sys.stderr.buffer.write(pending)
|
|
96
|
+
sys.stderr.flush()
|
|
97
|
+
try:
|
|
98
|
+
# Decode first: JSON represents null characters as escaped text.
|
|
99
|
+
report = json.loads(out.read_text(encoding="utf-8"), object_hook=lambda fields: {
|
|
100
|
+
key: value.replace("\0", "") if isinstance(value, str) else value
|
|
101
|
+
for key, value in fields.items()})
|
|
102
|
+
except (OSError, ValueError):
|
|
103
|
+
report = None
|
|
104
|
+
if code not in (0, 1, 2) or not isinstance(report, dict):
|
|
105
|
+
return [], last or f"it exited with code {code}"
|
|
106
|
+
# The helper moves a finding pinned outside the changed files to scope_rejected_findings and
|
|
107
|
+
# calls the review incomplete for it. Ordinary reviews keep those findings; sign-off requires
|
|
108
|
+
# a complete run even when rejected findings are present.
|
|
109
|
+
rejected = report.get("scope_rejected_findings") or []
|
|
110
|
+
if (strict or not rejected) and (code == 2 or report.get("review_status") == "incomplete"):
|
|
111
|
+
return [], "it reported the review as incomplete"
|
|
112
|
+
if strict and report.get("review_status") not in (
|
|
113
|
+
"scoped-clean", "findings", "filtered", "incorrect"):
|
|
114
|
+
return [], "it did not report a completed review"
|
|
115
|
+
raw = report.get("findings")
|
|
116
|
+
findings = ([_finding(f) for f in [*raw, *rejected]]
|
|
117
|
+
if isinstance(raw, list) and isinstance(rejected, list) else [None])
|
|
118
|
+
if None in findings:
|
|
119
|
+
return [], "it wrote findings Forge cannot read"
|
|
120
|
+
if not findings and report.get("overall_correctness") == "patch is incorrect":
|
|
121
|
+
return [], "it called the patch incorrect without naming a finding"
|
|
122
|
+
return findings, "" # type: ignore[return-value]
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _finding(raw: Any) -> dict[str, Any] | None:
|
|
126
|
+
"""The fields Forge uses from one finding, or None when they can't be read."""
|
|
127
|
+
where = raw.get("code_location") if isinstance(raw, dict) else None
|
|
128
|
+
if not isinstance(where, dict) or raw.get("priority") not in PRIORITIES:
|
|
129
|
+
return None
|
|
130
|
+
title = str(raw.get("title", ""))
|
|
131
|
+
body = str(raw.get("body", ""))
|
|
132
|
+
category = str(raw.get("category", "")).strip().casefold().replace("_", " ").replace("-", " ")
|
|
133
|
+
if category in ("security", "data loss") and not any(
|
|
134
|
+
name == category and pattern.search(body) for pattern, name in score.FLOORS[:2]):
|
|
135
|
+
body += f"\nRaise: {category.capitalize()}"
|
|
136
|
+
scores, body = score.normalise(title, body)
|
|
137
|
+
return {"priority": raw["priority"], "title": title, "body": body,
|
|
138
|
+
**(dict(zip(("gain", "work", "harm"), scores)) if scores else {}),
|
|
139
|
+
"file": str(where.get("file_path", "")), "line": where.get("line", 0)}
|