@robot-inventor/agent-skills 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/skills/arktype/SKILL.md +152 -0
- package/skills/simple-engineering/SKILL.md +0 -4
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
My personal collection of Agent Skills.
|
|
4
4
|
|
|
5
|
+
- [ArkType](skills/arktype/SKILL.md): The skill to use ArkType, a validation library for TypeScript.
|
|
5
6
|
- [cleanup-changes](skills/cleanup-changes/SKILL.md): The skill to revert unnecessary changes and leave only essential changes.
|
|
6
7
|
- [identify-search-maintenance](skills/identify-search-maintenance): The skill to identify web pages that are performing poorly in search results and require maintenance.
|
|
7
8
|
- [prove-it-diagnostics](skills/prove-it-diagnostics/SKILL.md): The skill to fix bugs and improve performance by proving the root cause through minimal reproduction code or benchmarks, rather than relying on speculation based solely on reading the code.
|
package/package.json
CHANGED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ArkType
|
|
3
|
+
description: This skill explains how to use ArkType, a validation library for TypeScript. Read this skill when writing validation logic using ArkType.
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: Robot-Inventor
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# ArkType
|
|
10
|
+
|
|
11
|
+
This skill explains how to use ArkType, a validation library for TypeScript. Read this skill when writing validation logic using ArkType. ArkType is a library that allows you to validate values using a notation very similar to that of TypeScript type definitions.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
If ArkType is not yet present in the project's dependencies, you can install it with `npm install arktype`. If the project uses a package manager other than npm, use that instead.
|
|
16
|
+
|
|
17
|
+
## Basic usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { type } from "arktype";
|
|
21
|
+
|
|
22
|
+
const User = type({
|
|
23
|
+
name: "string",
|
|
24
|
+
platform: "'android' | 'ios'",
|
|
25
|
+
email: "string.email",
|
|
26
|
+
score: "number.integer <= 100",
|
|
27
|
+
"versions?": "(number | string)[]",
|
|
28
|
+
details: {
|
|
29
|
+
// nested definitions don't need to be wrapped
|
|
30
|
+
"['devices' | 'apps']": "string[]"
|
|
31
|
+
},
|
|
32
|
+
"areWeCoolYet": "boolean = true"
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// extract the type if needed
|
|
36
|
+
type User = typeof User.infer;
|
|
37
|
+
|
|
38
|
+
const out = User(value);
|
|
39
|
+
|
|
40
|
+
if (out instanceof type.errors) {
|
|
41
|
+
console.error(out.summary);
|
|
42
|
+
} else {
|
|
43
|
+
console.log(`Hello, ${out.name}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// throws an error if the value is invalid.
|
|
47
|
+
const user = User.assert(value);
|
|
48
|
+
|
|
49
|
+
// `.allows()` is a type guard and does not apply morphs or transformations
|
|
50
|
+
if (User.allows(value)) {
|
|
51
|
+
console.log("value is correct");
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Note: Object types allow and preserve undeclared properties by default. Use `"+": "reject"` to reject them or `"+": "delete"` to strip them.
|
|
56
|
+
|
|
57
|
+
## Optional properties
|
|
58
|
+
|
|
59
|
+
Optional properties does not implicitly allow `undefined` as a value.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const User = type({
|
|
63
|
+
// `name` may be absent
|
|
64
|
+
"name?": "string",
|
|
65
|
+
// `value` is required, but may be undefined
|
|
66
|
+
value: "string | undefined",
|
|
67
|
+
// `label` may be absent or explicitly undefined
|
|
68
|
+
"label?": "string | undefined"
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Constraints
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
// you can add non-standard constraints with `.narrow()`
|
|
76
|
+
const Odd = type("number").narrow((n, ctx) =>
|
|
77
|
+
n % 2 === 0 ? ctx.mustBe("odd") : true
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Builtin keywords
|
|
82
|
+
|
|
83
|
+
In ArkType, for example, you can represent a URL-formatted string with `type("string.url")`, and you can morph it into a URL object while performing validation using `type("string.url.parse")`.
|
|
84
|
+
|
|
85
|
+
For all built-in primitives and keywords, refer to the documentation: https://arktype.io/docs/keywords
|
|
86
|
+
|
|
87
|
+
## Regex
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const User = type({
|
|
91
|
+
birthday: "x/^(?<month>\\d{2})-(?<day>\\d{2})-(?<year>\\d{4})$/"
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
const data = User.assert({ birthday: "05-21-1993" })
|
|
95
|
+
|
|
96
|
+
// fully type-safe
|
|
97
|
+
data.birthday.groups.month // "05"
|
|
98
|
+
data.birthday.groups.day // "21"
|
|
99
|
+
data.birthday.groups.year // "1993"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
If you don't need the full features of ArkType and only want to use type-safe regular expressions, you can use ArkRegex.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { regex } from "arkregex";
|
|
106
|
+
|
|
107
|
+
// RegExp-compatible
|
|
108
|
+
const semver = regex("^(\\d+)\\.(\\d+)\\.(\\d+)$");
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Morphs & JSON
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const morphed = type("string").pipe((s) => s.trim());
|
|
115
|
+
|
|
116
|
+
const parseJson = type("string.json.parse").to({
|
|
117
|
+
version: "string.semver"
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const out = parseJson('{ "version": "2.0.0" }');
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Recursive Types
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { scope } from "arktype"
|
|
127
|
+
|
|
128
|
+
const userScope = scope({
|
|
129
|
+
User: {
|
|
130
|
+
id: "string",
|
|
131
|
+
friends: "User[]"
|
|
132
|
+
},
|
|
133
|
+
UsersById: {
|
|
134
|
+
"[string]": "User | undefined"
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const userModule = userScope.export();
|
|
139
|
+
const out = userModule.User(value);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Creating validators and types from variables
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
// `as const` is required
|
|
146
|
+
const allowedValues = ["foo", "bar", "baz"] as const;
|
|
147
|
+
|
|
148
|
+
const AllowedValue = type.enumerated(...allowedValues);
|
|
149
|
+
|
|
150
|
+
// "foo" | "bar" | "baz"
|
|
151
|
+
type AllowedValue = typeof AllowedValue.infer;
|
|
152
|
+
```
|
|
@@ -37,7 +37,3 @@ Refactoring should not be done only at special times; if there are poorly design
|
|
|
37
37
|
## DRY principle and modifiability
|
|
38
38
|
|
|
39
39
|
Keep the DRY principle and modifiability in mind. Avoid defining the same thing repeatedly; instead, aim for code that is easy to modify, where changing a single location automatically updates all related processes. For instance, regarding i18n, the ideal approach is to manage available languages and their labels in one place, such that adding or removing a language requires only updating that single location and adding or removing the corresponding translation file.
|
|
40
|
-
|
|
41
|
-
## Establish a shared understanding
|
|
42
|
-
|
|
43
|
-
If `request_user_input` tool is available, actively use it when asking the user questions, especially while running the grilling session. Do not use it for a single yes/no question; instead, use it when asking multiple questions at once or when presenting multiple options. The tool description specifies limiting the number of questions to between one and three, but this is not a functional constraint. If you have more than four questions, enter all of them in `request_user_input`, without limiting yourself to three or fewer.
|