Skip to content

finos/morphir-scala / .claude/skills/squire

squire

Verified

Use when morphir-scala work needs environment diagnostics or build/network/sandbox unblocking; reference repository management; branch lifecycle refresh after squash-merging a target branch into main; Morphir IR spec/schema sync or export; or task-tracking configuration and beads mode resolution.

FileKindSize
.gitignoreother180 B
.mill-versionother19 B
README.mdmarkdown7.6 KB
SKILL.mdskill md6.7 KB
SquireBranch.scalaother6.4 KB
SquireCellar.scalaother7.4 KB
SquireChangelog.scalaother20.6 KB
SquireDoctor.scalaother13.9 KB
SquireEnv.scalaother16.2 KB
SquireModel.scalaother4.9 KB
SquireProcess.scalaother1.5 KB
SquireRepo.scalaother30.4 KB
SquireSchemas.scalaother25.2 KB
SquireSpec.scalaother35.6 KB
SquireTests.scalaother323.1 KB
SquireTracking.scalaother16.4 KB
SquireVersionCorpus.scalaother3.3 KB
millexecutablescript6.5 KB
mill.batscript9.7 KB
references/branch.mdmarkdown4.4 KB
references/cellar.mdmarkdown4.4 KB
references/doctor.mdmarkdown5.3 KB
references/env.mdmarkdown3.9 KB
references/mill-morphir.mdmarkdown1.6 KB
references/repo.mdmarkdown7.6 KB
references/spec-sync.mdmarkdown10.6 KB
references/tracking.mdmarkdown10.9 KB
squireexecutablescript1.2 KB
squire.batscript1.8 KB
squire.scalaother36.8 KB
test-resources/META-INF/services/kyo.test.Testother275 B
test-resources/schemas/morphir-ir-v4.jsonconfig107.1 KB
test-resources/schemas/morphir-ir-v4.yamlconfig74.2 KB

SquireModel.scala

View on GitHub
//| scalaVersion: 3.9.0
//| mvnDeps:
//| - io.getkyo::kyo-core:1.0.0-RC7
//| - io.getkyo::kyo-schema-json:1.0.0-RC7
//| - io.getkyo::kyo-schema-yaml:1.0.0-RC7
//| - io.getkyo::kyo-system:1.0.0-RC7

import kyo.*

sealed abstract class SquireError(message: String) extends RuntimeException(message)

object SquireError:
  final case class Failure(area: String, message: String, detail: Maybe[String] = Absent)
      extends SquireError(message)

object SquireJson:
  def encode[A: Schema](value: A): String = Json.encode(value)

  def decode[A: Schema](text: String): Result[DecodeException, A] = Json.decode(text)

  def pretty(value: Structure.Value): String =
    render(value, 0) + "\n"

  private def render(value: Structure.Value, depth: Int): String =
    value match
      case Structure.Value.Record(fields) => renderObject(fields, depth)
      case Structure.Value.VariantCase(name, value) =>
        renderObject(Chunk("name" -> Structure.Value.Str(name), "value" -> value), depth)
      case Structure.Value.Sequence(elements) => renderArray(elements, depth)
      case Structure.Value.MapEntries(entries) =>
        renderArray(entries.map { case (key, value) => Structure.Value.Sequence(Chunk(key, value)) }, depth)
      case Structure.Value.Str(value)     => Json.encode(value)
      case Structure.Value.Bool(value)    => Json.encode(value)
      case Structure.Value.Integer(value) => Json.encode(value)
      case Structure.Value.Decimal(value) => Json.encode(value)
      case Structure.Value.BigNum(value)  => Json.encode(value)
      case Structure.Value.Null           => "null"
      case Structure.Value.Bytes(_) | Structure.Value.Instant(_) | Structure.Value.Duration(_) =>
        throw SquireError.Failure("json", "value cannot be represented as deterministic JSON")

  private def renderObject(fields: Chunk[(String, Structure.Value)], depth: Int): String =
    if fields.isEmpty then "{}"
    else
      fields
        .map { case (name, value) =>
          s"${indent(depth + 1)}${Json.encode(name)}: ${render(value, depth + 1)}"
        }
        .mkString("{\n", ",\n", s"\n${indent(depth)}}")

  private def renderArray(elements: Chunk[Structure.Value], depth: Int): String =
    if elements.isEmpty then "[]"
    else
      elements
        .map(value => s"${indent(depth + 1)}${render(value, depth + 1)}")
        .mkString("[\n", ",\n", s"\n${indent(depth)}]")

  private def indent(depth: Int): String = "  " * depth

object SquireYaml:
  def encode[A: Schema](value: A): String = Yaml.encode(value)

  def decode[A: Schema](text: String): Result[DecodeException, A] = Yaml.decode(text)

object SquirePaths:
  def render(path: Path): String = path.toString

  def isUnder(child: Path, base: Path): Boolean =
    child.parts.take(base.parts.size) == base.parts

  def resolveUnder(candidate: Path, base: Path): Result[SquireError, Path] =
    try
      val baseReal                        = base.toJava.toRealPath()
      val (existingAncestor, missingTail) = nearestExisting(candidate.toJava.toAbsolutePath.normalize)
      val candidateAncestorReal           = existingAncestor.toRealPath()
      if candidateAncestorReal.startsWith(baseReal) then
        val resolved = missingTail.foldLeft(candidateAncestorReal)(_.resolve(_))
        Result.Success(Path(resolved.toString))
      else pathEscapeFailure
    catch
      case error: java.io.IOException =>
        Result.Failure(SquireError.Failure("path", "could not resolve path under configured base", Present(error.getMessage)))

  private def nearestExisting(path: java.nio.file.Path): (java.nio.file.Path, List[java.nio.file.Path]) =
    @scala.annotation.tailrec
    def loop(current: java.nio.file.Path, missing: List[java.nio.file.Path]): (java.nio.file.Path, List[java.nio.file.Path]) =
      if java.nio.file.Files.exists(current) then (current, missing)
      else if java.nio.file.Files.exists(current, java.nio.file.LinkOption.NOFOLLOW_LINKS) then
        throw java.nio.file.NoSuchFileException(current.toString, null, "path contains a dangling symbolic link")
      else
        Option(current.getParent) match
          case Some(parent) => loop(parent, current.getFileName :: missing)
          case None         => throw java.nio.file.NoSuchFileException(current.toString)
    loop(path, Nil)

  private def pathEscapeFailure: Result[SquireError, Path] =
    Result.Failure(SquireError.Failure("path", "path escapes its configured base"))

  /** `Path.exists` outside a capability runner. An inaccessible path already reads as absent, so a filesystem failure does too. */
  def exists(path: Path): Boolean < Sync =
    Abort.recover[FileSystemException](_ => false)(Path.runReadOnly(path.exists))

  def findRepoRoot(from: Path): Maybe[Path] < Sync =
    def loop(path: Path): Maybe[Path] < Sync =
      exists(path / ".git").flatMap { exists =>
        if exists then Present(path)
        else
          path.parent match
            case Present(parent) => loop(parent)
            case Absent          => Absent
      }
    loop(from)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall