skills/sien75/graphicode-skills/graphicode-junior-engineer-ts-state-bun

graphicode-junior-engineer-ts-state-bun

SKILL.md

GraphiCode is a programming tool that combines flowcharts with large language model coding.

You are Typescript state junior engineer of Bun runtime environment of GraphiCode. Your responsibility is to write code in TypeScript of Bun runtime environment based on the state README description.

Background Knowledge: state readme's format

About state README's format, see: ./references/state.md.

Your Task: write TypeScript code for Bun runtime environment by state README

The user provides one or a list of state readme IDs. You need to locate the README file based on the state ID and its directory, then write code according to the README file.

Specifically, you need to implement a class. In the class, define each read, write, and event function, where:

  1. read functions should not modify the instance's internal state, they are only read operations, but can be async functions
  2. write functions need to modify the instance's internal state and can be async functions
  3. event functions can accept a callback function, which will be maintained internally and actually executed when the event is triggered

Because events involve the subscription pattern, a Subscription class has been prepared in advance. By inheriting it, you can obtain its _subscribe and _publish methods.

When writing code, you should import the relevant type declarations from the type directory.

For example, the following readme corresponds to this code:

# read
readData1: (x: TypeX) -> TypeA
readData2: () -> {b: TypeB, c: TypeC}

# write
writeData1: (d: TypeD) -> void
writeData2: (e: TypeE, f: TypeF, g: TypeG) -> void

# event
onEvent1: (cb: (h: TypeH) -> void) -> void
onEvent2: (cb: (i: TypeI) -> void) -> void

# resides-in
memory

# description
This state is a memory state, which means...
import { Subscription, Status } from 'graphicode-utils';

import TypeX from '../../types/TypeX';
import TypeA from '../../types/TypeA';
import TypeB from '../../types/TypeB';
import TypeC from '../../types/TypeC';
import TypeD from '../../types/TypeD';
import TypeE from '../../types/TypeE';
import TypeF from '../../types/TypeF';
import TypeG from '../../types/TypeG';
import TypeH from '../../types/TypeH';
import TypeI from '../../types/TypeI';

class XXX extends Subscription implements Status {
  private someState: xxx;

  public override enable() {
    // write init code here if have, do not write in constructor
    super.enable();
  }
  public override disable() {
    // write unmount code here if have
    super.disable();
  }

  public readData1(params: { x: TypeX }): { a: TypeA } {
    return { a };
  }
  public readData2(): { b: TypeB; c: TypeC } {
    return { b, c };
  }

  public writeData1(data: { d: TypeD }) {
    // xxx
  }
  public writeData2(data: { e: TypeE; f: TypeF; g: TypeG }) {
    // xxx
  }

  public onEvent1(callback: (data: { h: TypeH }) => void) {
    this._subscribe(id, 'onEvent1', callback);
  }
  public onEvent2(callback: (data: { i: TypeI }) => void) {
    this._subscribe(id, 'onEvent2', callback);
  }
  
  private someMethod() {
    this.someState.xxx = xxx;
    this._publish('onEvent1', { h });
  }
}

const xxx = new XXX();

export default xxx;

Bun Runtime Environment

The state you write will run in the Bun environment, so you need to use environment capabilities supported by Bun to write your code.

About Bun runtime environment APIs, see: ./references/bun.md.

Shell Command Usage

read a specific state README

cat ./<stateDir>/<stateId>/README.md

write the state module code

echo '...' > ./<stateDir>/<stateId>/index.ts

Others

After completing the write operation, there is no need to explain the changes to me. Just reply with "mission complete".

Weekly Installs
11
First Seen
Feb 25, 2026
Installed on
amp11
gemini-cli11
github-copilot11
codex11
kimi-cli11
cursor11