Skip to content

Latest commit

 

History

History
89 lines (77 loc) · 3.81 KB

File metadata and controls

89 lines (77 loc) · 3.81 KB

Example — what finished output looks like

These are real excerpts from a tutorial series generated with this skill for the RosClaw project (a TypeScript plugin that controls ROS2 robots via chat). They show the two genres in their finished form. Source repo: https://github.com/PlaiPin/rosclaw (the series lives under learn/code/).


A) Flow main-line excerpt (Phase 1)

A few hops from the "journey of one command" doc. Note the file · function · line tags, the plain-language + analogy, and the forward links to deep-dives.

Station 4: the tool runs — tools/ros2-publish.ts

After the safety check passes, the ros2_publish tool's execute runs. Its job is surprisingly small — read params, get the transport, send.

📍 src/tools/ros2-publish.ts · execute() · lines 24–37

async execute(_toolCallId, params) {
  const topic = params["topic"] as string;        // pull the three params
  const message = params["message"] as Record<string, unknown>;
  const transport = getTransport();                // grab the shared connection
  transport.publish({ topic, type, msg: message }); // publish!
}
  • The tool is a thin layer: it doesn't care whether the transport underneath is WebSocket or WebRTC — it just hands the request to transport. That's the payoff of the layered design (Station 6).
  • 🔍 Deep-dive: doc 15 · ros2-publish.ts

Station quick-reference (excerpt)

# File Function Lines One line Deep-dive
4 tools/ros2-publish.ts execute() 24–37 read params → transport.publish 15
5 service.ts getTransport() 18–23 return the one shared connection 12
6 transport/rosbridge/adapter.ts publish() 55–58 hand off to TopicPublisher 10

B) Line-by-line excerpt (Phase 2)

The opening of a per-file deep-dive — locator block, then a chunk with a syntax mini-lesson the first time import appears.

Line-by-line ⑮: tools/ros2-publish.ts

Source file: src/tools/ros2-publish.ts

File 15 in the order — the first real tool. The previous doc covered the generic tool skeleton; here we fill it in with the simplest tool ("publish a message to a topic"). It's the entry point for "send a command to the robot."

Lines 1–3: imports

import { Type } from "@sinclair/typebox";
import type { OpenClawPluginApi } from "../plugin-api.js";
import { getTransport } from "../service.js";
  • import { Type } from "@sinclair/typebox"; — a value import of TypeBox's Type, an object with methods (Type.Object, Type.String, …) used to describe parameter shapes.

「Syntax mini-lesson」: import { X } from "Y" This pulls the named thing X out of module Y so this file can use it. Curly braces mean a named import (the module deliberately exposes X). Without braces it'd be a default import. We'll meet import type { … } next — same idea, but the type keyword says "only for type-checking; erased at runtime."

Chapter recap

  • This file registers one AI tool, ros2_publish, that forwards a message to the transport layer.

Syntax checklist (new / reinforced)

  • import { X } from "Y" — named import (first taught here)
  • import type { X } — type-only import (recall doc 01)

The full RosClaw series is 33 docs (one flow main-line + 32 per-file deep-dives) plus a 5-chapter intro, all in Chinese for "a beginner's beginner." This skill captures that exact workflow so you can reproduce it for any codebase.