@open-mercato/cli 0.6.7-develop.6685.1.77c0a5591b → 0.6.7-develop.6687.1.46a258e592
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/.turbo/turbo-build.log +2 -3
- package/build.mjs +21 -5
- package/dist/agentic/claude-code/hooks/entity-migration-check.ts +32 -88
- package/dist/agentic/codex/enforcement-rules.md +2 -16
- package/dist/agentic/cursor/hooks/entity-migration-check.mjs +19 -50
- package/dist/agentic/cursor/rules/entity-guard.mdc +9 -21
- package/dist/agentic/cursor/rules/generated-guard.mdc +3 -5
- package/dist/agentic/cursor/rules/open-mercato.mdc +3 -29
- package/dist/agentic/guides/ai-workflows.md +76 -0
- package/dist/agentic/guides/architecture.md +107 -0
- package/dist/agentic/guides/backend-ui.md +80 -0
- package/dist/agentic/guides/contracts.md +92 -0
- package/dist/agentic/guides/extensions.md +104 -0
- package/dist/agentic/guides/integrations.md +81 -0
- package/dist/agentic/guides/module-facts.json +217 -81
- package/dist/agentic/guides/module-system.md +12 -127
- package/dist/agentic/guides/modules/ai_assistant.md +1 -1
- package/dist/agentic/guides/modules/api_docs.md +1 -1
- package/dist/agentic/guides/modules/api_keys.md +1 -1
- package/dist/agentic/guides/modules/attachments.md +2 -2
- package/dist/agentic/guides/modules/audit_logs.md +2 -2
- package/dist/agentic/guides/modules/auth.md +1 -1
- package/dist/agentic/guides/modules/business_rules.md +1 -1
- package/dist/agentic/guides/modules/catalog.md +5 -5
- package/dist/agentic/guides/modules/channel_gmail.md +1 -1
- package/dist/agentic/guides/modules/channel_imap.md +1 -1
- package/dist/agentic/guides/modules/checkout.md +1 -1
- package/dist/agentic/guides/modules/communication_channels.md +1 -1
- package/dist/agentic/guides/modules/configs.md +1 -1
- package/dist/agentic/guides/modules/content.md +1 -1
- package/dist/agentic/guides/modules/currencies.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts.md +1 -1
- package/dist/agentic/guides/modules/customers.md +2 -2
- package/dist/agentic/guides/modules/dashboards.md +1 -1
- package/dist/agentic/guides/modules/data_sync.md +1 -1
- package/dist/agentic/guides/modules/dictionaries.md +1 -1
- package/dist/agentic/guides/modules/directory.md +1 -1
- package/dist/agentic/guides/modules/entities.md +2 -2
- package/dist/agentic/guides/modules/events.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe.md +1 -1
- package/dist/agentic/guides/modules/generators.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops.md +1 -1
- package/dist/agentic/guides/modules/integrations.md +1 -1
- package/dist/agentic/guides/modules/messages.md +1 -1
- package/dist/agentic/guides/modules/notifications.md +1 -1
- package/dist/agentic/guides/modules/onboarding.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways.md +1 -1
- package/dist/agentic/guides/modules/perspectives.md +1 -1
- package/dist/agentic/guides/modules/planner.md +1 -1
- package/dist/agentic/guides/modules/portal.md +1 -1
- package/dist/agentic/guides/modules/progress.md +1 -1
- package/dist/agentic/guides/modules/query_index.md +2 -2
- package/dist/agentic/guides/modules/record_locks.md +1 -1
- package/dist/agentic/guides/modules/resources.md +1 -1
- package/dist/agentic/guides/modules/sales.md +17 -17
- package/dist/agentic/guides/modules/scheduler.md +1 -1
- package/dist/agentic/guides/modules/search.md +1 -1
- package/dist/agentic/guides/modules/security.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers.md +1 -1
- package/dist/agentic/guides/modules/sso.md +1 -1
- package/dist/agentic/guides/modules/staff.md +2 -2
- package/dist/agentic/guides/modules/storage_s3.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo.md +1 -1
- package/dist/agentic/guides/modules/sync_excel.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays.md +1 -1
- package/dist/agentic/guides/modules/translations.md +1 -1
- package/dist/agentic/guides/modules/webhooks.md +2 -2
- package/dist/agentic/guides/modules/wms.md +2 -2
- package/dist/agentic/guides/modules/workflows.md +1 -1
- package/dist/agentic/guides/testing-debugging.md +74 -0
- package/dist/agentic/guides/upstream/AGENTS.md +297 -0
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +303 -0
- package/dist/agentic/guides/upstream/manifest.json +8 -0
- package/dist/agentic/shared/AGENTS.md.template +123 -311
- package/dist/agentic/shared/ai/agentic.config.json +1 -0
- package/dist/agentic/shared/ai/harness/README.md +48 -0
- package/dist/agentic/shared/ai/harness/RELEASE.md +57 -0
- package/dist/agentic/shared/ai/harness/cases.json +13487 -0
- package/dist/agentic/shared/ai/harness/cases.schema.json +132 -0
- package/dist/agentic/shared/ai/harness/fixtures/index.json +49 -0
- package/dist/agentic/shared/ai/harness/fixtures/seeds.json +162 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +20 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +43 -0
- package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +110 -0
- package/dist/agentic/shared/ai/harness/release-matrix.json +133 -0
- package/dist/agentic/shared/ai/harness/release-result.schema.json +219 -0
- package/dist/agentic/shared/ai/harness/result.schema.json +76 -0
- package/dist/agentic/shared/ai/harness/routing-response.schema.json +12 -0
- package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +73 -0
- package/dist/agentic/shared/ai/harness/validators.json +78 -0
- package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +1768 -0
- package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +1096 -0
- package/dist/agentic/shared/ai/review-checklist.md +36 -0
- package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +4 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +20 -241
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +16 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +53 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +13 -0
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +11 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +30 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +12 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +13 -0
- package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +14 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +28 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +22 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +12 -0
- package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +19 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +16 -601
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +19 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +13 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +14 -0
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +10 -0
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +14 -310
- package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +17 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +28 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +89 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +16 -0
- package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +17 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +25 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +11 -0
- package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +13 -0
- package/dist/agentic/shared/ai/skills/om-help/SKILL.md +15 -97
- package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +17 -0
- package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +20 -0
- package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +15 -156
- package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +12 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +24 -708
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +16 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +14 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +15 -0
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +12 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +20 -820
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +19 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +107 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +12 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +83 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +21 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +11 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +22 -0
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +13 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +19 -843
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +18 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +25 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +13 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +38 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +11 -0
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +15 -63
- package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +15 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +16 -467
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +16 -0
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +14 -0
- package/dist/agentic/shared/ai/skills/tiers.json +137 -20
- package/dist/agentic/shared/ai/skills/tiers.schema.json +52 -40
- package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +174 -0
- package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +2783 -0
- package/dist/agentic/shared/scripts/execution-sandbox.mjs +329 -0
- package/dist/agentic/shared/scripts/framework-context.mjs +894 -0
- package/dist/agentic/shared/scripts/install-skills.mjs +1029 -0
- package/dist/agentic/shared/scripts/install-skills.sh +4 -694
- package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +222 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +1761 -0
- package/dist/lib/__integration__/TC-INT-008.spec.js +87 -8
- package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
- package/dist/lib/agentic-init.js +13 -3
- package/dist/lib/agentic-init.js.map +2 -2
- package/dist/lib/agentic-setup.js +418 -186
- package/dist/lib/agentic-setup.js.map +2 -2
- package/dist/lib/generators/extensions/injection-widgets.js +20 -0
- package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
- package/dist/lib/generators/module-facts-discovery.js +41 -7
- package/dist/lib/generators/module-facts-discovery.js.map +2 -2
- package/dist/lib/generators/module-facts.js +65 -17
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-registry.js +5 -4
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/resolver.js +2 -0
- package/dist/lib/resolver.js.map +2 -2
- package/package.json +5 -5
- package/src/lib/__integration__/TC-INT-008.spec.ts +103 -8
- package/src/lib/__tests__/agentic-init.test.ts +41 -5
- package/src/lib/__tests__/agentic-setup.ownership.test.ts +380 -0
- package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
- package/src/lib/agentic-init.ts +15 -3
- package/src/lib/agentic-setup.ts +526 -224
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +6 -0
- package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.discovery.test.ts +54 -10
- package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +108 -0
- package/src/lib/generators/__tests__/module-subset.test.ts +18 -0
- package/src/lib/generators/extensions/injection-widgets.ts +51 -0
- package/src/lib/generators/module-facts-discovery.ts +58 -7
- package/src/lib/generators/module-facts.ts +84 -20
- package/src/lib/generators/module-registry.ts +8 -4
- package/src/lib/resolver.ts +3 -0
- package/dist/agentic/guides/cache.md +0 -45
- package/dist/agentic/guides/core.md +0 -453
- package/dist/agentic/guides/events.md +0 -117
- package/dist/agentic/guides/queue.md +0 -53
- package/dist/agentic/guides/search.md +0 -115
- package/dist/agentic/guides/shared.md +0 -108
- package/dist/agentic/guides/ui.md +0 -347
- package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +0 -27
- package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +0 -260
- package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +0 -146
- package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +0 -84
- package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +0 -193
- package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +0 -34
- package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +0 -762
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +0 -50
- package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +0 -97
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +0 -271
- package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +0 -101
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
[build:cli] found 96 entry points
|
|
2
2
|
Copied create-app/agentic/ → dist/agentic/
|
|
3
|
-
Discovered 7 standalone guides → dist/agentic/guides/
|
|
4
3
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for ai_assistant
|
|
5
4
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for channel_gmail
|
|
6
5
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for channel_imap
|
|
7
6
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for checkout
|
|
8
|
-
Generated 54 module fact-sheets → dist/agentic/guides/modules/
|
|
9
|
-
[build:cli] built successfully
|
|
10
7
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for content
|
|
11
8
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for api_docs
|
|
12
9
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for api_keys
|
|
@@ -49,7 +46,9 @@ Generated 54 module fact-sheets → dist/agentic/guides/modules/
|
|
|
49
46
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for sso
|
|
50
47
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for system_status_overlays
|
|
51
48
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for events
|
|
49
|
+
Generated 54 module fact-sheets → dist/agentic/guides/modules/
|
|
52
50
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for gateway_stripe
|
|
51
|
+
[build:cli] built successfully
|
|
53
52
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for onboarding
|
|
54
53
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for scheduler
|
|
55
54
|
[module-facts] module registry unavailable (registryPath not provided); API route auth omitted for search
|
package/build.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { createHash } from 'node:crypto'
|
|
2
3
|
import { dirname, join } from 'node:path'
|
|
3
4
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
4
5
|
import { atomicWriteFileSync } from '../../scripts/lib/add-js-extension.mjs'
|
|
@@ -26,11 +27,26 @@ await buildPackage(packageDir, {
|
|
|
26
27
|
// Copy agentic source files from create-app so generators can read them at runtime.
|
|
27
28
|
const agenticSrc = join(packageDir, '..', 'create-app', 'agentic')
|
|
28
29
|
if (existsSync(agenticSrc)) {
|
|
30
|
+
rmSync(join(outdir, 'agentic'), { recursive: true, force: true })
|
|
29
31
|
cpSync(agenticSrc, join(outdir, 'agentic'), { recursive: true })
|
|
30
32
|
console.log('Copied create-app/agentic/ → dist/agentic/')
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
const repositoryRoot = join(packageDir, '..', '..')
|
|
36
|
+
const upstreamDir = join(outdir, 'agentic', 'guides', 'upstream')
|
|
37
|
+
mkdirSync(upstreamDir, { recursive: true })
|
|
38
|
+
const cliVersion = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8')).version ?? null
|
|
39
|
+
const upstreamManifest = { version: 1, generator: `@open-mercato/cli@${cliVersion ?? 'unknown'}`, files: {} }
|
|
40
|
+
for (const file of ['AGENTS.md', 'BACKWARD_COMPATIBILITY.md']) {
|
|
41
|
+
const source = join(repositoryRoot, file)
|
|
42
|
+
const destination = join(upstreamDir, file)
|
|
43
|
+
cpSync(source, destination)
|
|
44
|
+
upstreamManifest.files[file] = createHash('sha256').update(readFileSync(source)).digest('hex')
|
|
45
|
+
}
|
|
46
|
+
writeFileSync(join(upstreamDir, 'manifest.json'), `${JSON.stringify(upstreamManifest, null, 2)}\n`)
|
|
47
|
+
|
|
48
|
+
// Discover module-specific standalone guides across sibling packages. Package-level
|
|
49
|
+
// guides are intentionally not shipped because they duplicate routed conceptual guides.
|
|
34
50
|
const packagesDir = join(packageDir, '..')
|
|
35
51
|
const guidesDestDir = join(outdir, 'agentic', 'guides')
|
|
36
52
|
mkdirSync(guidesDestDir, { recursive: true })
|
|
@@ -39,8 +55,7 @@ await buildPackage(packageDir, {
|
|
|
39
55
|
// retains a removed module's full guide or fact-sheet. The legacy `core.<module>.md`
|
|
40
56
|
// redirect stubs are no longer emitted (#3754); this purge also deletes any that linger
|
|
41
57
|
// in an incremental `dist/` from an older build. Mirrors packages/create-app/build.mjs;
|
|
42
|
-
//
|
|
43
|
-
// re-copied/re-discovered below.
|
|
58
|
+
// conceptual guides remain while stale single-dot package guides are removed below.
|
|
44
59
|
rmSync(join(guidesDestDir, 'modules'), { recursive: true, force: true })
|
|
45
60
|
for (const entry of readdirSync(guidesDestDir)) {
|
|
46
61
|
if (/^core\..+\.md$/.test(entry)) {
|
|
@@ -50,10 +65,11 @@ await buildPackage(packageDir, {
|
|
|
50
65
|
|
|
51
66
|
let guidesFound = 0
|
|
52
67
|
for (const pkg of readdirSync(packagesDir)) {
|
|
68
|
+
// Package-level source guides remain for monorepo context, but standalone apps route
|
|
69
|
+
// through conceptual and module-level guides, so remove their stale emitted copies.
|
|
53
70
|
const guideSource = join(packagesDir, pkg, 'agentic', 'standalone-guide.md')
|
|
54
71
|
if (existsSync(guideSource)) {
|
|
55
|
-
|
|
56
|
-
guidesFound++
|
|
72
|
+
rmSync(join(guidesDestDir, `${pkg}.md`), { force: true })
|
|
57
73
|
}
|
|
58
74
|
|
|
59
75
|
const modulesDir = join(packagesDir, pkg, 'src', 'modules')
|
|
@@ -1,121 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Code PostToolUse hook: entity-migration-check
|
|
3
|
-
*
|
|
4
|
-
* Fires after Write/Edit/MultiEdit. Detects entity file modifications
|
|
5
|
-
* without an accompanying migration and blocks the agent with a reminder.
|
|
6
|
-
*
|
|
7
|
-
* Three-state logic:
|
|
8
|
-
* 1. Migration file was written → exit 0 (agent is already on it)
|
|
9
|
-
* 2. Not an entity file → exit 0 (not relevant)
|
|
10
|
-
* 3. Entity written, no fresh migration → block with migration instructions
|
|
11
|
-
*/
|
|
12
|
-
|
|
1
|
+
/** Remind Claude Code to generate and review a schema diff after entity edits. */
|
|
13
2
|
import { readdirSync, statSync } from 'node:fs'
|
|
14
3
|
import { join, relative } from 'node:path'
|
|
15
4
|
|
|
16
|
-
const ENTITY_PATTERN = /^src\/modules\/([^/]+)\/entities
|
|
17
|
-
const MIGRATION_PATTERN = /^src\/modules\/([^/]+)\/migrations
|
|
5
|
+
const ENTITY_PATTERN = /^src\/modules\/([^/]+)\/data\/entities\.ts$/
|
|
6
|
+
const MIGRATION_PATTERN = /^src\/modules\/([^/]+)\/migrations\/[^/]+\.ts$/
|
|
18
7
|
|
|
19
8
|
interface PostToolUseInput {
|
|
20
|
-
tool_input?: {
|
|
21
|
-
file_path?: string
|
|
22
|
-
content?: string
|
|
23
|
-
}
|
|
24
|
-
tool_name?: string
|
|
9
|
+
tool_input?: { file_path?: string }
|
|
25
10
|
}
|
|
26
11
|
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
if (filePath.startsWith('/')) {
|
|
30
|
-
return relative(projectDir, filePath)
|
|
31
|
-
}
|
|
32
|
-
return filePath
|
|
12
|
+
function projectDir(): string {
|
|
13
|
+
return process.env.CLAUDE_PROJECT_DIR || process.cwd()
|
|
33
14
|
}
|
|
34
15
|
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
|
|
16
|
+
function normalizedRelative(filePath: string): string {
|
|
17
|
+
const value = filePath.startsWith('/') ? relative(projectDir(), filePath) : filePath
|
|
18
|
+
return value.replaceAll('\\', '/')
|
|
19
|
+
}
|
|
38
20
|
|
|
21
|
+
function hasFreshMigration(moduleId: string): boolean {
|
|
22
|
+
const migrationsDir = join(projectDir(), 'src', 'modules', moduleId, 'migrations')
|
|
39
23
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
for (const file of files) {
|
|
45
|
-
if (!file.endsWith('.ts')) continue
|
|
46
|
-
const stat = statSync(join(migrationsDir, file))
|
|
47
|
-
if (stat.mtimeMs > thirtySecondsAgo) {
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
}
|
|
24
|
+
const cutoff = Date.now() - 30_000
|
|
25
|
+
return readdirSync(migrationsDir).some((file) =>
|
|
26
|
+
file.endsWith('.ts') && statSync(join(migrationsDir, file)).mtimeMs > cutoff,
|
|
27
|
+
)
|
|
51
28
|
} catch {
|
|
52
|
-
|
|
29
|
+
return false
|
|
53
30
|
}
|
|
54
|
-
|
|
55
|
-
return false
|
|
56
31
|
}
|
|
57
32
|
|
|
58
33
|
async function main(): Promise<void> {
|
|
59
34
|
let input = ''
|
|
60
|
-
for await (const chunk of process.stdin)
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!input.trim()) {
|
|
65
|
-
process.exit(0)
|
|
66
|
-
}
|
|
35
|
+
for await (const chunk of process.stdin) input += chunk
|
|
36
|
+
if (!input.trim()) return
|
|
67
37
|
|
|
68
38
|
let data: PostToolUseInput
|
|
69
39
|
try {
|
|
70
40
|
data = JSON.parse(input)
|
|
71
41
|
} catch {
|
|
72
|
-
|
|
42
|
+
return
|
|
73
43
|
}
|
|
74
44
|
|
|
75
45
|
const filePath = data.tool_input?.file_path
|
|
76
|
-
if (!filePath)
|
|
77
|
-
|
|
78
|
-
|
|
46
|
+
if (!filePath) return
|
|
47
|
+
const rel = normalizedRelative(filePath)
|
|
48
|
+
if (MIGRATION_PATTERN.test(rel)) return
|
|
79
49
|
|
|
80
|
-
const
|
|
50
|
+
const match = rel.match(ENTITY_PATTERN)
|
|
51
|
+
if (!match || hasFreshMigration(match[1])) return
|
|
81
52
|
|
|
82
|
-
|
|
83
|
-
if (MIGRATION_PATTERN.test(rel)) {
|
|
84
|
-
process.exit(0)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// State 2: Not an entity file → not relevant
|
|
88
|
-
const entityMatch = rel.match(ENTITY_PATTERN)
|
|
89
|
-
if (!entityMatch) {
|
|
90
|
-
process.exit(0)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const moduleId = entityMatch[1]
|
|
94
|
-
|
|
95
|
-
// State 3: Entity written — check for fresh migration
|
|
96
|
-
if (hasFreshMigration(moduleId)) {
|
|
97
|
-
process.exit(0)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Block: entity modified without migration
|
|
101
|
-
const result = {
|
|
53
|
+
process.stdout.write(JSON.stringify({
|
|
102
54
|
decision: 'block',
|
|
103
55
|
reason: [
|
|
104
|
-
`Entity
|
|
105
|
-
'',
|
|
106
|
-
`Affected module: ${moduleId}`,
|
|
107
|
-
'',
|
|
108
|
-
'A database migration is likely needed. Ask the user whether to run:',
|
|
109
|
-
' yarn db:generate',
|
|
56
|
+
`Entity contract changed: ${rel}`,
|
|
110
57
|
'',
|
|
111
|
-
'
|
|
112
|
-
'
|
|
113
|
-
'',
|
|
114
|
-
'Do NOT run migrations automatically — always confirm with the user first.',
|
|
58
|
+
'Run `yarn db:generate` as a schema-diff probe and review only the scoped migration plus module snapshot.',
|
|
59
|
+
'Run `yarn generate` when discovery changed.',
|
|
60
|
+
'Do not apply the migration with `yarn db:migrate` without explicit user approval.',
|
|
115
61
|
].join('\n'),
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
process.stdout.write(JSON.stringify(result))
|
|
62
|
+
}))
|
|
119
63
|
}
|
|
120
64
|
|
|
121
|
-
main()
|
|
65
|
+
void main()
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
<!-- CODEX_ENFORCEMENT_RULES_START -->
|
|
2
|
-
##
|
|
2
|
+
## Codex enforcement
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
- STOP immediately before any further action
|
|
6
|
-
- Tell the user: "I modified an entity in module <id>. Should I create a migration?"
|
|
7
|
-
- If yes: run `yarn mercato db generate`
|
|
8
|
-
- Show the generated migration to the user before applying
|
|
9
|
-
- Ask for confirmation, then run `yarn mercato db migrate`
|
|
10
|
-
- Run `yarn generate` after migration is applied
|
|
4
|
+
Read and route through the rest of this file; its `Always`, `Never`, and Task Router sections are the authority for Codex too. They are stated once below rather than duplicated here, so this prelude costs the router no budget.
|
|
11
5
|
|
|
12
|
-
2. **After editing `src/modules.ts`**: immediately run `yarn generate`
|
|
13
|
-
|
|
14
|
-
3. **Never edit `.mercato/generated/*`**: edit the source and run `yarn generate` instead
|
|
15
|
-
|
|
16
|
-
4. **Before significant features**: check `.ai/specs/` for an existing spec.
|
|
17
|
-
If none exists, ask the user whether to create one first.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
6
|
<!-- CODEX_ENFORCEMENT_RULES_END -->
|
|
@@ -1,69 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cursor afterFileEdit hook: entity-migration-check
|
|
3
|
-
*
|
|
4
|
-
* Detects entity file modifications without an accompanying migration
|
|
5
|
-
* and exits non-zero to block the agent with a reminder.
|
|
6
|
-
*
|
|
7
|
-
* Three-state logic:
|
|
8
|
-
* 1. Migration file was written → exit 0 (agent is already on it)
|
|
9
|
-
* 2. Not an entity file → exit 0 (not relevant)
|
|
10
|
-
* 3. Entity written, no fresh migration → exit 1 with warning
|
|
11
|
-
*/
|
|
12
|
-
|
|
1
|
+
/** Remind Cursor to generate and review a schema diff after entity edits. */
|
|
13
2
|
import { readdirSync, statSync } from 'node:fs'
|
|
14
|
-
import { join, resolve } from 'node:path'
|
|
3
|
+
import { join, relative, resolve } from 'node:path'
|
|
15
4
|
|
|
16
|
-
const ENTITY_RE = /^src\/modules\/([^/]+)\/entities
|
|
17
|
-
const MIGRATION_RE = /^src\/modules\/([^/]+)\/migrations
|
|
5
|
+
const ENTITY_RE = /^src\/modules\/([^/]+)\/data\/entities\.ts$/
|
|
6
|
+
const MIGRATION_RE = /^src\/modules\/([^/]+)\/migrations\/[^/]+\.ts$/
|
|
18
7
|
|
|
19
8
|
function hasFreshMigration(projectDir, moduleId) {
|
|
20
9
|
const migrationsDir = join(projectDir, 'src', 'modules', moduleId, 'migrations')
|
|
21
10
|
try {
|
|
22
|
-
const files = readdirSync(migrationsDir)
|
|
23
11
|
const cutoff = Date.now() - 30_000
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (stat.mtimeMs > cutoff) return true
|
|
28
|
-
}
|
|
12
|
+
return readdirSync(migrationsDir).some((file) =>
|
|
13
|
+
file.endsWith('.ts') && statSync(join(migrationsDir, file)).mtimeMs > cutoff,
|
|
14
|
+
)
|
|
29
15
|
} catch {
|
|
30
|
-
|
|
16
|
+
return false
|
|
31
17
|
}
|
|
32
|
-
return false
|
|
33
18
|
}
|
|
34
19
|
|
|
35
20
|
const filePath = process.argv[2]
|
|
36
21
|
if (!filePath) process.exit(0)
|
|
37
22
|
|
|
38
23
|
const projectDir = resolve('.')
|
|
39
|
-
const rel = filePath.startsWith('/') ?
|
|
40
|
-
|
|
41
|
-
// State 1: Migration file written
|
|
24
|
+
const rel = (filePath.startsWith('/') ? relative(projectDir, filePath) : filePath).replaceAll('\\', '/')
|
|
42
25
|
if (MIGRATION_RE.test(rel)) process.exit(0)
|
|
43
26
|
|
|
44
|
-
// State 2: Not an entity file
|
|
45
27
|
const match = rel.match(ENTITY_RE)
|
|
46
|
-
if (!match) process.exit(0)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'',
|
|
57
|
-
`Affected module: ${moduleId}`,
|
|
58
|
-
'',
|
|
59
|
-
'A database migration is likely needed. Ask the user whether to run:',
|
|
60
|
-
' yarn db:generate',
|
|
61
|
-
'',
|
|
62
|
-
'Then regenerate registries:',
|
|
63
|
-
' yarn generate',
|
|
64
|
-
'',
|
|
65
|
-
'Do NOT run migrations automatically — always confirm with the user first.',
|
|
66
|
-
'',
|
|
67
|
-
].join('\n'),
|
|
68
|
-
)
|
|
28
|
+
if (!match || hasFreshMigration(projectDir, match[1])) process.exit(0)
|
|
29
|
+
|
|
30
|
+
process.stderr.write([
|
|
31
|
+
`Entity contract changed: ${rel}`,
|
|
32
|
+
'',
|
|
33
|
+
'Run `yarn db:generate` as a schema-diff probe and review only the scoped migration plus module snapshot.',
|
|
34
|
+
'Run `yarn generate` when discovery changed.',
|
|
35
|
+
'Do not apply the migration with `yarn db:migrate` without explicit user approval.',
|
|
36
|
+
'',
|
|
37
|
+
].join('\n'))
|
|
69
38
|
process.exit(1)
|
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Entity
|
|
2
|
+
description: Entity schema-diff guard for the canonical standalone entity file
|
|
3
3
|
globs:
|
|
4
|
-
- src/modules/*/entities
|
|
4
|
+
- src/modules/*/data/entities.ts
|
|
5
5
|
alwaysApply: false
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
# Entity
|
|
8
|
+
# Entity Schema Change
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Follow root `AGENTS.md` and `om-data-model-design`:
|
|
11
11
|
|
|
12
|
-
1.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
1. Run `yarn db:generate` as a schema-diff probe.
|
|
13
|
+
2. Review and keep only scoped migration SQL plus the touched module snapshot.
|
|
14
|
+
3. Run `yarn generate` when discovery changed.
|
|
15
|
+
4. Ask before applying with `yarn db:migrate`.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
3. **Apply the migration** (only after user confirms):
|
|
20
|
-
```
|
|
21
|
-
yarn db:migrate
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
4. **Regenerate registries**:
|
|
25
|
-
```
|
|
26
|
-
yarn generate
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Do NOT skip any step. Do NOT run migrations without user confirmation.
|
|
17
|
+
Never edit a shipped migration or generated registry.
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Prevent
|
|
2
|
+
description: Prevent edits to generated application registries
|
|
3
3
|
globs:
|
|
4
4
|
- .mercato/generated/**
|
|
5
5
|
alwaysApply: false
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# Generated File
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
To change generated output, edit the source modules in `src/modules/` and run `yarn generate`.
|
|
10
|
+
Do not edit this file. Change the app module source and run `yarn generate`; follow root `AGENTS.md` for the routed contract.
|
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: Route every standalone app task through the root agent rules
|
|
3
3
|
alwaysApply: true
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# {{PROJECT_NAME}} —
|
|
6
|
+
# {{PROJECT_NAME}} — Cursor Entry Point
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
A standalone Open Mercato application. Build domain features ON TOP of the framework.
|
|
11
|
-
To customise a core module beyond the extension system: `yarn mercato eject <module>`.
|
|
12
|
-
Never edit node_modules/@open-mercato/* directly.
|
|
13
|
-
|
|
14
|
-
## Task routing
|
|
15
|
-
|
|
16
|
-
Read AGENTS.md before starting any task — it maps task types to the minimum files to load.
|
|
17
|
-
|
|
18
|
-
## Module system
|
|
19
|
-
|
|
20
|
-
Modules in `src/modules/<id>/`. Register with `from: '@app'` in `src/modules.ts`.
|
|
21
|
-
Run `yarn generate` after any module or entity change. Never edit `.mercato/generated/*`.
|
|
22
|
-
|
|
23
|
-
## Entity and migration rule
|
|
24
|
-
|
|
25
|
-
After editing any entity in `src/modules/<id>/entities/`:
|
|
26
|
-
1. Create migration: `yarn db:generate`
|
|
27
|
-
2. Show migration to user, confirm before applying
|
|
28
|
-
3. Apply: `yarn db:migrate`
|
|
29
|
-
4. Regenerate: `yarn generate`
|
|
30
|
-
|
|
31
|
-
## Spec-driven development
|
|
32
|
-
|
|
33
|
-
Check `.ai/specs/` before any significant feature. If no spec exists, ask the user
|
|
34
|
-
whether to create one first.
|
|
8
|
+
Read `AGENTS.md`, match every applicable Task Router row, and load only the routed guides, skills, and module facts. The root file owns architecture, safety, writable paths, migrations, generation, and validation; do not duplicate or override it here.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# AI Agents, Orchestrators, and Workflows
|
|
2
|
+
|
|
3
|
+
Use typed module contracts for product AI and the workflow engine for durable business processes. Keep model/tool execution, mutation approval, scope, storage, and retries explicit.
|
|
4
|
+
|
|
5
|
+
## Choose the Surface
|
|
6
|
+
|
|
7
|
+
| Need | Use |
|
|
8
|
+
|---|---|
|
|
9
|
+
| In-app conversational or structured domain assistant | Module `ai-agents.ts` plus `ai-tools.ts`. |
|
|
10
|
+
| Low-level MCP/OpenCode or Code Mode work | `ai_assistant` installed contract: `registerMcpTool`, MCP server, OpenCode handlers/config, or the `search`/`execute` Code Mode tools. Do not conflate this with a typed product agent. |
|
|
11
|
+
| Add a few tools/prompt/suggestions to an installed agent | `aiAgentExtensions`. |
|
|
12
|
+
| Replace or disable an installed agent/tool | `aiAgentOverrides` / `aiToolOverrides` or module entry override. |
|
|
13
|
+
| Coding-agent orchestration with files, outcomes, samples, embedded skill, or subagents | Orchestrator file-agent contract; resolve its installed package guide first. |
|
|
14
|
+
| Durable business process, human task, timer, signal, compensation, or event trigger | Workflows module and `om-build-workflow`. |
|
|
15
|
+
| One background AI extraction | Object-mode agent invoked from a scoped command/worker. |
|
|
16
|
+
|
|
17
|
+
## Typed Module Agents and Tools
|
|
18
|
+
|
|
19
|
+
- Put `ai-agents.ts` and `ai-tools.ts` at the module root. Export typed arrays and run `yarn generate`.
|
|
20
|
+
- Give agent IDs `<module>.<agent>` and tool names stable namespaced IDs. Declare provider/model defaults through the framework registry/model factory, not provider SDK singletons.
|
|
21
|
+
- Every data tool has a Zod input schema, tenant/org scope, wildcard-aware `requiredFeatures`, bounded output, and a serializable result.
|
|
22
|
+
- Mark writes `isMutation: true`. Pair mutation-capable agents with `readOnly: false` and a confirmation policy.
|
|
23
|
+
- A write tool calls `prepareMutation`; the durable execute callback performs a command-based, optimistic-lock-aware mutation. Never write directly before approval.
|
|
24
|
+
- Use declarative loop controls/budgets. The wrapper-owned approval guard remains active on every step and execution engine.
|
|
25
|
+
- Validate attachments by type/size/scope. Store outputs through authorized artifact/attachment services with retention and encrypted sensitive metadata.
|
|
26
|
+
|
|
27
|
+
## MCP, OpenCode, and Code Mode
|
|
28
|
+
|
|
29
|
+
- Prefer `defineAiTool` in discovered `ai-tools.ts` for product agents, especially mutation-capable tools. Use low-level `registerMcpTool` only when the requested surface is explicitly the MCP/OpenCode registry. Both require Zod input, matching `moduleId`, wildcard-aware `requiredFeatures` for tenant data, bounded work, and a serializable handler result.
|
|
30
|
+
- OpenCode Code Mode exposes `search` over the generated OpenAPI document and `execute` through sandboxed `api.request()`. Endpoint-level RBAC and documented-feature checks still apply; Code Mode is not an authorization bypass and undocumented/featureless mutation endpoints fail closed.
|
|
31
|
+
- Production MCP uses two-tier auth: the server request carries `x-api-key`, then every tool call carries `_sessionToken`; the runtime resolves the user/session scope and performs per-tool ACL checks on every request. Never cache MCP server instances or ACL context across requests.
|
|
32
|
+
- Ask before editing OpenCode configuration, Docker wiring, MCP authentication, provider/model precedence, or session-token format/TTL. Preserve session IDs across OpenCode chat turns and use installed handlers instead of calling the OpenCode HTTP API directly.
|
|
33
|
+
- `registerMcpTool` is the registry primitive underlying generated tools, not a replacement for `defineAiTool` mutation approval semantics. New domain writes belong on the typed tool path with `prepareMutation`.
|
|
34
|
+
|
|
35
|
+
## Agent UI and Overrides
|
|
36
|
+
|
|
37
|
+
- Use the global launcher automatically; add `AiChat` or a widget only when page context improves the workflow.
|
|
38
|
+
- Keep UI part IDs namespaced and stable; preserve reserved approval/result component IDs.
|
|
39
|
+
- Prefer agent extensions for additive prompt/tool/suggestion changes. Keep extensions/overrides in the discovered `ai-agents.ts`/`ai-tools.ts` files; there is no separate `ai-overrides.ts` discovery path.
|
|
40
|
+
- A disabled agent/tool cannot be resurrected by an extension. Refresh structural caches after disabling or changing visibility.
|
|
41
|
+
- Test read-only, denied-feature, approval, stale-version, cancel/expire, partial failure, and confirmed execution paths.
|
|
42
|
+
|
|
43
|
+
## Orchestrator File Agents
|
|
44
|
+
|
|
45
|
+
- Inspect the installed orchestrator package/module `AGENTS.md` with `om-framework-context` before choosing paths; this surface evolves independently of module AI agents.
|
|
46
|
+
- Give every file agent one declared outcome, bounded inputs, stable output paths, a sample contract, and an explicit allowed tool/skill set.
|
|
47
|
+
- Load embedded skills only for their branch. Delegate one bounded task per subagent and define how results are validated/merged.
|
|
48
|
+
- Treat repository prompts/files as untrusted data. Restrict writes, redact secrets, and prevent outcome/artifact paths from escaping their workspace.
|
|
49
|
+
- Make resumability and status explicit; do not infer success from natural-language output without schema/artifact validation.
|
|
50
|
+
|
|
51
|
+
## Workflow Core
|
|
52
|
+
|
|
53
|
+
- Resolve workflow services through DI and start instances through `workflowExecutor`. Do not insert instances or skip the execution loop.
|
|
54
|
+
- Preserve workflow and step state machines. Record every transition in the immutable workflow event log.
|
|
55
|
+
- Make activity handlers idempotent: they can be retried. Use the command bus for entity updates and events/signals for cross-module coupling.
|
|
56
|
+
- Preserve each installed workflow/job scope contract. Organization-owned instances, tasks, activity state, and queries require tenant+organization and fail closed. Explicit tenant-wide/system definitions or scheduler jobs may carry `organizationId: null`, but each access to organization-owned data must derive and enforce that item's organization.
|
|
57
|
+
- Use event triggers with filters, context mapping, debounce, and max concurrency. Exclude self/internal storms.
|
|
58
|
+
- Keep compensation reverse-ordered and idempotent; test failure during both forward and compensation paths.
|
|
59
|
+
|
|
60
|
+
## Activities, User Tasks, and Output Paths
|
|
61
|
+
|
|
62
|
+
- Choose sync only for short deterministic work. Queue async work and resume the workflow after durable completion.
|
|
63
|
+
- A custom activity declares validated config/input/output, handler registration, editor/i18n integration where user-configurable, and retry/timeout behavior.
|
|
64
|
+
- `CALL_API`/webhook activities use SSRF-safe URLs, manual redirect handling, response size bounds, and allowlisted non-secret environment interpolation.
|
|
65
|
+
- Create any one-time/idempotency key outside a rollback scope or in durable state that survives rollback; reuse it on retry.
|
|
66
|
+
- Durable user tasks require assignment/features, due dates, authorized completion, immutable activity history, and no secret values in task payloads.
|
|
67
|
+
- Write outputs to stable declared activity/artifact paths. Validate path containment and access; clean temporary files while retaining declared deliverables.
|
|
68
|
+
- Emit progress/events for long work and render them through shared progress/UI contracts rather than unbounded polling.
|
|
69
|
+
|
|
70
|
+
## Verification
|
|
71
|
+
|
|
72
|
+
1. Run `yarn generate` and confirm agent/tool/workflow registrations.
|
|
73
|
+
2. Test missing provider/configuration, denied ACL, missing scope, timeout, retry, duplicate, and cancellation.
|
|
74
|
+
3. For AI writes, prove no domain write occurs before approval and a stale approval cannot overwrite newer data.
|
|
75
|
+
4. For workflows, prove event log/state transitions and idempotency across worker restart and injected rollback.
|
|
76
|
+
5. For orchestrators, validate output schema/artifacts and allowed-write boundaries, not just prose.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Standalone Architecture and Discovery
|
|
2
|
+
|
|
3
|
+
Use this guide to choose ownership, locate module surfaces, and keep generated discovery correct.
|
|
4
|
+
|
|
5
|
+
## Context Ownership and Scattering
|
|
6
|
+
|
|
7
|
+
The harness is intentionally layered so an agent can assemble precise context without paying for the whole framework:
|
|
8
|
+
|
|
9
|
+
| Layer | Owns | Loading rule |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Root `AGENTS.md` | Non-negotiable safety, validation, precedence, and the three-axis router | Load first and always; it is the only initial bundle. |
|
|
12
|
+
| `.ai/guides/*.md` | Stable framework concepts and contracts by area | Load the de-duplicated set selected by the area and primitive axes. |
|
|
13
|
+
| Thin task skills | Branching procedure and links to focused references | Load only matched skills; open only the references needed by the chosen branch. |
|
|
14
|
+
| `.ai/guides/modules/*.md` | Generated identifiers and discovered surfaces for an exact installed module/version | Load only for installed modules named, changed, integrated with, or used as hosts. |
|
|
15
|
+
| `om-framework-context` output | Exact installed instructions, source/types, and bounded search results | Last-mile escalation after app call sites, facts, and concept guides cannot answer the question. |
|
|
16
|
+
| External `open-mercato/skills` | SDLC and delivery workflows | Select independently only when the requested lifecycle needs one. |
|
|
17
|
+
|
|
18
|
+
Match area, work units, and delivery independently, then de-duplicate their union by path and skill. A business one-shot is not one giant context category: split it into units such as entity, command, API, admin UI, public capture, CRM extension, event, and provider, and give each unit only its owning area and contract. Do not preload all module facts, skill references, upstream guides, or installed package source.
|
|
19
|
+
|
|
20
|
+
Keep facts and source in different roles. Facts answer “what identifier or surface exists?”; exact installed source answers “how does this version implement or type the contract?” The latter is read-only evidence, never a writable escape hatch.
|
|
21
|
+
|
|
22
|
+
## Ownership Decision
|
|
23
|
+
|
|
24
|
+
| Need | Choose |
|
|
25
|
+
|---|---|
|
|
26
|
+
| App-specific domain capability | Create `src/modules/<id>/` and register `{ id, from: '@app' }` in `src/modules.ts`. |
|
|
27
|
+
| Additive change to an installed module | Use the smallest UMES mechanism from `.ai/guides/extensions.md`. |
|
|
28
|
+
| Disable/replace a supported installed contract | Use the target module entry's `overrides` in `src/modules.ts`. |
|
|
29
|
+
| Reusable external provider | Add/install a dedicated provider package; do not place provider logic in a generic core module. |
|
|
30
|
+
| Change unsupported by UMES/overrides | Inspect exact installed context, then use `om-eject-and-customize` only with user approval. |
|
|
31
|
+
| Framework defect affecting all consumers | Reproduce against the installed version and report an upstream change; never patch `node_modules`. |
|
|
32
|
+
|
|
33
|
+
## Writable and Read-Only Trees
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
src/modules/<id>/ writable app modules
|
|
37
|
+
src/modules.ts enabled modules and supported overrides
|
|
38
|
+
.mercato/generated/ generated, never edit
|
|
39
|
+
.ai/guides/modules/ generated facts, never edit
|
|
40
|
+
node_modules/@open-mercato/*/ exact installed packages, read-only
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Do not copy an installed module merely to learn it. Generated facts and the context resolver expose the exact installed source without widening the writable surface.
|
|
44
|
+
|
|
45
|
+
## Canonical Module Shape
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
src/modules/<id>/
|
|
49
|
+
├── index.ts
|
|
50
|
+
├── data/{entities,validators,extensions,enrichers}.ts
|
|
51
|
+
├── api/**/route.ts
|
|
52
|
+
├── backend/**/{page.tsx,page.meta.ts}
|
|
53
|
+
├── frontend/**/{page.tsx,page.meta.ts}
|
|
54
|
+
├── commands/
|
|
55
|
+
├── subscribers/
|
|
56
|
+
├── workers/
|
|
57
|
+
├── widgets/{injection,injection-table.ts,components.ts}
|
|
58
|
+
├── acl.ts
|
|
59
|
+
├── setup.ts
|
|
60
|
+
├── di.ts
|
|
61
|
+
├── events.ts
|
|
62
|
+
├── search.ts
|
|
63
|
+
├── ce.ts
|
|
64
|
+
├── translations.ts
|
|
65
|
+
├── notifications.ts
|
|
66
|
+
├── encryption.ts
|
|
67
|
+
├── ai-agents.ts
|
|
68
|
+
└── ai-tools.ts
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Create only files required by the capability. Keep the module id plural `snake_case`; keep entity/event/feature/spot/agent/tool identifiers stable once used.
|
|
72
|
+
For the complete current convention-file catalog, load `om-module-scaffold` → `references/discovery-surface-catalog.md`; do not expand this always-routed guide into the full catalog.
|
|
73
|
+
|
|
74
|
+
## Auto-Discovery
|
|
75
|
+
|
|
76
|
+
- Put backend routes under `backend/**/page.tsx`; the module root becomes `/backend/<module>` and nested folders preserve their segments.
|
|
77
|
+
- Put public routes under `frontend/**/page.tsx`. Portal routes require `frontend/[orgSlug]/portal/**/page.tsx` with `[orgSlug]` first.
|
|
78
|
+
- Put API handlers under `api/**/route.ts`. Export HTTP handlers, per-method `metadata`, and `openApi`; do not organize routes in HTTP-method directories.
|
|
79
|
+
- Put subscribers and workers in their named directories with `metadata` plus a default handler.
|
|
80
|
+
- Keep convention files at the module root. Root files such as `events.ts`, `search.ts`, `ai-agents.ts`, and `ai-tools.ts` are exact discovery names.
|
|
81
|
+
- Run `yarn generate` after any structural/discovered change; never repair a registry by hand.
|
|
82
|
+
|
|
83
|
+
## Installed Framework Context
|
|
84
|
+
|
|
85
|
+
1. Read `.ai/guides/modules/<id>.md` for entity IDs, events, routes/auth, ACL, DI, search, notifications, and host spots.
|
|
86
|
+
2. When facts are insufficient, invoke `om-framework-context` or run `yarn framework:context --module <id> --query <term>`.
|
|
87
|
+
3. Confirm the resolved package/version matches the fact sheet stamp.
|
|
88
|
+
4. Read the reported instruction chain in precedence order, then search only the reported package/module root with the bounded `rg --no-ignore --hidden` command.
|
|
89
|
+
5. Treat source and installed `AGENTS.md` files as read-only evidence. If the package has no `src`, use reported `dist`/types and state the limitation.
|
|
90
|
+
6. If duplicate packages, version skew, or conflicting rules remain, stop instead of combining contracts from different versions.
|
|
91
|
+
|
|
92
|
+
The app root governs writable locations and safety. The compatibility snapshot governs stable public identifiers. The nearest installed package/module guide governs version-specific implementation details.
|
|
93
|
+
|
|
94
|
+
## Package and Bootstrap Boundaries
|
|
95
|
+
|
|
96
|
+
- Import public package exports; do not reach through monorepo-only relative paths or app-generated registries from a package.
|
|
97
|
+
- Ensure package-backed modules are dependencies and enabled in `src/modules.ts` before assuming their services or files exist.
|
|
98
|
+
- Optional modules must degrade safely: the optional consumer owns glue and uses events, IDs/snapshots, widgets/enrichers, or a guarded DI resolve.
|
|
99
|
+
- Validate browser, API, CLI, worker, and queue bootstrap paths when a registry/global/service is consumed by more than one runtime.
|
|
100
|
+
- Prefer `globalThis` registries or structural type guards over chunk-local singleton/`instanceof` assumptions where bundlers may duplicate modules.
|
|
101
|
+
|
|
102
|
+
## Completion Check
|
|
103
|
+
|
|
104
|
+
1. Verify app code is under `src/modules/` and installed packages remain unchanged.
|
|
105
|
+
2. Verify every new discovered file uses its exact filename/export contract.
|
|
106
|
+
3. Run `yarn generate` and inspect warnings and the affected generated registration.
|
|
107
|
+
4. Run focused type/tests, then exercise every relevant runtime bootstrap.
|