A mech game prototype, pushed by GPT-6-Astra

agent (cont.)

+40:26
  • exec_commandrg --files ~/context && sed -n '1,220p' kit/mech.py && sed -n '1,155p' kit/lib.py (+1 more)

    command

    rg --files ~/context && sed -n '1,220p' kit/mech.py && sed -n '1,155p' kit/lib.py
    
    cat src/view/clip.ts && cat src/main.ts | head -95 && sed -n '1,180p' src/render/space.ts && sed -n '1,170p' src/render/materials.ts

    result, 7 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    Warning: truncated output (original token count: 11549)
    Total output lines: 2
    
    {"chunk_id":"7c3dce","wall_time_seconds":0.00000329,"exit_code":0,"original_token_count":5381,"output":"~/context/brief-sortie-full.md\n~/context/project_sortie_mech_game.md\n~/context/reflect/sortie.html\n\"\"\"Mech frames. A frame is a tree of joint empties with rigid armour parented to them, so the game\nposes it by rotating joints (no skinning). Left is +X (the model faces -Y).\n\nJoint tree (names are the contract with src/render/mech.ts):\n  frame > pelvis > waist > torso > neck > head\n                                   torso > shoulder.L > upperarm.L > forearm.L > hand.L > grip.L\n                                   torso > backpack > binder.L\n                                   torso > cockpit\n          pelvis > thigh.L > shin.L > foot.L\nThruster exits are empties named nozzle.* with a \"dir\" extra (exhaust direction, glTF axes).\n\nProportions follow measured Gundam 00 line art (review/out/refs/proportions.md): head about a tenth\nof the height, hip joint at 60%, shoulder span about half the height on shells that stand off a\ncompact chest, a waist a ninth of the height, every limb in layered shells over a dark inner frame.\n\"\"\"\nfrom mathutils import Matrix, Vector\n\nfrom lib import (circle, clip, copy, cylinder, empty, halves, loft, merge, mirror_x, nozzle, octo, piston, prism, rot, slats, solid,\n                 transform, two_view)\n\nBEVEL = 0.05\n\n\ndef gltf_dir(v):\n    v = Vector(v).normalized()\n    return [round(v.x, 4), round(v.z, 4), round(-v.y, 4)]\n\n\ndef place(bm, at, direction):\n    \"\"\"Turn a part built along -Z to point along `direction`, then move it to `at`.\"\"\"\n    q = Vector((0, 0, -1)).rotation_difference(Vector(direction).normalized())\n    return transform(bm, Matrix.Translation(Vector(at)) @ q.to_matrix().to_4x4())\n\n\ndef pair(name, bm_left, role, jl, jr, **kw):\n    \"\"\"Make the left part and its mirror on the right.\"\"\"\n    bm_right = mirror_x(bm_left)\n    return solid(f\"{name}.L\", bm_left, role, jl, **kw), solid(f\"{name}.R\", bm_right, role, jr, **kw)\n\n\ndef nozzle_pair(name, at, direction, r, length, jl, jr, shell=\"frame\", housing=True):\n    ex = Vector(at)\n    for side, j, sx in ((\"L\", jl, 1), (\"R\", jr, -1)):\n        p = Vector((ex.x * sx, ex.y, ex.z))\n        d = Vector((direction[0] * sx, direction[1], direction[2]))\n        bell, glow = nozzle(r, length)\n        solid(f\"{name}.{side}\", place(bell, p, d), shell, j, smooth=True)\n        solid(f\"{name}.{side}.glow\", place(glow, p, d), \"glow_thruster\", j, outline=False)\n        # an armoured housing around the throat, so the nozzle reads as mounted, not floating\n        if housing:\n            house = loft([(length * .5, octo(r * 2.5, r * 2.5, r * .6)), (-length * .3, octo(r * 2.3, r * 2.3, r * .55))])\n            solid(f\"{name}_housing.{side}\", place(house, p, d), \"main\", j, bevel=.02, panels=False)\n        empty(f\"nozzle.{name}.{side}\", p + d.normalized() * length, j, dir=gltf_dir(d), radius=r)\n\n\ndef seam(bm, a, b, gap=.05):\n    \"\"\"Split a solid along the line a->b of the front view (x, z): two plates with a real seam.\"\"\"\n    a, b = Vector((a[0], 0, a[1])), Vector((b[0], 0, b[1]))\n    d = (b - a).normalized()\n    n = Vector((-d.z, 0, d.x))\n    return halves(bm, a, n, gap)\n\n\ndef pair_pieces(name, pieces, role, jl, jr, **kw):\n    for i, bm in enumerate(pieces):\n        pair(f\"{name}{i}\", bm, role, jl, jr, **kw)\n\n\ndef joints():\n    J = {\"frame\": empty(\"frame\", (0, 0, 0), frame=\"striker\", height=17.6)}\n    J[\"pelvis\"] = empty(\"pelvis\", (0, 0, 10.6), J[\"frame\"])\n    J[\"waist\"] = empty(\"waist\", (0, 0, 11.1), J[\"pelvis\"])\n    J[\"torso\"] = empty(\"torso\", (0, 0, 11.9), J[\"waist\"])\n    J[\"neck\"] = empty(\"neck\", (0, 0, 15.3), J[\"torso\"])\n    J[\"head\"] = empty(\"head\", (0, 0, 15.85), J[\"neck\"])\n    J[\"backpack\"] = empty(\"backpack\", (0, 1.5, 13.8), J[\"torso\"])\n    J[\"cockpit\"] = empty(\"cockpit\", (0, -0.75, 13.7), J[\"torso\"])\n    for s, sx in ((\"L\", 1), (\"R\", -1)):\n        J[\"shoulder\", s] = empty(f\"shoulder.{s}\", (2.0 * sx, 0, 14.6), J[\"torso\"])\n        J[\"upperarm\", s] = empty(f\"upperarm.{s}\", (2.45 * sx, 0, 14.4), J[\"shoulder\", s])\n        J[\"forearm\", s] = empty(f\"forearm.{s}\", (2.5 * sx, 0, 11.95), J[\"upperarm\", s])\n        J[\"hand\", s] = empty(f\"hand.{s}\", (2.5 * sx, 0, 9.6), J[\"forearm\", s])\n        J[\"grip\", s] = empty(f\"grip.{s}\", (2.36 * sx, -0.02, 9.12), J[\"hand\", s])\n        J[\"thigh\", s] = empty(f\"thigh.{s}\", (1.15 * sx, 0, 10.55), J[\"pelvis\"])\n        J[\"shin\", s] = empty(f\"shin.{s}\", (1.2 * sx, 0, 6.1), J[\"thigh\", s])\n        J[\"foot\", s] = empty(f\"foot.{s}\", (1.2 * sx, 0.1, 1.55), J[\"shin\", s])\n        J[\"binder\", s] = empty(f\"binder.{s}\", (0.9 * sx, 2.25, 14.7), J[\"backpack\"])\n    return J\n\n\ndef lr(J, part):\n    return J[part, \"L\"], J[part, \"R\"]\n\n\ndef build_pelvis(J):\n    P = J[\"pelvis\"]\n    solid(\"pelvis_core\", loft([(9.95, octo(.9, 1.3, .25)), (10.4, octo(2.2, 1.7, .4)), (11.0, octo(2.3, 1.75, .45))]),\n          \"frame\", P, BEVEL)\n    # the waist belt flares from the abdomen out to hip width; everything below hangs from it\n    solid(\"belt\", loft([(10.55, octo(3.2, 2.05, .5)), (10.98, octo(2.1, 1.7, .42))]), \"main\", P, BEVEL)\n    solid(\"belt_buckle\", two_view([(-.3, 10.58), (.3, 10.58), (.18, 10.96), (-.18, 10.96)],\n                                  [(-1.14, 10.58), (-.96, 10.58), (-.86, 10.96), (-1.02, 10.96)]), \"trim\", P, .02)\n    pair(\"hip_block\", loft([(10.2, octo(.42, .95, .1, x=1.74)), (10.72, octo(.42, .95, .1, x=1.74))]), \"frame\", P, P, bevel=.02)\n    solid(\"codpiece\", two_view([(-.2, 9.62), (.2, 9.62), (.32, 10.2), (.3, 10.58), (-.3, 10.58), (-.32, 10.2)],\n                               [(-1.14, 9.68), (-.75, 9.68), (-.8, 10.58), (-1.08, 10.58), (-1.22, 10.2)]), \"trim\", P, BEVEL)\n    # front skirt: two blades sweeping out from the centre like an arrowhead\n    pair(\"skirt_front\", two_view([(.45, 10.62), (1.45, 10.62), (2.05, 10.3), (1.65, 9.6), (.65, 9.9)],\n                                 [(-1.34, 9.55), (-1.02, 9.55), (-.94, 10.66), (-1.24, 10.66)]), \"main\", P, P, bevel=BEVEL)\n    pair(\"skirt_front_edge\", two_view([(.68, 9.85), (1.64, 9.55), (1.74, 9.71), (.72, 9.99)],\n                                      [(-1.4, 9.47), (-1.06, 9.47), (-1.02, 10.05), (-1.36, 10.05)]), \"accent\", P, P, bevel=0.015)\n    # side skirts flare out toward the bottom, tips swept back\n    # side skirts hinge from the hip blocks: a cap plate over a ridged main plate\n    pair(\"skirt_side\", two_view([(2.0, 9.5), (2.34, 9.5), (2.12, 10.5), (1.86, 10.52)],\n                                [(-.6, 9.5), (1.05, 9.5), (.95, 10.54), (-.9, 10.54)],\n                                top=[(1.8, -1.0), (2.17, -1.0), (2.42, .05), (2.17, 1.15), (1.8, 1.15)]), \"main\", P, P, bevel=BEVEL)\n    pair(\"skirt_side_cap\", two_view([(1.86, 10.28), (2.3, 10.22), (2.22, 10.74), (1.86, 10.76)],\n                                    [(-.72, 10.22), (.92, 10.22), (.86, 10.76), (-.78, 10.76)]), \"accent\", P, P, bevel=0.025)\n    pair(\"skirt_side_plate\", two_view([(2.26, 9.66), (2.4, 9.69), (2.26, 10.16), (2.12, 10.14)],\n                                      [(-.4, 9.66), (.85, 9.66), (.78, 10.16), (-.55, 10.16)]), \"frame\", P, P, bevel=0.015)\n    # rear skirt as two overlapping scales with a gap over the hip mechanism\n    # rear skirt: descending chevrons, a gap at the centre\n    pair(\"skirt_rear\", two_view([(.14, 10.6), (1.26, 10.66), (1.61, 10.35), (1.46, 9.92), (.64, 9.82), (.18, 10.05)],\n                                [(.92, 9.75), (1.26, 9.75), (1.32, 10.7), (.94, 10.7)]), \"main\", P, P, bevel=BEVEL)\n    pair(\"skirt_rear_low\", two_view([(.14, 10.1), (.62, 9.93), (1.3, 10.02), (1.3, 9.63), (.6, 9.4), (.14, 9.6)],\n                                    [(1.02, 9.36), (1.36, 9.36), (1.36, 10.14), (1.02, 10.14)]), \"main\", P, P, bevel=0.03)\n\n\ndef build_waist(J):\n    W = J[\"waist\"]\n    solid(\"abdomen\", loft([(10.9, octo(1.6, 1.4, .35)), (11.95, octo(1.85, 1.55, .38))]), \"joint\", W, 0.03)\n    # three stacked plates in front, each a little wider and further forward than the one below\n    for i, (z0, z1, hw, y) in enumerate(((10.98, 11.34, .64, -.84), (11.28, 11.64, .72, -.88), (11.58, 11.96, .8, -.92))):\n        solid(f\"abs{i}\", two_view([(-hw, z0), (hw, z0), (hw + .06, z1), (-hw - .06, z1)],\n                                  [(y + .02, z0), (y + .24, z0), (y + .24, z1), (y - .02, z1)],\n                                  top=[(-hw - .1, y + .3), (hw + .1, y + .3), (hw + .1, y + .1), (0, y - .06), (-hw - .1, y + .1)]),\n              \"frame\", W, 0.02)\n    pair(\"abs_side\", two_view([(.72, 11.0), (.96, 11.05), (1.02, 11.92), (.78, 11.92)],\n                              [(-.5, 11.0), (.5, 11.0), (.56, 11.92), (-.56, 11.92)]), \"frame\", W, W, bevel=0.02)\n\n\ndef build_torso(J):\n    T = J[\"torso\"]\n    # a dark structural core; the armour is separate plates over it\n    solid(\"chest\", loft([(11.9, octo(1.9, 1.6, .4, y=.05)), (12.6, octo(2.4, 2.05, .45)), (13.9, octo(3.0, 2.45, .55, y=-.05)),\n                         (14.9, octo(2.8, 2.25, .5)), (15.3, octo(1.8, 1.55, .4))]), \"frame\", T, BEVEL)\n    # central hatch: a ridged block down the chest front that carries the reactor lens\n    solid(\"hatch\", two_view([(-.55, 12.75), (.55, 12.75), (.6, 14.5), (.4, 14.78), (-.4, 14.78), (-.6, 14.5)],\n                            [(-1.62, 12.75), (-1.2, 12.75), (-1.3, 14.78), (-1.66, 14.62), (-1.8, 13.8)],\n                            top=[(-.7, -1.0), (.7, -1.0), (.7, -1.55), (0, -1.84), (-.7, -1.55)]), \"main\", T, .03)\n    pair(\"chest_plate\", two_view([(.58, 14.82), (1.18, 14.88), (1.55, 14.62), (1.78, 14.28), (1.55, 13.85), (.6, 14.08)],\n                                 [(-1.64, 13.6), (-1.1, 13.6), (-1.26, 14.88), (-1.5, 14.88), (-1.72, 13.85)]),\n         \"accent\", T, T, bevel=BEVEL)\n    rib = two_view([(.6, 12.7), (.9, 12.6), (1.6, 13.2), (1.62, 13.54), (.6, 13.88)],\n                   [(-1.49, 12.5), (-.95, 12.5), (-1.1, 13.92), (-1.35, 13.92), (-1.57, 13.55)])\n    pair_pieces(\"rib_plate\", seam(rib, (.6, 13.22), (1.62, 13.05)), \"accent\", T, T, bevel=0.03)\n    pair(\"chest_strip\", two_view([(.6, 14.84), (1.18, 14.9), (1.57, 14.64), (1.8, 14.28), (1.64, 14.2), (1.42, 14.5), (1.1, 14.7),\n                                  (.6, 14.64)],\n                                 [(-1.72, 13.9), (-1.22, 13.9), (-1.36, 14.96), (-1.6, 14.96), (-1.8, 14.2)]), \"main\", T, T, bevel=0.02)\n    pair(\"side_plate\", two_view([(1.42, 12.9), (1.62, 12.9), (1.68, 14.4), (1.48, 14.6)],\n                                [(-.95, 12.9), (.9, 12.9), (.95, 14.4), (-1.05, 14.45)]), \"main\", T, T, bevel=0.03)\n    solid(\"belly\", two_view([(-.95, 11.92), (.95, 11.92), (1.22, 12.62), (-1.22, 12.62)],\n                            [(-1.34, 11.9), (-.98, 11.9), (-1.08, 12.66), (-1.4, 12.66)]), \"main\", T, BEVEL)\n    solid(\"belly_vent\", slats(-.6, .6, 12.02, 12.48, -1.38, 3, depth=.08), \"frame\", T)\n    # the reactor lens in the chest\n    solid(\"lens_socket\", prism(circle(.44, 12, 0, 13.62), -1.92, -1.5, \"xz\"), \"frame\", T, 0.03)\n    solid(\"lens\", prism(circle(.33, 12, 0, 13.62), -1.97, -1.9, \"xz\"), \"sensor\", T, smooth=True)\n    solid(\"lens_core\", prism(circle(.11, 8, 0, 13.62), -1.99, -1.95, \"xz\"), \"glow_core\", T)\n    # collar: thin folded plates (front and side) with room around the neck\n    pair(\"collar\", two_view([(.55, 14.72), (1.46, 14.76), (1.55, 15.3), (1.1, 15.55), (.62, 15.45)],\n                            [(-1.0, 14.7), (-.84, 14.7), (-.68, 15.55), (-.84, 15.55)]), \"main\", T, T, bevel=0.025)\n    pair(\"collar_side\", two_view([(1.36, 14.7), (1.52, 14.7), (1.42, 15.5), (1.26, 15.5)],\n                                 [(-.9, 14.7), (.7, 14.7), (.6, 15.5), (-.7, 15.5)]), \"main\", T, T, bevel=0.025)\n    pair(\"collar_vent\", slats(.72, 1.26, 14.86, 15.2, -1.0, 3, depth=.06), \"frame\", T, T)\n    solid(\"neck_guard\", two_view([(-.55, 15.2), (.55, 15.2), (.5, 15.86), (-.5, 15.86)],\n                                 [(.25, 15.2), (.72, 15.2), (.64, 15.86), (.36, 15.86)]), \"main\", T, .02)\n    solid(\"back_plate\", two_view([(-.95, 12.35), (.95, 12.35), (1.62, 14.92), (-1.62, 14.92)],\n                                 [(1.14, 12.35), (1.46, 12.35), (1.52, 14.92), (1.24, 14.92)]), \"accent\", T, BEVEL)\n\n\ndef build_head(J):\n    N, H = J[\"neck\"], J[\"head\"]\n    solid(\"neck_core\", cylinder(.36, 15.25, 16.0, 10), \"joint\", N, smooth=True)\n    solid(\"neck_ring\", loft([(15.5, octo(.95, .9, .2)), (15.68, octo(.86, .82, .18))]), \"frame\", N, .015)\n    # cranium: the top plate, tapered toward the back in plan\n    solid(\"cranium\", two_view([(-.62, 16.66), (.62, 16.66), (.58, 17.05), (.36, 17.28), (-.36, 17.28), (-.58, 17.05)],\n                              [(-.86, 16.7), (-.5, 17.2), (.25, 17.3), (.72, 17.0), (.78, 16.66)],\n                              top=[(-.4, -.88), (.4, -.88), (.62, -.4), (.55, .6), (0, .86), (-.55, .6), (-.62, -.4)]), \"main\", H, .03)\n    solid(\"skull\", loft([(15.95, octo(.9, 1.15, .25, y=.05)), (16.7, octo(1.1, 1.4, .3, y=.0))]), \"frame\", H, .02)\n    # side plates frame the face and run back past the ears\n    pair(\"helmet_side\", two_view([(.48, 15.98), (.7, 16.28), (.77, 16.9), (.62, 17.04), (.55, 16.5), (.42, 16.06)],\n                                 [(-.72, 15.98), (.62, 15.98), (.74, 16.6), (.5, 17.04), (-.56, 17.0), (-.82, 16.52)]), \"main\", H, H, bevel=.025)\n    # sensor band under a broad, slightly peaked brow hood\n    solid(\"visor\", two_view([(-.6, 16.48), (.6, 16.48), (.6, 16.64), (-.6, 16.64)],\n                            [(-.97, 16.46), (-.62, 16.46), (-.62, 16.66), (-.95, 16.66)]), \"visor\", H, 0.01)\n    solid(\"sensor_band\", two_view([(-.5, 16.535), (.5, 16.535), (.5, 16.585), (-.5, 16.585)],\n                                  [(-.99, 16.5), (-.93, 16.5), (-.93, 16.62), (-.99, 16.62)]), \"glow_eye\", H)\n    solid(\"brow_hood\", two_view([(-.68, 16.62), (.68, 16.62), (.62, 16.8), (.18, 16.88), (-.18, 16.88), (-.62, 16.8)],\n                                [(-1.07, 16.62), (-.55, 16.62), (-.55, 16.88), (-.95, 16.86)],\n                                top=[(-.7, -.5), (.7, -.5), (.7, -.92), (0, -1.1), (-.7, -.92)]), \"main\", H, 0.02)\n    # lower face: a dark recessed mask with vertical vents, two faceted plates over it\n    solid(\"mask\", two_view([(-.3, 15.9), (.3, 15.9), (.42, 16.45), (-.42, 16.45)],\n                           [(-.72, 15.9), (-.5, 15.9), (-.55, 16.46), (-.8, 16.46)]), \"frame\", H, 0.015)\n    vents = [prism([(x - .025, 15.98), (x + .025, 15.98), (x + .025, 16.3), (x - .025, 16.3)], -.8, -.7, \"xz\") for x in (-.1, 0, .1)]\n    solid(\"mask_vents\", merge(*vents), \"joint\", H)\n    pair(\"mask_plate\", two_view([(.12, 15.92), (.36, 16.0), (.44, 16.42), (.16, 16.42)],\n                                [(-.84, 15.95), (-.6, 15.95), (-.62, 16.44), (-.88, 16.44)]), \"main\", H, H, bevel=0.015)\n    # ear sensors: blocks with a lens on the outer face\n    pair(\"ear\", two_view([(.7, 16.3), (.86, 16.33), (.86, 16.66), (.7, 16.7)],\n                         [(-.25, 16.3), (.22, 16.3), (.28, 16.66), (-.2, 16.7)]), \"accent\", H, H, bevel=.02)\n    pair(\"ear_lens\", cylinder(.085, .85, .9, 12, axis=\"x\", at=(-.01, 16.48)), \"sensor\", H, H, smooth=True)\n    solid(\"helmet_rear\", two_view([(-.55, 16.08), (.55, 16.08), (.6, 16.7), (-.6, 16.7)],\n                                  [(.42, 16.04), (.8, 16.2), (.82, 16.7), (.52, 16.76)]), \"main\", H, .02)\n    solid(\"rear_fin\", prism([(.45, 16.95), (.92, 16.86), (1.0, 17.0), (.62, 17.18)], -.05, .05, \"yz\"), \"frame\", H, .01)\n    solid(\"crest\", two_view([(-.1, 16.9), (.1, 16.9), (.04, 17.62), (-.04, 17.62)],\n                            [(-.62, 16.98), (-.34, 17.25), (.48, 17.60), (.67, 17.54), (.15, 17.12), (-.32, 16.94)]), \"trim\", H, 0.01)\n\n\ndef build_arms(J):\n    pair(\"shoulder_block\", loft([(1.45, octo(1.5, 1.4, .35, y=14.55)), (2.62, octo(1.45, 1.35, .35, y=14.55))], axis=\"x\"),\n         \"frame\", *lr(J, \"shoulder\"), bevel=BEVEL)\n\"\"\"Modelling helpers shared by every kit script.\n\nBlender units are metres, Z is up, and models face -Y (Blender's front view). The glTF exporter turns\nthat into three.js's Y up with models facing +Z.\n\nParts are solids built from a few primitives:\n  loft      cross-sections stacked along an axis (most armour, limbs, hulls)\n  prism     a 2D outline pushed through a depth\n  two_view  a front outline and a side outline intersected, the classic hard-surface blockout\nEvery solid gets a material role (main, accent, frame, glow_eye, ...). The game maps roles to toon\nmaterials, so one model can wear any faction's paint.\n\"\"\"\nimport math\n\nimport bmesh\nimport bpy\nfrom mathutils import Matrix, Vector\n\n# Preview colours only, for anyone opening a .blend. The game ignores them.\nPREVIEW = {\n    \"main\": (0.86, 0.87, 0.9), \"accent\": (0.12, 0.3, 0.55), \"trim\": (0.85, 0.55, 0.12),\n    \"frame\": (0.2, 0.21, 0.24), \"joint\": (0.12, 0.12, 0.14), \"visor\": (0.05, 0.06, 0.08),\n    \"glow_eye\": (0.3, 1.0, 0.9), \"glow_core\": (0.3, 1.0, 0.9), \"glow_thruster\": (0.6, 0.78, 1.0),\n    \"glow_exhaust\": (0.31, 0.56, 1.0),\n    \"metal\": (0.55, 0.57, 0.6), \"hull\": (0.72, 0.73, 0.75), \"hull_dark\": (0.32, 0.33, 0.36),\n    \"deck\": (0.25, 0.26, 0.28), \"hazard\": (0.9, 0.75, 0.1), \"light\": (1.0, 0.97, 0.9),\n    \"screen\": (0.2, 0.8, 0.75), \"glass\": (0.1, 0.2, 0.25), \"lamp_red\": (1.0, 0.2, 0.15),\n    \"lamp_green\": (0.3, 1.0, 0.4), \"suit\": (0.14, 0.19, 0.36), \"glow_hot\": (0.92, 1.0, 0.98),\n    # raider salvage (palette.ts): donor paint, primer, rust, hand paint\n    \"donor_a\": (0.78, 0.76, 0.72), \"donor_b\": (0.24, 0.34, 0.43), \"donor_c\": (0.36, 0.38, 0.26), \"primer\": (0.54, 0.55, 0.52),\n    \"rust\": (0.42, 0.23, 0.13), \"handpaint\": (0.93, 0.89, 0.8), \"warpaint\": (0.76, 0.23, 0.15),\n    # markings: pattern codes, service text, unit codes (a decal layer in geometry)\n    \"stencil\": (0.13, 0.14, 0.16),\n    \"crystal\": (0.8, 0.81, 0.84), \"crystal_lit\": (0.55, 0.45, 0.78), \"glow_violet\": (0.66, 0.48, 1.0),\n}\n\n\ndef reset():\n    for o in list(bpy.data.objects):\n        bpy.data.objects.remove(o, do_unlink=True)\n    for coll in (bpy.data.meshes, bpy.data.materials):\n        for item in list(coll):\n            coll.remove(item)\n\n\ndef material(role):\n    m = bpy.data.materials.get(role)\n    if m is None:\n        m = bpy.data.materials.new(role)\n        c = PREVIEW.get(role, (0.7, 0.7, 0.7))\n        m.diffuse_color = (*c, 1.0)\n    return m\n\n\ndef link(o):\n    bpy.context.scene.collection.objects.link(o)\n    return o\n\n\ndef empty(name, at=(0, 0, 0), parent=None, **extras):\n    \"\"\"A joint or marker. Children keep their world placement when parented to it.\"\"\"\n    o = link(bpy.data.objects.new(name, None))\n    o.empty_display_size = 0.4\n    o.location = Vector(at) if parent is None else parent.matrix_world.inverted() @ Vector(at)\n    if parent is not None:\n        o.parent = parent\n    for k, v in extras.items():\n        o[k] = v\n    bpy.context.view_layer.update()\n    return o\n\n\ndef attach(o, parent):\n    \"\"\"Parent without moving: geometry is authored in world (rest pose) coordinates.\"\"\"\n    bpy.context.view_layer.update()\n    mw = o.matrix_world.copy()\n    o.parent = parent\n    o.matrix_parent_inverse = parent.matrix_world.inverted()\n    o.matrix_world = mw\n    return o\n\n\n# ---- 2D outlines ------------------------------------------------------------------------------------------\ndef octo(w, d, c=0.2, cf=None, cb=None, x=0.0, y=0.0):\n    \"\"\"A chamfered rectangle, w along X and d along Y, CCW seen from above. The front (-Y) and back\…1549 tokens truncated…REE.Vector3();\n  const look_ = new THREE.Vector3();\n  const up = new THREE.Vector3(0, 1, 0);\n  const yawQ = new THREE.Quaternion();\n  const DT = 1 / 120;\n  let clock = 0;\n\n  const feed = (state: Parameters<typeof benchInput>[0], t: number, dt: number) => {\n    const f = benchInput(state, t);\n    reading.x = f.thrust.x;\n    reading.y = f.thrust.y;\n    reading.z = f.thrust.z;\n    reading.boosting = f.boosting;\n    reading.assault = f.assault;\n    reading.quick = f.quick;\n    rig.thrust(reading, clock, dt);\n    rig.lightExhaust(light);\n  };\n\n  const render = (i: number) => {\n    const f = frames[i];\n    const v = shotView(f);\n    // thrusters step at 120 Hz whatever the clip's frame rate, as a game would\n    const dt = f.cut ? 0 : 1 / fps;\n    if (f.cut) for (let k = 0; k < 120; k++) { clock += DT; feed('idle', k * DT, DT); }\n    for (let s = 0; s < dt - 1e-9; s += DT) {\n      clock += DT;\n      feed(f.state, Math.max(0, f.stateT - dt + s), DT);\n    }\n    if (dt === 0) feed(f.state, f.stateT, 0);\n\n    root.rotation.y = THREE.MathUtils.degToRad(v.mechYaw);\n    rig.apply(v.bend > 0 ? mixPose(POSES.stand, BEND_POSE, v.bend) : POSES[v.pose]);\n    root.updateMatrixWorld(true);\n    ground.visible = v.ground;\n    centre.set(0, footY + height * v.lookAt, 0);\n    const fov = v.chase ? chase.camera.fov : 35;\n    if (camera.fov !== fov) {\n      camera.fov = fov;\n      camera.updateProjectionMatrix();\n    }\n    if (v.chase) {\n      // where the game's chase camera sits (src/view/cameras.ts), over the shoulder, scaled to the frame\n      yawQ.setFromAxisAngle(up, THREE.MathUtils.degToRad(v.camYaw));\n      offset.set(chase.shoulder * size, chase.chaseOffset.y * size, chase.chaseOffset.z * size).applyQuaternion(yawQ);\n      camera.position.copy(centre).add(offset);\n      look_.set(chase.shoulder * size, (chase.chaseOffset.y - chase.lookDrop) * size, 400).applyQuaternion(yawQ).add(centre);\n      camera.up.copy(up);\n      camera.lookAt(look_);\n    } else {\n      const yaw = THREE.MathUtils.degToRad(v.camYaw), pitch = THREE.MathUtils.degToRad(v.pitch);\n      camera.position.set(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), Math.cos(yaw) * Math.cos(pitch)).multiplyScalar(v.dist * height).add(centre);\n      if (v.ground) camera.position.y = Math.max(camera.position.y, footY + 1.6); // eye height, above the deck\n      camera.up.copy(up);\n      camera.lookAt(centre);\n    }\n    camera.updateMatrixWorld(true);\n    followSun(sun, centre);\n    pipe.render();\n    // read straight after the draw, in the same task, while the buffer still holds it\n    return canvas.toDataURL('image/jpeg', 0.93);\n  };\n\n  const win = window as unknown as { __clip: unknown; __ready: boolean };\n  win.__clip = { frames: frames.length, fps, render };\n  win.__ready = true;\n}\nimport '@fontsource/chakra-petch/400.css';\nimport '@fontsource/chakra-petch/600.css';\nimport '@fontsource/share-tech-mono/400.css';\nimport './hud/hud.css';\nimport { startViewer } from './view/viewer';\nimport { installHelp } from './hud/help';\n\nconst canvas = document.getElementById('view') as HTMLCanvasElement;\nconst q = new URLSearchParams(location.search);\n\nif (window.matchMedia?.('(pointer: coarse)').matches && !window.matchMedia('(pointer: fine)').matches) {\n  const note = document.createElement('div');\n  note.className = 'touch-note';\n  note.textContent = 'Sortie needs a keyboard and mouse.';\n  document.body.appendChild(note);\n}\n\nif (q.has('sheet')) {\n  import('./view/sheet').then(({ startSheet }) => startSheet(canvas, q));\n} else if (q.get('view') === 'thrusters') {\n  import('./view/thrusters').then(({ startThrusterBench }) => startThrusterBench(canvas, q));\n} else if (q.get('view') === 'clip') {\n  import('./view/clip').then(({ startClip }) => startClip(canvas, q));\n} else if (q.has('view')) {\n  startViewer(canvas, q);\n} else {\n  // F1 or H: the controls, over the picker and the game\n  installHelp();\n  // On an artifact page, published updates reload the page; the viewer's hot hook hands back what\n  // the last version saved, so a republish doesn't throw the pilot back into the hangar.\n  const hot = (window as unknown as { claude?: { hot?: HotHook } }).claude?.hot;\n  // a republish hands back a saved game: skip the picker then, the save knows its frame\n  const start = (data: unknown) =>\n    import('./game/picker').then(({ pickFrame, restoreFrame }) => (data ? restoreFrame(q) : pickFrame(q)))\n      .then(() => import('./game/game'))\n      .then(({ startGame }) => startGame(canvas, document.getElementById('hud')!, q, data, hot));\n  if (hot?.ready) hot.ready(start);\n  else start(hot?.data ?? null);\n}\n\nexport interface HotHook {\n  ready?: (start: (data: unknown) => void) => void;\n  data?: unknown;\n  snapshot?: (save: () => unknown) => void;\n}\nimport * as THREE from 'three';\n\n// The backdrop is drawn at infinity: it turns with the camera but never moves (pipeline.ts).\n\n// The renderer uses a logarithmic depth buffer, so custom shaders write depth the same way.\nconst LOGV = '#include <common>\\n#include <logdepthbuf_pars_vertex>\\n';\nconst LOGF = '#include <logdepthbuf_pars_fragment>\\n';\nconst logv = (body: string) => LOGV + body.replace(/gl_Position = ([^;]+);/, 'gl_Position = $1;\\n#include <logdepthbuf_vertex>\\n');\nconst logf = (body: string) => LOGF + body.replace(/void main\\(\\) \\{/, 'void main() {\\n#include <logdepthbuf_fragment>');\n\nconst NOISE = /* glsl */ `\n  float hash(vec3 p) { p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }\n  float noise(vec3 x) {\n    vec3 i = floor(x); vec3 f = fract(x); f = f * f * (3.0 - 2.0 * f);\n    return mix(mix(mix(hash(i), hash(i + vec3(1,0,0)), f.x), mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y),\n               mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x), mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y), f.z);\n  }\n  float fbm(vec3 p) { float a = 0.5, s = 0.0; for (int i = 0; i < 5; i++) { s += a * noise(p); p *= 2.03; a *= 0.5; } return s; }\n`;\n\nfunction stars(count: number, seed = 7): THREE.Points {\n  let s = seed;\n  const rnd = () => ((s = (s * 16807) % 2147483647) / 2147483647);\n  const pos = new Float32Array(count * 3);\n  const col = new Float32Array(count * 3);\n  const tint = [new THREE.Color('#cfe0ff'), new THREE.Color('#ffffff'), new THREE.Color('#ffe2c4'), new THREE.Color('#b9fff4')];\n  for (let i = 0; i < count; i++) {\n    const u = rnd() * 2 - 1;\n    const t = rnd() * Math.PI * 2;\n    const r = Math.sqrt(1 - u * u);\n    pos.set([r * Math.cos(t) * 9e5, u * 9e5, r * Math.sin(t) * 9e5], i * 3);\n    const c = tint[Math.floor(rnd() * tint.length)].clone().multiplyScalar(0.25 + Math.pow(rnd(), 3) * 1.6);\n    col.set([c.r, c.g, c.b], i * 3);\n  }\n  const g = new THREE.BufferGeometry();\n  g.setAttribute('position', new THREE.BufferAttribute(pos, 3));\n  g.setAttribute('color', new THREE.BufferAttribute(col, 3));\n  return new THREE.Points(g, new THREE.PointsMaterial({ size: 1.6, sizeAttenuation: false, vertexColors: true, depthWrite: false }));\n}\n\nfunction nebula(sunDir: THREE.Vector3): THREE.Mesh {\n  const m = new THREE.ShaderMaterial({\n    side: THREE.BackSide,\n    depthWrite: false,\n    uniforms: { sunDir: { value: sunDir } },\n    vertexShader: logv(/* glsl */ `\n      varying vec3 vDir;\n      void main() { vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`),\n    fragmentShader: logf(/* glsl */ `\n      ${NOISE}\n      uniform vec3 sunDir;\n      varying vec3 vDir;\n      void main() {\n        vec3 d = normalize(vDir);\n        float n = fbm(d * 2.2 + vec3(3.1, 0.0, 1.7));\n        float m = fbm(d * 4.5 + n * 1.5);\n        float band = exp(-pow(dot(d, normalize(vec3(0.3, 0.85, -0.4))) * 2.6, 2.0));\n        vec3 deep = vec3(0.012, 0.016, 0.035);\n        vec3 c1 = vec3(0.10, 0.05, 0.20) * smoothstep(0.45, 0.8, n) * band;\n        vec3 c2 = vec3(0.02, 0.13, 0.17) * smoothstep(0.5, 0.85, m) * band;\n        float sun = max(dot(d, sunDir), 0.0);\n        vec3 glare = vec3(1.0, 0.85, 0.65) * (pow(sun, 900.0) * 6.0 + pow(sun, 60.0) * 0.25 + pow(sun, 8.0) * 0.04);\n        gl_FragColor = vec4(deep + c1 + c2 + glare, 1.0);\n      }`),\n  });\n  return new THREE.Mesh(new THREE.SphereGeometry(9.5e5, 48, 24), m);\n}\n\nfunction planet(sunDir: THREE.Vector3): THREE.Group {\n  const g = new THREE.Group();\n  const R = 1.4e5;\n  const body = new THREE.Mesh(\n    new THREE.SphereGeometry(R, 96, 64),\n    new THREE.ShaderMaterial({\n      uniforms: { sunDir: { value: sunDir } },\n      vertexShader: logv(/* glsl */ `\n        varying vec3 vN; varying vec3 vObj; varying vec3 vView;\n        void main() {\n          vObj = normalize(position);\n          vN = normalize(mat3(modelMatrix) * normal);\n          vec4 wp = modelMatrix * vec4(position, 1.0);\n          vView = normalize(cameraPosition - wp.xyz);\n          gl_Position = projectionMatrix * viewMatrix * wp;\n        }`),\n      fragmentShader: logf(/* glsl */ `\n        ${NOISE}\n        uniform vec3 sunDir;\n        varying vec3 vN; varying vec3 vObj; varying vec3 vView;\n        void main() {\n          float land = smoothstep(0.52, 0.56, fbm(vObj * 3.0 + vec3(1.3, 4.2, 0.7)));\n          float cloud = smoothstep(0.5, 0.72, fbm(vObj * 5.0 + vec3(fbm(vObj * 2.0) * 2.0)));\n          vec3 ocean = vec3(0.07, 0.22, 0.42);\n          vec3 ground = mix(vec3(0.2, 0.36, 0.18), vec3(0.55, 0.47, 0.32), fbm(vObj * 9.0));\n          vec3 c = mix(ocean, ground, land);\n          c = mix(c, vec3(0.92, 0.95, 1.0), cloud * 0.85);\n          float l = dot(normalize(vN), sunDir);\n          float band = l > 0.25 ? 1.0 : l > 0.0 ? 0.62 : l > -0.12 ? 0.18 : 0.03;\n          float rim = pow(1.0 - max(dot(normalize(vN), vView), 0.0), 3.0);\n          vec3 atmo = vec3(0.35, 0.65, 1.0) * rim * smoothstep(-0.25, 0.3, l) * 1.4;\n          vec3 night = vec3(1.0, 0.7, 0.35) * land * (1.0 - cloud) * step(fbm(vObj * 40.0), 0.42) * step(l, -0.12) * 0.35;\n          gl_FragColor = vec4(c * band + atmo + night, 1.0);\n        }`),\n    }),\n  );\n  g.add(body);\n  const halo = new THREE.Mesh(\n    new THREE.SphereGeometry(R * 1.035, 96, 64),\n    new THREE.ShaderMaterial({\n      transparent: true,\n      blending: THREE.AdditiveBlending,\n      depthWrite: false,\n      side: THREE.BackSide,\n      uniforms: { sunDir: { value: sunDir } },\n      vertexShader: logv(/* glsl */ `\n        varying vec3 vN; varying vec3 vView;\n        void main() {\n          vN = normalize(mat3(modelMatrix) * normal);\n          vec4 wp = modelMatrix * vec4(position, 1.0);\n          vView = normalize(cameraPosition - wp.xyz);\n          gl_Position = projectionMatrix * viewMatrix * wp;\n        }`),\n      fragmentShader: logf(/* glsl */ `\n        uniform vec3 sunDir;\n        varying vec3 vN; varying vec3 vView;\n        void main() {\n          float f = pow(max(dot(-normalize(vN), vView), 0.0), 2.5);\n          float lit = smoothstep(-0.3, 0.4, dot(normalize(vN), sunDir));\n          gl_FragColor = vec4(vec3(0.3, 0.6, 1.0) * f * lit * 1.2, 1.0);\n        }`),\n    }),\n  );\n  g.add(halo);\n  g.position.set(-1.1e5, -2.6e5, 2.2e5);\n  return g;\n}\n\nexport const SUN_DIR = new THREE.Vector3(0.75, 0.5, 0.42).normalize();\n\nexport function createBackdrop(sunDir = SUN_DIR): THREE.Scene {\n  const scene = new THREE.Scene();\n  scene.add(nebula(sunDir));\n  scene.add(stars(7000));\n  scene.add(planet(sunDir));\n  return scene;\n}\n\n/**\n * The nebula and planet shaders are noise-heavy and never change, so render them once into a cube\n * map and draw that as the background. Stars stay as live points so they stay sharp.\n */\nexport function bakeBackdrop(renderer: THREE.WebGLRenderer, backdrop: THREE.Scene, size = 1024): THREE.Scene {\n  const target = new THREE.WebGLCubeRenderTarget(size, { type: THREE.HalfFloatType, generateMipmaps: false });\n  const cam = new THREE.CubeCamera(1, 2e6, target);\n  const stars = backdrop.children.filter((o) => (o as THREE.Points).isPoints);\n  for (const s of stars) s.visible = false;\n  cam.update(renderer, backdrop);\n  const baked = new THREE.Scene();\n  baked.background = target.texture;\n  for (const s of stars) {\n    s.visible = true;\n    baked.add(s.clone());\n  }\n  return baked;\n}\n\n/** Sunlight (shadow-casting, following `focus`) plus a dim cool fill from the planet below. */\nexport function addSpaceLight(scene: THREE.Scene, sunDir = SUN_DIR): THREE.DirectionalLight {\n  const sun = new THREE.DirectionalLight('#fff4e6', 3.2);\n  sun.position.copy(sunDir).multiplyScalar(200);\n  sun.castShadow = true;\n  sun.shadow.mapSize.set(2048, 2048);\n  const c = sun.shadow.camera;\n  c.left = c.bottom = -28;\n  c.right = c.top = 28;\n  c.near = 1;\n  c.far = 500;\n  sun.shadow.bias = -0.0004;\n  sun.shadow.normalBias = 0.04;\n  scene.add(sun);\n  scene.add(sun.target);\nimport * as THREE from 'three';\nimport type { Palette, Role } from './palette';\nimport { addPaintVariation, look } from './look';\n\n/** Painted armour roles: their finish follows the look (matte field paint or gloss kit paint). */\nconst PAINT = new Set<Role>(['main', 'accent', 'trim', 'hull', 'suit', 'donor_a', 'donor_b', 'donor_c', 'primer', 'handpaint',\n  'warpaint']);\n/** Unpainted roles: no wear, grime or ink lines from the detail pass (alien crystal). */\nexport const BARE = new Set<Role>(['crystal', 'crystal_lit']);\n\n// Physically based materials by role: painted armour, bare and dark metal, glass, and unlit glows\n// that feed the bloom.\n\n/** Diagonal hazard stripes from world position, so no UVs are needed. */\nfunction addStripes(m: THREE.MeshStandardMaterial) {\n  m.onBeforeCompile = (shader) => {\n    shader.vertexShader = shader.vertexShader\n      .replace('#include <common>', '#include <common>\\nvarying vec3 vStripePos;')\n      .replace('#include <worldpos_vertex>', '#include <worldpos_vertex>\\nvStripePos = (modelMatrix * vec4(transformed, 1.0)).xyz;');\n    shader.fragmentShader = shader.fragmentShader\n      .replace('#include <common>', '#include <common>\\nvarying vec3 vStripePos;')\n      .replace(\n        '#include <color_fragment>',\n        `#include <color_fragment>\n         float stripe = step(0.5, fract((vStripePos.x + vStripePos.y + vStripePos.z) * 0.6));\n         diffuseColor.rgb = mix(vec3(0.03, 0.03, 0.035), diffuseColor.rgb, stripe);`,\n      );\n  };\n  m.customProgramCacheKey = () => 'stripes';\n}\n\nconst cache = new Map<string, THREE.Material>();\n\nlet bands: THREE.DataTexture | null = null;\n/** Three lighting bands for the sketch look: shade, half-tone, lit. */\nfunction toonBands() {\n  if (bands) return bands;\n  const d = new Uint8Array([60, 60, 60, 140, 255, 255]);\n  bands = new THREE.DataTexture(d, d.length, 1, THREE.RedFormat);\n  bands.minFilter = bands.magFilter = THREE.NearestFilter;\n  bands.needsUpdate = true;\n  return bands;\n}\n\nexport function material(palette: Palette, role: Role, key: string): THREE.Material {\n  const l = look();\n  const id = `${key}:${role}:${l.name}`;\n  const hit = cache.get(id);\n  if (hit) return hit;\n  const p = palette[role] ?? { color: '#ff00ff' };\n  let m: THREE.Material;\n  if (p.glow) {\n    m = new THREE.MeshBasicMaterial({ color: new THREE.Color(p.color).multiplyScalar(p.glow) });\n  } else {\n    // A floor on roughness: a near-mirror catching the sun makes a highlight brighter than the\n    // half-float buffers can hold, and the bloom smears that across the whole screen.\n    const painted = PAINT.has(role);\n    // a lacquered livery keeps its own finish under a matte look: its roughness at most, and a clear coat\n    const lacquer = painted ? p.lacquer ?? 0 : 0;\n    const paintRough = lacquer ? Math.min(l.paintRough, p.rough ?? l.paintRough) : l.paintRough;\n    const roughness = Math.max(0.2, painted ? paintRough : p.rough ?? 0.5);\n    const coat = painted ? Math.max(l.gloss ? 0.6 : 0, lacquer) : p.coat ?? 0;\n    const color = new THREE.Color(p.color);\n    if (painted && l.desaturate > 0) {\n      // weathered paint: pulled toward grey and warmed slightly, less so under lacquer\n      const grey = color.r * 0.3 + color.g * 0.59 + color.b * 0.11;\n      color.lerp(new THREE.Color(grey, grey, grey), l.desaturate * (1 - lacquer * 0.6)).multiply(new THREE.Color(1.0, 0.98, 0.94));\n    }\n    if (l.toon) {\n      const t = new THREE.MeshToonMaterial({ color, gradientMap: toonBands() });\n      t.name = role;\n      if (role === 'hazard') addStripes(t as unknown as THREE.MeshStandardMaterial);\n      cache.set(id, t);\n      return t;\n    }\n    const s = coat >= 0.5\n      ? new THREE.MeshPhysicalMaterial({ color, roughness, metalness: p.metal ?? 0, clearcoat: coat, clearcoatRoughness: 0.25 })\n      : new THREE.MeshStandardMaterial({ color, roughness, metalness: p.metal ?? 0 });\n    if (p.emit) s.emissive.copy(color).multiplyScalar(p.emit);\n    if (role === 'hazard') addStripes(s);\n    else if (painted || role === 'frame' || role === 'joint' || role === 'rust') addPaintVariation(s, l.grime * (painted ? 1 : 0.6));\n    if (p.rust) addRust(s, p.rust);\n    m = s;\n  }\n  m.name = role;\n  cache.set(id, m);\n  return m;\n}\n\n/** Rust from world position, so no UVs are needed: blotches that grow with `amount`, streaks running down\n *  from them, rougher and duller where the paint has gone. */\nfunction addRust(m: THREE.MeshStandardMaterial, amount: number) {\n  const prev = m.onBeforeCompile;\n  m.onBeforeCompile = (shader, r) => {\n    prev?.call(m, shader, r);\n    shader.vertexShader = shader.vertexShader\n      .replace('#include <common>', '#include <common>\\nvarying vec3 vRustPos;')\n      .replace('#include <worldpos_vertex>', '#include <worldpos_vertex>\\nvRustPos = (modelMatrix * vec4(transformed, 1.0)).xyz;');\n    shader.fragmentShader = shader.fragmentShader\n      .replace('#include <common>', `#include <common>\n        varying vec3 vRustPos;\n        float rn(vec3 p) { vec3 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);\n          vec3 k = vec3(12.9, 78.2, 37.7);\n          return mix(mix(mix(fract(sin(dot(i, k)) * 43758.5), fract(sin(dot(i + vec3(1,0,0), k)) * 43758.5), f.x),\n                         mix(fract(sin(dot(i + vec3(0,1,0), k)) * 43758.5), fract(sin(dot(i + vec3(1,1,0), k)) * 43758.5), f.x), f.y),\n                     mix(mix(fract(sin(dot(i + vec3(0,0,1), k)) * 43758.5), fract(sin(dot(i + vec3(1,0,1), k)) * 43758.5), f.x),\n                         mix(fract(sin(dot(i + vec3(0,1,1), k)) * 43758.5), fract(sin(dot(i + vec3(1,1,1), k)) * 43758.5), f.x), f.y), f.z); }\n        float rustMask(vec3 p) {\n          // patches where paint has gone, fine-grained, and thin streaks running down from them\n          float blot = rn(p * 1.3) * 0.6 + rn(p * 4.7) * 0.4;\n          float t = 1.0 - ${(0.7 * amount).toFixed(3)};\n          float streak = smoothstep(0.6, 0.82, rn(vec3(p.x * 9.0, p.y * 0.22, p.z * 9.0))) * smoothstep(t - 0.2, t, rn(p * 0.9));\n          return clamp(smoothstep(t, t + 0.06, blot) + streak * 0.6, 0.0, 1.0);\n        }`)\n      .replace('#include <color_fragment>', `#include <color_fragment>\n        float rm = rustMask(vRustPos);\n        vec3 rc = mix(vec3(0.15, 0.065, 0.03), vec3(0.34, 0.14, 0.055), rn(vRustPos * 6.0));\n        diffuseColor.rgb = mix(diffuseColor.rgb, rc, rm);`)\n      .replace('#include <roughnessmap_fragment>', `#include <roughnessmap_fragment>\n        roughnessFactor = mix(roughnessFactor, 0.92, rm);`)\n      .replace('#include <metalnessmap_fragment>', `#include <metalnessmap_fragment>\n        metalnessFactor = mix(metalnessFactor, 0.15, rm);`);\n  };\n  const key = m.customProgramCacheKey?.bind(m);\n  m.customProgramCacheKey = () => `${key ? key() : ''}rust${amount}`;\n}\n\nexport function isRole(name: string): name is Role {\n  return /^[a-z_]+$/.test(name);\n}\n"}
  • apply_patch, exec_commandapply_patch (+1 more)

    input

    text(await tools.apply_patch("*** Begin Patch\n*** Add File: ~/work/sortie/tools/astra/time_step.py\n+\"\"\"Append a measured stage boundary to this refinement's local timeline.\"\"\"\n+import json\n+from datetime import datetime, timezone\n+from pathlib import Path\n+import sys\n+\n+path = Path(__file__).resolve().parents[2] / 'review/out/astra/refinement-time.json'\n+events = json.loads(path.read_text()) if path.exists() else []\n+events.append({'utc': datetime.now(timezone.utc).isoformat(), 'stage': sys.argv[1],\n+               'note': ' '.join(sys.argv[2:])})\n+path.write_text(json.dumps(events, indent=2) + '\\n')\n+print(events[-1])\n*** End Patch"));
    text(await tools.exec_command({cmd:"python tools/astra/time_step.py design 'New task. Same block_dummy joint positions. Design from the rear. Control S is striker.glb.' && sed -n '310,470p' kit/lib.py && sed -n '600,740p' kit/lib.py && sed -n '170,310p' src/render/pipeline.ts && cat .gitignore","max_output_tokens":7000}));
    

    result, 4 lines

    Script completed
    Wall time 0.1 seconds
    Output:
    {}{"chunk_id":"3687bb","wall_time_seconds":0.00000669,"exit_code":0,"original_token_count":2209,"output":"{'utc': '2026-11-15T03:56:00.316363+00:00', 'stage': 'design', 'note': 'New task. Same block_dummy joint positions. Design from the rear. Control S is striker.glb.'}\ndef halves(bm, co, no, gap=.04):\n    \"\"\"Split a solid along a plane into two capped pieces with a gap between them: a panel seam\n    with real depth, so the dark frame beneath shows through.\"\"\"\n    co, no = Vector(co), Vector(no).normalized()\n    a = _keep_side(copy(bm), co - no * gap / 2, no, below=True)\n    b = _keep_side(bm, co + no * gap / 2, no, below=False)\n    return a, b\n\n\ndef panels(bm, cuts, gap=.04):\n    \"\"\"Cut a solid by several planes [(point, normal), ...] into panels with seams between them.\"\"\"\n    pieces = [bm]\n    for co, no in cuts:\n        out = []\n        for p in pieces:\n            for h in halves(p, co, no, gap):\n                if len(h.faces) >= 4:\n                    out.append(h)\n                else:\n                    h.free()\n        pieces = out\n    return pieces\n\n\ndef fold(objs, t, half, y0, y1):\n    \"\"\"Fold the front of a part into a shallow V: in front of y0 (fully in front of y1) every vertex\n    moves forward (-Y) by t * (half - |x|), so the centre line becomes a ridge and both sides angle\n    back. Meshes are cut on the centre line first so flat plates fold instead of tilting. Works on\n    mesh coordinates, which are the authored ones.\"\"\"\n    for ob in objs:\n        bm = bmesh.new()\n        bm.from_mesh(ob.data)\n        if bm.verts and min(v.co.y for v in bm.verts) < y0:\n            geom = bm.verts[:] + bm.edges[:] + bm.faces[:]\n            bmesh.ops.bisect_plane(bm, geom=geom, plane_co=(0, 0, 0), plane_no=(1, 0, 0))\n            for v in bm.verts:\n                ax = abs(v.co.x)\n                if v.co.y < y0 and ax < half:\n                    w = min(1.0, (y0 - v.co.y) / (y0 - y1))\n                    v.co.y -= t * (half - ax) * w * w * (3 - 2 * w)\n            bm.to_mesh(ob.data)\n        bm.free()\n\n\ndef piston(p0, p1, r=.12, n=8):\n    \"\"\"A hydraulic piston from p0 to p1: a body over the first 60%, a thinner rod the rest, end eyes.\"\"\"\n    p0, p1 = Vector(p0), Vector(p1)\n    axis = p1 - p0\n    m = Matrix.Translation(p0) @ Vector((0, 0, 1)).rotation_difference(axis.normalized()).to_matrix().to_4x4()\n    L = axis.length\n    body = loft([(0, circle(r, n)), (L * .6, circle(r, n))])\n    rod = loft([(L * .55, circle(r * .45, n)), (L, circle(r * .45, n))])\n    eyes = merge(loft([(-r * .4, circle(r * .7, n)), (r * .4, circle(r * .7, n))]),\n                 loft([(L - r * .4, circle(r * .6, n)), (L + r * .4, circle(r * .6, n))]))\n    return transform(merge(body, rod, eyes), m)\n\n\ndef subd(bm, levels=2, sharp=45, crease=1.0):\n    \"\"\"Smooth a low-poly cage with Catmull-Clark subdivision. Edges whose faces meet at more than\n    `sharp` degrees are creased, so they stay crisp while everything else rounds off: helmets and\n    shells that are soft where they should be and hard where they shouldn't.\"\"\"\n    me = bpy.data.meshes.new(\"_subd\")\n    bm.to_mesh(me)\n    bm.free()\n    attr = me.attributes.get(\"crease_edge\") or me.attributes.new(\"crease_edge\", \"FLOAT\", \"EDGE\")\n    probe = bmesh.new()\n    probe.from_mesh(me)\n    probe.edges.ensure_lookup_table()\n    lim = math.radians(sharp)\n    for e in probe.edges:\n        f = e.link_faces\n        if len(f) == 2 and f[0].normal.angle(f[1].normal, 0) > lim:\n            attr.data[e.index].value = crease\n    probe.free()\n    o = link(bpy.data.objects.new(\"_subd\", me))\n    mod = o.modifiers.new(\"subd\", \"SUBSURF\")\n    mod.levels = mod.render_levels = levels\n    bake(o)\n    out = bmesh.new()\n    out.from_mesh(o.data)\n    data = o.data\n    bpy.data.objects.remove(o, do_unlink=True)\n    bpy.data.meshes.remove(data)\n    return out\n\n\ndef cylinder(r, z0, z1, n=10, r1=None, axis=\"z\", at=(0, 0)):\n    \"\"\"An n-sided cylinder (or cone with r1) between z0 and z1 along an axis, centred at `at` in the\n    other two coordinates.\"\"\"\n    r1 = r if r1 is None else r1\n    return loft([(z0, circle(r, n, *at)), (z1, circle(r1, n, *at))], axis=axis)\n\n\ndef nozzle(r_out, length, n=12, flare=1.25):\n    \"\"\"A thruster bell along -Z from the origin (throat at z=0, exit at z=-length), open-ended with\n    a thick lip. Returns (shell bmesh, glow disc bmesh).\"\"\"\n    ro, ri = r_out, r_out * 0.78\n    rings_out = [(0, circle(ro / flare, n)), (-length * 0.6, circle(ro * 0.92, n)), (-length, circle(ro, n))]\n    rings_in = [(-length, circle(ri, n)), (-length * 0.6, circle(ri * 0.9, n)), (0.0, circle(ri / flare * 0.9, n))]\n    bm = bmesh.new()\n    loops = []\n    for h, pts in rings_out + rings_in:\n        loops.append([bm.verts.new((u, v, h)) for u, v in pts])\n    for a, b in zip(loops, loops[1:]):\n        for i in range(n):\n            j = (i + 1) % n\n            bm.faces.new((a[i], a[j], b[j], b[i]))\n    bm.faces.new(list(reversed(loops[0])))\n    _outward(bm)\n    glow = loft([(-length * 0.15, circle(ri / flare * 0.85, n)), (-length * 0.12, circle(ri / flare * 0.85, n))])\n    return bm, glow\n\n\ndef slats(x0, x1, z0, z1, y, n, depth=0.12, gap=0.35):\n    \"\"\"Horizontal vent slats on a plane facing -Y at depth y.\"\"\"\n    out = []\n    h = (z1 - z0) / n\n    for i in range(n):\n        zb = z0 + i * h\n        out.append(prism([(x0, zb), (x1, zb), (x1, zb + h * (1 - gap)), (x0, zb + h * (1 - gap))],\n                         y - depth, y + 0.05, \"xz\"))\n    return merge(*out)\n\n\ndef export(path, extras=True):\n    bpy.ops.export_scene.gltf(filepath=path, export_format=\"GLB\", export_apply=True, export_yup=True,\n                              export_extras=extras, export_cameras=False, export_lights=False,\n                              export_materials=\"EXPORT\", export_normals=True, export_texcoords=False)\n    this.resize();\n  }\n\n  /** The sun whose shadow map follows the tier. */\n  set shadowLight(sun: THREE.DirectionalLight) {\n    this.sun = sun;\n    this.shadowSize();\n  }\n\n  private shadowSize() {\n    const s = this.quality.tier === 'high' ? 2048 : 1024;\n    const sh = this.sun?.shadow;\n    if (!sh || sh.mapSize.x === s) return;\n    sh.mapSize.set(s, s);\n    sh.map?.dispose();\n    sh.map = null;\n  }\n\n  applyLook(l: Look) {\n    const u = this.detail.uniforms;\n    u.ridgeK.value = l.ridge;\n    u.valleyK.value = l.valley;\n    u.inkK.value = l.ink;\n    u.chipped.value = l.chipped ? 1 : 0;\n    u.hatch.value = l.hatch ?? 0;\n    this.grade.uniforms.paper.value = l.paper ?? 0;\n    this.detailWanted = l.ridge + l.valley + l.ink > 0;\n    this.detail.enabled = this.detailWanted && this.quality?.tier !== 'low';\n    this.grade.uniforms.grain.value = l.grain;\n    this.grade.uniforms.vignette.value = l.vignette;\n  }\n\n  /** A scene drawn over the world with its own depth range (the cockpit), after the world's detail pass. */\n  setOverlay(scene: THREE.Scene, camera: THREE.PerspectiveCamera) {\n    this.overlay = new ScenePass(scene, camera, null, false);\n    this.composer.insertPass(this.overlay, this.composer.passes.indexOf(this.detail) + 1);\n    this.resize();\n  }\n\n  set backdrop(scene: THREE.Scene | null) {\n    this.world.backdrop = scene;\n  }\n\n  set overlayVisible(v: boolean) {\n    if (this.overlay) this.overlay.enabled = v;\n  }\n\n  get camera() {\n    return this.world.camera;\n  }\n\n  resize(w = window.innerWidth, h = window.innerHeight) {\n    this.renderer.setSize(w, h, false);\n    const pr = this.renderer.getPixelRatio();\n    fitComposer(this.composer, w, h, pr);\n    this.normals?.setSize(Math.round(w * pr), Math.round(h * pr));\n    this.detail?.uniforms.px.value.set(1 / (w * pr), 1 / (h * pr));\n    for (const c of [this.world.camera, this.overlay?.camera]) {\n      if (!c) continue;\n      c.aspect = w / h;\n      c.updateProjectionMatrix();\n    }\n  }\n\n  render() {\n    if (this.detail.enabled) {\n      // normals and depth of detailed meshes only, for the detail pass\n      const { renderer } = this;\n      const scene = this.world.scene, camera = this.world.camera;\n      camera.layers.set(DETAIL_LAYER);\n      const bg = scene.background;\n      scene.background = null;\n      scene.overrideMaterial = this.normalMat;\n      renderer.setRenderTarget(this.normals);\n      renderer.setClearColor(0x000000, 0);\n      renderer.clear();\n      renderer.render(scene, camera);\n      scene.overrideMaterial = null;\n      scene.background = bg;\n      camera.layers.set(0);\n      this.detail.uniforms.near.value = camera.near;\n      this.detail.uniforms.far.value = camera.far;\n      this.detail.uniforms.projInv.value.copy(camera.projectionMatrixInverse);\n      this.detail.uniforms.viewInv.value.copy(camera.matrixWorld);\n    }\n    this.grade.uniforms.time.value = (performance.now() % 10000) / 1000;\n    this.composer.render();\n  }\n}\nnode_modules/\ndist/\nreview/out/\n*.blend1\n__pycache__/\n# block models are scratch until one is worth keeping\npublic/assets/block_*.glb\n\n# worktrees of finished agents, see docs/housekeeping.md\n.claude/worktrees/\n"}