Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Windows Build
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Workflow events and checkout ref are pinned to a single feature branch, causing PR CI to test the wrong commit and becoming dead after the branch is merged.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/workflows/windows-build.yml:

<comment>Workflow events and checkout ref are pinned to a single feature branch, causing PR CI to test the wrong commit and becoming dead after the branch is merged.</comment>

<file context>
@@ -0,0 +1,70 @@
+name: Windows Build
+
+on:
+  push:
+    branches:
+      - fix/issue-97-multiplying-numbers
+  pull_request:
+    branches:
+      - fix/issue-97-multiplying-numbers
</file context>


on:
push:
branches:
- fix/issue-97-multiplying-numbers
pull_request:
branches:
- fix/issue-97-multiplying-numbers
workflow_dispatch:

jobs:
build-windows:
name: Build on Windows
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: fix/issue-97-multiplying-numbers

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

# better-sqlite3 uses node-gyp during install; Node on PATH helps native builds.
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Compile packages
run: bun run build

- name: Package OpenCode + CLI artifact
shell: pwsh
run: ./scripts/package-windows-artifact.ps1

- name: Verify artifact layout
shell: pwsh
run: |
$root = "artifact/magic-context-compiled"
$required = @(
"$root/plugin/package.json",
"$root/plugin/dist/index.js",
"$root/plugin/src/tui/index.tsx",
"$root/plugin/src/shared",
"$root/plugin/node_modules/@opencode-ai/plugin",
"$root/cli/package.json",
"$root/cli/dist/index.js",
"$root/INSTALL.md"
)
foreach ($path in $required) {
if (-not (Test-Path $path)) {
throw "Missing required artifact path: $path"
}
}
Write-Host "Artifact verification passed."

- name: Upload compiled build
uses: actions/upload-artifact@v4
with:
name: magic-context-windows-build
path: artifact/magic-context-compiled/
retention-days: 14
44 changes: 44 additions & 0 deletions packages/plugin/src/hooks/magic-context/tool-drop-target.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MessageLike, ThinkingLikePart } from "./tag-messages";
import {
createToolDropTarget,
extractToolCallObservation,
hasMeaningfulPart,
type ToolCallIndex,
ToolMutationBatch,
} from "./tool-drop-target";
Expand Down Expand Up @@ -353,4 +354,47 @@ describe("tool-drop-target", () => {
});
});
});

describe("hasMeaningfulPart", () => {
it("returns false for empty text", () => {
expect(hasMeaningfulPart({ type: "text", text: "" })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: " " })).toBe(false);
});

it("returns false for text containing only tag prefixes", () => {
expect(hasMeaningfulPart({ type: "text", text: "§424§ " })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: "§424§" })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: "§424§ " })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: "§1§ §2§ " })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: '§15298">§15298§ ' })).toBe(false);
expect(hasMeaningfulPart({ type: "text", text: '§15298">§ ' })).toBe(false);
});

it("returns true for text with actual content", () => {
expect(hasMeaningfulPart({ type: "text", text: "hello" })).toBe(true);
expect(hasMeaningfulPart({ type: "text", text: "§424§ hello" })).toBe(true);
expect(hasMeaningfulPart({ type: "text", text: '§15298">§15298§ hello' })).toBe(true);
});

it("returns true for tools", () => {
expect(hasMeaningfulPart({ type: "tool" })).toBe(true);
expect(hasMeaningfulPart({ type: "tool_result" })).toBe(true);
});

it("returns false for non-record types", () => {
expect(hasMeaningfulPart(null)).toBe(false);
expect(hasMeaningfulPart(undefined)).toBe(false);
expect(hasMeaningfulPart("string")).toBe(false);
expect(hasMeaningfulPart(123)).toBe(false);
});

it("returns false for ignored part types", () => {
expect(hasMeaningfulPart({ type: "step-start" })).toBe(false);
expect(hasMeaningfulPart({ type: "step-finish" })).toBe(false);
expect(hasMeaningfulPart({ type: "thinking" })).toBe(false);
expect(hasMeaningfulPart({ type: "reasoning" })).toBe(false);
expect(hasMeaningfulPart({ type: "redacted_thinking" })).toBe(false);
expect(hasMeaningfulPart({ type: "meta" })).toBe(false);
});
});
});
8 changes: 7 additions & 1 deletion packages/plugin/src/hooks/magic-context/tool-drop-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ function truncateInputValues(input: Record<string, unknown>): void {
}
}

const MALFORMED_TAG_PREFIX_REGEX = /^(?:§\d+">§(?:\d+§)?\s*)+/;
const TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/;

export function hasMeaningfulPart(part: unknown): boolean {
if (!isRecord(part)) return false;
const type = part.type;
if (type === "text") {
return typeof part.text === "string" && part.text.trim().length > 0;
if (typeof part.text !== "string") return false;
let stripped = part.text.replace(MALFORMED_TAG_PREFIX_REGEX, "");
stripped = stripped.replace(TAG_PREFIX_REGEX, "");
return stripped.trim().length > 0;
}
if (typeof type !== "string") return false;
if (IGNORE_PART_TYPES.has(type)) return false;
Expand Down
114 changes: 114 additions & 0 deletions scripts/package-windows-artifact.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Packages a portable Windows install tree for local OpenCode use.
# Output layout:
# artifact/magic-context-compiled/
# plugin/ - OpenCode server + TUI plugin (@cortexkit/opencode-magic-context)
# cli/ - magic-context CLI
# INSTALL.md

$ErrorActionPreference = "Stop"

$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
$outRoot = Join-Path $repoRoot "artifact/magic-context-compiled"
$pluginSrc = Join-Path $repoRoot "packages/plugin"
$cliSrc = Join-Path $repoRoot "packages/cli"

if (-not (Test-Path (Join-Path $pluginSrc "dist/index.js"))) {
throw "packages/plugin/dist/index.js is missing. Run 'bun run build' first."
}

if (-not (Test-Path (Join-Path $cliSrc "dist/index.js"))) {
throw "packages/cli/dist/index.js is missing. Run 'bun run build' first."
}

if (Test-Path $outRoot) {
Remove-Item $outRoot -Recurse -Force
}

$pluginOut = Join-Path $outRoot "plugin"
$cliOut = Join-Path $outRoot "cli"
New-Item -ItemType Directory -Force -Path $pluginOut, $cliOut | Out-Null

function Copy-Tree {
param(
[Parameter(Mandatory = $true)][string]$Source,
[Parameter(Mandatory = $true)][string]$Destination
)
if (-not (Test-Path $Source)) {
throw "Source path not found: $Source"
}
New-Item -ItemType Directory -Force -Path $Destination | Out-Null
Copy-Item -Path (Join-Path $Source "*") -Destination $Destination -Recurse -Force
}

# OpenCode plugin: dist (server) + src/tui + src/shared (TUI export) + package.json
Copy-Item (Join-Path $pluginSrc "package.json") $pluginOut -Force
Copy-Tree -Source (Join-Path $pluginSrc "dist") -Destination (Join-Path $pluginOut "dist")
Copy-Tree -Source (Join-Path $pluginSrc "src/tui") -Destination (Join-Path $pluginOut "src/tui")
Copy-Tree -Source (Join-Path $pluginSrc "src/shared") -Destination (Join-Path $pluginOut "src/shared")

if (Test-Path (Join-Path $pluginSrc "README.md")) {
Copy-Item (Join-Path $pluginSrc "README.md") $pluginOut -Force
}

# Runtime deps for dist/index.js externals and TUI TSX imports.
Push-Location $pluginOut
bun install --production
Pop-Location

# CLI
Copy-Item (Join-Path $cliSrc "package.json") $cliOut -Force
Copy-Tree -Source (Join-Path $cliSrc "dist") -Destination (Join-Path $cliOut "dist")
if (Test-Path (Join-Path $cliSrc "README.md")) {
Copy-Item (Join-Path $cliSrc "README.md") $cliOut -Force
}

Push-Location $cliOut
bun install --production
Pop-Location

$installDoc = @"
# Magic Context — Windows compiled install

Extract this folder to e.g. ``D:\Coding\_tools\magic-context-compiled``.

## OpenCode config

**``%USERPROFILE%\.config\opencode\opencode.jsonc``** (server plugin):

```jsonc
"plugin": [
"file:///D:/Coding/_tools/magic-context-compiled/plugin/dist/index.js"
]
```

**``%USERPROFILE%\.config\opencode\tui.jsonc``** (TUI side panel — use package directory, not dist/index.js):

```jsonc
"plugin": [
"file:///D:/Coding/_tools/magic-context-compiled/plugin"
]
```

Do **not** point ``tui.jsonc`` at ``dist/index.js`` (that is the server export only).
Do **not** use ``dist/tui/index.js`` — the upstream build does not emit it; TUI loads ``exports["./tui"]`` → ``src/tui/index.tsx``.

Restart OpenCode after changing config.

## CLI

```powershell
bun "D:\Coding\_tools\magic-context-compiled\cli\dist\index.js" doctor
```

Or add ``cli`` to PATH and run ``magic-context doctor``.

## Verify

- ``plugin/dist/index.js`` exists
- ``plugin/src/tui/index.tsx`` exists
- ``plugin/package.json`` exports ``./tui`` → ``./src/tui/index.tsx``
"@

Set-Content -Path (Join-Path $outRoot "INSTALL.md") -Value $installDoc -Encoding utf8

Write-Host "Packaged artifact at $outRoot"