mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 20:09:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The native Runner connects Paperclip tasks to Codex app-server. > - Paperclip passed its runtime context as `baseInstructions`. > - That field replaces the stock Codex base prompt. > - This pull request sends the same Paperclip context as additive developer instructions. > - Codex keeps its stock prompt and still receives Paperclip task instructions and tools. ## Linked Issues or Issue Description **What happened?** The native Codex driver and Rust provider sent Paperclip context through `baseInstructions` on thread start and resume. Codex used this text in place of its stock base instructions. Direct-chat resume also sent an empty replacement base. The Runner Lab session path used the same replacement field. **Expected behavior** Codex should retain its stock base prompt. Paperclip should add its runtime context through `developerInstructions`. Other provider facades should retain their current instruction handling. **Steps to reproduce** 1. Create a native Codex session through Paperclip Runner. 2. Inspect the `thread/start` request in the native provider trace. 3. Resume the session and inspect `thread/resume`. 4. Before this fix, these paths set `baseInstructions`. After this fix, the Codex paths set `developerInstructions` and omit `baseInstructions`. **Paperclip version or commit** Reproduced against master at `cad26c6bfb736039c8ed5743da650a44792a083c`. **Deployment mode** Built from source. Native Codex app-server and runnerd paths. A local protocol probe used codex-cli 0.153.4 and a localhost Responses stub. No duplicate fix or matching public issue was found in the GitHub search. ## What Changed - Send additive developer instructions on Codex start and resume in the TypeScript driver, Rust provider, and Runner Lab session path. - Carry the additive fragment through runnerd, including runtime asset path mapping. - Preserve existing instruction fields for other provider facades, including OpenCode. - Add start/resume/direct-chat regression coverage and check the actual Rust provider request. - Document the historical option and trace field names. Record progress and follow-ups in the working checklist. ## Verification - `pnpm -r typecheck` — passed. - `pnpm build` — passed. - Targeted Codex driver lifecycle, driver, and live-session Vitest suites — 139 tests passed. - `cargo test --manifest-path packages/paperclip-runner/runner/Cargo.toml --locked -p paperclip-runner-core --test codex_provider` — 91 passed, 2 ignored subprocess helpers. - Real app-server probe: a localhost Responses stub captured identical 14,732-character stock base instructions on fresh start and cold resume. Both requests retained the Paperclip marker in developer input. Both stub turns completed. No paid inference was used. - Runnerd transport Vitest suite — 182 tests passed. - The initial `pnpm test:run` attempt reported local dependency-loading, embedded PostgreSQL startup, and macOS `/var` versus `/private/var` path failures. It was stopped after those failures. Loading-suite reruns passed 1,428 tests after the build; native interaction/finalization reruns passed 38 tests. A seven-suite diagnostic rerun passed 463 tests and isolated the remaining path and PostgreSQL setup failures. - With `TMPDIR=/private/tmp`, workspace, gateway, interaction, and attachment suites passed all 356 tests. The remaining environment-image and native-session-resumption suites passed all 44 tests with the same canonical temp path. All affected suites passed on rerun. The original full local command was stopped after failures and is not claimed as passing. - All 55 PR checks passed at `83281439456181396f3707eecda5d2ebc90bd14d`. Greptile scored 5/5 with no open review threads. - No paid live campaign or Product E2E browser suite was run. This change has protocol and regression coverage; it does not claim improved task quality. ## Risks - Stock Codex behavior may differ from behavior under the previous Paperclip replacement prompt. Restoring that behavior is the intended change. - Existing Codex threads retain their saved replacement base prompt. They need a provider session reset to receive the stock base. This PR does not reset active sessions or alter recovery rules. - The legacy `baseInstructions` option and trace field names remain for compatibility. They now describe the additive Paperclip fragment for Codex. - The separate Codex-through-ACP dependency patch remains a follow-up in the harness coverage checklist. This PR covers native app-server execution. ## Model Used OpenAI Codex, GPT-6. The exact runtime model variant and context window are not exposed in this session. Used reasoning, repository inspection, code editing, shell execution, and test tools. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
184 lines
6.4 KiB
TypeScript
184 lines
6.4 KiB
TypeScript
import type {
|
|
PrpCapabilities,
|
|
PrpEvent,
|
|
PrpStructuredRunResult,
|
|
} from "../protocol/replay-contract.js";
|
|
import type { SessionSnapshot } from "../reducer/session-reducer.js";
|
|
import {
|
|
PRP_BLOCK_RESULT_OUTPUT_SCHEMA,
|
|
PRP_BLOCK_RESULT_PROVIDER_INPUT_SCHEMA,
|
|
PRP_BLOCK_TOOL_NAME,
|
|
PRP_COMPLETION_RESULT_OUTPUT_SCHEMA,
|
|
PRP_COMPLETION_RESULT_PROVIDER_INPUT_SCHEMA,
|
|
PRP_COMPLETION_TOOL_NAME,
|
|
PRP_SEMANTIC_TOOL_NAMES,
|
|
} from "./completion-result.js";
|
|
|
|
export const CODEX_TASK_ENVELOPE_SCHEMA = "paperclip.skillless_task.v1" as const;
|
|
export const CODEX_CODEX_PROTOCOL_VERSION = "v2" as const;
|
|
/** @deprecated Use the provider-neutral PRP completion contract exports. */
|
|
export const CODEX_COMPLETION_TOOL_NAME = PRP_COMPLETION_TOOL_NAME;
|
|
/** @deprecated Use the provider-neutral PRP completion contract exports. */
|
|
export const CODEX_BLOCK_TOOL_NAME = PRP_BLOCK_TOOL_NAME;
|
|
/** @deprecated Use the provider-neutral PRP completion contract exports. */
|
|
export const CODEX_SEMANTIC_TOOL_NAMES = PRP_SEMANTIC_TOOL_NAMES;
|
|
export const CODEX_SKILLLESS_BASE_INSTRUCTIONS =
|
|
"Complete only the supplied task envelope. Do not discover or invoke skills. Do not call a control-plane API. Return exactly one semantic completion result; use paperclip_finish when the work is done, needs review, or is explicitly yielding for the next response, and paperclip_block only when work cannot continue." as const;
|
|
|
|
export interface CodexTaskEnvelope {
|
|
schema: typeof CODEX_TASK_ENVELOPE_SCHEMA;
|
|
objective: string;
|
|
completionContract: {
|
|
revision: string;
|
|
criteria: Array<{ id: string; requirement: string }>;
|
|
};
|
|
constraints: string[];
|
|
expectedResultSchema: "paperclip.run_result.v1";
|
|
}
|
|
|
|
export interface CodexModelContextSnapshot {
|
|
protocolVersion: typeof CODEX_CODEX_PROTOCOL_VERSION;
|
|
codexVersion: string;
|
|
clientInfo: {
|
|
name: "paperclip-runner";
|
|
title: "Paperclip Runner";
|
|
version: string;
|
|
};
|
|
model: string;
|
|
modelProvider: string;
|
|
workingDirectory: string;
|
|
collaborationMode: "default" | "plan";
|
|
sandbox: unknown;
|
|
approvalPolicy: unknown;
|
|
/** Historical trace field for the Paperclip instruction fragment, supplied
|
|
* to Codex as developerInstructions rather than replacing its stock base. */
|
|
baseInstructions: string;
|
|
instructionSources: string[];
|
|
instructionPolicy: {
|
|
skillInstructions: boolean;
|
|
appInstructions: false;
|
|
collaborationInstructions: boolean;
|
|
};
|
|
environmentKeys: string[];
|
|
dynamicToolNames: string[];
|
|
modelInputKinds: ["text"];
|
|
liveConsole?: {
|
|
conversationMode?: "task" | "direct" | "prepared";
|
|
runtimeRequestResolution: boolean;
|
|
goals: boolean;
|
|
threadLineage: boolean;
|
|
};
|
|
envelope: CodexTaskEnvelope;
|
|
}
|
|
|
|
export interface CodexRunMetadata {
|
|
schema: "paperclip.runner.codex.metadata.v1";
|
|
fixtureName: string;
|
|
identity: {
|
|
schema: "paperclip.prp.identity.v1";
|
|
companyId: string;
|
|
issueId: string;
|
|
runId: string;
|
|
environmentLeaseId: string;
|
|
runnerInstanceId: string;
|
|
normalizedSessionId: string;
|
|
driverSessionId?: string;
|
|
providerSessionId?: string;
|
|
};
|
|
capabilities: PrpCapabilities;
|
|
}
|
|
|
|
export interface CodexRunTrace {
|
|
schema: "paperclip.runner.codex.trace.v1";
|
|
metadata: CodexRunMetadata;
|
|
context: CodexModelContextSnapshot;
|
|
events: PrpEvent[];
|
|
proposedResult: unknown | null;
|
|
result: PrpStructuredRunResult | null;
|
|
resultDecision: CodexResultDecision;
|
|
liveSnapshot: SessionSnapshot;
|
|
replaySnapshot: SessionSnapshot;
|
|
diagnostics: string[];
|
|
assertions: {
|
|
exactlyOneTerminalResult: boolean;
|
|
proposalAccepted: boolean;
|
|
liveReplayParity: boolean;
|
|
stableIdentity: boolean;
|
|
sourceSequenceContinuous: boolean;
|
|
stableItemIdentity: boolean;
|
|
contextIsSkillless: boolean;
|
|
unrelatedSkillsAbsent: boolean;
|
|
credentialsAbsent: boolean;
|
|
};
|
|
}
|
|
|
|
export interface CodexResultValidationIssue {
|
|
code:
|
|
| "schema_validation"
|
|
| "contract_revision_mismatch"
|
|
| "unknown_criterion"
|
|
| "missing_criterion"
|
|
| "duplicate_criterion"
|
|
| "invalid_disposition";
|
|
path: string;
|
|
message: string;
|
|
}
|
|
|
|
export type CodexResultDecision =
|
|
| { status: "accepted"; result: PrpStructuredRunResult; issues: [] }
|
|
| { status: "rejected"; result: null; issues: CodexResultValidationIssue[] };
|
|
|
|
export function createCodexTaskEnvelope(input: {
|
|
objective: string;
|
|
contractRevision?: string;
|
|
criteria?: Array<{ id: string; requirement: string }>;
|
|
constraints?: string[];
|
|
}): CodexTaskEnvelope {
|
|
return {
|
|
schema: CODEX_TASK_ENVELOPE_SCHEMA,
|
|
objective: input.objective,
|
|
completionContract: {
|
|
revision: input.contractRevision ?? "codex-demo-v1",
|
|
criteria:
|
|
input.criteria ?? [{ id: "objective", requirement: "Complete the objective safely." }],
|
|
},
|
|
constraints: input.constraints ?? [
|
|
"Do not discover or invoke skills.",
|
|
"Do not call a control-plane API.",
|
|
"Return one semantic completion result.",
|
|
],
|
|
expectedResultSchema: "paperclip.run_result.v1",
|
|
};
|
|
}
|
|
|
|
/** @deprecated Use PRP_COMPLETION_RESULT_OUTPUT_SCHEMA. */
|
|
export const CODEX_RESULT_OUTPUT_SCHEMA = PRP_COMPLETION_RESULT_OUTPUT_SCHEMA;
|
|
/** @deprecated Use PRP_BLOCK_RESULT_OUTPUT_SCHEMA. */
|
|
export const CODEX_BLOCK_RESULT_OUTPUT_SCHEMA = PRP_BLOCK_RESULT_OUTPUT_SCHEMA;
|
|
export const CODEX_RESULT_PROVIDER_INPUT_SCHEMA = PRP_COMPLETION_RESULT_PROVIDER_INPUT_SCHEMA;
|
|
export const CODEX_BLOCK_RESULT_PROVIDER_INPUT_SCHEMA = PRP_BLOCK_RESULT_PROVIDER_INPUT_SCHEMA;
|
|
|
|
export function isSkilllessCodexContext(
|
|
context: CodexModelContextSnapshot,
|
|
options: { dynamicTools: boolean } = { dynamicTools: true },
|
|
): boolean {
|
|
const serialized = JSON.stringify(context).toLowerCase();
|
|
const expectedTools = options.dynamicTools ? [...CODEX_SEMANTIC_TOOL_NAMES] : [];
|
|
return (
|
|
context.instructionSources.length === 0 &&
|
|
context.baseInstructions === CODEX_SKILLLESS_BASE_INSTRUCTIONS &&
|
|
context.modelInputKinds.length === 1 &&
|
|
context.modelInputKinds[0] === "text" &&
|
|
context.dynamicToolNames.length === expectedTools.length &&
|
|
context.dynamicToolNames.every((name) =>
|
|
expectedTools.includes(name as (typeof expectedTools)[number]),
|
|
) &&
|
|
context.instructionPolicy.skillInstructions === false &&
|
|
context.instructionPolicy.appInstructions === false &&
|
|
!serialized.includes("paperclip_api_key") &&
|
|
!serialized.includes("authorization: bearer") &&
|
|
!serialized.includes("/api/issues/") &&
|
|
!serialized.includes('"type":"skill"')
|
|
);
|
|
}
|