Skip to content

Conversation

@mnismt
Copy link
Owner

@mnismt mnismt commented Sep 27, 2025

Description

Introduce OPX v1: A clean-room, original XML protocol for Overwrite

  • Core ops: Create, patch, replace, remove, and move files with explicit elements and new literals.
  • Simple schema, optional metadata, and occurrence handling for reliable generation and parsing.

Solve #1

Protocol Specification

  • Top-level: One or more elements; optional wrapper is allowed.
  • attributes:
    • Required: file, op
    • Optional: root (for multi-root workspaces)
  • Paths: Prefer workspace‑relative; don’t reference outside the workspace.
  • Literals: In /, content must be between full-line markers <<< and >>>. Auto-heals lone <, <<, >, >> to proper markers.

Operations

op Meaning Required children
new Create file
patch Search-and-replace region ,
replace Replace entire file
remove Delete file none
move Rename/move file

Notes:

  • is optional for a short reason.
  • may use occurrence="first|last|N" to pick a specific match.

Example

New file

<edit file="src/utils/strings.ts" op="new">
  <why>Create utility module</why>
  <put>
<<<
export function titleCase(s: string): string {
  return s.split(/\s+/).map(w => w ? w[0]!.toUpperCase() + w.slice(1) : w).join(' ')
}
>>>
  </put>
</edit>

Patch region

<edit file="src/api/users.ts" op="patch">
  <why>Add timeout and error logging</why>
  <find occurrence="first">
<<<
export async function fetchUser(id: string) {
  const res = await fetch(`/api/users/${id}`);
  if (!res.ok) throw new Error(`Request failed: ${res.status}`);
  return res.json();
}
>>>
  </find>
  <put>
<<<
async function withTimeout<T>(p: Promise<T>, ms = 10000): Promise<T> {
  const t = new Promise<never>((_, r) => setTimeout(() => r(new Error('Request timed out')), ms));
  return Promise.race([p, t]);
}

export async function fetchUser(id: string) {
  try {
    const res = await withTimeout(fetch(`/api/users/${id}`), 10000);
    if (!res.ok) throw new Error(`Request failed: ${res.status}`);
    return res.json();
  } catch (err) {
    console.error('[api] fetchUser error', err);
    throw err;
  }
}
>>>
  </put>
</edit>

Replace entire file

<edit file="src/config/index.ts" op="replace">
  <put>
<<<
export interface AppConfig {
  apiBaseUrl: string;
  enableTelemetry: boolean;
  maxConcurrentJobs: number;
}

export const config: AppConfig = {
  apiBaseUrl: process.env.API_BASE_URL || 'http://localhost:3000',
  enableTelemetry: process.env.TELEMETRY === '1',
  maxConcurrentJobs: Number(process.env.MAX_JOBS || 4),
};
>>>
  </put>
</edit>

Remove file

<edit file="tests/legacy/user-auth.spec.ts" op="remove" />

Move / rename file

<edit file="src/lib/flags.ts" op="move">
  <to file="src/lib/feature-flags.ts" />
</edit>

@mnismt mnismt marked this pull request as ready for review September 27, 2025 17:37
@mnismt mnismt merged commit a881610 into main Sep 27, 2025
4 checks passed
@mnismt mnismt deleted the feat/opx-v1 branch September 27, 2025 17:44
@mnismt mnismt mentioned this pull request Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants