-
Notifications
You must be signed in to change notification settings - Fork 0
feat(runtime): add channel-neutral execution context #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7efea7a
feat(runtime): add channel-neutral execution context
chitcommit 21b56a7
feat(runtime): mount execution context after authorization
chitcommit 61e758d
feat(runtime): type execution context in Hono variables
chitcommit 0b49f10
feat(audit): attach execution provenance to ledger writes
chitcommit 8993c9b
feat(mcp): label canonical capability and intent
chitcommit dffa4d5
test(runtime): prove channel-neutral execution context
chitcommit 74cd44e
docs(agents): define channel-neutral execution context
chitcommit 4c3dd02
docs(security): document cross-channel provenance boundary
chitcommit c500607
docs(charter): declare portable execution context
chitcommit f6923b4
docs(chitty): describe provider-neutral runtime context
chitcommit 6d9d509
fix(runtime): sanitize claimed provenance and intent inference
chitcommit 055c2a6
fix(audit): type execution provenance enrichment
chitcommit b5b498a
fix(mcp): declare execution intent per tool
chitcommit f54aacd
test(runtime): cover provenance sanitization and exact intent matching
chitcommit 1b676cf
test(mcp): align unknown-tool validation behavior
chitcommit 1074941
fix(runtime): fail safe on intent and distinguish claimed provenance
chitcommit 458d9a6
fix(mcp): canonicalize resource capabilities and preserve errors
chitcommit 82970eb
test(mcp): verify real execution capability wiring
chitcommit a749d27
test(audit): verify ledger execution provenance enrichment
chitcommit 8007be6
docs(security): mark provenance and intent non-authoritative
chitcommit b21d4c4
docs(agents): clarify audit-only execution intent
chitcommit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { Hono } from 'hono'; | ||
| import type { HonoEnv } from '../env'; | ||
| import { | ||
| executionContextMiddleware, | ||
| inferExecutionIntent, | ||
| setExecutionOperation, | ||
| } from '../middleware/execution-context'; | ||
|
|
||
| function buildApp() { | ||
| const app = new Hono<HonoEnv>(); | ||
|
|
||
| app.use('*', async (c, next) => { | ||
| c.set('userId', 'user-1'); | ||
| c.set('authMethod', 'chittyauth'); | ||
| c.set('tenantId', 'tenant-authorized'); | ||
| await next(); | ||
| }); | ||
| app.use('*', executionContextMiddleware); | ||
|
|
||
| app.get('/api/test', (c) => c.json(c.get('executionContext'))); | ||
| app.post('/api/allocations/preview', (c) => c.json(c.get('executionContext'))); | ||
| app.post('/api/allocations/execute', (c) => c.json(c.get('executionContext'))); | ||
| app.post('/mcp-test', (c) => { | ||
| setExecutionOperation(c, 'finance.mcp.tool:get-property-advice', 'suggest'); | ||
| return c.json(c.get('executionContext')); | ||
| }); | ||
|
|
||
| return app; | ||
| } | ||
|
|
||
| describe('execution context', () => { | ||
| it('infers read, preview, suggest, and execute mechanically', () => { | ||
| expect(inferExecutionIntent('GET', '/api/accounts')).toBe('read'); | ||
| expect(inferExecutionIntent('POST', '/api/allocations/preview')).toBe('preview'); | ||
| expect(inferExecutionIntent('POST', '/api/classification/suggest')).toBe('suggest'); | ||
| expect(inferExecutionIntent('POST', '/api/allocations/execute')).toBe('execute'); | ||
| expect(inferExecutionIntent('POST', '/api/x/preview-and-commit')).toBe('execute'); | ||
| }); | ||
|
|
||
| it('captures sanitized channel-neutral provenance from source header and W3C baggage', async () => { | ||
| const app = buildApp(); | ||
| const res = await app.request('/api/test', { | ||
| headers: { | ||
| 'X-Source-Service': 'chittyclaw', | ||
| baggage: 'chitty.channel=slack;prop=1,chitty.workspace=workspace-1,chitty.session=session-1', | ||
| traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01', | ||
| }, | ||
| }); | ||
| const body = await res.json() as any; | ||
|
|
||
| expect(body.actor).toEqual({ userId: 'user-1', authMethod: 'chittyauth' }); | ||
| expect(body.source).toEqual({ | ||
| service: 'chittyclaw', | ||
| claimed: true, | ||
| channel: 'slack', | ||
| workspace: 'workspace-1', | ||
| session: 'session-1', | ||
| }); | ||
| expect(body.scope).toEqual({ tenantId: 'tenant-authorized' }); | ||
| expect(body.intent).toBe('read'); | ||
| expect(body.trace.traceparent).toContain('4bf92f3577b34da6a3ce929d0e0e4736'); | ||
| expect(body.trace.requestId).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('drops malformed or oversized provenance values', async () => { | ||
| const app = buildApp(); | ||
| const res = await app.request('/api/test', { | ||
| headers: { | ||
| 'X-Source-Service': 'x'.repeat(129), | ||
| baggage: 'chitty.channel=' + 'y'.repeat(9000), | ||
| traceparent: 'not-a-traceparent', | ||
| }, | ||
| }); | ||
| const body = await res.json() as any; | ||
|
|
||
| expect(body.source.service).toBe('finance.chitty.cc'); | ||
| expect(body.source.channel).toBeUndefined(); | ||
| expect(body.trace.traceparent).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('uses chitty.source baggage only as a claimed provenance fallback', async () => { | ||
| const app = buildApp(); | ||
| const body = await (await app.request('/api/test', { | ||
| headers: { baggage: 'chitty.source=claude' }, | ||
| })).json() as any; | ||
|
|
||
| expect(body.source.service).toBe('claude'); | ||
| expect(body.source.claimed).toBe(true); | ||
| }); | ||
|
|
||
| it('does not derive financial scope from source metadata', async () => { | ||
| const app = buildApp(); | ||
| const res = await app.request('/api/test', { | ||
| headers: { | ||
| baggage: 'chitty.workspace=tenant-attacker,chitty.session=tenant-other', | ||
| }, | ||
| }); | ||
| const body = await res.json() as any; | ||
|
|
||
| expect(body.scope.tenantId).toBe('tenant-authorized'); | ||
| expect(body.source.workspace).toBe('tenant-attacker'); | ||
| }); | ||
|
|
||
| it('marks preview and execute routes distinctly', async () => { | ||
| const app = buildApp(); | ||
|
|
||
| const preview = await (await app.request('/api/allocations/preview', { method: 'POST' })).json() as any; | ||
| const execute = await (await app.request('/api/allocations/execute', { method: 'POST' })).json() as any; | ||
|
|
||
| expect(preview.intent).toBe('preview'); | ||
| expect(execute.intent).toBe('execute'); | ||
| }); | ||
|
|
||
| it('allows MCP to override the generic HTTP operation with canonical capability intent', async () => { | ||
| const app = buildApp(); | ||
| const body = await (await app.request('/mcp-test', { method: 'POST' })).json() as any; | ||
|
|
||
| expect(body.capability).toBe('finance.mcp.tool:get-property-advice'); | ||
| expect(body.intent).toBe('suggest'); | ||
| expect(body.actor.userId).toBe('user-1'); | ||
| expect(body.scope.tenantId).toBe('tenant-authorized'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new middleware only runs through
protectedRoute, butprotectedPrefixesdoes not include/api/allocations. Consequently, real requests to/api/allocations/previewand/api/allocations/executenever receive anexecutionContext, despite the new test asserting those intents using an isolated app that mounts the middleware globally; in particular, theallocation.executedledger entry remains unenriched. Add the allocation prefix to the production middleware registration rather than relying on the test-only setup.Useful? React with 👍 / 👎.