Skip to content

Commit 890b38f

Browse files
claude[bot]claude
andauthored
fix(spec): published agent prompts reference real exports (#9545) (#9615)
Three published agent-authoring prompts in packages/spec/prompts told agents to import five symbols @objectstack/spec does not export. Four failed loudly. The fifth did not: `import { Object } from '@objectstack/spec/data'` does not resolve, so `export const AccountObject: Object = { ... }` bound to the JavaScript global instead, and metadata authored from that prompt type-checked against a type that constrains nothing -- false assurance handed to an automated author. Every substitution was measured against the built .d.ts, not guessed: - Object -> ObjectSchema.create({ ... }), the house authoring convention (34 uses across the example apps; zero uses of the annotation form). Making the form genuinely constrain exposed that the prompt's own example set enable.audit / enable.workflow, neither of which exists; they are now trackHistory / files, the pair the schema's own docstring uses. - implement-objectql.md keeps the real Field and QuerySchema imports and derives the metadata type as z.infer of typeof ObjectSchema, matching prompts/instructions.md and spec's own src/contracts/schema-driver.ts. No bare Object type is exported -- it would shadow the JS global. - ManifestSchema -> ObjectStackDefinitionSchema on the package root. The prompt's subject is objectstack.config.ts, which is neither /system manifest. - IdentitySchema / PolicySchema have no bare referent anywhere in spec. Rule #2 now names RLSUserContextSchema and RowLevelSecurityPolicySchema from @objectstack/spec/security. - The three dead "Key Files to Watch" paths now point at stack.zod.ts, security/rls.zod.ts and kernel/events.zod.ts. The five baseline entries are deleted in the same commit; the gate is reconciled in both directions and green. Claude-Session: https://claude.ai/code/session_01Fs18A2DdXLVN2h8PaaFBcP Co-authored-by: Claude <noreply@anthropic.com>
1 parent 07e630e commit 890b38f

5 files changed

Lines changed: 69 additions & 40 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
Published agent-authoring prompts now reference real exports.
6+
7+
`prompts/create-new-project.md`, `prompts/implement-objectql.md` and
8+
`prompts/implement-objectos.md` told agents to import five symbols that
9+
`@objectstack/spec` does not export. Four failed loudly. The fifth did not:
10+
`import { Object } from '@objectstack/spec/data'` does not resolve, so the
11+
annotation in `export const AccountObject: Object = { ... }` bound to the
12+
**JavaScript global** `Object` instead — metadata authored from that prompt
13+
type-checked against a type that constrains nothing.
14+
15+
- Object definitions now use the house authoring convention measured in the
16+
example apps, `ObjectSchema.create({ ... })`, which genuinely validates.
17+
Correcting it exposed that the prompt's own example set `enable.audit` /
18+
`enable.workflow`, neither of which exists; they are now `trackHistory` /
19+
`files`, the pair the schema's own docstring uses.
20+
- `implement-objectql.md` keeps the real `Field` and `QuerySchema` imports and
21+
derives the object metadata type as `z.infer<typeof ObjectSchema>`, matching
22+
both `prompts/instructions.md` ("interfaces must be inferred from Zod") and
23+
spec's own `src/contracts/schema-driver.ts`.
24+
- `ManifestSchema` becomes `ObjectStackDefinitionSchema` from the package root:
25+
the prompt's subject is `objectstack.config.ts`, which is neither of the
26+
`/system` manifests.
27+
- `IdentitySchema` / `PolicySchema` have no bare referent; Rule #2 now names
28+
`RLSUserContextSchema` and `RowLevelSecurityPolicySchema` from
29+
`@objectstack/spec/security`.
30+
- The three non-existent "Key Files to Watch" paths
31+
(`system/{manifest,identity,events}.zod.ts`) now point at `stack.zod.ts`,
32+
`security/rls.zod.ts` and `kernel/events.zod.ts`.

packages/spec/prompts/create-new-project.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ my-app/
3838

3939
# Implementation Rules
4040

41-
1. **Strict Typing:** Always explicit types.
41+
1. **Strict Typing:** Always define metadata through its schema, never as a bare literal.
4242
* BAD: `const MyObject = { ... }`
43-
* GOOD: `export const MyObject: Object = { ... }`
43+
* GOOD: `export const MyObject = ObjectSchema.create({ ... })`
4444

4545
2. **Naming Conventions:**
4646
* **File Names:** `snake_case` or `domain.feature.ts` (e.g., `account.object.ts`).
@@ -49,14 +49,14 @@ my-app/
4949

5050
3. **Code Pattern (Object Definition):**
5151
```typescript
52-
import { Object } from '@objectstack/spec/data';
52+
import { ObjectSchema } from '@objectstack/spec/data';
5353

54-
export const AccountObject: Object = {
54+
export const AccountObject = ObjectSchema.create({
5555
name: 'account',
5656
label: 'Corporate Account',
5757
enable: {
58-
audit: true,
59-
workflow: true
58+
trackHistory: true,
59+
files: true
6060
},
6161
fields: {
6262
name: { type: 'text', label: 'Account Name', required: true },
@@ -66,7 +66,7 @@ my-app/
6666
},
6767
owner: { type: 'lookup', reference: 'user' }
6868
}
69-
};
69+
});
7070
```
7171

7272
4. **Code Pattern (App Config):**

packages/spec/prompts/implement-objectos.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ Your source of truth is `node_modules/@objectstack/spec`.
1212

1313
### Rule #1: Manifest Driven Boot
1414
The system MUST boot by loading and validating the `objectstack.config.ts`.
15+
That file's authoring surface is `defineStack`, and its schema is
16+
`ObjectStackDefinitionSchema` on the package root — not one of the `/system`
17+
manifests (`AppManifestSchema` installs an app into a running stack;
18+
`DeployManifestSchema` describes a deploy bundle).
1519
```typescript
16-
import { ManifestSchema } from '@objectstack/spec/system';
20+
import { ObjectStackDefinitionSchema } from '@objectstack/spec';
1721
// The kernel starts here
18-
const config = ManifestSchema.parse(loadedConfig);
22+
const config = ObjectStackDefinitionSchema.parse(loadedConfig);
1923
```
2024

2125
### Rule #2: Security First (Identity & Policy)
22-
All request handlers must validate against `IdentitySchema`.
23-
No operation proceeds without checking `PolicySchema`.
26+
All request handlers must validate the caller's security context against
27+
`RLSUserContextSchema`. No operation proceeds without evaluating the applicable
28+
`RowLevelSecurityPolicySchema` rules against that context.
2429
```typescript
25-
import { IdentitySchema, PolicySchema } from '@objectstack/spec/system';
30+
import {
31+
RLSUserContextSchema,
32+
RowLevelSecurityPolicySchema,
33+
} from '@objectstack/spec/security';
2634
```
35+
There is no bare `Identity` or `Policy` schema: identity is the per-request RLS
36+
user context, and policy is per-object and per-operation. Broader posture lives
37+
in the qualified schemas (`TenantSecurityPolicySchema`, `PermissionSetSchema`).
2738

2839
### Rule #3: API Gateway Contract
2940
The HTTP/Gateway layer must perform strict request/response validation using `api/contract.zod.ts` and `api/endpoint.zod.ts`.
@@ -36,13 +47,13 @@ Do not invent event formats. Use the standard CloudEvents-compatible structure.
3647

3748
## 3. Workflow
3849

39-
1. **Define Configuration**: Start by mapping `ManifestSchema` to your runtime config.
40-
2. **Initialize Identity**: Implement the Auth Provider using `IdentitySchema`.
50+
1. **Define Configuration**: Start by mapping `ObjectStackDefinitionSchema` to your runtime config.
51+
2. **Initialize Identity**: Implement the Auth Provider so it produces a context that satisfies `RLSUserContextSchema`.
4152
3. **Setup Gateway**: Configure routes based on `ApiRoutesSchema` (from `api/discovery.zod.ts`).
4253

4354
## 4. Key Files to Watch
4455

45-
- `system/manifest.zod.ts`: The "Kernel Configuration".
46-
- `system/identity.zod.ts`: The "Security Context".
47-
- `system/events.zod.ts`: The "System Bus".
56+
- `stack.zod.ts`: The "Kernel Configuration" (`ObjectStackDefinitionSchema`, `defineStack`).
57+
- `security/rls.zod.ts`: The "Security Context" (`RLSUserContextSchema`, `RowLevelSecurityPolicySchema`).
58+
- `kernel/events.zod.ts`: The "System Bus" (`EventSchema`; the `kernel/events/*` sub-modules are internal — import from the published `@objectstack/spec/kernel` entrypoint).
4859
- `api/contract.zod.ts`: The "Wire Protocol".

packages/spec/prompts/implement-objectql.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ Your source of truth is `node_modules/@objectstack/spec`.
1111
## 2. Implementation Rules
1212

1313
### Rule #1: Never Redefine Types
14-
Do not create your own interfaces for `Object`, `Field`, or `Query`.
15-
ALWAYS import them:
14+
Do not create your own interfaces for object metadata, `Field`, or `Query`.
15+
ALWAYS import them, and derive any type you need from the schema:
1616
```typescript
17-
import { type Object, ObjectSchema } from '@objectstack/spec/data';
17+
import { z } from 'zod';
18+
import { ObjectSchema, type Field, QuerySchema } from '@objectstack/spec/data';
19+
20+
// The object metadata type is NOT exported under the name `Object` — that would
21+
// shadow the JS global and silently type-check against it. Derive it instead:
22+
type ObjectMetadata = z.infer<typeof ObjectSchema>;
23+
type Query = z.infer<typeof QuerySchema>;
1824
```
1925

2026
### Rule #2: Schema-First Validation

scripts/published-readme-exports.baseline.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,6 @@
4242
{
4343
"id": "@objectstack/spec|packages/spec/README.md|import|@objectstack/spec/ai|MCPServerConfigSchema",
4444
"why": "@objectstack/spec/ai exports `MCPServerRefSchema`; there is no `MCPServerConfigSchema`. This is the protocol package's own front page."
45-
},
46-
{
47-
"id": "@objectstack/spec|packages/spec/prompts/create-new-project.md|import|@objectstack/spec/data|Object",
48-
"why": "@objectstack/spec/data exports `ObjectSchema`. `Object` resolves to the JS global instead of failing loudly — the worst shape for a published AGENT-AUTHORING prompt."
49-
},
50-
{
51-
"id": "@objectstack/spec|packages/spec/prompts/implement-objectos.md|import|@objectstack/spec/system|ManifestSchema",
52-
"why": "@objectstack/spec/system exports `AppManifestSchema` and `DeployManifestSchema`; there is no bare `ManifestSchema`. Published agent-authoring prompt."
53-
},
54-
{
55-
"id": "@objectstack/spec|packages/spec/prompts/implement-objectos.md|import|@objectstack/spec/system|IdentitySchema",
56-
"why": "@objectstack/spec/system exports `Identity`; there is no `IdentitySchema`. Published agent-authoring prompt."
57-
},
58-
{
59-
"id": "@objectstack/spec|packages/spec/prompts/implement-objectos.md|import|@objectstack/spec/system|PolicySchema",
60-
"why": "@objectstack/spec/system has no bare `PolicySchema` — only qualified ones (`KeyRotationPolicySchema`, `IncidentResponsePolicySchema`, `DataClassificationPolicySchema`, …). Published agent-authoring prompt."
61-
},
62-
{
63-
"id": "@objectstack/spec|packages/spec/prompts/implement-objectql.md|import|@objectstack/spec/data|Object",
64-
"why": "Same fabrication as create-new-project.md: `ObjectSchema` is the real export."
6545
}
6646
]
6747
}

0 commit comments

Comments
 (0)