-
Notifications
You must be signed in to change notification settings - Fork 0
feat: tell Codex to run contextbridge open outside the sandbox #115
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
6 commits
Select commit
Hold shift + click to select a range
e66197d
feat: tell Codex to run contextbridge open outside the sandbox
blimmer 0bc46bc
refactor(skills): format rendered SKILL.md through prettier
blimmer 1836cc9
refactor(skills): drop open-specific text from codex sandbox partial
blimmer 6b00532
Merge branch 'main' into feat/skill-template-rendering
blimmer 56531a0
chore: pr feedback
blimmer c679f6c
refactor(skills): inject pino logger into build scripts via BaseContext
blimmer 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
| import { type BaseContext, createBaseContext, createLogger } from '@contextbridge/context'; | ||
|
|
||
| export function createScriptContext(): BaseContext { | ||
| const logger = createLogger({ level: 'info', destination: process.stderr }); | ||
| return createBaseContext({ | ||
| logger, | ||
| distinctId: 'skills-script', | ||
| telemetryDisabled: true, | ||
| }); | ||
| } |
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 |
|---|---|---|
| @@ -1,18 +1,27 @@ | ||
| import { mkdirSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { dirname } from 'node:path'; | ||
| import type { BaseContext, Logger } from '@contextbridge/context'; | ||
| import { SKILL_RENDERABLE_HARNESSES } from '@contextbridge/harness'; | ||
| import { loadAllFrom } from '#src/skills.ts'; | ||
| import { type RenderTarget, SOURCES_DIR, outDirFor, targetsFor } from './renderTargets.ts'; | ||
| import { createScriptContext } from './context.ts'; | ||
| import { type RenderTarget, SOURCES_DIR, outDirFor, targetsForAll } from './renderTargets.ts'; | ||
|
|
||
| function main(): void { | ||
| async function main(ctx: BaseContext): Promise<void> { | ||
| const { logger } = ctx; | ||
| SKILL_RENDERABLE_HARNESSES.forEach((harness) => rmSync(outDirFor(harness), { recursive: true, force: true })); | ||
| loadAllFrom(SOURCES_DIR).flatMap(targetsFor).forEach(writeTarget); | ||
| const skills = loadAllFrom(SOURCES_DIR); | ||
| const targetResult = await targetsForAll(skills); | ||
| if (targetResult.isErr()) { | ||
| logger.error(targetResult.error.message); | ||
| process.exit(1); | ||
| } | ||
| targetResult.value.forEach((target) => writeTarget(logger, target)); | ||
| } | ||
|
|
||
| function writeTarget({ path, body }: RenderTarget): void { | ||
| function writeTarget(logger: Logger, { path, body }: RenderTarget): void { | ||
| mkdirSync(dirname(path), { recursive: true }); | ||
| writeFileSync(path, body); | ||
| console.log(`wrote ${path}`); | ||
| logger.info(`wrote ${path}`); | ||
| } | ||
|
|
||
| main(); | ||
| await main(createScriptContext()); |
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
3 changes: 3 additions & 0 deletions
3
packages/skills/sources/_partials/codex/sandbox-escalation.md
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,3 @@ | ||
| ## Running this from Codex | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many skills will need this, so introducing the idea of a partial |
||
|
|
||
| This skill runs commands that require resources outside Codex's default sandbox. When invoking them, set `sandbox_permissions: "require_escalated"` and supply a brief `justification` describing what the command does. If the user runs the command regularly, suggest a matching `prefix_rule` (e.g., `["contextbridge", "<subcommand>"]`) so future invocations don't require re-approval. | ||
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,29 @@ | ||
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import Handlebars from 'handlebars'; | ||
|
|
||
| export type HandlebarsEnv = ReturnType<typeof Handlebars.create>; | ||
|
|
||
| export function createHandlebars(partialsDir: string): HandlebarsEnv { | ||
| const env = Handlebars.create(); | ||
| env.registerHelper('eq', (a: unknown, b: unknown) => a === b); | ||
| for (const { name, source } of loadPartials(partialsDir)) { | ||
| env.registerPartial(name, source); | ||
| } | ||
| return env; | ||
| } | ||
|
|
||
| interface LoadedPartial { | ||
| readonly name: string; | ||
| readonly source: string; | ||
| } | ||
|
|
||
| function loadPartials(rootDir: string): LoadedPartial[] { | ||
| if (!existsSync(rootDir)) return []; | ||
| return Array.from(new Bun.Glob('**/*.md').scanSync(rootDir)) | ||
| .sort((a, b) => a.localeCompare(b)) | ||
| .map((relPath) => ({ | ||
| name: relPath.replace(/\.md$/, ''), | ||
| source: readFileSync(join(rootDir, relPath), 'utf8'), | ||
| })); | ||
| } |
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.
I figure we'll have this with other harnesses eventually